[FFmpeg-devel] [PATCH rfc] use bswap builtins where available

Alexander Strange astrange
Sat Aug 15 00:09:26 CEST 2009

gcc 4.2+ provides __builtin_bswap32/64. Since it's usually a good idea  
to use these instead of asm (they can be optimized more, don't clobber  
flags, their size is known, etc) I tried using them for bswap_32/64.

The resulting binary is ~32kb smaller on x86-32; it actually has less  
bswap instructions (3658 vs 4072) but this is likely due to more  

H.264 CABAC:
old: avg 4.274 min 4.274 max 4.274 std.dev. 0.0
new: avg 4.25 min 4.25 max 4.25 std.dev. 0.0

old: avg 0.599 min 0.599 max 0.599 std.dev. 0.0
new: avg 0.598 min 0.598 max 0.598 std.dev. 0.0

Unfortunately the code for __builtin_bswap64+gcc 4.2+x86-32 is  
terrible, although fine in later versions, so it's under  
HAVE_FAST_64BIT for now.
And there's no __builtin_bswap16; (x>>8)|(x<<8) generates rotates on  
its own even with gcc2.95, but I ended up with a slightly larger  
binary when I tried it here.

Any different numbers for other architectures?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: builtin_bswap.diff
Type: text/x-diff
Size: 669 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090814/b69db024/attachment.diff>
-------------- next part --------------

More information about the ffmpeg-devel mailing list