This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 9/10] Tilera (and Linux asm-generic) support for glibc


(New change since v1 of patch.)

2011-11-09  Chris Metcalf  <cmetcalf@tilera.com>

  * bits/byteswap.h (__bswap*): Use __builtin_bswap for gcc 4.3 and
  above.  Improves code generation for gcc 4.3 and 4.4 compilers
  without bswap pattern detection.

diff --git a/bits/byteswap.h b/bits/byteswap.h
index 45cb947..89036bc 100644
--- a/bits/byteswap.h
+++ b/bits/byteswap.h
@@ -24,42 +24,53 @@
 #ifndef _BITS_BYTESWAP_H
 #define _BITS_BYTESWAP_H 1
 
+#include <features.h>
+
+#if __GNUC_PREREQ (4,3)
+# define __bswap_16(x) ((unsigned short int) (__builtin_bswap32 (x) >> 16))
+# define __bswap_32(x) ((unsigned int) __builtin_bswap32 (x))
+# define __bswap_64(x) ((unsigned long long int) __builtin_bswap64 (x))
+# define __bswap_constant_16(x) __bswap_16 (x)
+# define __bswap_constant_32(x) __bswap_32 (x)
+# define __bswap_constant_64(x) __bswap_64 (x)
+#else
+
 /* Swap bytes in 16 bit value.  */
-#define __bswap_constant_16(x) \
+# define __bswap_constant_16(x) \
      ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
 
-#ifdef __GNUC__
-# define __bswap_16(x) \
+# ifdef __GNUC__
+#  define __bswap_16(x) \
     (__extension__							      \
      ({ unsigned short int __bsx = (x); __bswap_constant_16 (__bsx); }))
-#else
+# else
 static __inline unsigned short int
 __bswap_16 (unsigned short int __bsx)
 {
   return __bswap_constant_16 (__bsx);
 }
-#endif
+# endif
 
 /* Swap bytes in 32 bit value.  */
-#define __bswap_constant_32(x) \
+# define __bswap_constant_32(x) \
      ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >>  8) |	      \
       (((x) & 0x0000ff00u) <<  8) | (((x) & 0x000000ffu) << 24))
 
-#ifdef __GNUC__
-# define __bswap_32(x) \
+# ifdef __GNUC__
+#  define __bswap_32(x) \
   (__extension__							      \
    ({ register unsigned int __bsx = (x); __bswap_constant_32 (__bsx); }))
-#else
+# else
 static __inline unsigned int
 __bswap_32 (unsigned int __bsx)
 {
   return __bswap_constant_32 (__bsx);
 }
-#endif
+# endif
 
-#if defined __GNUC__ && __GNUC__ >= 2
+# if defined __GNUC__ && __GNUC__ >= 2
 /* Swap bytes in 64 bit value.  */
-# define __bswap_constant_64(x) \
+#  define __bswap_constant_64(x) \
      ((((x) & 0xff00000000000000ull) >> 56)				      \
       | (((x) & 0x00ff000000000000ull) >> 40)				      \
       | (((x) & 0x0000ff0000000000ull) >> 24)				      \
@@ -69,7 +80,7 @@ __bswap_32 (unsigned int __bsx)
       | (((x) & 0x000000000000ff00ull) << 40)				      \
       | (((x) & 0x00000000000000ffull) << 56))
 
-# define __bswap_64(x) \
+#  define __bswap_64(x) \
      (__extension__							      \
       ({ union { __extension__ unsigned long long int __ll;		      \
 		 unsigned int __l[2]; } __w, __r;			      \
@@ -82,6 +93,8 @@ __bswap_32 (unsigned int __bsx)
 	     __r.__l[1] = __bswap_32 (__w.__l[0]);			      \
 	   }								      \
 	 __r.__ll; }))
+# endif
+
 #endif
 
 #endif /* _BITS_BYTESWAP_H */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]