]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blobdiff - libc/arch-x86/include/machine/endian.h
Switch x86 and x86-64 to __builtin_bswap*.
[android-sdk/platform-bionic.git] / libc / arch-x86 / include / machine / endian.h
index e7ad25784efa95983fd5f0d4451105eb2f49053b..5feebd8d24c7d721196059b8481e34acfca01a0b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: endian.h,v 1.14 2005/12/13 00:35:23 millert Exp $     */
+/*     $OpenBSD: endian.h,v 1.17 2011/03/12 04:03:04 guenther Exp $    */
 
 /*-
  * Copyright (c) 1997 Niklas Hallqvist.  All rights reserved.
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _I386_ENDIAN_H_
-#define _I386_ENDIAN_H_
+#ifndef _MACHINE_ENDIAN_H_
+#define _MACHINE_ENDIAN_H_
 
-#ifdef __GNUC__
-
-#if defined(_KERNEL) && !defined(I386_CPU)
-#define        __swap32md(x) ({                                                \
-       uint32_t __swap32md_x = (x);                                    \
-                                                                       \
-       __asm ("bswap %1" : "+r" (__swap32md_x));                       \
-       __swap32md_x;                                                   \
-})
-#else
-#define        __swap32md(x) ({                                                \
-       uint32_t __swap32md_x = (x);                                    \
-                                                                       \
-       __asm ("rorw $8, %w1; rorl $16, %1; rorw $8, %w1" :             \
-           "+r" (__swap32md_x));                                       \
-       __swap32md_x;                                                   \
-})
-#endif /* _KERNEL && !I386_CPU */
-
-#define        __swap64md(x) ({                                                \
-       uint64_t __swap64md_x = (x);                                    \
-                                                                       \
-       (uint64_t)__swap32md(__swap64md_x >> 32) |                      \
-           (uint64_t)__swap32md(__swap64md_x & 0xffffffff) << 32;      \
-})
-#define        __swap16md(x) ({                                                \
-       uint16_t __swap16md_x = (x);                                    \
-                                                                       \
-       __asm ("rorw $8, %w1" : "+r" (__swap16md_x));                   \
-       __swap16md_x;                                                   \
-})
+/* Use GCC builtins */
+#define __swap16md(x) __builtin_bswap16(x)
+#define __swap32md(x) __builtin_bswap32(x)
+#define __swap64md(x) __builtin_bswap64(x)
 
 /* Tell sys/endian.h we have MD variants of the swap macros.  */
 #define MD_SWAP
 
-#endif /* __GNUC__ */
-
 #define _BYTE_ORDER _LITTLE_ENDIAN
 #include <sys/types.h>
 #include <sys/endian.h>
 
-#endif /* _I386_ENDIAN_H_ */
+#endif /* _MACHINE_ENDIAN_H_ */