Bug 2803 - uClibc should use __builtin_bswap{32,64} on at least some archs
Summary: uClibc should use __builtin_bswap{32,64} on at least some archs
Status: NEW
Alias: None
Product: uClibc
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-13 20:18 UTC by Peter Collingbourne
Modified: 2012-04-19 03:46 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
[PATCH] byteswap: use compiler builtins if available (1.56 KB, patch)
2010-11-13 20:18 UTC, Peter Collingbourne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Collingbourne 2010-11-13 20:18:33 UTC
Created attachment 2665 [details]
[PATCH] byteswap: use compiler builtins if available

GCC has provided the builtins __builtin_bswap32 and __builtin_bswap64 since 4.2.  If we have a sufficient GCC version, we should use the builtins instead of our own implementation.  This allows the compiler to apply optimisations (e.g. bswap(bswap(x)) = x).

Attached is a patch which should act as a starting point.

One issue to be decided: on which architectures should we use the builtin?  The patch uses the builtin on all architectures, but looking through the gcc source code it appears that the set of optimised bswap implementations overlaps but differs between gcc and uClibc.  gcc covers all the major architectures though, so this may not be such a crucial point.
Comment 1 Bernhard Reutner-Fischer 2012-04-17 21:29:34 UTC
IIRC you should get a bswap pass in -fexpensive-optimizations
Comment 2 Mike Frysinger 2012-04-19 03:46:29 UTC
Comment on attachment 2665 [details]
[PATCH] byteswap: use compiler builtins if available

i don't think it should be blindly overriding the arch code.  using the builtins should be done only if the arch hasn't selected it.

look at glibc's bits/byteswap.h.