From patchwork Wed Dec 27 17:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 183527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1571384dyb; Wed, 27 Dec 2023 09:38:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9Nn6+I+Y7VSOcccopnYjR+OrjT56OGLHmoRY7nNUhJZ1ghWag8QASXTDFnXkZT75agah6 X-Received: by 2002:a05:620a:198f:b0:77f:32c6:c6b8 with SMTP id bm15-20020a05620a198f00b0077f32c6c6b8mr12538301qkb.112.1703698730416; Wed, 27 Dec 2023 09:38:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703698730; cv=none; d=google.com; s=arc-20160816; b=iW9ebRUrip6AWT/HMiAHxqsYdTNA2MWAgqDrIcdUzD9GBblPKXQsiKt6tSuYYc5BJV FZhca3of4cj8JZuJELtgXyulKovwwEe98ZfsqcM1hbOkbHoI/YTuUtBK+3sZtVSsDI6s x3FABJ7shFkJVEWrdy9mXcm4LuofZCy8aEYgfJL1DIPMtxSpMJvOy4E1K4sjpN8xYjTS fHdQ3y9/zImPlMZyC8rqiIozXEgOzMEWX7NzloZOpQRBtZST2TP0dlZacyUmT67zfGcw IKnt6z2fVCQciARk6rZEdzrFr2cIWs5gKL+j9FwM/iYQ/4/neLen2x3fKkkDZ5u7bmr7 /d5g== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12177-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ov8-20020a05620a628800b007815fe669aesi1774844qkn.50.2023.12.27.09.38.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 09:38:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12177-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12177-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 38C801C2248C for ; Wed, 27 Dec 2023 17:38:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF56F4777C; Wed, 27 Dec 2023 17:38:21 +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 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= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786457599662844910 X-GMAIL-MSGID: 1786457599662844910 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