From 2d7d8c05e7404fbebf1f0fe24c13bc5bb58d2338 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 21 Mar 2011 09:40:01 +0000 Subject: - Merge changes to the base system to support OFED. These include a wider arg2 for sysctl, updates to vlan code, IFT_INFINIBAND, and other miscellaneous small features. --- sys/i386/include/endian.h | 67 +++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 29 deletions(-) (limited to 'sys/i386') diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h index 6522ec4..c09dfb1 100644 --- a/sys/i386/include/endian.h +++ b/sys/i386/include/endian.h @@ -69,50 +69,59 @@ extern "C" { #if defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE_BUILTIN_CONSTANT_P) -#define __byte_swap_int_var(x) \ -__extension__ ({ register __uint32_t __X = (x); \ - __asm ("bswap %0" : "+r" (__X)); \ - __X; }) - -#ifdef __OPTIMIZE__ - -#define __byte_swap_int_const(x) \ - ((((x) & 0xff000000) >> 24) | \ - (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | \ - (((x) & 0x000000ff) << 24)) -#define __byte_swap_int(x) (__builtin_constant_p(x) ? \ - __byte_swap_int_const(x) : __byte_swap_int_var(x)) - -#else /* __OPTIMIZE__ */ - -#define __byte_swap_int(x) __byte_swap_int_var(x) - -#endif /* __OPTIMIZE__ */ +#define __bswap64_const(_x) \ + (((_x) >> 56) | \ + (((_x) >> 40) & (0xffULL << 8)) | \ + (((_x) >> 24) & (0xffULL << 16)) | \ + (((_x) >> 8) & (0xffULL << 24)) | \ + (((_x) << 8) & (0xffULL << 32)) | \ + (((_x) << 24) & (0xffULL << 40)) | \ + (((_x) << 40) & (0xffULL << 48)) | \ + ((_x) << 56)) + +#define __bswap32_const(_x) \ + (((_x) >> 24) | \ + (((_x) & (0xff << 16)) >> 8) | \ + (((_x) & (0xff << 8)) << 8) | \ + ((_x) << 24)) + +#define __bswap16_const(_x) (__uint16_t)((_x) << 8 | (_x) >> 8) static __inline __uint64_t -__bswap64(__uint64_t _x) +__bswap64_var(__uint64_t __x) { - return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | - ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | - ((_x << 24) & ((__uint64_t)0xff << 40)) | - ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); + return __bswap64_const(__x); } + static __inline __uint32_t -__bswap32(__uint32_t _x) +__bswap32_var(__uint32_t _x) { - return (__byte_swap_int(_x)); + __asm ("bswap %0" : "+r" (_x)); + return (_x); } static __inline __uint16_t -__bswap16(__uint16_t _x) +__bswap16_var(__uint16_t _x) { - return (_x << 8 | _x >> 8); + + return (__bswap16_const(_x)); } +#define __bswap64(_x) \ + (__builtin_constant_p(_x) ? \ + __bswap64_const((__uint64_t)(_x)) : __bswap64_var(_x)) + +#define __bswap32(_x) \ + (__builtin_constant_p(_x) ? \ + __bswap32_const((__uint32_t)(_x)) : __bswap32_var(_x)) + +#define __bswap16(_x) \ + (__builtin_constant_p(_x) ? \ + __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x)) + #define __htonl(x) __bswap32(x) #define __htons(x) __bswap16(x) #define __ntohl(x) __bswap32(x) -- cgit v1.1