summaryrefslogtreecommitdiffstats
path: root/sys/i386/include/endian.h
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2000-10-15 00:45:19 +0000
committerbrian <brian@FreeBSD.org>2000-10-15 00:45:19 +0000
commit79f21507692b81b7e0999b841e69d9bf0bb32d90 (patch)
treea8995533f8dfffc3b17947e13fa9ceac53450133 /sys/i386/include/endian.h
parent5ae4a9caff315b6411d5ab22b4dd78cdc04e4413 (diff)
downloadFreeBSD-src-79f21507692b81b7e0999b841e69d9bf0bb32d90.zip
FreeBSD-src-79f21507692b81b7e0999b841e69d9bf0bb32d90.tar.gz
Redefine __word_swap_long, __byte_swap_long and __byte_swap_word
as inline functions, renaming them to __uint16_swap_uint32, __uint8_swap_uint32 and __uint8_swap_uint16. Doing it properly suggested by: msmith Reviewed by: msmith
Diffstat (limited to 'sys/i386/include/endian.h')
-rw-r--r--sys/i386/include/endian.h65
1 files changed, 31 insertions, 34 deletions
diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h
index 9e79a09..e505f50 100644
--- a/sys/i386/include/endian.h
+++ b/sys/i386/include/endian.h
@@ -66,52 +66,49 @@ unsigned long ntohl __P((unsigned long));
unsigned short ntohs __P((unsigned short));
__END_DECLS
-#define __word_swap_long(x) \
-__extension__ ({ register u_long __X = (x); \
- __asm ("rorl $16, %1" \
- : "=r" (__X) \
- : "0" (__X)); \
- __X; })
+static __inline uint32_t
+__uint16_swap_uint32(uint32_t x)
+{
+ __asm ("rorl $16, %1" : "=r" (x) : "0" (x));
-#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
+ return x;
+}
-#define __byte_swap_long(x) \
-__extension__ ({ register u_long __X = (x); \
- __asm ("bswap %0" \
- : "=r" (__X) \
- : "0" (__X)); \
- __X; })
+static __inline uint32_t
+__uint8_swap_uint32(uint32_t x)
+{
+#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
+ __asm ("bswap %0" : "=r" (x) : "0" (x));
#else
-
-#define __byte_swap_long(x) \
-__extension__ ({ register u_long __X = (x); \
- __asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
- : "=q" (__X) \
- : "0" (__X)); \
- __X; })
+ __asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1"
+ : "=q" (x) : "0" (x));
#endif
+ return x;
+}
-#define __byte_swap_word(x) \
-__extension__ ({ register u_short __X = (x); \
- __asm ("xchgb %h1, %b1" \
- : "=q" (__X) \
- : "0" (__X)); \
- __X; })
+static __inline uint16_t
+__uint8_swap_uint16(uint16_t x)
+{
+ __asm ("xchgb %h1, %b1" : "=q" (x) : "0" (x));
+
+ return x;
+}
/*
* Macros for network/external number representation conversion.
*/
#ifdef __GNUC__
-#define ntohl __byte_swap_long
-#define ntohs __byte_swap_word
-#define htonl __byte_swap_long
-#define htons __byte_swap_word
+#define ntohl __uint8_swap_uint32
+#define ntohs __uint8_swap_uint16
+#define htonl __uint8_swap_uint32
+#define htons __uint8_swap_uint16
#endif
-#define NTOHL(x) ((x) = ntohl((u_long)(x)))
-#define NTOHS(x) ((x) = ntohs((u_short)(x)))
-#define HTONL(x) ((x) = htonl((u_long)(x)))
-#define HTONS(x) ((x) = htons((u_short)(x)))
+#define NTOHL(x) ((x) = ntohl(x))
+#define NTOHS(x) ((x) = ntohs(x))
+#define HTONL(x) ((x) = htonl(x))
+#define HTONS(x) ((x) = htons(x))
+
#endif /* ! _POSIX_SOURCE */
OpenPOWER on IntegriCloud