summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/amd64/include/endian.h44
-rw-r--r--sys/arch/arm/include/endian.h45
-rw-r--r--sys/arch/i386/include/endian.h49
-rw-r--r--sys/arch/sh/include/endian.h47
4 files changed, 93 insertions, 92 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
diff --git a/sys/arch/arm/include/endian.h b/sys/arch/arm/include/endian.h
index 410a05682f6..739ee04af3c 100644
--- a/sys/arch/arm/include/endian.h
+++ b/sys/arch/arm/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.10 2017/02/06 03:52:35 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.11 2018/10/02 21:30:44 naddy Exp $ */
/*
* Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
@@ -19,49 +19,44 @@
#ifndef _ARM_ENDIAN_H_
#define _ARM_ENDIAN_H_
-#ifdef _KERNEL
-#ifdef __GNUC__
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/_types.h>
+#endif
-static inline __uint16_t
-___swap16md(__uint16_t x)
+static __inline __uint16_t
+__swap16md(__uint16_t _x)
{
- __uint16_t rv;
+ __uint16_t _rv;
- __asm ("rev16 %0, %1" : "=r" (rv) : "r" (x));
+ __asm ("rev16 %0, %1" : "=r" (_rv) : "r" (_x));
- return (rv);
+ return (_rv);
}
-#define __swap16md(x) ___swap16md(x)
-static inline __uint32_t
-___swap32md(__uint32_t x)
+static __inline __uint32_t
+__swap32md(__uint32_t _x)
{
- __uint32_t rv;
+ __uint32_t _rv;
- __asm ("rev %0, %1" : "=r" (rv) : "r" (x));
+ __asm ("rev %0, %1" : "=r" (_rv) : "r" (_x));
- return (rv);
+ return (_rv);
}
-#define __swap32md(x) ___swap32md(x)
-static inline __uint64_t
-___swap64md(__uint64_t x)
+static __inline __uint64_t
+__swap64md(__uint64_t _x)
{
- __uint64_t rv;
+ __uint64_t _rv;
- rv = (__uint64_t)__swap32md(x >> 32) |
- (__uint64_t)__swap32md(x) << 32;
+ _rv = (__uint64_t)__swap32md(_x >> 32) |
+ (__uint64_t)__swap32md(_x) << 32;
- return (rv);
+ return (_rv);
}
-#define __swap64md(x) ___swap64md(x)
/* Tell sys/endian.h we have MD variants of the swap macros. */
#define __HAVE_MD_SWAP
-#endif /* __GNUC__ */
-#endif /* _KERNEL */
-
#define _BYTE_ORDER _LITTLE_ENDIAN
#define __STRICT_ALIGNMENT
diff --git a/sys/arch/i386/include/endian.h b/sys/arch/i386/include/endian.h
index 1f58500c862..b107da44df9 100644
--- a/sys/arch/i386/include/endian.h
+++ b/sys/arch/i386/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.18 2014/07/12 16:25:08 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.19 2018/10/02 21:30:44 naddy Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
@@ -27,33 +27,34 @@
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
-#ifdef __GNUC__
-
-#define __swap32md(x) __statement({ \
- __uint32_t __swap32md_x = (x); \
- \
- __asm ("bswap %0" : "+r" (__swap32md_x)); \
- __swap32md_x; \
-})
-
-#define __swap64md(x) __statement({ \
- __uint64_t __swap64md_x = (x); \
- \
- (__uint64_t)__swap32md(__swap64md_x >> 32) | \
- (__uint64_t)__swap32md(__swap64md_x & 0xffffffff) << 32; \
-})
-#define __swap16md(x) __statement({ \
- __uint16_t __swap16md_x = (x); \
- \
- __asm ("rorw $8, %w0" : "+r" (__swap16md_x)); \
- __swap16md_x; \
-})
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/_types.h>
+#endif
+
+static __inline __uint16_t
+__swap16md(__uint16_t _x)
+{
+ __asm ("rorw $8, %w0" : "+r" (_x));
+ return (_x);
+}
+
+static __inline __uint32_t
+__swap32md(__uint32_t _x)
+{
+ __asm ("bswap %0" : "+r" (_x));
+ return (_x);
+}
+
+static __inline __uint64_t
+__swap64md(__uint64_t _x)
+{
+ return ((__uint64_t)__swap32md(_x >> 32) |
+ (__uint64_t)__swap32md(_x & 0xffffffff) << 32);
+}
/* 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
diff --git a/sys/arch/sh/include/endian.h b/sys/arch/sh/include/endian.h
index daba001f12b..ef0050be1ad 100644
--- a/sys/arch/sh/include/endian.h
+++ b/sys/arch/sh/include/endian.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: endian.h,v 1.5 2014/07/12 16:25:09 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2018/10/02 21:30:44 naddy Exp $ */
/* $NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $ */
/* Written by Manuel Bouyer. Public domain */
@@ -6,30 +6,35 @@
#ifndef _SH_ENDIAN_H_
#define _SH_ENDIAN_H_
-#ifdef __GNUC__
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/_types.h>
+#endif
-#define __swap64md __swap64gen
+static __inline __uint16_t
+__swap16md(__uint16_t _x)
+{
+ __uint16_t _rv;
-#define __swap16md(x) __statement({ \
- uint16_t rval; \
- \
- __asm volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x)); \
- \
- rval; \
-})
-
-#define __swap32md(x) __statement({ \
- uint32_t rval; \
- \
- __asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0" \
- : "=r"(rval) : "r"(x)); \
- \
- rval; \
-})
+ __asm volatile ("swap.b %1,%0" : "=r"(_rv) : "r"(_x));
-#define __HAVE_MD_SWAP
+ return (_rv);
+}
+
+static __inline __uint32_t
+__swap32md(__uint32_t _x)
+{
+ __uint32_t _rv;
-#endif /* __GNUC_ */
+ __asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"
+ : "=r"(_rv) : "r"(_x));
+
+ return (_rv);
+}
+
+#define __swap64md __swap64gen
+
+/* Tell sys/endian.h we have MD variants of the swap macros. */
+#define __HAVE_MD_SWAP
#ifdef __LITTLE_ENDIAN__
#define _BYTE_ORDER _LITTLE_ENDIAN