summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-04-08 19:06:47 +0000
committered <ed@FreeBSD.org>2009-04-08 19:06:47 +0000
commit9141c649b8dd9a1be83d66da54cb8f2f34f7a9be (patch)
tree1595a4719281107660c01afb844de3b02c3d9bba
parentc781ca9c84dbc014af3281962e1b5ac3f8970ef3 (diff)
downloadFreeBSD-src-9141c649b8dd9a1be83d66da54cb8f2f34f7a9be.zip
FreeBSD-src-9141c649b8dd9a1be83d66da54cb8f2f34f7a9be.tar.gz
Implement __bswap16() without using inline assembly.
Most compilers nowadays (including GCC) are smart enough to know what's going on and generate more efficient code anyway. Submitted by: Christoph Mallon <christoph.mallon@gmx.de>
-rw-r--r--sys/amd64/include/endian.h23
-rw-r--r--sys/i386/include/endian.h23
2 files changed, 2 insertions, 44 deletions
diff --git a/sys/amd64/include/endian.h b/sys/amd64/include/endian.h
index 24e59e4..60e4b97 100644
--- a/sys/amd64/include/endian.h
+++ b/sys/amd64/include/endian.h
@@ -135,26 +135,6 @@ __extension__ ({ register __uint64_t __X = (x); \
#endif /* __OPTIMIZE__ */
-#define __byte_swap_word_var(x) \
-__extension__ ({ register __uint16_t __X = (x); \
- __asm ("xchgb %h0, %b0" : "+Q" (__X)); \
- __X; })
-
-#ifdef __OPTIMIZE__
-
-#define __byte_swap_word_const(x) \
- ((((x) & 0xff00) >> 8) | \
- (((x) & 0x00ff) << 8))
-
-#define __byte_swap_word(x) (__builtin_constant_p(x) ? \
- __byte_swap_word_const(x) : __byte_swap_word_var(x))
-
-#else /* __OPTIMIZE__ */
-
-#define __byte_swap_word(x) __byte_swap_word_var(x)
-
-#endif /* __OPTIMIZE__ */
-
static __inline __uint64_t
__bswap64(__uint64_t _x)
{
@@ -172,8 +152,7 @@ __bswap32(__uint32_t _x)
static __inline __uint16_t
__bswap16(__uint16_t _x)
{
-
- return (__byte_swap_word(_x));
+ return (_x << 8 | _x >> 8);
}
#define __htonl(x) __bswap32(x)
diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h
index 59fa4a5..98fceb6 100644
--- a/sys/i386/include/endian.h
+++ b/sys/i386/include/endian.h
@@ -109,26 +109,6 @@ __extension__ ({ register __uint32_t __X = (x); \
#endif /* __OPTIMIZE__ */
-#define __byte_swap_word_var(x) \
-__extension__ ({ register __uint16_t __X = (x); \
- __asm ("xchgb %h0, %b0" : "+q" (__X)); \
- __X; })
-
-#ifdef __OPTIMIZE__
-
-#define __byte_swap_word_const(x) \
- ((((x) & 0xff00) >> 8) | \
- (((x) & 0x00ff) << 8))
-
-#define __byte_swap_word(x) (__builtin_constant_p(x) ? \
- __byte_swap_word_const(x) : __byte_swap_word_var(x))
-
-#else /* __OPTIMIZE__ */
-
-#define __byte_swap_word(x) __byte_swap_word_var(x)
-
-#endif /* __OPTIMIZE__ */
-
static __inline __uint64_t
__bswap64(__uint64_t _x)
{
@@ -149,8 +129,7 @@ __bswap32(__uint32_t _x)
static __inline __uint16_t
__bswap16(__uint16_t _x)
{
-
- return (__byte_swap_word(_x));
+ return (_x << 8 | _x >> 8);
}
#define __htonl(x) __bswap32(x)
OpenPOWER on IntegriCloud