From patchwork Wed Jan 11 16:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 641255 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp3348023pvb; Wed, 11 Jan 2023 08:32:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBdFGbV4fJxHUaaCj7NSj94fyZKc9lEMAMQGLOPRKAFoxPGuMKNcXWVRAO74GTgZXfXmwm X-Received: by 2002:a05:6214:5713:b0:4e8:178d:7ec7 with SMTP id lt19-20020a056214571300b004e8178d7ec7mr47121947qvb.26.1673454738467; Wed, 11 Jan 2023 08:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673454738; cv=none; d=google.com; s=arc-20160816; b=lB2PY9wEEfYgGYrC+RoqbCRqUtVj3P5umnd3RlHOUuObsVDXlE9uByz13r9SivnREg 538dkiE1ApSxtOjyziY+EOX7EMOLJq2ZooZenwuH79ktB3G/Xwb+9P2qWrU+/UTGejma mCrak7BHF9FB3/z9ApI3ZJGnQu0oQngSuhJh3sCU3vGTZxB4UHHDgOfLFNt0S1jt0zF9 qqRiSyA0r6cZjrUW96vTjIBwC2+L0nRglurxfb5ObkCk/GAnp1t6Yylch1HCuWXd+Gwx 6q9B+krIfUuhkASV0o+WcB3bseD7nJCnq5rh9L2GMrYDTOygHyNLcxXZ36ImTgxYljQa IpLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mYffee02pGXsDaWEK6vxcHOMS52J5/C+ETdo1/oigCU=; b=HgGOVI6Wa8FG1blhwFtwYbtYibSZ58zzH4QVX4/97kJe9m8u4ya4mTfnMjjIVRNJVZ D4gUHcAUu5vE4swU7nXfeUR2Ije1QlX1Eu2imUCtL1r6ZhjcE87/x8l9nZti1fiWFLBf xPey/lSUjUTs6tfalqBaPFoG9bgsc6Uv3gNguQYqTJPzi+ojkZphoFhBIk+rspFkwgoL AVNuVWWimaTpVye30FcSBd1AdpMjS1i6smvlfRO0iT3UZ+jqeslFns8+ylFF5kxVVySE vlMrFfrDNG2fXHcZUfq46dFNrb7NE4iMrYDODpY4Cz3Z+7siuH3nLRy2eEbtbxDnyCkd ldLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ks2Xu7NC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 3-20020a0562140d6300b005341e35ead7si3082182qvs.47.2023.01.11.08.32.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Jan 2023 08:32:18 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ks2Xu7NC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFe1A-0001FU-61; Wed, 11 Jan 2023 11:32:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pFe18-0001F4-DM for qemu-devel@nongnu.org; Wed, 11 Jan 2023 11:31:58 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pFe16-0006BP-RY for qemu-devel@nongnu.org; Wed, 11 Jan 2023 11:31:58 -0500 Received: by mail-wm1-x332.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so13127007wms.2 for ; Wed, 11 Jan 2023 08:31:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mYffee02pGXsDaWEK6vxcHOMS52J5/C+ETdo1/oigCU=; b=Ks2Xu7NCVAGfIFkzDPbgINU73TtdKiS+26nh4ZR/niaw4OnmjeQgpAm15D+HV4iNTj SG5adEyerflqWOnzefO68YDCWB5AcrAjemROlSXvfchQqLaQqZ/MLppO3nm83g6LBIA2 0h3RzqCCSfQsCi9RTgEnpGTaa+hW5FbEN7EQzcXJqAbDQ7lR5kyKY/7uqxCv6ogVm1gB uYXcpgOJJXq8wGImx0uNJr62HKw8lPJyZLKcmG8KU0fe3olrypd6Etb5EJYWlW2HC4GE laEMFKniML349jUcb3HYIOa7iDpXpn5pZJRVXcuRenV0hu28odU2YtvoQmeZWQhjRIYj acGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mYffee02pGXsDaWEK6vxcHOMS52J5/C+ETdo1/oigCU=; b=ZaszEbjD8valSMDcAeRu2aUfaEHm7s4KZi6JzTFwif7n6QgItCje3cToS7DTLS9TG5 Px8RgforvH+nA8qTWdjFaJUxAEFQXvqTeLsRW0UzRkwyRqUFlUL1kkXpbp1LXYUNdybr ychC9vy6mCwzI2RG8kkNvaDFqBjCiWRmdUNVOmo8+SQD/5h5HoSTtaLB7Mh+yJ3yvGHE 0dor97DJnkAoRvnBGuIFO9rMFv5QVon7DPbQbQjtXEIWkN4SMFVuL9964ij3G27eAAVw EwhKU6JPp3pRam2TvhGWGyokX+heonENaTvQxLgHwLPSPIZgzrvyG38IDT2F+V8+yrIh A5wA== X-Gm-Message-State: AFqh2kouCIH/Zk0UfqmyJdqV2DxBdqzET3Q7GGhQBaXxJ06AMWFRryjV hYIk8r/9p1i9UWvxYbnU8+XacvOQUNX4tk7T X-Received: by 2002:a05:600c:3b90:b0:3d1:f0f1:ceb4 with SMTP id n16-20020a05600c3b9000b003d1f0f1ceb4mr52762995wms.19.1673454715084; Wed, 11 Jan 2023 08:31:55 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id l14-20020a05600c1d0e00b003da105437besm801426wms.29.2023.01.11.08.31.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 11 Jan 2023 08:31:54 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Ryo ONODERA , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Thomas Huth , Ira Weiny , Paolo Bonzini , Kamil Rytarowski , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Reinoud Zandijk , Jonathan Cameron , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Richard Henderson Subject: [PATCH v3 1/6] qemu/bswap: Replace bswapXX() by compiler __builtin_bswap() Date: Wed, 11 Jan 2023 17:31:42 +0100 Message-Id: <20230111163147.71761-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230111163147.71761-1-philmd@linaro.org> References: <20230111163147.71761-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Use the compiler built-in function to byte swap values, as the compiler is clever and will fold constants. Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- include/qemu/bswap.h | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 346d05f2aa..ca2b4c3f15 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -37,31 +37,12 @@ static inline uint64_t bswap64(uint64_t x) #endif #ifdef BSWAP_FROM_FALLBACKS -static inline uint16_t bswap16(uint16_t x) -{ - return (((x & 0x00ff) << 8) | - ((x & 0xff00) >> 8)); -} - -static inline uint32_t bswap32(uint32_t x) -{ - return (((x & 0x000000ffU) << 24) | - ((x & 0x0000ff00U) << 8) | - ((x & 0x00ff0000U) >> 8) | - ((x & 0xff000000U) >> 24)); -} - -static inline uint64_t bswap64(uint64_t x) -{ - return (((x & 0x00000000000000ffULL) << 56) | - ((x & 0x000000000000ff00ULL) << 40) | - ((x & 0x0000000000ff0000ULL) << 24) | - ((x & 0x00000000ff000000ULL) << 8) | - ((x & 0x000000ff00000000ULL) >> 8) | - ((x & 0x0000ff0000000000ULL) >> 24) | - ((x & 0x00ff000000000000ULL) >> 40) | - ((x & 0xff00000000000000ULL) >> 56)); -} +#undef bswap16 +#define bswap16(_x) __builtin_bswap16(_x) +#undef bswap32 +#define bswap32(_x) __builtin_bswap32(_x) +#undef bswap64 +#define bswap64(_x) __builtin_bswap64(_x) #endif #undef BSWAP_FROM_BYTESWAP