svn commit: r216122 - head/sys/powerpc/include
Nathan Whitehorn
nwhitehorn at FreeBSD.org
Thu Dec 2 15:10:27 UTC 2010
Author: nwhitehorn
Date: Thu Dec 2 15:10:27 2010
New Revision: 216122
URL: http://svn.freebsd.org/changeset/base/216122
Log:
Define bswap macros for constants to allow the compiler to pre-compute
byte-swapped versions of compile-time constants. This allows use of
bswap() and htole*() in initializers, which is required to cross-build
btxld.
Obtained from: sparc64
Modified:
head/sys/powerpc/include/endian.h
Modified: head/sys/powerpc/include/endian.h
==============================================================================
--- head/sys/powerpc/include/endian.h Thu Dec 2 13:40:21 2010 (r216121)
+++ head/sys/powerpc/include/endian.h Thu Dec 2 15:10:27 2010 (r216122)
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*
* @(#)endian.h 8.1 (Berkeley) 6/10/93
- * $NetBSD: endian.h,v 1.7 1999/08/21 05:53:51 simonb Exp $
* $FreeBSD$
*/
@@ -79,17 +78,36 @@
#define BYTE_ORDER _BYTE_ORDER
#endif
-#ifdef __CC_SUPPORTS___INLINE
+#if defined(__GNUCLIKE_BUILTIN_CONSTANT_P)
+#define __is_constant(x) __builtin_constant_p(x)
+#else
+#define __is_constant(x) 0
+#endif
+
+#define __bswap16_const(x) ((((__uint16_t)(x) >> 8) & 0xff) | \
+ (((__uint16_t)(x) << 8) & 0xff00))
+#define __bswap32_const(x) ((((__uint32_t)(x) >> 24) & 0xff) | \
+ (((__uint32_t)(x) >> 8) & 0xff00) | \
+ (((__uint32_t)(x)<< 8) & 0xff0000) | \
+ (((__uint32_t)(x) << 24) & 0xff000000))
+#define __bswap64_const(x) ((((__uint64_t)(x) >> 56) & 0xff) | \
+ (((__uint64_t)(x) >> 40) & 0xff00) | \
+ (((__uint64_t)(x) >> 24) & 0xff0000) | \
+ (((__uint64_t)(x) >> 8) & 0xff000000) | \
+ (((__uint64_t)(x) << 8) & ((__uint64_t)0xff << 32)) | \
+ (((__uint64_t)(x) << 24) & ((__uint64_t)0xff << 40)) | \
+ (((__uint64_t)(x) << 40) & ((__uint64_t)0xff << 48)) | \
+ (((__uint64_t)(x) << 56) & ((__uint64_t)0xff << 56)))
static __inline __uint16_t
-__bswap16(__uint16_t _x)
+__bswap16_var(__uint16_t _x)
{
return ((_x >> 8) | ((_x << 8) & 0xff00));
}
static __inline __uint32_t
-__bswap32(__uint32_t _x)
+__bswap32_var(__uint32_t _x)
{
return ((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) |
@@ -97,7 +115,7 @@ __bswap32(__uint32_t _x)
}
static __inline __uint64_t
-__bswap64(__uint64_t _x)
+__bswap64_var(__uint64_t _x)
{
return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) |
@@ -106,20 +124,16 @@ __bswap64(__uint64_t _x)
((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)));
}
+#define __bswap16(x) (__is_constant(x) ? __bswap16_const(x) : \
+ __bswap16_var(x))
+#define __bswap32(x) (__is_constant(x) ? __bswap32_const(x) : \
+ __bswap32_var(x))
+#define __bswap64(x) (__is_constant(x) ? __bswap64_const(x) : \
+ __bswap64_var(x))
+
#define __htonl(x) ((__uint32_t)(x))
#define __htons(x) ((__uint16_t)(x))
#define __ntohl(x) ((__uint32_t)(x))
#define __ntohs(x) ((__uint16_t)(x))
-#else /* !__CC_SUPPORTS___INLINE */
-
-/*
- * 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 /* __CC_SUPPORTS___INLINE */
-
#endif /* !_MACHINE_ENDIAN_H_ */
More information about the svn-src-all
mailing list