Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3512930rdb; Wed, 27 Dec 2023 09:38:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEODqdS+Gmq9sRRFZHefo4HCV0fA/uybcz0b42c7UMrH9PTpOujJ0152A0aI9aP/KG1O0qJ X-Received: by 2002:a05:6e02:2408:b0:35d:6121:3794 with SMTP id bs8-20020a056e02240800b0035d61213794mr16685539ilb.54.1703698712052; Wed, 27 Dec 2023 09:38:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703698712; cv=none; d=google.com; s=arc-20160816; b=pNNdqfndhnK50WhVBjYc3F8DucH6FORuVdzIoAlqU0/fWOlSO7tmeqvUyLffOONWJf 4loYF7g6BIiJrZoFImGku90FB8+GLqzkMpbkjXSWJz848nkEfBAI6MhTf2EITkzQv8og IwlnEQ5p6bdUn0ptXWOp14PEiTi8f+b8eqbgRxv1qmRniFXvCAEdH+2RdNhsfvBSkQpZ DAikwrsZP3p+4Cx8Tu7nSePW61h/7ouz+Hb7FS6Uq4PoGHZWWQIjeXTHzSCYFMUjy9ns sCo/B1bNRIgfeJeBA0Q5p1VtXnA5UAg+sC3XspdeWDLIZccmsOCwbNEeMd93KjOYY0fn 9z3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=SjqGV1Kb/P5zbkrU4HZj42U242Y4ucdb6cKzFhJu16E=; fh=/2pBhCeCxif4vz26VltnBSv5BVMDpayc9qNl8XVXCvk=; b=XP7ezR9SJndugwNbWGjsS/r6cCztdACrJD5iBQ5hjCwPVJbaZJdZot0w1PxXI7zNPP kv1RkJ8RFIb16QMkI1rIuFEYuB+1fYzulhpUJ2/7Ktu8jCy2Oe3/1IVgp6xvxUs78lDq M0rqy/mEnvdp+31wtC8FfGdceJSSJ+cqaajoTGBFVfS8rtNDB08qKVdl2eWFolB9MUcz 1/nIUSPXfnje/dAx8O0vznrJNoXPuLaGsPj8k+xKXKsBPQBJlby+i+8w04dZ3gCNJX9s s7HrooZpAh+HOadC25/h4SyN/irtrDbLZVY+lBEist4DCELSGVaBZe8SlYRJa7iqwGWb bSjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=yhj7MLO9; spf=pass (google.com: domain of linux-kernel+bounces-12177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12177-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l30-20020a63571e000000b00577475ee5f6si11203317pgb.618.2023.12.27.09.38.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 09:38:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=yhj7MLO9; spf=pass (google.com: domain of linux-kernel+bounces-12177-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12177-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7C68FB21E17 for ; Wed, 27 Dec 2023 17:38:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E007F46540; Wed, 27 Dec 2023 17:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="yhj7MLO9" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA26646524 for ; Wed, 27 Dec 2023 17:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6dbfdb41a63so1033620a34.0 for ; Wed, 27 Dec 2023 09:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703698696; x=1704303496; 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=SjqGV1Kb/P5zbkrU4HZj42U242Y4ucdb6cKzFhJu16E=; b=yhj7MLO9Z49Q5VMVFTNWdgbyvd3rwUksJZZS+bIxTx+cGTp0yLRURUCKYFG/7CpruH 3oBBHIPkoDMFGuGKsjYBobcq4gwfEF/OTmC1368T5qQlccrCMch0hwhtCxPJpiQsKFh2 blUIDGw1JUBw3CYLD5FZC6tU6HDyS/qp5l9KkgE5pTjEbpI2jXrMMVZrmE02Eh9lcT1g Z//aT0yacblpMw2q9o03E3TxP1GwMd/D54K4VxyEMgOkeNSEE+BeaUbXkChO4+uJrpHP t0dQECo9B9PqG5tcGObbbJ0sk/fKG7nuAOaUOUaHqXD7ecDUp7NrCsdjToOrT0tZh6hh LTRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703698696; x=1704303496; 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=SjqGV1Kb/P5zbkrU4HZj42U242Y4ucdb6cKzFhJu16E=; b=OP17LEd4lFpQvp//DQBZ7oM2QTxGlMw3KDo1XNSMl1RU/DdasZ5ZTMXy5osPOzYKQa BFjFmrnFDcj2ALke4edOzSFR4/pckObRxtvELphnngkxAbrmdYQ20xDJE25VPt7+u9tK EwR3GlneQ4Uir1aGUodmq5cIQsiO1pK/8nXY+IPDjwqi9TtsZ/mkMO+aT9jfBlSCtlWg DwHHmw7YgXtDxHF1UToVhydHEFtkLYIwYHpE4cxqKlrAI1Xux5fTEdH0FQt0FwwO4ukV fLmImDbY5qv7eNRQvfr574WiUmegGto6eNtsUbdmxJgLultIpfUmghU5K3NmfDwq9acf 44ig== X-Gm-Message-State: AOJu0YzFFTAIc4kHglovZgNcr2AMCNc34ZmV3EEA6eA5GJM6pVa3LuJZ v7wTTFw/b4dco3KDRU3gJKI+reOU/R6ybg== X-Received: by 2002:a05:6870:5313:b0:203:985a:d559 with SMTP id j19-20020a056870531300b00203985ad559mr12222142oan.23.1703698696650; Wed, 27 Dec 2023 09:38:16 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id rl15-20020a056871650f00b002049c207104sm1337173oab.27.2023.12.27.09.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 09:38:15 -0800 (PST) From: Charlie Jenkins Date: Wed, 27 Dec 2023 09:38:00 -0800 Subject: [PATCH v14 1/5] asm-generic: Improve csum_fold Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231227-optimize_checksum-v14-1-ddfd48016566@rivosinc.com> References: <20231227-optimize_checksum-v14-0-ddfd48016566@rivosinc.com> In-Reply-To: <20231227-optimize_checksum-v14-0-ddfd48016566@rivosinc.com> To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , Xiao Wang , Evan Green , Guo Ren , 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-Developer-Signature: v=1; a=ed25519-sha256; t=1703698692; l=1517; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=FtbING0Tg9V1myoJvDDTr8ph0mEbsa+4mbxe/ijBRBI=; b=EVQ2R0oDdrjYUCtjGIG7LtR556zWizaK9KP7EpvcICoCvv2FlTnhqyqWoF3f+c6pInR/9M0b7 MOvIb/8692VDNcd4u/I4PxPCe8+Rkmq1PqyHlRthW/n1TVwHLgqPb8o X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= 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.43.0