aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2012-04-10 10:22:42 -0700
committerRoland McGrath <roland@hack.frob.com>2012-04-10 10:22:42 -0700
commitd715c9144bdf32211cd512530d2240dc28648435 (patch)
treedd2199a2dce09cef45a30fb31651b46585487909
parent8f9a2faee0619ed5fad7b9c54b64f866b0264bde (diff)
parent9904dc47c88d9592ec66e5990754369bfde84c02 (diff)
downloadglibc-d715c9144bdf32211cd512530d2240dc28648435.tar
glibc-d715c9144bdf32211cd512530d2240dc28648435.tar.gz
glibc-d715c9144bdf32211cd512530d2240dc28648435.tar.bz2
glibc-d715c9144bdf32211cd512530d2240dc28648435.zip
Merge commit '9904dc47c88d9592ec66e599075436'
-rw-r--r--ChangeLog6
-rw-r--r--bits/byteswap.h24
2 files changed, 27 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index a85a1c06ef..cede7b8ee3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -120,6 +120,12 @@
2012-04-06 H.J. Lu <hongjiu.lu@intel.com>
+ * bits/byteswap.h: Include <features.h>.
+ (__bswap_32): Use __builtin_bswap32 for GCC >= 4.2.
+ (__bswap_64): Use __builtin_bswap64 for GCC >= 4.2.
+
+2012-04-06 H.J. Lu <hongjiu.lu@intel.com>
+
* bits/byteswap.h (__bswap_16): Removed.
Include <bits/byteswap-16.h> to get __bswap_16.
* sysdeps/i386/bits/byteswap.h: Likewise.
diff --git a/bits/byteswap.h b/bits/byteswap.h
index 6e3ed3ffae..d818293a4c 100644
--- a/bits/byteswap.h
+++ b/bits/byteswap.h
@@ -23,6 +23,8 @@
#ifndef _BITS_BYTESWAP_H
#define _BITS_BYTESWAP_H 1
+#include <features.h>
+
/* Swap bytes in 16 bit value. */
#define __bswap_constant_16(x) \
((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
@@ -36,9 +38,17 @@
(((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
#ifdef __GNUC__
-# define __bswap_32(x) \
+# if __GNUC_PREREQ (4, 2)
+static __inline unsigned int
+__bswap_32 (unsigned int __bsx)
+{
+ return __builtin_bswap32 (__bsx);
+}
+# else
+# define __bswap_32(x) \
(__extension__ \
({ register unsigned int __bsx = (x); __bswap_constant_32 (__bsx); }))
+# endif
#else
static __inline unsigned int
__bswap_32 (unsigned int __bsx)
@@ -47,8 +57,8 @@ __bswap_32 (unsigned int __bsx)
}
#endif
-#if defined __GNUC__ && __GNUC__ >= 2
/* Swap bytes in 64 bit value. */
+#if __GNUC_PREREQ (2, 0)
# define __bswap_constant_64(x) \
(__extension__ ((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
@@ -59,7 +69,14 @@ __bswap_32 (unsigned int __bsx)
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56)))
-# define __bswap_64(x) \
+# if __GNUC_PREREQ (4, 2)
+static __inline unsigned long long int
+__bswap_64 (unsigned long long int __bsx)
+{
+ return __builtin_bswap64 (__bsx);
+}
+# else
+# define __bswap_64(x) \
(__extension__ \
({ union { __extension__ unsigned long long int __ll; \
unsigned int __l[2]; } __w, __r; \
@@ -72,6 +89,7 @@ __bswap_32 (unsigned int __bsx)
__r.__l[1] = __bswap_32 (__w.__l[0]); \
} \
__r.__ll; }))
+# endif
#elif __GLIBC_HAVE_LONG_LONG
# define __bswap_constant_64(x) \
((((x) & 0xff00000000000000ull) >> 56) \