summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornwhitehorn <nwhitehorn@FreeBSD.org>2010-12-02 15:10:27 +0000
committernwhitehorn <nwhitehorn@FreeBSD.org>2010-12-02 15:10:27 +0000
commit058617f3a0a0de5441176e9d76314c696c5e76f6 (patch)
treec23c0abaa5e526dd2c30d6eaf0ebbdd0e6ff7c96
parent37a5968ad36aef19e345edf83c467c43a25c207c (diff)
downloadFreeBSD-src-058617f3a0a0de5441176e9d76314c696c5e76f6.zip
FreeBSD-src-058617f3a0a0de5441176e9d76314c696c5e76f6.tar.gz
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
-rw-r--r--sys/powerpc/include/endian.h46
1 files changed, 30 insertions, 16 deletions
diff --git a/sys/powerpc/include/endian.h b/sys/powerpc/include/endian.h
index 176c710..15dd7db 100644
--- a/sys/powerpc/include/endian.h
+++ b/sys/powerpc/include/endian.h
@@ -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_ */
OpenPOWER on IntegriCloud