Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4837381pxb; Sat, 12 Feb 2022 21:51:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyb0CMnfGJc56Qzj4DkQIXUNRoikFTk97MqAx+WuCLjo2ZhquO6RMVG6i3+cN2r/L2WHnum X-Received: by 2002:a50:cb8c:: with SMTP id k12mr9194625edi.69.1644731473357; Sat, 12 Feb 2022 21:51:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644731473; cv=none; d=google.com; s=arc-20160816; b=HSkpvoleharj/2PvTt0mVPfsPhOuUlfsK5WOuq0il5RWxR3JMnVNZlPKGz0S2kMlH5 Z8P+8MqVfJYbx/Do29+0g3rGMwZkGpE1/qg/YW7rbwxH4QODUzIPgZk7lNYY/gSrGw+C DrGvGNcY2MAjRknwyfkjGGs3ekw33wIJKpnfrIc5L+wJeivgyuXmL+rdhQGYhwaq8IXI aOmqdd8YwdUA7Sr4F8b6oAa+JQI6TvIFdj/oCbRUr3ooxPHWfMgzYOIzDDD1MKUWosz8 FKSq4o3FQ17Kgper67NltN8I7h2t6/3o0dllwQQR+AoMC+8kTbDYSf9WycDjI9Jdz9yZ FC5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=jrba/3b1Ti0agbpzkAyeErKB80SiRr1GKvnPKj8ek9Y=; b=q6BWsqbLEmrT/HP64RfyAjCrcEqQBOiOfLOPJfQ6sL9ndI4+kN1JQdGd8p+f7hxvZg vMvVybyJQWVty+phK1WGpIVV3CGSaJCgQO0/PRagGmELhXNtZYYP8B0K8YIcOqhxAIxn ZF7P/KUn6lvvsVPviIQZQczXoUvb8vbnQaaEtiKTrkGrhEmBKEP3i3L40q4qItG9zcW5 NfQhBVuR4W0+3amUbVZpKo9U1em0XYD0VCiIhDHbbvl/8yNMCPbZ3M0Q2kta7jACWZE+ OjiAQ2zTrgRzwcTQiYuLPR4KM3oM6mXOOml/xBlAJXUbY68b2z2cVIQrbTDg4m0NQKca u0vA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4si22872433ejs.825.2022.02.12.21.50.50; Sat, 12 Feb 2022 21:51:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348195AbiBKIsh (ORCPT + 94 others); Fri, 11 Feb 2022 03:48:37 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348187AbiBKIsg (ORCPT ); Fri, 11 Feb 2022 03:48:36 -0500 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8129AE54 for ; Fri, 11 Feb 2022 00:48:35 -0800 (PST) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4Jw6hx4vY8z9sSM; Fri, 11 Feb 2022 09:48:33 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id klDIzGqmxZ6I; Fri, 11 Feb 2022 09:48:33 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4Jw6hx4Bhzz9sSL; Fri, 11 Feb 2022 09:48:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7ED5A8B77D; Fri, 11 Feb 2022 09:48:33 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id rtRKHQ_BcwTx; Fri, 11 Feb 2022 09:48:33 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.6.91]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 36EBB8B764; Fri, 11 Feb 2022 09:48:33 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 21B8mNGc936763 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 11 Feb 2022 09:48:23 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 21B8mMRd936762; Fri, 11 Feb 2022 09:48:22 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "David S. Miller" , Jakub Kicinski Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org Subject: [PATCH] net: Remove branch in csum_shift() Date: Fri, 11 Feb 2022 09:48:16 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1644569294; l=1792; s=20211009; h=from:subject:message-id; bh=bn4qVlTEECkFmk/D3ReBpu/1ueTQNT/DDGPwdR54bMw=; b=YfWOLv3f7QPdV7JOLEvppeShwBCfk+aGgbZur22GW+m9WX6XeuSeUHvizGFhnuzg3csBcc4Zfcbu MOrUk6ZGDv8PKhpkllz2TJosNNk2sqMNIrrXLeIPI0EXjv6RY/gs X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Today's implementation of csum_shift() leads to branching based on parity of 'offset' 000002f8 : 2f8: 70 a5 00 01 andi. r5,r5,1 2fc: 41 a2 00 08 beq 304 300: 54 84 c0 3e rotlwi r4,r4,24 304: 7c 63 20 14 addc r3,r3,r4 308: 7c 63 01 94 addze r3,r3 30c: 4e 80 00 20 blr Use first bit of 'offset' directly as input of the rotation instead of branching. 000002f8 : 2f8: 54 a5 1f 38 rlwinm r5,r5,3,28,28 2fc: 20 a5 00 20 subfic r5,r5,32 300: 5c 84 28 3e rotlw r4,r4,r5 304: 7c 63 20 14 addc r3,r3,r4 308: 7c 63 01 94 addze r3,r3 30c: 4e 80 00 20 blr And change to left shift instead of right shift to skip one more instruction. This has no impact on the final sum. 000002f8 : 2f8: 54 a5 1f 38 rlwinm r5,r5,3,28,28 2fc: 5c 84 28 3e rotlw r4,r4,r5 300: 7c 63 20 14 addc r3,r3,r4 304: 7c 63 01 94 addze r3,r3 308: 4e 80 00 20 blr Signed-off-by: Christophe Leroy --- include/net/checksum.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/net/checksum.h b/include/net/checksum.h index 5218041e5c8f..9badcd5532ef 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -83,9 +83,7 @@ static inline __sum16 csum16_sub(__sum16 csum, __be16 addend) static inline __wsum csum_shift(__wsum sum, int offset) { /* rotate sum to align it with a 16b boundary */ - if (offset & 1) - return (__force __wsum)ror32((__force u32)sum, 8); - return sum; + return (__force __wsum)rol32((__force u32)sum, (offset & 1) << 3); } static inline __wsum -- 2.34.1