From 4b03c3c4f878e8e0254d012719e0a7e8e516e959 Mon Sep 17 00:00:00 2001 From: Christian Weisgerber Date: Mon, 1 Oct 2018 17:42:17 +0000 Subject: 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'" --- sys/arch/arm64/include/endian.h | 55 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'sys/arch/arm64') 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 @@ -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 +#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 -- cgit v1.2.3