From patchwork Fri Sep 15 03:49:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 140127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp790640vqi; Thu, 14 Sep 2023 21:04:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVnpkBQXO9g74vWsnKZ7HZ2bty+YtRU4NYtKSRneFoZas9AwSj7a+moGz3+VCpQBp+gFpQ X-Received: by 2002:a17:902:e551:b0:1c3:2c2f:1132 with SMTP id n17-20020a170902e55100b001c32c2f1132mr599606plf.54.1694750645302; Thu, 14 Sep 2023 21:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694750645; cv=none; d=google.com; s=arc-20160816; b=wUfNQxubCG9WDSdipj6pBeTGxpZM5GawB6hIp4YVUtoFZ4TkRNsPuIKt38kpFbnSwv hxi8x3M2b59FI+8wZZFcMInAhUXzhpvzOEH8kO+zEeIaU699Y1yUaBop/5dMRij37MH9 CTAHrYrWVv3GfDDHh8dEVXTGyOLjKd0xz7o62b/vC79Xe1oPJY81AVmYhG9qvmbrjdsh 2SJJECjna6t606JBMLP02slG25CqJocBogWc0SHquMIJhRjnRgN54G79JUoXrHV1258u w1z0y6uza3feaX1uQkvCypzHjlO21uWwILXoTeoad1G3ic3u6Jox1aT8FN7GwgwE7JDk hGEw== 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=hYrxQXlYsxlbzxTi4wO/BXPj8sXNJd30qJO9BW1+NbI=; fh=gOzr2J2/AaC/1DdOEiJ/vMVIpQG7VS7WGUZu6JUmCr4=; b=o6QQWFNsiSk1eqmk9xfq1puSRrURFw/2/TsbdlqDo5rcFiDpFZqdDWNtGHLn0G5M8k J1iIvazN+Ik0Lrq8JzPp4xHkl/vSW8EXJFLnd4wd42PW60D65b10HZM1igiHUL0QZhXB Z/0rKAKcr+2m7F8O6vKOGbfR3s8k46lczy/gonesc2TiNpfV43SqlhhyyrAeLWPmxfPM /s607655yklhNolpdlbsc5HmIg7XG7VHqpTKlDJPBmFmevtgh1VKZb0JvHZWo4+VzWgd EkDM8GuKYvHYjBfYvwZdzZ5HedoxqOOkw9yNMzADiab3vfOiLf4B3SJlvJqt5JTB3v0Q CFqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=w9pW4kwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d3-20020a170902f14300b001b8a6bf59cfsi2603692plb.378.2023.09.14.21.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 21:04:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=w9pW4kwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 489B481DC7BC; Thu, 14 Sep 2023 20:49:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbjIODtt (ORCPT + 33 others); Thu, 14 Sep 2023 23:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbjIODtr (ORCPT ); Thu, 14 Sep 2023 23:49:47 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4304A196 for ; Thu, 14 Sep 2023 20:49:43 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-26fc9e49859so1404619a91.0 for ; Thu, 14 Sep 2023 20:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694749782; x=1695354582; 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=hYrxQXlYsxlbzxTi4wO/BXPj8sXNJd30qJO9BW1+NbI=; b=w9pW4kwXoRnN24mTCa23KvD2uArcbmnnkwJJTIat4sFVVPLEZIV/0ZERLBTnDX73TN The3+O0bJUyLDiTkDVtNBBetlV4Wq3zIytFOV2U1QceS79u1NR2GbkzfgahSlGFvjcNU 5WfcH60q8TveMDa1fJz8vVwGQqhtyasICgByFp8K/Wo7yV5uvQh3Kla36zEUdWc6+sGs CCnY3ivoFtoqmwK64GazD0rsPwgmwg3P4zrGDGl4vM8Ve5z+iCC2nXvbfHLbmoKjykX5 TaSrYUK4Aj448x36gQ4HWpqeuA6a7ELouuSyomDADJUx5H3Mbkqz/vYZ7BUxt2p4Ffgx ESbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694749782; x=1695354582; 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=hYrxQXlYsxlbzxTi4wO/BXPj8sXNJd30qJO9BW1+NbI=; b=lzkX0BIeiiBNmoW7kAcZmXqrcXJfVTjs+WMvbItMNgciB+mfF+A0I06U1Y6rssEDCX bB0OvnsUN5tDc4UijeGMXuCWM/mGWKBSzE8R71+TyqUk1msHNynd/WsOCwEcPkfksfFy ZlabSwCybAHiqh2D8vajPNfwH0i2DGtg9pCeMxiB2Z1qj+H3eIZQILTSF+t8KBpyGR/A N5+7CwDcejfBJzhHCTq8ha6npkoumTm45YvjSlCfDMq7+qHYWECeTh/MEAWvXltDMIuC AMTKTtIQi6wPs91xDVNMWJ8TZtMHFpczD1HCuPuhIEQdVcmVvAZPjenfYOYBxVwQEH0y No6A== X-Gm-Message-State: AOJu0YwmafJR2S+cs17t7L7gBPCixwlfLbLLbWTAtViulnnEY6Kedkd3 OAY6eJhq8scXQHLOckD70nUZpvIar8nGCjb04xg= X-Received: by 2002:a17:90a:c245:b0:268:3f6d:9751 with SMTP id d5-20020a17090ac24500b002683f6d9751mr416214pjx.23.1694749782539; Thu, 14 Sep 2023 20:49:42 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id g5-20020a17090adac500b002739282db53sm3881409pjx.32.2023.09.14.20.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 20:49:42 -0700 (PDT) From: Charlie Jenkins Date: Thu, 14 Sep 2023 20:49:37 -0700 Subject: [PATCH v5 1/4] asm-generic: Improve csum_fold MIME-Version: 1.0 Message-Id: <20230914-optimize_checksum-v5-1-c95b82a2757e@rivosinc.com> References: <20230914-optimize_checksum-v5-0-c95b82a2757e@rivosinc.com> In-Reply-To: <20230914-optimize_checksum-v5-0-c95b82a2757e@rivosinc.com> To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Paul Walmsley , Albert Ou X-Mailer: b4 0.12.3 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]); Thu, 14 Sep 2023 20:49:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777074853009020023 X-GMAIL-MSGID: 1777074853009020023 This csum_fold implementation introduced into arch/arc by Vineet Gupta is better than the default implementation on at least arc, x86, arm, and riscv. Using GCC trunk and compiling non-inlined version, this implementation has 41.6667%, 25%, 16.6667% fewer instructions on riscv64, x86-64, and arm64 respectively with -O3 optimization. Signed-off-by: Charlie Jenkins Reviewed-by: David Laight --- include/asm-generic/checksum.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h index 43e18db89c14..adab9ac4312c 100644 --- a/include/asm-generic/checksum.h +++ b/include/asm-generic/checksum.h @@ -30,10 +30,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)((~csum - ror32(csum, 16)) >> 16); } #endif