Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5025971rdb; Tue, 12 Dec 2023 17:18:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSIqgAA7uk12K1QtmeYAfHkOogtP5YAD9AdAR647LUGVAuXl8ITyUsFELxKbz34daESbB8 X-Received: by 2002:a05:6a20:3d01:b0:190:15a2:91ac with SMTP id y1-20020a056a203d0100b0019015a291acmr9651249pzi.27.1702430330380; Tue, 12 Dec 2023 17:18:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702430330; cv=none; d=google.com; s=arc-20160816; b=uUon46nQOVkzdJx2S+BrKfg2N9UpbI7JAPdo2NTdXlMl6yXHcsDVWLY8DmA8/joRJb Nm0rJm37EjwU/S4MWXUxXSWuLt5/CVs2D2xfmjRS6apji9w+RCf2I6WHBlKyudOxe69+ vmNprptBqZWQfaNlVg9YrJ7eRoAZ/fiFh825TjfaidTFl9qK3GaCabUoBo8xTk5N3zEh A3ynv9m7ZHFaIqhlhnzCMpM6lK0DT/HaioxxHh8CkvOvUU/X1XdwhK/JCIl9em8RMlLr nN4OxFj/HedZwb8EaVbjZMDL8QvVfpS0hqtskuU1Xxe6k+CM5AEejGpJWoqT+jN4U+Xj OelA== 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=SjqGV1Kb/P5zbkrU4HZj42U242Y4ucdb6cKzFhJu16E=; fh=WrYWo2NWGfDp1Q0L0IXsGjg4kDrSbEOOvn62+ocLtXY=; b=L7pZyrwJCyzVxwkg1bxt9puJEmIAogQKYXsUq8g2A/xg+BCkW+NdoQc+QJUz48wi3o AHmbilBOVU5QfyRjRsI5FG+Z3l5kUkWQLf6zQjQWFuaKCvYgX9rb3gQXOL5NnwQleNQC Jj39D5fuFIDCe+lOx21LqBO5Qhxx6Kbi2/+rAYTBSnaVkNIvFzjoTDpq2WxOlF2AGDPG ZZ1V0xBWEtiVvj3oXMVUmik+Gt0TjnFowjWP1tZRZUUT3U4CnYFbvir3QNWzpWiyjKCQ 2p3DM4v3Zo8ntzQ9CdorBg5Ag6TTOo01LKm039vugZqx/9NIC71roHp/pXzi5jbOgZtB JwDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TKw0O7f0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h7-20020a63e147000000b005c6763c0965si8780102pgk.58.2023.12.12.17.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 17:18:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=TKw0O7f0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 5D7D48092DA3; Tue, 12 Dec 2023 17:18:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378157AbjLMBSi (ORCPT + 99 others); Tue, 12 Dec 2023 20:18:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378152AbjLMBSh (ORCPT ); Tue, 12 Dec 2023 20:18:37 -0500 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76A45A5 for ; Tue, 12 Dec 2023 17:18:43 -0800 (PST) Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6d9e9b72ecfso3568859a34.3 for ; Tue, 12 Dec 2023 17:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702430323; x=1703035123; 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=TKw0O7f0+RjFtPX/EoJru2ueXfI3wGXJuk/UFASokbPUubJk+TWmZvm1U9PCvCjGFK rnXvaC+HPaLKdtFAdNyXL7jUWmob6gpbHef+9uZk2UmExJNwnuDxeITV/my6qedL/Y3Z vocryzYjOFH/UF4wLsou6Dw0QParbESABM42BdQwgcqGqO3mweeKdZTBb7R+Enrb+KQ4 pFY7S0guRKiN4ao0TfMrdrKuk7yapYIsVOOWIt4TjHrGXhosrZif5+/OLZ2y20OMzjYg UPv4pFjWuHpJzbilxw6loAolYVnw7d8GVTqZCTTUjj1tjBnTDufrp0k9XzD7l+07t/vK EATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702430323; x=1703035123; 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=UBmzEjWUrNrgXHZpxAsHSdrlIydMPnvACz7JlfFkRE04LENt+QX1Jp2cLiKoXBvIJA q3uxB9IJT/wTCTegWH35cPzeQD9qXNyVM7Pf/fq5ivkZp8j3proBiN2pwo8NeEHfe7bS uSfEvp6fFLopprPPEkjXYB9YhQHkmgAcNnCzHTmlHNQtOoTOM9YuWbOs3ADVnDW4fTnk 9iBjOyENTz5YSOffTcwjOTuatiO7XMKP10WrXnb2vFHuqi4Yinh9TtyEyZ0G+j5xhVZF gCSKEPR8o0TiTost0CUtYyUFmxASRBbmoeyZGKbo3OR1tI68/AF1yb1apfsx8Otg50Ma F2+Q== X-Gm-Message-State: AOJu0YzKhylNGbrvbY+tXYWNE3FloXnKI/nkq9jwsUfkMzBGIKiDbJh9 ydPXQA9MgRGrzpj969zKB91UQg== X-Received: by 2002:a05:6870:7f03:b0:1fa:1f04:e5f1 with SMTP id xa3-20020a0568707f0300b001fa1f04e5f1mr8946584oab.34.1702430322830; Tue, 12 Dec 2023 17:18:42 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id cy26-20020a056830699a00b006d9a339773csm172548otb.27.2023.12.12.17.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 17:18:42 -0800 (PST) From: Charlie Jenkins Date: Tue, 12 Dec 2023 17:18:38 -0800 Subject: [PATCH v12 1/5] asm-generic: Improve csum_fold MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231212-optimize_checksum-v12-1-419a4ba6d666@rivosinc.com> References: <20231212-optimize_checksum-v12-0-419a4ba6d666@rivosinc.com> In-Reply-To: <20231212-optimize_checksum-v12-0-419a4ba6d666@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=1702430319; l=1517; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=FtbING0Tg9V1myoJvDDTr8ph0mEbsa+4mbxe/ijBRBI=; b=dJ5wOJMjymK/YpMtfR6jvWWktdU7txotFEvdWb2yuqaSvy9+MkF/Rz3ht0deRKm8zz0sRZ+ph Cz3UO09uQmsCFOG5spy3fV0k06pu9P/54kSRkrQ0X38OTK6yYmeYPna X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 17:18:49 -0800 (PST) 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