[FFmpeg-devel] [PATCH] Simplify some declarations of aligned arrays

Måns Rullgård mans
Sat Aug 29 01:37:04 CEST 2009

Michael Niedermayer <michaelni at gmx.at> writes:

> On Fri, Aug 28, 2009 at 09:32:26AM +0100, Mans Rullgard wrote:
>> If DECLARE_ALIGNED_16 works on uint64_t it will work smaller types too.
> but if it doesnt work on either, uint64_t will possibly at least provide
> 8 byte alignment

Not necessarily.  On many machines, 4-byte alignment is sufficient for

> and has a 50% chance to provide 16bytes, this may have a performance
> advantage but either way, i dont think this messy code has been
> added without it being needed for some gcc version (just my
> oppinion, i didnt investigat the history of this at all)

All compilers I'm aware of support alignment of locals in one the
following three ways:

1. You always get what you ask for.  These are rare.

2. You get what you ask for up to the required stack alignment.  This
is 16 bytes on PPC-ELF, 8 bytes on ARM.  GCC often maintains a 16-byte
aligned stack even when not required by ABI, in which case local
variables can be reliably aligned to 16 bytes.

3. No alignment specifiers whatsoever are supported.

Arguments for cleaning this up as in my patch:

- The mess helps only with compilers in the third category, and then
only if we're lucky.

- A lot of code elsewhere in FFmpeg does it the clean way, and that
seems to cause no more problems.

- I have unfinished patches to make aligned stack variables reliable
with any compiler.

M?ns Rullg?rd
mans at mansr.com

More information about the ffmpeg-devel mailing list