Message ID | 20231101-optimize_checksum-v10-1-a498577bb969@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9114:0:b0:429:e9f3:4b66 with SMTP id r20csp730809vqg; Wed, 1 Nov 2023 15:48:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBnY20RFsvzdkFwN+RU2fitqp3PBGSXGm2TLR+Qgk3Y0PvbfrOAq+uJQOb0xOj57TxkVpV X-Received: by 2002:a05:6a00:b4e:b0:6b2:2a2d:7a25 with SMTP id p14-20020a056a000b4e00b006b22a2d7a25mr16092096pfo.29.1698878912831; Wed, 01 Nov 2023 15:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698878912; cv=none; d=google.com; s=arc-20160816; b=ETx9zJdLpgsnGZgG/oEjzBPmUaR+cQUPG6kf+Y7s9GC8dDstK6fZUWXt3pNR+lL4D7 YkYre/xRuB3Pq9kcqFmnZ6oDD87TY+Q6hxK7WpgyAnb7b+hLXO+9XrT5mFdnb/rYkKpN erCt5uKVV9bHcs0kgt7ra5GP/dE8SCn7FprWJbp7pmxmbvk0n/VI7TffouL1E1bcgEaT H1jnmz7bsAe4xcRCzbpsD58gKlCLWBC82KaltDn5DvAkBg19nH13ZgnvNF7Yueh+APt4 s98EobZvGcsGVibpBK5MCCOu6A0Ch6mCy11g2OrzXzzw/ufyLYEJe3RcrPM9lGRcGeI9 QAMQ== 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=F3v2UY84qD184cV7yiHpISBxTsZmE1I0o4wNfRkmRoYWc3A6W5HTlnuBLXZi5oVZl9 /5rO/RxMI+GM7nRZX8h7dAI/PL6QPCBSme9pSsl/X0TIyuNb32q3w+kVm1u1bG1Y3wNu xY5ktN5uTz/tyTHtvd2G52GdMkj+IwBg4bzOXygVdcD4c3AVtBEtG7QODIXwp2HgCXrc zJaPWngC0hrSe10BdtI6eB4fTG1cBgPulKsJ9zaLPq19G55m+6cpAJwYmD9vCs2P2Hez v88gbsE6mEnRx57tOSEfzTG0bthOF85LHAl+llTyAgpunIwXQAhLLp0B6P2i5A4NkcRV Jhjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Q8NpzZsn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id fi26-20020a056a00399a00b0068e3f550763si2578736pfb.101.2023.11.01.15.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:48:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Q8NpzZsn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id A1B768053B1D; Wed, 1 Nov 2023 15:48:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347154AbjKAWsT (ORCPT <rfc822;heyuhang3455@gmail.com> + 35 others); Wed, 1 Nov 2023 18:48:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346931AbjKAWsS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 1 Nov 2023 18:48:18 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C4F121 for <linux-kernel@vger.kernel.org>; Wed, 1 Nov 2023 15:48:15 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3b2e330033fso194821b6e.3 for <linux-kernel@vger.kernel.org>; Wed, 01 Nov 2023 15:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698878895; x=1699483695; 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=Q8NpzZsnzm+e7dGuWHEv3MoqJEjTrDteUl3eUVNlhKi8B3WmLYjcuEydrzmLJ/g8M/ vT/4V4GrYph93j2U9ZklIP4fGvcJtroRnvqMiqPwtUIy7uKACxtWCroFXEHQUmnkB4Jp IfMPxIMZ7Gb5roBXLO9w/gUu/p3JCkExaZKLgVvXxVC8F2zf8/bX7/YlwLdSeGY1/sPY 5WDsXdUwLX4xY0f3kiYecwpu/zpofU9QF4R8CrMnc54KWp9qAy1FFQUqgajIWY9WIRU9 rB+O6M870utoRGvFjnL1VEXfM0fapnFzGJzKqwpT11Whb+1lT5J+MLl/GLDKWmo5XwdU FIeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698878895; x=1699483695; 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=XDmcs6PuxsbP2Vy7Au60gB6NKPueoly4QcDSp/MjErsZDhUoA+5bMKw50r9dm/IvtB aOdBowvRUlmdfy1vzsqYwI03rulHZqND/fAMP0wl3dF0/7q4HTTrZhA50hHJDRS6auG4 FdWL6fWaK/qBLSePpq2OitDDFhhZVizTgbQ3YskjbLocDZMCf5yjMPm2y5ctJI2nEHqb u5+uT+1nLuRLAH+dBXbbAZg3ZZ4B70UeS3NfahrzAEtaCiPyIIrrWjf3wjLQuqQbLbZe KVPjF98bBZzbFnxbBNYYsPHxPTH1XK43PXHbvjjlzBGA4VEtP+OwcOk4mD2/xQHJDz2c rMpA== X-Gm-Message-State: AOJu0YzbGUt8Y6ainqmm08HuoMTLdXqoUVAIq72JFChmTqXpNBEv+TYW Y/XblqqS2GAMhuqda1g++PvhpQ== X-Received: by 2002:a05:6808:1b20:b0:3a1:dfa0:7e18 with SMTP id bx32-20020a0568081b2000b003a1dfa07e18mr21827450oib.25.1698878895176; Wed, 01 Nov 2023 15:48:15 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id be24-20020a056808219800b003b274008e46sm376580oib.0.2023.11.01.15.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:48:14 -0700 (PDT) From: Charlie Jenkins <charlie@rivosinc.com> Date: Wed, 01 Nov 2023 15:48:11 -0700 Subject: [PATCH v10 1/5] asm-generic: Improve csum_fold MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231101-optimize_checksum-v10-1-a498577bb969@rivosinc.com> References: <20231101-optimize_checksum-v10-0-a498577bb969@rivosinc.com> In-Reply-To: <20231101-optimize_checksum-v10-0-a498577bb969@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>, Xiao Wang <xiao.w.wang@intel.com>, Evan Green <evan@rivosinc.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,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 fry.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 (fry.vger.email [0.0.0.0]); Wed, 01 Nov 2023 15:48:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781403654922928263 X-GMAIL-MSGID: 1781403654922928263 |
Series | riscv: Add fine-tuned checksum functions | |
Commit Message
Charlie Jenkins
Nov. 1, 2023, 10:48 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 | 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 <linux/bitops.h> + /* * 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