summaryrefslogtreecommitdiff
path: root/sys/arch/amd64
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2018-10-02 21:30:45 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2018-10-02 21:30:45 +0000
commit491aedcdbec0f0ca718296e56874a00b7f08bb40 (patch)
treec571df7eaaa6bcb1519b95a608dea192e638fdfe /sys/arch/amd64
parente432202b1919bb33356ba6ef483f333607327326 (diff)
Unify the MD byteswapping code as much as possible across architectures.
Use inline functions instead of GNU C statement expressions, and make them available to userland. With clues from guenther@. ok guenther@ kettenis@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r--sys/arch/amd64/include/endian.h44
1 files changed, 22 insertions, 22 deletions
diff --git a/sys/arch/amd64/include/endian.h b/sys/arch/amd64/include/endian.h
index 14c451e46f5..3b077cd9295 100644
--- a/sys/arch/amd64/include/endian.h
+++ b/sys/arch/amd64/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:08 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.7 2018/10/02 21:30:44 naddy Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -27,34 +27,34 @@
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
-#ifdef __GNUC__
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/_types.h>
+#endif
-#define __swap32md(x) __statement({ \
- __uint32_t __swap32md_x = (x); \
- \
- __asm ("bswap %0" : "+r" (__swap32md_x)); \
- __swap32md_x; \
-})
+static __inline __uint16_t
+__swap16md(__uint16_t _x)
+{
+ __asm ("rorw $8, %w0" : "+r" (_x));
+ return (_x);
+}
-#define __swap64md(x) __statement({ \
- __uint64_t __swap64md_x = (x); \
- \
- __asm ("bswapq %0" : "+r" (__swap64md_x)); \
- __swap64md_x; \
-})
+static __inline __uint32_t
+__swap32md(__uint32_t _x)
+{
+ __asm ("bswap %0" : "+r" (_x));
+ return (_x);
+}
-#define __swap16md(x) __statement({ \
- __uint16_t __swap16md_x = (x); \
- \
- __asm ("rorw $8, %w0" : "+r" (__swap16md_x)); \
- __swap16md_x; \
-})
+static __inline __uint64_t
+__swap64md(__uint64_t _x)
+{
+ __asm ("bswapq %0" : "+r" (_x));
+ return (_x);
+}
/* Tell sys/endian.h we have MD variants of the swap macros. */
#define __HAVE_MD_SWAP
-#endif /* __GNUC__ */
-
#define _BYTE_ORDER _LITTLE_ENDIAN
#ifndef __FROM_SYS__ENDIAN