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: 1724737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Ks2Xu7NC; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsY9t5B1wz23fY for ; Thu, 12 Jan 2023 03:32:18 +1100 (AEDT) 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-Google-Smtp-Source: AMrXdXvDcMYJ7YqMd8jkETn++un/h+TCUuRk87eI5N75q5wAu0Om76nQXC00Zb6iQj8ILYzsLX7RXg== 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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