[syslinux:lwip] core: factor out byteswap.h from netinet/in.h

syslinux-bot for Eric W. Biederman ebiederm at xmission.com
Fri Apr 22 20:05:53 PDT 2011


Commit-ID:  a8e782f8cefdf0311902ded3e67ab48cec892163
Gitweb:     http://syslinux.zytor.com/commit/a8e782f8cefdf0311902ded3e67ab48cec892163
Author:     Eric W. Biederman <ebiederm at xmission.com>
AuthorDate: Sat, 9 Apr 2011 23:00:14 -0700
Committer:  Eric W. Biederman <ebiederm at xmission.com>
CommitDate: Tue, 12 Apr 2011 14:40:54 -0700

core: factor out byteswap.h from netinet/in.h

This is a logical generalization, follows the precedent set
by glibc and it will allow us to avoid problems with
lwips definition of the network byte swap functions.

Signed-off-by: Eric W. Biederman <ebiederm at xmission.com>


---
 com32/include/byteswap.h   |   50 ++++++++++++++++++++++++++++++++++++++++++++
 com32/include/netinet/in.h |   48 +++++++-----------------------------------
 2 files changed, 58 insertions(+), 40 deletions(-)

diff --git a/com32/include/byteswap.h b/com32/include/byteswap.h
new file mode 100644
index 0000000..11870e9
--- /dev/null
+++ b/com32/include/byteswap.h
@@ -0,0 +1,50 @@
+#ifndef _BYTESWAP_H
+#define _BYTESWAP_H
+
+/* COM32 will be running on an i386 platform */
+
+#include <stdint.h>
+#include <klibc/compiler.h>
+
+#define __bswap_16_macro(v) ((uint16_t)		  			\
+			     (((uint16_t)(v) << 8) | 			\
+			      ((uint16_t)(v) >> 8)))
+
+static inline __constfunc uint16_t __bswap_16(uint16_t v)
+{
+    return __bswap_16_macro(v);
+}
+
+#define bswap_16(x) (__builtin_constant_p(x) ?				\
+			__bswap_16_macro(x) : __bswap_16(x))
+
+#define __bswap_32_macro(v) ((uint32_t)					\
+			     ((((uint32_t)(v) & 0x000000ff) << 24) |	\
+			      (((uint32_t)(v) & 0x0000ff00) << 8)  |	\
+			     (((uint32_t)(v) & 0x00ff0000) >> 8)  |	\
+			      (((uint32_t)(v) & 0xff000000) >> 24)))
+
+static inline __constfunc uint32_t __bswap_32(uint32_t v)
+{
+    asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
+	: "+q" (v));
+    return v;
+}
+
+#define bswap_32(x) (__builtin_constant_p(x) ?				\
+			 __bswap_32_macro(x) : __bswap_32(x))
+
+
+#define __bswap_64_macro(v) ((uint64_t)					\
+    (((uint64_t)__bswap_32_macro((uint32_t)(v)) << 32) |		\
+     (__bswap_32__macro((uint32_t)((uint64_t)(v) >> 32)))))
+
+static inline __constfunc uint64_t __bswap_64(uint64_t v)
+{
+    return ((uint64_t)__bswap_32(v) << 32) | __bswap_32(v >> 32);
+}
+
+#define bswap_64(x) (__builtin_constant_p(x) ? 				\
+			__bswap_64_macro(x) :  __bswap_64(x))
+
+#endif /* byteswap.h */
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index ccf0475..70cdc93 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -5,46 +5,14 @@
 
 #include <stdint.h>
 #include <klibc/compiler.h>
-
-#define __htons_macro(v) ((uint16_t)		  			\
-			  (((uint16_t)(v) << 8) | 			\
-			   ((uint16_t)(v) >> 8)))
-
-static inline __constfunc uint16_t __htons(uint16_t v)
-{
-    return __htons_macro(v);
-}
-
-#define htons(x) (__builtin_constant_p(x) ? __htons_macro(x) :  __htons(x))
-#define ntohs(x) htons(x)
-
-#define __htonl_macro(v) ((uint32_t)					\
-                          ((((uint32_t)(v) & 0x000000ff) << 24) |	\
-			   (((uint32_t)(v) & 0x0000ff00) << 8)  |	\
-			  (((uint32_t)(v) & 0x00ff0000) >> 8)  |	\
-			   (((uint32_t)(v) & 0xff000000) >> 24)))
-
-static inline __constfunc uint32_t __htonl(uint32_t v)
-{
-    asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
-	: "+q" (v));
-    return v;
-}
-
-#define htonl(x) (__builtin_constant_p(x) ? __htonl_macro(x) : __htonl(x))
-#define ntohl(x) htonl(x)
-
-#define __htonq_macro(v) ((uint64_t)					\
-    (((uint64_t)__htonl_macro((uint32_t)(v)) << 32) |			\
-     (__htonl_macro((uint32_t)((uint64_t)(v) >> 32)))))
-
-static inline __constfunc uint64_t __htonq(uint64_t v)
-{
-    return ((uint64_t)__htonl(v) << 32) | __htonl(v >> 32);
-}
-
-#define htonq(x) (__builtin_constant_p(x) ? __htonq_macro(x) :  __htonq(x))
-#define ntohq(x) htonq(x)
+#include <byteswap.h>
+
+#define htons(x) bswap_16(x)
+#define ntohs(x) bswap_16(x)
+#define htonl(x) bswap_32(x)
+#define ntohl(x) bswap_32(x)
+#define htonq(x) bswap_64(x)
+#define ntohq(x) bswap_64(x)
 
 typedef uint32_t in_addr_t;
 typedef uint16_t in_port_t;



More information about the Syslinux-commits mailing list