Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp28389rdb; Wed, 1 Nov 2023 15:48:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5OdP+VluQu+B5S0X4sVu03vXNxleRNtDjxDE/rMNcehoG3U9ZTm+1GwF5PghpIRtJW5di X-Received: by 2002:a05:6a20:3943:b0:181:8654:826c with SMTP id r3-20020a056a20394300b001818654826cmr974042pzg.8.1698878930200; Wed, 01 Nov 2023 15:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698878930; cv=none; d=google.com; s=arc-20160816; b=KVBX3MCnZ/Ims9rcsXVjZJQKwPxXrQ8CpqmFM/cAVJb819m766DFnxCot1MwITJZh2 +Ca+ylTMSrLJUgbm6ufKyUZEhjT9D99uxMc3vK2lJv750EQANCnn/jcIL6VTZE0KkV6Q +xfTMN1zf9ydeCzFpdwBXxPATZ9VK0WLyissRknpAHh4H2DXXeRRm3uk4Q7bqy8mUoAW KjuJS5qyGAbRW1/Nm8eKF1b+PxMRCaDvPLCpl10zZ4kjuGov6zpZT4QlECupk6y/lJEc 9z0P5+m+oslrv7+Ac0TadFUZvE/THzVseRctrYX4FkEGE4ErSoiJf000lWmyr4yDaV1s QN2w== 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 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t29-20020a056a00139d00b006b7d62ed165si2690419pfg.94.2023.11.01.15.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 15:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; 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 2620:137:e000::3:5 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 94D5880C255A; Wed, 1 Nov 2023 15:48:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346547AbjKAWsT (ORCPT + 99 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 ); 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 ; Wed, 1 Nov 2023 15:48:15 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3b2e330033fso194821b6e.3 for ; 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 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 , 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]); Wed, 01 Nov 2023 15:48:40 -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.34.1