Received: by 2002:ac8:760c:0:b0:40f:fb00:664b with SMTP id t12csp916334qtq; Thu, 14 Sep 2023 22:17:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/F0xx9JpI1/sGf/hmQbBzbMXhczLpyfxabbdXmAzmEeNI0DgdoOVGUEKOT0rvBCcAAfix X-Received: by 2002:a05:6808:20a4:b0:3a7:a299:1203 with SMTP id s36-20020a05680820a400b003a7a2991203mr921080oiw.22.1694755041094; Thu, 14 Sep 2023 22:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694755041; cv=none; d=google.com; s=arc-20160816; b=rioSFYS2KI+T5Kxy66ZY7O3yETbTSLGgDbsr/pIYXfrHq+F+ZEjLmjS1G4r7iBoC10 QIptJHJTEAJW0X4DJryn/SYtc9S95M5LDbGrcROW1LOVFCOKhV5HoUmgWJEtBD0RfAQc hI8jADEQJiCI4Vm4FEyu/3PLPOybJjzTGtQzkTVy1GnYlGYKFy0NXRf34CGzEYSiYjR9 WToFs7VcK5tHWvkNOcAFyaoTcleyyr3vAzdtwwFV81SL51I08kCfI3dwGogPbvrTRGxC 5SUmLx+GqE5pcPlScDyrPRPkt59sQEGAnYlf8fOiAIap8MNL03RizfaVSpmj7U8XShYw fcxg== 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:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id e3-20020a636903000000b0056357813fc2si2548070pgc.183.2023.09.14.22.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 22:17:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; 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:4 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 howler.vger.email (Postfix) with ESMTP id 70D3782DC637; Thu, 14 Sep 2023 20:49:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231519AbjIODtt (ORCPT + 99 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 (howler.vger.email [0.0.0.0]); Thu, 14 Sep 2023 20:49:53 -0700 (PDT) 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 --- 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 -- 2.42.0