From patchwork Wed Dec 20 23:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13500796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 283B1C46CD8 for ; Wed, 20 Dec 2023 23:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DB3/T/t0FM/jPoLM60N26bZS+7GupNpWMkbWoDfAez4=; b=DS0JMj++mCxi5h ZB0R4TJbMZWq2v3zZ7sVhS5r5sPwdoZQ9akva3RUK8DTpeSzZbPL3Smfc197ou8QOdapyD/mFKPqT K7kHxCpM55VMS7YKMjgCBl2zqMrujUyDnsF/UieMQcirlWmstRePQE3UrD/vuyqKWBl6wAWApz2j/ +zQgWQdxlJ2KO03p/bHIAOt6lQ9Aknav/JOUkZXYjMgMVwXyQ6hZ0zIOFGaAB9bvMUegYfOzKNfg+ dgQJ1zwCMqmA41zfVDtIpFhwwXeRM/MH+aAiculpemoGXaA3KLkIgT/z7X/hH9+ID7xJs/wbSR9rp QbVFdIL0ufX95gBvGRDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rG68J-001GWL-2u; Wed, 20 Dec 2023 23:37:47 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rG68H-001GVA-20 for linux-riscv@lists.infradead.org; Wed, 20 Dec 2023 23:37:46 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1f066fc2a2aso80524fac.0 for ; Wed, 20 Dec 2023 15:37:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703115463; x=1703720263; darn=lists.infradead.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=AouF0jJAIfkw//q+jF0haJYVNaVcx6d5tRGbFG19ua9Mn0a56sVUOfxGMoyB7PormG rKJjbvR9HM/QOPfhJZ6U0GVyldPpewazKRkxrLqqlQIYyIkyvG4fvAExan/IlHE6Uqu8 7EtNn574j5h87DyqamD3d/7bXpJ8ZX37AeNoa7jRFvVHUsffH9Eu0TCjFv0KocNiBKWp UoS0TlHAAtDlYPYHoWzUozdjk+6QJlhzPlLysz4IbaUQcdR0UisVPs//kVKRT2KdTQ0M xerxESLH/hqbaUfmk08W0ux0SbBmDsLMqmyiOgUzwVeQial0QC+po9uSOgRr36TEXST6 EfCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703115463; x=1703720263; 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=SC4YSAq+/nEs8k58nx2dN2s6G7tx1QPxX4y79QPrQ7lIo8XobY8HT+meZgWWAosaTo v56uuxUF9W5Ehopda9Pb8QsRtsAX1v7/Lr1sqP9N+y9WAjdY58I3OAx7xnGajY6O16P+ 1QDCC+RuPJNTdj/n8+AdabLMEd64NusZRW/cmGkvnfxYq/puubtp2vbHHXsmdJcxfsy2 sJkE2lriAAfncaKMbmSYLT0rKwEdvbfJVgtGDv04qSF8qTxOTUS5OV8CsozCB06ynaAa EJqkwT46MfTiilozpepxmI+a2EVpr29ZX7VNjixNCNH35a7uVyJNFC7ucEMm9p/KZTff 57rA== X-Gm-Message-State: AOJu0YwhyBnXXYQ3j1EctnMNPuDgqpZQC2G+DNESrCyfRuvQ3h5MvYc+ sat84meWT518YnH0w7K2Gqrtheo2Yr/VBc83UkQ= X-Google-Smtp-Source: AGHT+IGHNOnr8Aim6MPnEshwNbtCD3bmjs0I4LnJU8bFAnjzSSgQbv7AbRhjY0LeHpmhPl0ncXT31A== X-Received: by 2002:a05:6870:2406:b0:204:1640:871 with SMTP id n6-20020a056870240600b0020416400871mr540390oap.33.1703115463452; Wed, 20 Dec 2023 15:37:43 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id k5-20020a056830150500b006d87e38f91asm132834otp.56.2023.12.20.15.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 15:37:43 -0800 (PST) From: Charlie Jenkins Date: Wed, 20 Dec 2023 15:37:39 -0800 Subject: [PATCH v13 1/5] asm-generic: Improve csum_fold MIME-Version: 1.0 Message-Id: <20231220-optimize_checksum-v13-1-a73547e1cad8@rivosinc.com> References: <20231220-optimize_checksum-v13-0-a73547e1cad8@rivosinc.com> In-Reply-To: <20231220-optimize_checksum-v13-0-a73547e1cad8@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-Developer-Signature: v=1; a=ed25519-sha256; t=1703115460; l=1517; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=FtbING0Tg9V1myoJvDDTr8ph0mEbsa+4mbxe/ijBRBI=; b=xEtGAzIZTi0hssL5BrH22sQ/Z/VxvZj1DqZ2xODP/wyuVs3LLvuUYmbbKU/IWSuPywx+xI7Vd 9xXGrsLI9uQDaY3XpdcikT0hlogpiuc94AKvf2h4XD1x0mqkd4yUqVi X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_153745_656922_45592FF7 X-CRM114-Status: GOOD ( 10.54 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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