[Ffmpeg-devel] x86/SSE fix to ensure 16-byte alignment on local variables

Rich Felker dalias
Sat Nov 11 04:10:50 CET 2006


On Fri, Nov 10, 2006 at 10:30:20AM +0100, Guillaume Poirier wrote:
> Hi,
> 
> Christophe Mutricy wrote:
> >>Attached the patch against today's svn from the files Thorsten sent.
> > 
> > 
> > Arghh. I manage to send the worng one.
> > Here's the good one.
> 
> I think I can safely say that this patch is rejected in its corrent
> form. It leads to unreadable code (at least, to my eyes) to support a
> corner case.
> 
> I'm not even sure if a patch that would do smth like:
> 
> #ifndef BROKEN_STACK
>     DECLARE_ALIGNED_16(DCTELEM, d1[64]);
> #elif
>     // TJ: force alignment to 16.
>     //DCTELEM is short
>     //DECLARE_ALIGNED_16(DCTELEM, d1[64]);
>     DCTELEM d1_[64+8];
>     DCTELEM* d1 = (DCTELEM*)((((unsigned long)d1_)+0xf)&~0xf);
>     // end force
> #end
> 
> would be accepted. The maintainer would have to tell.

With gcc, BROKEN_STACK is _always_ the case. gcc simply does not align
the stack. However the code above is wrong in any case. It should
read:

DCTELEM d1_buf[64+8];
DCTELEM *d1 = d1_buf + (-(unsigned)d1_buf & 15)/sizeof(DCTELEM);

or similar. This is the ONLY reliable way to get aligned data on the
stack since gcc developers refuse to fix their broken crap and make
gcc actually align the stack...

Rich





More information about the ffmpeg-devel mailing list