From patchwork Tue Sep 19 18:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 142226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3888662vqi; Tue, 19 Sep 2023 22:21:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7zNM3Tt/A2pIaYKUKrAbqR0JZcPTIJx6RvRcmDJWjbnbHgzKevuo4SRiplrnnZzslnTpi X-Received: by 2002:a17:903:11c6:b0:1c4:1343:8329 with SMTP id q6-20020a17090311c600b001c413438329mr1598352plh.27.1695187268203; Tue, 19 Sep 2023 22:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695187268; cv=none; d=google.com; s=arc-20160816; b=fjbPdwzt4nvMV0Qdj8jXnct44mouqLoNb5y/Jy09oWe0lu7lNJlUVmYMvVNicxxTvU IByICSJtx7mB+P/KWP/CD+jdu5EIFbLoqT5ypWpf0YMj7WzUqMY+Hp1ZoH1E+kh8R+15 GB0TDasALOXBnru+2AU56L6YtkHoU4cDBUY3YWVdC8TIgwLPx+VANi8Xn3Amari25Tsi 1bFxU1+Gxu4MCWNn7A38Vz4UhpgIDV54qeI2/3YcTouP0jkeynloFfOZyMaoKsa98euR y3AlmXLAds+/mzcjyUnoU8EixFPg+BuZ/ERGblUNtGZKpTx0YYAJHIB/kzNmh4ols57h 0D/A== 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 Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e11-20020a17090301cb00b001b7eb771d5esi11546304plh.527.2023.09.19.22.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 22:21:08 -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 3838681E9A55; 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 S232414AbjISSpJ (ORCPT + 26 others); Tue, 19 Sep 2023 14:45:09 -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 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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777532685333457494 X-GMAIL-MSGID: 1777532685333457494 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