[Mplayer-cvslog] CVS: main/postproc rgb2rgb_template.c,1.54,1.55

Michael Niedermayer michaelni at gmx.at
Mon Jul 1 10:57:52 CEST 2002


Hi

On Monday 01 July 2002 10:41, Nick Kurshev wrote:
[...]
> > > > --- rgb2rgb_template.c	29 Jun 2002 21:26:15 -0000	1.54
> > > > +++ rgb2rgb_template.c	29 Jun 2002 21:43:28 -0000	1.55
> > > > @@ -256,13 +256,13 @@
> > > >    register const uint8_t* s=src;
> > > >    register uint8_t* d=dst;
> > > >    register const uint8_t *end;
> > > > -  uint8_t *mm_end;
> > > > +  const uint8_t *mm_end;
> > > >    end = s + src_size;
> > > >  #ifdef HAVE_MMX
> > > >    __asm __volatile(PREFETCH"	%0"::"m"(*s));
> > > >    __asm __volatile("movq	%0, %%mm7"::"m"(mask15rg));
> > > >    __asm __volatile("movq	%0, %%mm6"::"m"(mask15b));
> > > > -  mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
> > > > +  mm_end = end - 15;
> > >
> > > IMHO it would be better to use something like this:
> > > mm_end = end & ~15
> >
> > thats identical to what it was before and it overwrites upto 15 bytes at
> > the end of the array, just make cs_test && ./cs_test mmx if u dont
> > believe me
> >
> > > else your code allow integer computing anyway (even if size of data is
> > > 256-byte aligned). This code should prevent only accessing of last part
> > > of data which can't be fitted into MMX registers and can cause segfault
> > > due array's index out of range [snip]
> >
> > if src_size is a multiple of 16 than only mmx will be used ...
>
> Well:
> 256 & ~15 = 256
> 256 - 15 = 241
> thus in your case we always have 15 bytes for integer computations.
no

uint8_t* s=src;     = 0
end = s + src_size; = 256
mm_end = end - 15;  = 241
while(s < mm_end)   0   < 241
while(s < mm_end)   16  < 241
...
while(s < mm_end)   240  < 241 !!!!
while(s < mm_end)   256  < 241
-------------------------------------
and now an example which overwrites the end with mm_end&= ~15
uint8_t* s=src;     = 14
end = s + src_size; = 256 (src_size=242)
mm_end = end& ~15 ; = 256
while(s < mm_end)   14   < 256
while(s < mm_end)   30   < 256
...
while(s < mm_end)   254  < 256 -> overwrites 14 bytes
while(s < mm_end)   270  < 256

[...]

Michael



More information about the MPlayer-cvslog mailing list