svn commit: trunk/uClibc/utils

vapier at uclibc.org vapier at uclibc.org
Mon Feb 9 22:51:29 UTC 2009


Author: vapier
Date: 2009-02-09 22:51:27 +0000 (Mon, 09 Feb 2009)
New Revision: 25282

Log:
unify byte order cruft in bswap.h and porting.h and add a bswap_64() replacement

Modified:
   trunk/uClibc/utils/bswap.h
   trunk/uClibc/utils/porting.h


Changeset:
Modified: trunk/uClibc/utils/bswap.h
===================================================================
--- trunk/uClibc/utils/bswap.h	2009-02-09 21:48:48 UTC (rev 25281)
+++ trunk/uClibc/utils/bswap.h	2009-02-09 22:51:27 UTC (rev 25282)
@@ -6,40 +6,6 @@
 #ifndef _BSWAP_H
 #define	_BSWAP_H 1
 
-#if !defined(__BYTE_ORDER) && defined(BYTE_ORDER)
-# define __BYTE_ORDER BYTE_ORDER
-# if !defined(__BIG_ENDIAN) && defined(BIG_ENDIAN)
-#  define __BIG_ENDIAN BIG_ENDIAN
-# endif
-# if !defined(__LITTLE_ENDIAN) && defined(LITTLE_ENDIAN)
-#  define __LITTLE_ENDIAN LITTLE_ENDIAN
-# endif
-#endif
-
-#ifndef __BYTE_ORDER
-# ifdef __linux__
-#  include <endian.h>
-# else
-#  define __LITTLE_ENDIAN 1234	/* least-significant byte first (vax, pc) */
-#  define __BIG_ENDIAN    4321	/* most-significant byte first (IBM, net) */
-#  define __PDP_ENDIAN    3412	/* LSB first in word, MSW first in long (pdp) */
-
-#  if defined(sun386) || defined(i386) || defined(__LITTLE_ENDIAN__)
-#   define __BYTE_ORDER __LITTLE_ENDIAN
-#  endif
-
-#  if defined(sparc) || defined(__BIG_ENDIAN__)
-#   define __BYTE_ORDER __BIG_ENDIAN
-#  endif
-
-# endif /* __linux__ */
-#endif /* __BYTE_ORDER */
-
-
-#ifndef __BYTE_ORDER
-# error "Undefined __BYTE_ORDER"
-#endif
-
 #ifdef __linux__
 # include <byteswap.h>
 #else
@@ -56,6 +22,24 @@
 	        (((x) & 0x0000ff00) <<  8) | \
 	        (((x) & 0x000000ff) << 24));
 }
+static __inline__ uint64_t bswap_64(uint64_t x)
+{
+#define _uswap_64(x, sfx) \
+	return ((((x) & 0xff00000000000000##sfx) >> 56) | \
+	        (((x) & 0x00ff000000000000##sfx) >> 40) | \
+	        (((x) & 0x0000ff0000000000##sfx) >> 24) | \
+	        (((x) & 0x000000ff00000000##sfx) >>  8) | \
+	        (((x) & 0x00000000ff000000##sfx) <<  8) | \
+	        (((x) & 0x0000000000ff0000##sfx) << 24) | \
+	        (((x) & 0x000000000000ff00##sfx) << 40) | \
+	        (((x) & 0x00000000000000ff##sfx) << 56));
+#if defined(__GNUC__)
+	_uswap_64(x, ull)
+#else
+	_uswap_64(x, )
 #endif
+#undef _uswap_64
+}
+#endif
 
 #endif

Modified: trunk/uClibc/utils/porting.h
===================================================================
--- trunk/uClibc/utils/porting.h	2009-02-09 21:48:48 UTC (rev 25281)
+++ trunk/uClibc/utils/porting.h	2009-02-09 22:51:27 UTC (rev 25282)
@@ -44,13 +44,23 @@
 # define UCLIBC_RUNTIME_PREFIX "/"
 #endif
 
+#undef UCLIBC_ENDIAN_HOST
 #define UCLIBC_ENDIAN_LITTLE 1234
 #define UCLIBC_ENDIAN_BIG    4321
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
-#elif __BYTE_ORDER == __BIG_ENDIAN
-# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
-#else
+#if defined(BYTE_ORDER)
+# if BYTE_ORDER == LITTLE_ENDIAN
+#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
+# elif BYTE_ORDER == BIG_ENDIAN
+#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
+# endif
+#elif defined(__BYTE_ORDER)
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
+# elif __BYTE_ORDER == __BIG_ENDIAN
+#  define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
+# endif
+#endif
+#if !defined(UCLIBC_ENDIAN_HOST)
 # error "Unknown host byte order!"
 #endif
 



More information about the uClibc-cvs mailing list