Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp809269rdb; Fri, 17 Nov 2023 13:29:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtcub6eiTgErerx5EoTJN5983aM1fsoPGdjmaqnMAzcu4EeiVkJDQiyMlGg+pAStXFOXmY X-Received: by 2002:a05:6e02:e0f:b0:34b:ac73:eb97 with SMTP id a15-20020a056e020e0f00b0034bac73eb97mr746606ilk.14.1700256588122; Fri, 17 Nov 2023 13:29:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700256588; cv=none; d=google.com; s=arc-20160816; b=q/6O9L0YwVL/1MVZbBGMjy+M1Dj0PHdtWyfe8MyipYuCAUwoAPdDbu6KIXQYjUgPyX VmT0aUQgFkaXLJdDdOESgS6aI8c/Ygvu40JCAcOcb/6MbGvNQNsW/o8lTLN0YnRuQ8gj oXMc78an6JP7gKXcwqK8NKF4sguTgWB3Ch1phB6/PZK8+zaGbu2ERO2KO3dBET1JLG/e SSp5RUsXU4g8AFITfJnIk3hck09vzvUvZrUBU4Vp0iAPE5k30wfCnulTAqBoFoqzVC6M 344RBudGGgEGlfAEFHWgu09xXgvb9BOTgVrnTrMDXfgmKq+oLjWlpy9q8ZqKT5LDq2xO xNTA== 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=iQdBfGrxgT0Dp0rMc/ALsHZTaxuvWcxH/0MUqWK8IuU=; fh=WrYWo2NWGfDp1Q0L0IXsGjg4kDrSbEOOvn62+ocLtXY=; b=zVcBDZiqUHPekMylYVTL1AhvXZ5ojRiSFJv0hl58Xe8I/dszkEtlyLyAUcE8MnzRbu 3we0lo6d0JMgFtvqZGKNQAcrPFBcopq7ln5giRtHhNY8FzYk4yukzQULVzzOKbIIwt+4 PGIGXlZX9T9ttMiVPTnnpdTlOG2H8t9JPQAp0NAOFopYrAxm9hmjUkQEJbDdVciLaVos mx0MZ23At9qO2Sq++hfzAByzEWK5nhtdPVp/rozbkekWlKaTlPoN97eC7iZW65ITb4am J6/1tXYvpsh9Wj8IdMsKn0H5a2PskrRHvWcp0N/KlRCNVvozrhRL4rnijtUAs9OyRobl vJGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=f70WRS7y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id by11-20020a056a02058b00b005b64e8336dfsi2783765pgb.604.2023.11.17.13.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:29:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=f70WRS7y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id D5B808325FF8; Fri, 17 Nov 2023 13:29:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235755AbjKQV2o (ORCPT + 99 others); Fri, 17 Nov 2023 16:28:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235857AbjKQV2a (ORCPT ); Fri, 17 Nov 2023 16:28:30 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF9EBAD for ; Fri, 17 Nov 2023 13:28:10 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6ce2add34c9so1314406a34.1 for ; Fri, 17 Nov 2023 13:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700256490; x=1700861290; 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=iQdBfGrxgT0Dp0rMc/ALsHZTaxuvWcxH/0MUqWK8IuU=; b=f70WRS7yyv+xBIlfF9WkxxyBns6g68kJl5Zcq9FaMGwv3Nk0XF2LNc2GdRXTAZGF7d r8pQ/bwH57C5ZLNJV1pX5OkNzoFL8YP+5TTDLJVOfZe+hNxgNqoseP05l962ZI5IK2Iw j5WyQ8DXl+zVuzEPtA6uqDMmBrASNBe0IIAiY0lvr5TB93BCGN19V4cqAYpchLQ0Yx70 bLH0rPqxKeMTm7I2SkgVcbXZWpPB12e0HR+moIalyE3QARMyFtfV92/Is82hO6EAl03H C7l76vhulPQv0fKWnG+87DDse1XBgl3JKUjbiXej8dOgLC1tvb53tKII8zxn1Fh9Wd5s HsNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700256490; x=1700861290; 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=iQdBfGrxgT0Dp0rMc/ALsHZTaxuvWcxH/0MUqWK8IuU=; b=h0FbLjvY7DXXnz/KUVsF+XdQlDHfqJ8EWd3A87fO4dYufuQWEf8Q5fdtZYBu/INXlt A5frV/nGFmgZsNdqzaF/PenlfJKfx5GfkXdeid3LkoUj5B3yD4frgvwZmYszC3N+TbX1 lO5PdTuuz7dvpETMaf4gIl7EilCKu1aFwNgxb8wMciDaKEaqVH6zMBGGPLlu4TjbFujZ fQfELjZWNRhdus6M44vhfAa06Yw5IEfU5gs+ZcigfXEyWlPsCeXZH8E3zJcoNsEHrI+8 PT3vi7Z4eDe/5z0c4Q7dWZwC5MseMTOOsUkUGSt5weqUfvUzGB69rRPhiEshrWNIGPVb +ElQ== X-Gm-Message-State: AOJu0Yxaw0SfcqQzDclFISXg19GiNxRvHpdkPvmNUT6hqMUSPs+j/UuA UYvq9OcIxHd4Op73/YXH/l3m1ZSCP0wxQOf19Ao= X-Received: by 2002:a05:6871:3788:b0:1f5:2b0c:706b with SMTP id nq8-20020a056871378800b001f52b0c706bmr394978oac.28.1700256489806; Fri, 17 Nov 2023 13:28:09 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id e2-20020a05683013c200b006d3127234d7sm365677otq.8.2023.11.17.13.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:28:09 -0800 (PST) From: Charlie Jenkins Date: Fri, 17 Nov 2023 13:27:59 -0800 Subject: [PATCH v11 1/5] asm-generic: Improve csum_fold MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231117-optimize_checksum-v11-1-7d9d954fe361@rivosinc.com> References: <20231117-optimize_checksum-v11-0-7d9d954fe361@rivosinc.com> In-Reply-To: <20231117-optimize_checksum-v11-0-7d9d954fe361@rivosinc.com> To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , Xiao Wang , Evan Green , 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=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Fri, 17 Nov 2023 13:29:35 -0800 (PST) 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.34.1