From owner-svn-src-all@FreeBSD.ORG Fri Mar 9 11:48:56 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE0BD106564A; Fri, 9 Mar 2012 11:48:56 +0000 (UTC) (envelope-from tijl@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A86B08FC18; Fri, 9 Mar 2012 11:48:56 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q29Bmuoi005153; Fri, 9 Mar 2012 11:48:56 GMT (envelope-from tijl@svn.freebsd.org) Received: (from tijl@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q29BmuIp005151; Fri, 9 Mar 2012 11:48:56 GMT (envelope-from tijl@svn.freebsd.org) Message-Id: <201203091148.q29BmuIp005151@svn.freebsd.org> From: Tijl Coosemans Date: Fri, 9 Mar 2012 11:48:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232721 - head/sys/x86/include X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Mar 2012 11:48:56 -0000 Author: tijl Date: Fri Mar 9 11:48:56 2012 New Revision: 232721 URL: http://svn.freebsd.org/changeset/base/232721 Log: Clean up x86 endian.h: - Remove extern "C". There are no functions with external linkage here. [1] - Rename bswapNN_const(x) to bswapNN_gen(x) to indicate that these macros are generic implementations that can take non-constant arguments. [1] - Split up __GNUCLIKE_ASM && __GNUCLIKE_BUILTIN_CONSTANT_P and deal with each separately. - Replace _LP64 with __amd64__ because asm instructions are machine dependent, not ABI dependent. Submitted by: bde [1] Reviewed by: bde Modified: head/sys/x86/include/endian.h Modified: head/sys/x86/include/endian.h ============================================================================== --- head/sys/x86/include/endian.h Fri Mar 9 09:32:20 2012 (r232720) +++ head/sys/x86/include/endian.h Fri Mar 9 11:48:56 2012 (r232721) @@ -36,10 +36,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - /* * Define the order of 32-bit words in 64-bit words. */ @@ -67,51 +63,63 @@ extern "C" { #define BYTE_ORDER _BYTE_ORDER #endif -#if defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE_BUILTIN_CONSTANT_P) - -#define __bswap16_const(_x) (__uint16_t)((_x) << 8 | (_x) >> 8) - -#define __bswap16(_x) \ - (__builtin_constant_p(_x) ? \ - __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x)) - -#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)) +#define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8) +#define __bswap32_gen(x) \ + (((__uint32_t)__bswap16(x) << 16) | __bswap16((x) >> 16)) +#define __bswap64_gen(x) \ + (((__uint64_t)__bswap32(x) << 32) | __bswap32((x) >> 32)) + +#ifdef __GNUCLIKE_BUILTIN_CONSTANT_P +#define __bswap16(x) \ + (__builtin_constant_p(x) ? \ + __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)) +#define __bswap32(x) \ + (__builtin_constant_p(x) ? \ + __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x)) +#define __bswap64(x) \ + (__builtin_constant_p(x) ? \ + __bswap64_gen((__uint64_t)(x)) : __bswap64_var(x)) +#else +/* XXX these are broken for use in static initializers. */ +#define __bswap16(x) __bswap16_var(x) +#define __bswap32(x) __bswap32_var(x) +#define __bswap64(x) __bswap64_var(x) +#endif -#define __bswap64(_x) \ - (__builtin_constant_p(_x) ? \ - __bswap64_const((__uint64_t)(_x)) : __bswap64_var(_x)) +/* These are defined as functions to avoid multiple evaluation of x. */ static __inline __uint16_t __bswap16_var(__uint16_t _x) { - return (__bswap16_const(_x)); + return (__bswap16_gen(_x)); } static __inline __uint32_t __bswap32_var(__uint32_t _x) { - __asm ("bswap %0" : "+r" (_x)); +#ifdef __GNUCLIKE_ASM + __asm("bswap %0" : "+r" (_x)); return (_x); +#else + return (__bswap32_gen(_x)); +#endif } static __inline __uint64_t __bswap64_var(__uint64_t _x) { -#ifdef _LP64 - __asm ("bswap %0" : "+r" (_x)); + +#if defined(__amd64__) && defined(__GNUCLIKE_ASM) + __asm("bswap %0" : "+r" (_x)); return (_x); #else - return (__bswap64_const(_x)); + /* + * It is important for the optimizations that the following is not + * really generic, but expands to 2 __bswap32_var()'s. + */ + return (__bswap64_gen(_x)); #endif } @@ -120,19 +128,4 @@ __bswap64_var(__uint64_t _x) #define __ntohl(x) __bswap32(x) #define __ntohs(x) __bswap16(x) -#else /* !(__GNUCLIKE_ASM && __GNUCLIKE_BUILTIN_CONSTANT_P) */ - -/* - * No optimizations are available for this compiler. Fall back to - * non-optimized functions by defining the constant usually used to prevent - * redefinition. - */ -#define _BYTEORDER_FUNC_DEFINED - -#endif /* __GNUCLIKE_ASM && __GNUCLIKE_BUILTIN_CONSTANT_P */ - -#ifdef __cplusplus -} -#endif - #endif /* !_MACHINE_ENDIAN_H_ */