svn commit: r232266 - in head/sys: amd64/include i386/include
tijl at freebsd.org
Tue Feb 28 21:32:36 UTC 2012
On Tuesday 28 February 2012 21:55:57 Dimitry Andric wrote:
> On 2012-02-28 20:39, Tijl Coosemans wrote:
>> Author: tijl
>> Date: Tue Feb 28 19:39:54 2012
>> New Revision: 232266
>> URL: http://svn.freebsd.org/changeset/base/232266
>> Copy amd64 endian.h to x86 and merge with i386 endian.h. Replace
>> amd64/i386/pc98 endian.h with stubs.
>> In __bswap64_const(x) the conflict between 0xffUL and 0xffULL has been
>> resolved by reimplementing the macro in terms of __bswap32(x). As a side
>> effect __bswap64_var(x) is now implemented using two bswap instructions on
>> i386 and should be much faster. __bswap32_const(x) has been reimplemented
>> in terms of __bswap16(x) for consistency.
>> +#define __bswap32_const(_x) \
>> + (((__uint32_t)__bswap16(_x) << 16) | __bswap16((_x) >> 16))
>> +#define __bswap32(_x) \
>> + (__builtin_constant_p(_x) ? \
>> + __bswap32_const((__uint32_t)(_x)) : __bswap32_var(_x))
>> +#define __bswap64_const(_x) \
>> + (((__uint64_t)__bswap32(_x) << 32) | __bswap32((_x) >> 32))
> Hmm, shouldn't __bswap32_const() be implemented in terms of
> __bswap16_const(), and similarly for __bswap64_const(), which should be
> implemented in terms of __bswap32_const()?
> The whole reason for the difficult dance with __builtin_constant_p is to
> allow for compile-time resolving of bswap'd constants. Invoking the
> regular __bswap() macros doesn't gain you anything here.
__bswap64_const is also used in __bswap64_var, so its argument isn't
always a compile time constant and then __bswap32 becomes __bswap32_var.
If it is a constant __bswap32 becomes __bswap32_const (even at -O0).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 228 bytes
Desc: This is a digitally signed message part.
Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20120228/0d6d386f/attachment.pgp
More information about the svn-src-head