Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1290257rdb; Wed, 20 Sep 2023 05:23:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgAJz5bOsXGMNZBA2gVcIiuIQfNSjs5CWuPQynJWybgewWpv9KAVIaJ1vJ9izO05G0zPv4 X-Received: by 2002:a17:902:9a09:b0:1c3:343c:f8b0 with SMTP id v9-20020a1709029a0900b001c3343cf8b0mr1856081plp.66.1695212614675; Wed, 20 Sep 2023 05:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695212614; cv=none; d=google.com; s=arc-20160816; b=pyuRqPBK5yqrt+caQ2RcvMMAhGW2R53GMDDAqd58C1pENKRfR9E7FyqjifAS/rLGoR DM48UMLK/ORKSJTjhiC008SqRLqHRWr+0LLZx+GLJG+bXZuaQ/x5596iqgwWPjRNz/Lj BOF2JoMf/Ivu5pvbve3z5qWzT4C3w4Bx2gC6r68VzpodotgqYf1+V7H4hsLd5F4twwwO Y4qwSUXwZjFYNmllrc+EyOEEf1+K3bhFMYceJJNmjQMADOK+K+cEl6JgHKJ/2PMpjj44 bY6bGL7vUVnDwtJBG6HXruP4T50DDe35INfIfc+8JrruS8B6YbUFv/AcBgj7N2C0aaxz NZRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=55gQAkGJdgEhOiqM5Y2FlQbtEmx2dMpuljRL7f6iQqU=; fh=Y565EP4XCbbHzyjsLQMNVA5sHkqrC9GPqaO5xfn/wHs=; b=QThoIrx2FcUqgQJx/U3wobO1CFWl8s2aVqRBI+AIdL2zCcP345JAB9wiwmhADxkYqt iuq+SZcda4BbrjfafQA2SEjTuZEipHLSTMkIAC+lqqbmYSQYk6x/SW56mDqomYUf+yVn C1vB9f4F3BW7C7yvzMktn6nI/sE774mBvYFFU6xOorEcGlpyM67YnQAX9OokkgLQxdFm sea8WdaLgII1L7gOwrvzQ6bhB1R3G2y3pbNYaSYaZZbm1Cbb3L07OBW7BuffmmffEXjZ vDJNXq6utSY3XFtsA7T0k58YxF2Uqu/5mu9b4dfYLVcG71aXTj/nKO15OdZLzZ8DI8S5 +wiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=XCbLVV0l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l11-20020a170902f68b00b001b841d54b7csi12041452plg.206.2023.09.20.05.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=XCbLVV0l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3812F81E9A54; Tue, 19 Sep 2023 11:45:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbjISSpI (ORCPT + 99 others); Tue, 19 Sep 2023 14:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231906AbjISSpF (ORCPT ); Tue, 19 Sep 2023 14:45:05 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D42A59D for ; Tue, 19 Sep 2023 11:44:59 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-274dd099cd5so2278802a91.3 for ; Tue, 19 Sep 2023 11:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1695149099; x=1695753899; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=55gQAkGJdgEhOiqM5Y2FlQbtEmx2dMpuljRL7f6iQqU=; b=XCbLVV0lEuRuMWmbkS2DAnRlA2m1WcgRUoze3SvalSCYLhRsJpB3SIVKJd3Be8maef 87pcQzbBefQna6mgkoEluugcLYOTiOPfFU93WjbbJUP4sQehWK+uBhGmpXxT5p0aq1Ja 8MVQIKK8kjlBFsENBOgN73LGoWz+kwQofngw6hOJ3c2bh1aWiYsI59K0tzMvbZbdNv6D dmIxVarXUwcQHQrzL5PpLdpkl5S1pU4HF4Ua54u3RRBOCKLzhVDjRvDs2G5jl+94NgX/ PHaYITMxJZeWysocYekXcCYxL9d3aWFlryioRD7fuJokkOz951L8OGQDI7+lW+enMVqw 5XLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695149099; x=1695753899; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=55gQAkGJdgEhOiqM5Y2FlQbtEmx2dMpuljRL7f6iQqU=; b=l7kLF4SpfswZxpLNS6IlZ6WDPd1KhfrLcNzhIiC9HNZdBOhgbQXeMhPA4wxgC735K7 NnByf/6yB9QFCxewUgJrGUApHtM+FH7Yd8Mr705ccR3aud/qhPs0hLQoeMtuqMK3ufQj QnikJUkMMOMJltVek8aAvFx5ALQ78Vz24gbDNQh25piDNk2OB/nogiWqEmwCRxvK4eHW 7CunsW4kKRosqPpcvp7HoGQCxuHEXJrL3x0HAS4RTWEgn7mHgobkGpAKcCmOnCBsnQqF bvGfb+v1Ow96Q7/MgzDuRfEoZ7ypJctKPFQbm4LemUySUqDTbSPVL5CwihIiuLrG696T PPhA== X-Gm-Message-State: AOJu0YyH2cWqQlDqf0XgP2y05LnMm1b4LncQUkBNjgQymaDSNum5wfuA rDxJulg89eJSFDbU9NqKvG30Iw== X-Received: by 2002:a17:90b:23c1:b0:26c:f9a5:4493 with SMTP id md1-20020a17090b23c100b0026cf9a54493mr539248pjb.5.1695149099376; Tue, 19 Sep 2023 11:44:59 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id m5-20020a17090b068500b0026309d57724sm3876846pjz.39.2023.09.19.11.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 11:44:59 -0700 (PDT) From: Charlie Jenkins Date: Tue, 19 Sep 2023 11:44:30 -0700 Subject: [PATCH v7 1/4] asm-generic: Improve csum_fold MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230919-optimize_checksum-v7-1-06c7d0ddd5d6@rivosinc.com> References: <20230919-optimize_checksum-v7-0-06c7d0ddd5d6@rivosinc.com> In-Reply-To: <20230919-optimize_checksum-v7-0-06c7d0ddd5d6@rivosinc.com> To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Paul Walmsley , Albert Ou , Arnd Bergmann , David Laight X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 11:45:08 -0700 (PDT) This csum_fold implementation introduced into arch/arc by Vineet Gupta is better than the default implementation on at least arc, x86, and riscv. Using GCC trunk and compiling non-inlined version, this implementation has 41.6667%, 25% fewer instructions on riscv64, x86-64 respectively with -O3 optimization. Most implmentations override this default in asm, but this should be more performant than all of those other implementations except for arm which has barrel shifting and sparc32 which has a carry flag. Signed-off-by: Charlie Jenkins Reviewed-by: David Laight --- include/asm-generic/checksum.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h index 43e18db89c14..ad928cce268b 100644 --- a/include/asm-generic/checksum.h +++ b/include/asm-generic/checksum.h @@ -2,6 +2,8 @@ #ifndef __ASM_GENERIC_CHECKSUM_H #define __ASM_GENERIC_CHECKSUM_H +#include + /* * computes the checksum of a memory block at buff, length len, * and adds in "sum" (32-bit) @@ -31,9 +33,7 @@ extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl); static inline __sum16 csum_fold(__wsum csum) { u32 sum = (__force u32)csum; - sum = (sum & 0xffff) + (sum >> 16); - sum = (sum & 0xffff) + (sum >> 16); - return (__force __sum16)~sum; + return (__force __sum16)((~sum - ror32(sum, 16)) >> 16); } #endif -- 2.42.0