[FFmpeg-devel] [PATCH] EA TGQ video fixes

Måns Rullgård mans
Thu Apr 16 21:01:39 CEST 2009

Michael Niedermayer <michaelni at gmx.at> writes:

> On Thu, Apr 16, 2009 at 07:03:17PM +0100, M?ns Rullg?rd wrote:
>> Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:
>> > On Thu, Apr 16, 2009 at 07:46:38PM +0200, Vitor Sessak wrote:
>> >> Reimar D?ffinger wrote:
>> >> >> > -    DCTELEM block[6][64];
>> >> >> > +    DECLARE_ALIGNED_8(DCTELEM, block[6][64]);
>> >> >> >  
>> >> >> >      mode = bytestream_get_byte((const uint8_t**)bs);
>> >> >> >      if (mode>buf_end-*bs) {
>> >> > 
>> >> > Moving it into the context instead should be more reliable.
>> >> 
>> >> Why?
>> >
>> > Because you are declaring a stack variable as aligned which only works
>> > up to the value that the stack is already aligned usually which in the
>> > past on e.g. Windows usually meant it wouldn't be aligned.
>> > The situation should be better now but I doubt it is flawless and I also
>> > don't really see a point in keeping the variable on the stack anyway.
>> Very few platforms are capable of aligning stack variables to 16 bytes
>> or more.  It's pretty much only gcc on x86, and then only if main()
> may i protest, its not a limitation of platforms but compilers.

In this respect, the compiler can be considered part of the platform.
I could have made this more clear.

> you certainly can align the stack as much as you like by using asm()

That's highly non-portable.

> also theres no relation to main() beyond the compilers just being utter
> crap.

As long as those are the compilers we have to used, we must live with
their limitations.

> the following will fix up alignment in a nearly porable way given that
> the function uses the right amount of stack space itself
> align_stack(func_ptr, int align){
>     some variables
>     if(stack is not aligned by align)
>         return align_stack(func_ptr, align);
>     else
>         return func_ptr()
> }

Doing that in every function that needs an aligned stack is not good.

> a variable size array could also be used to achive this like
> align_stack2(func_ptr, int eat){
>     volatile char x[eat];
>     return func_ptr();
> }

The compiler is free to optimise that array out entirely, and *you*
would call it crap if it did not.

> for(i=0; i<123; i++)
>     if(align_stack2(check_align, i))
>         break;
> eat= i;
> anyway, iam of course aware this stuff above has issues like when a compiler
> tries to preserve (non existing) alignment
> but that just from a users POV, a compiler itself could easily fix things
> up using such an approuch

But they do not.  Now please stop pretending otherwise.

M?ns Rullg?rd
mans at mansr.com

More information about the ffmpeg-devel mailing list