diff options
author | Christian Weisgerber <naddy@cvs.openbsd.org> | 2018-10-01 17:42:17 +0000 |
---|---|---|
committer | Christian Weisgerber <naddy@cvs.openbsd.org> | 2018-10-01 17:42:17 +0000 |
commit | 4b03c3c4f878e8e0254d012719e0a7e8e516e959 (patch) | |
tree | 234cdb72826f8912ba051c1b98afe985939a29bc /sys | |
parent | 3f741288a37c81dec92ad20a8b8477f650326456 (diff) |
Use inline functions instead of GNU C statement expressions for the MD
byteswapping code.
ok guenther@ kettenis@
This fixes a corner case triggered by the comms/hylafax port where
htons() can't be compiled in C++ code:
"Don't know how to handle indirect register inputs yet for constraint 'r'"
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/arm64/include/endian.h | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/sys/arch/arm64/include/endian.h b/sys/arch/arm64/include/endian.h index 6283c882370..605a4a73a19 100644 --- a/sys/arch/arm64/include/endian.h +++ b/sys/arch/arm64/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.2 2017/02/06 04:08:57 dlg Exp $ */ +/* $OpenBSD: endian.h,v 1.3 2018/10/01 17:42:16 naddy Exp $ */ /* * Copyright (c) 2015 David Gwynne <dlg@openbsd.org> @@ -19,26 +19,39 @@ #ifndef _MACHINE_ENDIAN_H_ #define _MACHINE_ENDIAN_H_ -#define __swap32md(x) __statement({ \ - __uint32_t __swap32md_x; \ - \ - __asm ("rev %w0, %w1" : "=r" (__swap32md_x) : "r"(x)); \ - __swap32md_x; \ -}) - -#define __swap64md(x) __statement({ \ - __uint64_t __swap64md_x; \ - \ - __asm ("rev %x0, %x1" : "=r" (__swap64md_x) : "r"(x)); \ - __swap64md_x; \ -}) - -#define __swap16md(x) __statement({ \ - __uint16_t __swap16md_x; \ - \ - __asm ("rev16 %w0, %w1" : "=r" (__swap16md_x) : "r"(x)); \ - __swap16md_x; \ -}) +#ifndef __FROM_SYS__ENDIAN +#include <sys/_types.h> +#endif + +static __inline __uint16_t +__swap16md(__uint16_t _x) +{ + __uint16_t _rv; + + __asm ("rev16 %w0, %w1" : "=r" (_rv) : "r"(_x)); + + return (_rv); +} + +static __inline __uint32_t +__swap32md(__uint32_t _x) +{ + __uint32_t _rv; + + __asm ("rev %w0, %w1" : "=r" (_rv) : "r"(_x)); + + return (_rv); +} + +static __inline __uint64_t +__swap64md(__uint64_t _x) +{ + __uint64_t _rv; + + __asm ("rev %x0, %x1" : "=r" (_rv) : "r"(_x)); + + return (_rv); +} /* Tell sys/endian.h we have MD variants of the swap macros. */ #define __HAVE_MD_SWAP |