[FFmpeg-devel] Stack variables alignment check in libavcodec/dsputil.c

Michael Niedermayer michaelni
Tue Jul 31 01:12:32 CEST 2007


On Mon, Jul 30, 2007 at 03:42:54PM -0700, Roman Shaposhnick wrote:
> On Tue, 2007-07-31 at 01:18 +0300, Uoti Urpala wrote:
> > On Mon, 2007-07-30 at 14:47 -0700, Roman Shaposhnick wrote:
> > > P.S. I wonder if a clever macro allocating +(align-1) bytes on the
> > > stack and then coercing a pointer wouldn't be as efficient as 
> > > the current implementation relying on half-broken gcc...
> > 
> > It would be less efficient. Normally GCC at least maintains stack
> > alignment by making all stack frames a multiple of 16 bytes, so no
> > additional code per aligned variable is needed (if you can rely on other
> > programs in the call chain not breaking the alignment). Doing additional
> > manual alignment like you suggested would add overhead.
>   Not to start yet another gcc flame war, but I'm sick and tired
> of hearing what gcc is *supposed* to do and how much better it
> is supposed to be if it *works*. Well, it doesn't work, I'm sorry.
> Hence the efficiency becomes moot.
>  Michael, would you consider a patch with a reasonable performance
> deviation to be acceptable replacement for trying to make gcc align
> stack variables?

if this bothers you so much, you can just write wraper functions which
realign the stack, something like

    if(realign_stack(&ret, avcodec_encode_video, bytes used for args on stack))
        return ret


realign_stack() would check if the stack is aligned and if so just return 0
if not it would align the stack, copy the function arguments to the aligned
stack, call the function ptr, set ret to what the function returned and
return 1

yes you have to write realign_stack() in asm

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070731/8fac8ebd/attachment.pgp>

More information about the ffmpeg-devel mailing list