From 3a22adf90f02a48c220ef03ba895de849d198c94 Mon Sep 17 00:00:00 2001 From: naddy Date: Tue, 7 May 2024 14:26:48 +0000 Subject: [PATCH] drop the MD byte-swap micro-optimizations on clang architectures The compiler already translates the generic code into arithmetic byte-swap instructions or byte-swapping memory load and store instructions if available on an architecture. ok deraadt@ guenther@ --- sys/arch/amd64/include/endian.h | 30 +------------ sys/arch/arm/include/endian.h | 41 +---------------- sys/arch/arm64/include/endian.h | 41 +---------------- sys/arch/i386/include/endian.h | 30 +------------ sys/arch/powerpc/include/endian.h | 68 +---------------------------- sys/arch/powerpc64/include/endian.h | 67 +--------------------------- 6 files changed, 8 insertions(+), 269 deletions(-) diff --git a/sys/arch/amd64/include/endian.h b/sys/arch/amd64/include/endian.h index 3b077cd9295..3a2b46d2c51 100644 --- a/sys/arch/amd64/include/endian.h +++ b/sys/arch/amd64/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.7 2018/10/02 21:30:44 naddy Exp $ */ +/* $OpenBSD: endian.h,v 1.8 2024/05/07 14:26:48 naddy Exp $ */ /*- * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. @@ -27,34 +27,6 @@ #ifndef _MACHINE_ENDIAN_H_ #define _MACHINE_ENDIAN_H_ -#ifndef __FROM_SYS__ENDIAN -#include -#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) -{ - __asm ("bswapq %0" : "+r" (_x)); - return (_x); -} - -/* Tell sys/endian.h we have MD variants of the swap macros. */ -#define __HAVE_MD_SWAP - #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 739ee04af3c..1e31015f77c 100644 --- a/sys/arch/arm/include/endian.h +++ b/sys/arch/arm/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.11 2018/10/02 21:30:44 naddy Exp $ */ +/* $OpenBSD: endian.h,v 1.12 2024/05/07 14:26:48 naddy Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -19,48 +19,11 @@ #ifndef _ARM_ENDIAN_H_ #define _ARM_ENDIAN_H_ -#ifndef __FROM_SYS__ENDIAN -#include -#endif - -static __inline __uint16_t -__swap16md(__uint16_t _x) -{ - __uint16_t _rv; - - __asm ("rev16 %0, %1" : "=r" (_rv) : "r" (_x)); - - return (_rv); -} - -static __inline __uint32_t -__swap32md(__uint32_t _x) -{ - __uint32_t _rv; - - __asm ("rev %0, %1" : "=r" (_rv) : "r" (_x)); - - return (_rv); -} - -static __inline __uint64_t -__swap64md(__uint64_t _x) -{ - __uint64_t _rv; - - _rv = (__uint64_t)__swap32md(_x >> 32) | - (__uint64_t)__swap32md(_x) << 32; - - return (_rv); -} - -/* Tell sys/endian.h we have MD variants of the swap macros. */ -#define __HAVE_MD_SWAP - #define _BYTE_ORDER _LITTLE_ENDIAN #define __STRICT_ALIGNMENT #ifndef __FROM_SYS__ENDIAN #include #endif + #endif /* _ARM_ENDIAN_H_ */ diff --git a/sys/arch/arm64/include/endian.h b/sys/arch/arm64/include/endian.h index 605a4a73a19..db5d10fd985 100644 --- a/sys/arch/arm64/include/endian.h +++ b/sys/arch/arm64/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.3 2018/10/01 17:42:16 naddy Exp $ */ +/* $OpenBSD: endian.h,v 1.4 2024/05/07 14:26:48 naddy Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -19,48 +19,11 @@ #ifndef _MACHINE_ENDIAN_H_ #define _MACHINE_ENDIAN_H_ -#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 - - #define _BYTE_ORDER _LITTLE_ENDIAN #define __STRICT_ALIGNMENT #ifndef __FROM_SYS__ENDIAN #include #endif + #endif /* _MACHINE_ENDIAN_H_ */ diff --git a/sys/arch/i386/include/endian.h b/sys/arch/i386/include/endian.h index b107da44df9..248f984734f 100644 --- a/sys/arch/i386/include/endian.h +++ b/sys/arch/i386/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.19 2018/10/02 21:30:44 naddy Exp $ */ +/* $OpenBSD: endian.h,v 1.20 2024/05/07 14:26:48 naddy Exp $ */ /*- * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. @@ -27,34 +27,6 @@ #ifndef _MACHINE_ENDIAN_H_ #define _MACHINE_ENDIAN_H_ -#ifndef __FROM_SYS__ENDIAN -#include -#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 - #define _BYTE_ORDER _LITTLE_ENDIAN #ifndef __FROM_SYS__ENDIAN diff --git a/sys/arch/powerpc/include/endian.h b/sys/arch/powerpc/include/endian.h index 11ce8200c8c..993a872e839 100644 --- a/sys/arch/powerpc/include/endian.h +++ b/sys/arch/powerpc/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.21 2014/10/22 23:56:47 dlg Exp $ */ +/* $OpenBSD: endian.h,v 1.22 2024/05/07 14:26:48 naddy Exp $ */ /*- * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. @@ -27,72 +27,6 @@ #ifndef _POWERPC_ENDIAN_H_ #define _POWERPC_ENDIAN_H_ -#ifdef _KERNEL - -static inline __uint16_t -__mswap16(volatile const __uint16_t *m) -{ - __uint16_t v; - - __asm("lhbrx %0, 0, %1" - : "=r" (v) - : "r" (m), "m" (*m)); - - return (v); -} - -static inline __uint32_t -__mswap32(volatile const __uint32_t *m) -{ - __uint32_t v; - - __asm("lwbrx %0, 0, %1" - : "=r" (v) - : "r" (m), "m" (*m)); - - return (v); -} - -static inline __uint64_t -__mswap64(volatile const __uint64_t *m) -{ - __uint32_t *a = (__uint32_t *)m; - __uint64_t v; - - v = (__uint64_t)__mswap32(a + 1) << 32 | - (__uint64_t)__mswap32(a); - - return (v); -} - -static inline void -__swapm16(volatile __uint16_t *m, __uint16_t v) -{ - __asm("sthbrx %1, 0, %2" - : "=m" (*m) - : "r" (v), "r" (m)); -} - -static inline void -__swapm32(volatile __uint32_t *m, __uint32_t v) -{ - __asm("stwbrx %1, 0, %2" - : "=m" (*m) - : "r" (v), "r" (m)); -} - -static inline void -__swapm64(volatile __uint64_t *m, __uint64_t v) -{ - __uint32_t *a = (__uint32_t *)m; - - __swapm32(a + 1, v >> 32); - __swapm32(a, v); -} - -#define __HAVE_MD_SWAPIO -#endif /* _KERNEL */ - #undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */ #define _BYTE_ORDER _BIG_ENDIAN diff --git a/sys/arch/powerpc64/include/endian.h b/sys/arch/powerpc64/include/endian.h index 5803ecdb9a1..5e02d2a9140 100644 --- a/sys/arch/powerpc64/include/endian.h +++ b/sys/arch/powerpc64/include/endian.h @@ -1,4 +1,4 @@ -/* $OpenBSD: endian.h,v 1.2 2020/06/08 14:12:00 naddy Exp $ */ +/* $OpenBSD: endian.h,v 1.3 2024/05/07 14:26:48 naddy Exp $ */ /*- * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. @@ -27,71 +27,6 @@ #ifndef _MACHINE_ENDIAN_H_ #define _MACHINE_ENDIAN_H_ -#ifdef _KERNEL - -static inline __uint16_t -__mswap16(volatile const __uint16_t *m) -{ - __uint16_t v; - - __asm("lhbrx %0, 0, %1" - : "=r" (v) - : "r" (m), "m" (*m)); - - return (v); -} - -static inline __uint32_t -__mswap32(volatile const __uint32_t *m) -{ - __uint32_t v; - - __asm("lwbrx %0, 0, %1" - : "=r" (v) - : "r" (m), "m" (*m)); - - return (v); -} - -static inline __uint64_t -__mswap64(volatile const __uint64_t *m) -{ - __uint64_t v; - - __asm("ldbrx %0, 0, %1" - : "=r" (v) - : "r" (m), "m" (*m)); - - return (v); -} - -static inline void -__swapm16(volatile __uint16_t *m, __uint16_t v) -{ - __asm("sthbrx %1, 0, %2" - : "=m" (*m) - : "r" (v), "r" (m)); -} - -static inline void -__swapm32(volatile __uint32_t *m, __uint32_t v) -{ - __asm("stwbrx %1, 0, %2" - : "=m" (*m) - : "r" (v), "r" (m)); -} - -static inline void -__swapm64(volatile __uint64_t *m, __uint64_t v) -{ - __asm("stdbrx %1, 0, %2" - : "=m" (*m) - : "r" (v), "r" (m)); -} - -#define __HAVE_MD_SWAPIO -#endif /* _KERNEL */ - #undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */ #define _BYTE_ORDER _BIG_ENDIAN -- 2.20.1