Message ID | 20230915-optimize_checksum-v6-1-14a6cf61c618@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1309831vqi; Fri, 15 Sep 2023 13:47:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlMmx/YuPrSnXxEI7S1sDDmOmMJVWMI1GMSCg3hzJW4rdOGEOtIXsnDjaAy+6Ht5BKam32 X-Received: by 2002:a05:6a20:7d88:b0:13e:99c0:fe6e with SMTP id v8-20020a056a207d8800b0013e99c0fe6emr7856758pzj.5.1694810829257; Fri, 15 Sep 2023 13:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694810829; cv=none; d=google.com; s=arc-20160816; b=u7r8AXSLSYxvxfgWqKq6u82LvGe8id3QcVfMF67nSeqNER49sBx7jSMA7o4ijv60u5 rJQN9hHKsOHHA8l6zChd0zjU5T3vJ1f0yCh0JQcw+oRv1jcLPs+n/+s9tWNrHabhZKaA XGe+Af2fpcZZakV3oRLjxU2/dcmQdWXz28nKabehtRDINt+W2CTg00KLbexN4Uzrw05h 7XMhmwuILm5lJ4Q3x1ohOar6uXC3+FF/an5SxHE8vCXgfanjpphwAg1NXqLru96U3MBp t8mVEofceV7wQCtBETg6vpEXgZp+nA+mVQjrvgI4euSbCi37EPjU7ldWXEn3BU4ylUAc /2vw== 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=bFaSlC1Eanb+aGEVXbnD8fQMHZ9ukouqu1oCkaPSAho=; fh=Y565EP4XCbbHzyjsLQMNVA5sHkqrC9GPqaO5xfn/wHs=; b=taBTuis38GnU2WRATEQViFoz6xabuaEOAkEIT0hhQoexUrDjw9JKtXIh2UcZPt980X R2Hn5TA0AafqRdKArhcxfActldExMbfjz6LtbIuUPe1FsxpdKzNhVq545i239J62GVFA +9h8fPdPYRCR6Aq7fCQr6WltVES89HOCiSVb/FRZgBfIsJ+kegWeZk/PUQ8PW8t4rN/d vr2b9p6T8KoYwrVwTcsi1xvrx+nTi653YB0TbTUZmQ6hTCJZAWt93R5YmjKt61ERBzoi gbUA1c3n86ygIUXmhW9k87puyk0iErqwgf26Ou4AagvT0sNdOqwP3pCGI6e6TOLhPu9D MDUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AMqGV4LW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ca20-20020a056a02069400b005740e906e46si4020675pgb.358.2023.09.15.13.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:47:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AMqGV4LW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 7577B82195EE; Fri, 15 Sep 2023 10:03:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235229AbjIORDB (ORCPT <rfc822;ruipengqi7@gmail.com> + 30 others); Fri, 15 Sep 2023 13:03:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235452AbjIORCh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 15 Sep 2023 13:02:37 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B52FF2703 for <linux-kernel@vger.kernel.org>; Fri, 15 Sep 2023 10:02:31 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bf1935f6c2so17526365ad.1 for <linux-kernel@vger.kernel.org>; Fri, 15 Sep 2023 10:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694797351; x=1695402151; 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=bFaSlC1Eanb+aGEVXbnD8fQMHZ9ukouqu1oCkaPSAho=; b=AMqGV4LWYluMA2CXitPG5LrXIL/L6LC7fUq3EO4giRqbZN018okEFAaIYpemNHDDBY WmBl+BUrU3/6lqgqGvakoUB1V87JzbpqtyKGysUVwDJmJi7W0wq0LyNqXViFSty478oB tdgh8cSNkqSsbO3zT8h3tlyPvR1rAc+L1OyoFgae2kHF7LwaGYdci815ZMYt98lG/RY7 Kq7a08DJZM0Ea6gATUq2tJ1w3Rq6ojpOf7mNw+o7egSfGyWIKN5FxJA4eEf9ngdsSUge 060tzEBP4/t/lche3fdU1PzqekIgK9OaH+Y7UfoeSnP9LV34E9S/wBqpe1lvMD5wdfIc i+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694797351; x=1695402151; 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=bFaSlC1Eanb+aGEVXbnD8fQMHZ9ukouqu1oCkaPSAho=; b=DDTjQ9/jnKkFZ9OnmJycHGnpZtfAigtmlUex9duObADmt+5xnxNyPCAFT2G3UhLYuU TGnLOyrV6yLlsSlRZsG6MoAfv614DzIyn9P2o+OA/0DJC6WCq5GSOos8CgXgIis7dSBy yP5C0TX3kJo8LMP/w9/ZNC7PCflUCNuS56EcqGZFa4mtljbzqGaJSx1v7/AJsvk0Rn95 CeiM+mKriWv+U0W9bwvGVgp/8ieEj08hfUXhM9TGb276CqXpJZBf2fGUBXE/nBkS8XZ/ wE/ctzaXrwhwrFNY26PeGIK5IAn2y9nsdCttZeF+4H7h2KyXHozk8WFFuJK4fvXH49mn KXtA== X-Gm-Message-State: AOJu0YzkazsMS0b1vHxgYX5Nls9LHk9oU1V0wlu/PxfFbSZOsZXH3uuS edO/SNx+sLujgJVuklmWZw1tgA== X-Received: by 2002:a17:902:dacb:b0:1c0:bcbc:d67 with SMTP id q11-20020a170902dacb00b001c0bcbc0d67mr8332563plx.22.1694797351144; Fri, 15 Sep 2023 10:02:31 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id g22-20020a1709029f9600b001c44c8d857esm34299plq.120.2023.09.15.10.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:02:30 -0700 (PDT) From: Charlie Jenkins <charlie@rivosinc.com> Date: Fri, 15 Sep 2023 10:01:17 -0700 Subject: [PATCH v6 1/4] asm-generic: Improve csum_fold MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230915-optimize_checksum-v6-1-14a6cf61c618@rivosinc.com> References: <20230915-optimize_checksum-v6-0-14a6cf61c618@rivosinc.com> In-Reply-To: <20230915-optimize_checksum-v6-0-14a6cf61c618@rivosinc.com> To: Charlie Jenkins <charlie@rivosinc.com>, Palmer Dabbelt <palmer@dabbelt.com>, Conor Dooley <conor@kernel.org>, Samuel Holland <samuel.holland@sifive.com>, David Laight <David.Laight@aculab.com>, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Paul Walmsley <paul.walmsley@sifive.com>, Albert Ou <aou@eecs.berkeley.edu>, Arnd Bergmann <arnd@arndb.de>, David Laight <david.laight@aculab.com> 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 10:03:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777137960105296130 X-GMAIL-MSGID: 1777137960105296130 |
Series |
riscv: Add fine-tuned checksum functions
|
|
Commit Message
Charlie Jenkins
Sept. 15, 2023, 5:01 p.m. UTC
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 <charlie@rivosinc.com> Reviewed-by: David Laight <david.laight@aculab.com> --- include/asm-generic/checksum.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Comments
On Fri, Sep 15, 2023 at 10:01:17AM -0700, Charlie Jenkins wrote: > 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 <charlie@rivosinc.com> > Reviewed-by: David Laight <david.laight@aculab.com> > --- > include/asm-generic/checksum.h | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h > index 43e18db89c14..37f5ec70ac93 100644 > --- a/include/asm-generic/checksum.h > +++ b/include/asm-generic/checksum.h > @@ -31,9 +31,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); Breaks the build on RISC-V in a way that is repaired by later patches in the series, so you likely did not notice: ./include/asm-generic/checksum.h:34:35: error: call to undeclared function 'ror32'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] ../include/linux/bitops.h:134:21: error: static declaration of 'ror32' follows non-static declaration Cheers, Conor.
diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h index 43e18db89c14..37f5ec70ac93 100644 --- a/include/asm-generic/checksum.h +++ b/include/asm-generic/checksum.h @@ -31,9 +31,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