summaryrefslogtreecommitdiffstats
path: root/sys/i386/include/endian.h
diff options
context:
space:
mode:
authordyson <dyson@FreeBSD.org>1996-11-29 16:22:22 +0000
committerdyson <dyson@FreeBSD.org>1996-11-29 16:22:22 +0000
commit3b5f0bc30376be71cc3ed070066c6fc06b7b1456 (patch)
treee11f5dd906f1b537a86dbe0dcbf07d14a4c06729 /sys/i386/include/endian.h
parent47e902fb56c7869d1b8aeb3265484fe4305da007 (diff)
downloadFreeBSD-src-3b5f0bc30376be71cc3ed070066c6fc06b7b1456.zip
FreeBSD-src-3b5f0bc30376be71cc3ed070066c6fc06b7b1456.tar.gz
Relax the constraints on the bswap opcode (it works on non-byte
registers.) Also clean up some namespace pollution, and remove gcc-1 support (nothing really works with it anymore anyway.) Submitted by: Bruce Evans <bde@freebsd.org> and me.
Diffstat (limited to 'sys/i386/include/endian.h')
-rw-r--r--sys/i386/include/endian.h40
1 files changed, 16 insertions, 24 deletions
diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h
index 6e31c7d..dfa6268 100644
--- a/sys/i386/include/endian.h
+++ b/sys/i386/include/endian.h
@@ -31,11 +31,11 @@
* SUCH DAMAGE.
*
* from: @(#)endian.h 7.8 (Berkeley) 4/3/91
- * $Id: endian.h,v 1.7 1996/10/21 17:15:05 nate Exp $
+ * $Id: endian.h,v 1.8 1996/11/29 07:04:03 dyson Exp $
*/
#ifndef _MACHINE_ENDIAN_H_
-#define _MACHINE_ENDIAN_H_ 1
+#define _MACHINE_ENDIAN_H_
/*
* Define the order of 32-bit words in 64-bit words.
@@ -58,20 +58,22 @@
#endif
#define __word_swap_long(x) \
-({ register u_long __X = (x); \
+__extension__ ({ register u_long __X = (x); \
__asm ("rorl $16, %1" \
: "=r" (__X) \
: "0" (__X)); \
__X; })
-#if __GNUC__ >= 2
+
#if defined(KERNEL) && !defined(I386_CPU)
+
#define __byte_swap_long(x) \
__extension__ ({ register u_long __X = (x); \
__asm ("bswap %0" \
- : "=q" (__X) \
+ : "=r" (__X) \
: "0" (__X)); \
__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" \
@@ -79,26 +81,13 @@ __extension__ ({ register u_long __X = (x); \
: "0" (__X)); \
__X; })
#endif
+
#define __byte_swap_word(x) \
__extension__ ({ register u_short __X = (x); \
__asm ("xchgb %h1, %b1" \
: "=q" (__X) \
: "0" (__X)); \
__X; })
-#else /* __GNUC__ >= 2 */
-#define __byte_swap_long(x) \
-({ register u_long __X = (x); \
- __asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
- : "=r" (__X) \
- : "0" (__X)); \
- __X; })
-#define __byte_swap_word(x) \
-({ register u_short __X = (x); \
- __asm ("rorw $8, %w1" \
- : "=r" (__X) \
- : "0" (__X)); \
- __X; })
-#endif /* __GNUC__ >= 2 */
/*
* Macros for network/external number representation conversion.
@@ -116,14 +105,17 @@ __extension__ ({ register u_short __X = (x); \
#else
+#ifdef __GNUC__
#define ntohl __byte_swap_long
#define ntohs __byte_swap_word
#define htonl __byte_swap_long
#define htons __byte_swap_word
+#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((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)))
#endif
-#endif /* _MACHINE_ENDIAN_H_ */
+
+#endif /* !_MACHINE_ENDIAN_H_ */
OpenPOWER on IntegriCloud