[FFmpeg-devel] [PATCH/RFC] intreadwrite.h rewrite

Michael Niedermayer michaelni
Mon Apr 6 19:41:11 CEST 2009

On Sun, Apr 05, 2009 at 11:42:24PM +0100, M?ns Rullg?rd wrote:
> I would like to propose a rework of intreadwrite.h.  This new version
> supports per-arch implementations of the various macros allowing us to
> take advantage of special instructions or other properties the
> compiler does not know about.
> ARMv6 and later support unaligned loads and stores for single
> word/halfword but not double/multiple.  GCC is ignorant of this and
> will always use bytewise accesses for unaligned data.  Casting to an
> int32_t pointer is dangerous since a load/store double or multiple
> instruction might be used (this happens with some code in FFmpeg).
> Implementing the AV_[RW]* macros with inline asm using only supported
> instructions gives fast and safe unaligned accesses.  This gives an
> overall speedup of up to 10% in some cases.
> PPC is normally big endian but has special little endian load/store
> instructions.  Using these avoids a separate byteswap.  This makes the
> vorbis decoder about 5% faster.  Not much else uses little-endian
> read/write extensively.  GCC generates horrible PPC code for the
> default AV_[RW]B64 (which uses a packed struct), so I have overridden
> it with a plain pointer cast.
> For other architectures the definitions of these macros should remain
> unchanged.
> I'm attaching the complete files instead of a diff since the diff
> since this is largely a rewrite.  Sorry for attaching three files with
> same name; I'm sure you can work out which is which.


> /*
>  * GCC fails miserably on the packed struct version which is used by
>  * default, so we override it here.
>  */
> #define AV_RB64 AV_RB64
> static inline uint64_t AV_RB64(const void *p)
> {
>     return *(const uint64_t *)p;
> }
> #define AV_WB64 AV_WB64
> static inline void AV_WB64(void *p, uint64_t v)
> {
>     *(uint64_t *)p = v;
> }

why are these inline functions instead of macros?

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No great genius has ever existed without some touch of madness. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090406/ffcbb4ab/attachment.pgp>

More information about the ffmpeg-devel mailing list