From owner-dev-commits-src-branches@freebsd.org Thu Feb 4 18:02:01 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E319152AA03; Thu, 4 Feb 2021 18:02:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DWmbD36vRz4hQ4; Thu, 4 Feb 2021 18:01:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 04D8B7EFE; Thu, 4 Feb 2021 18:01:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 114I1taa052783; Thu, 4 Feb 2021 18:01:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 114I1tWv052782; Thu, 4 Feb 2021 18:01:55 GMT (envelope-from git) Date: Thu, 4 Feb 2021 18:01:55 GMT Message-Id: <202102041801.114I1tWv052782@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 1a2bc12c4b25 - stable/13 - x86: use compiler intrinsics for bswap* MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1a2bc12c4b2563628f329e2e971d1619e0240429 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Feb 2021 18:02:02 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=1a2bc12c4b2563628f329e2e971d1619e0240429 commit 1a2bc12c4b2563628f329e2e971d1619e0240429 Author: Mateusz Guzik AuthorDate: 2021-02-01 03:00:13 +0000 Commit: Mateusz Guzik CommitDate: 2021-02-04 18:01:13 +0000 x86: use compiler intrinsics for bswap* (cherry picked from commit e6ff6154d2034c13f3d0da73c1e00d69fdb36516) --- sys/x86/include/endian.h | 62 +++--------------------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) diff --git a/sys/x86/include/endian.h b/sys/x86/include/endian.h index 9c39f4fddf80..18d52fb8a6fa 100644 --- a/sys/x86/include/endian.h +++ b/sys/x86/include/endian.h @@ -65,65 +65,9 @@ #define BYTE_ORDER _BYTE_ORDER #endif -#define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8) -#define __bswap32_gen(x) \ - (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16)) -#define __bswap64_gen(x) \ - (((__uint64_t)__bswap32((x) & 0xffffffff) << 32) | __bswap32((x) >> 32)) - -#ifdef __GNUCLIKE_BUILTIN_CONSTANT_P -#define __bswap16(x) \ - ((__uint16_t)(__builtin_constant_p(x) ? \ - __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x))) -#define __bswap32(x) \ - (__builtin_constant_p(x) ? \ - __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x)) -#define __bswap64(x) \ - (__builtin_constant_p(x) ? \ - __bswap64_gen((__uint64_t)(x)) : __bswap64_var(x)) -#else -/* XXX these are broken for use in static initializers. */ -#define __bswap16(x) __bswap16_var(x) -#define __bswap32(x) __bswap32_var(x) -#define __bswap64(x) __bswap64_var(x) -#endif - -/* These are defined as functions to avoid multiple evaluation of x. */ - -static __inline __uint16_t -__bswap16_var(__uint16_t _x) -{ - - return (__bswap16_gen(_x)); -} - -static __inline __uint32_t -__bswap32_var(__uint32_t _x) -{ - -#ifdef __GNUCLIKE_ASM - __asm("bswap %0" : "+r" (_x)); - return (_x); -#else - return (__bswap32_gen(_x)); -#endif -} - -static __inline __uint64_t -__bswap64_var(__uint64_t _x) -{ - -#if defined(__amd64__) && defined(__GNUCLIKE_ASM) - __asm("bswap %0" : "+r" (_x)); - return (_x); -#else - /* - * It is important for the optimizations that the following is not - * really generic, but expands to 2 __bswap32_var()'s. - */ - return (__bswap64_gen(_x)); -#endif -} +#define __bswap16(x) __builtin_bswap16(x) +#define __bswap32(x) __builtin_bswap32(x) +#define __bswap64(x) __builtin_bswap64(x) #define __htonl(x) __bswap32(x) #define __htons(x) __bswap16(x)