From owner-svn-src-projects@FreeBSD.ORG Fri Aug 13 03:15:42 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16CA61065694; Fri, 13 Aug 2010 03:15:42 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F01EB8FC0A; Fri, 13 Aug 2010 03:15:41 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7D3Ff18077428; Fri, 13 Aug 2010 03:15:41 GMT (envelope-from jeff@svn.freebsd.org) Received: (from jeff@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7D3Ff5w077426; Fri, 13 Aug 2010 03:15:41 GMT (envelope-from jeff@svn.freebsd.org) Message-Id: <201008130315.o7D3Ff5w077426@svn.freebsd.org> From: Jeff Roberson Date: Fri, 13 Aug 2010 03:15:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211266 - projects/ofed/head/sys/amd64/include X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2010 03:15:42 -0000 Author: jeff Date: Fri Aug 13 03:15:41 2010 New Revision: 211266 URL: http://svn.freebsd.org/changeset/base/211266 Log: - Allow endian related macros to do compile time conversion of constants. Sponsored by: Isilon Systems, iX Systems, and Panasas. Modified: projects/ofed/head/sys/amd64/include/endian.h Modified: projects/ofed/head/sys/amd64/include/endian.h ============================================================================== --- projects/ofed/head/sys/amd64/include/endian.h Fri Aug 13 03:15:02 2010 (r211265) +++ projects/ofed/head/sys/amd64/include/endian.h Fri Aug 13 03:15:41 2010 (r211266) @@ -69,10 +69,16 @@ 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; }) +static inline __uint32_t +__byte_swap_int_var(__uint32_t x) +{ + register __uint32_t _x; + + + _x = x; + __asm ("bswap %0" : "+r" (_x)); + return (_x); +} #ifdef __OPTIMIZE__ @@ -81,60 +87,47 @@ __extension__ ({ register __uint32_t __X (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | \ (((x) & 0x000000ff) << 24)) -#define __byte_swap_int(x) (__builtin_constant_p(x) ? \ +#define __bswap32(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) +#define __bswap32(x) __byte_swap_int_var(x) #endif /* __OPTIMIZE__ */ -#define __byte_swap_long_var(x) \ -__extension__ ({ register __uint64_t __X = (x); \ - __asm ("bswap %0" : "+r" (__X)); \ - __X; }) +static inline __uint64_t +__byte_swap_long_var(__uint64_t x) +{ + register __uint64_t _x; + + _x = x; + __asm ("bswap %0" : "+r" (_x)); + return (_x); +} #ifdef __OPTIMIZE__ #define __byte_swap_long_const(x) \ - (((x >> 56) | \ - ((x >> 40) & 0xff00) | \ - ((x >> 24) & 0xff0000) | \ - ((x >> 8) & 0xff000000) | \ - ((x << 8) & (0xfful << 32)) | \ - ((x << 24) & (0xfful << 40)) | \ - ((x << 40) & (0xfful << 48)) | \ - ((x << 56)))) + ((__uint64_t)(((__uint64_t)x >> 56) | \ + (((__uint64_t)x >> 40) & 0xff00) | \ + (((__uint64_t)x >> 24) & 0xff0000) | \ + (((__uint64_t)x >> 8) & 0xff000000) | \ + (((__uint64_t)x << 8) & (0xfful << 32)) | \ + (((__uint64_t)x << 24) & (0xfful << 40)) | \ + (((__uint64_t)x << 40) & (0xfful << 48)) | \ + (((__uint64_t)x << 56)))) -#define __byte_swap_long(x) (__builtin_constant_p(x) ? \ +#define __bswap64(x) (__builtin_constant_p(x) ? \ __byte_swap_long_const(x) : __byte_swap_long_var(x)) #else /* __OPTIMIZE__ */ -#define __byte_swap_long(x) __byte_swap_long_var(x) +#define __bswap64(x) __byte_swap_long_var(x) #endif /* __OPTIMIZE__ */ -static __inline __uint64_t -__bswap64(__uint64_t _x) -{ - - return (__byte_swap_long(_x)); -} - -static __inline __uint32_t -__bswap32(__uint32_t _x) -{ - - return (__byte_swap_int(_x)); -} - -static __inline __uint16_t -__bswap16(__uint16_t _x) -{ - return (_x << 8 | _x >> 8); -} +#define __bswap16(_x) (__uint16_t)((_x) << 8 | (_x) >> 8) #define __htonl(x) __bswap32(x) #define __htons(x) __bswap16(x)