From patchwork Wed Nov 1 00:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 160385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp103158vqx; Tue, 31 Oct 2023 17:19:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZY+QB5XaTEhNKO7lr+k9SUPsmzb7aO4zPppgFxHrqo6z+Nzk3rNLPc/7M7EGAj33rjskf X-Received: by 2002:a05:6870:239a:b0:1bf:77e2:95cc with SMTP id e26-20020a056870239a00b001bf77e295ccmr17141813oap.17.1698797963966; Tue, 31 Oct 2023 17:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698797963; cv=none; d=google.com; s=arc-20160816; b=TfF9ebJ60m6oTAUJWZ1B/p01TPEPBX1PwJuuSTa5Ed6ri3iI1EtOogbKwKI6GIBhFb Ur3mB8XGcPQ6Jc6xqNORMdOJusbdAzqUzyRI7E4SzmhB5AysVIpSzutvVD0JgVL6bTp9 XQBqDA5JS+/JV4E0NPq1uL6dGy7eGfrE7BzDteBvQ6fMCogfJ6/egP/DIU5TM57QGgt0 sX3J7qlTK+I1AUakvBXF4mltHGXhl94waYR2v1gsk4Cox99LhJG+/7SP+N3H2iAxN6Ew McdoL1AhKO5yuznG1k1/wt+Ek+EUKxXUlluUpQtKrVsyhfIulMl28iUplpEcpi8fudQq EgKA== 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=iQdBfGrxgT0Dp0rMc/ALsHZTaxuvWcxH/0MUqWK8IuU=; fh=WrYWo2NWGfDp1Q0L0IXsGjg4kDrSbEOOvn62+ocLtXY=; b=EUe/0Q7MAPcm8ze3blHmr3/nY2lmsxKv2oR3OcztNkvu8Nz/b9Pus0fTzPiCZyvthE UMrDtog4hSS0pF5douDkjPb3kCdrrnjVVLoVqVX0lwi4IU3IOYAo+bE2kZJOwdgMO2Dx 0q7j2SLfykoi/83EW0FQUNCrnYimrs2LvkwF2LR5Qp2R83ci++zR000duTPklRCfxq11 sjQz9JUw7fkvZfgz/ywzeEhwaBOYynmU4g8EeHxg8I7Uarmwjo/LzV3CXXKvyXL3M6yj onUrU0oZ5fNTXSRW0mQ7WVvk9I5Z/iwKf8f7YZ2VtgGGLl2kcgq1UmEIXreJrO0/A9o2 iqaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=lHahO2sb; 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 bq5-20020a056a02044500b005b8f24e6526si2013076pgb.234.2023.10.31.17.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 17:19:23 -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=lHahO2sb; 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 21F0C8116E6B; Tue, 31 Oct 2023 17:19:23 -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 S1345100AbjKAATQ (ORCPT + 34 others); Tue, 31 Oct 2023 20:19:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbjKAATM (ORCPT ); Tue, 31 Oct 2023 20:19:12 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EDF1F5 for ; Tue, 31 Oct 2023 17:19:10 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b2e22f1937so3375857b6e.1 for ; Tue, 31 Oct 2023 17:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698797950; x=1699402750; 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=iQdBfGrxgT0Dp0rMc/ALsHZTaxuvWcxH/0MUqWK8IuU=; b=lHahO2sbfNBOA8ej35WphXmr1UmF+eEj5loUBcT0VNfxHWgJe3P5Yfkf+9H3U4A72U dXO+Q+ho5u0Ckul022CtSXnTqmOT2uZP6c4Nf/cGJXY+JBImtkvexciVRzPwesW0mFkT AYqqmpAUgDxqCBFk3cl+ltHghe2+v4C4Anbeof8maMkPnDQ/vDz2kwr3ef8KQeh6sp4f MjYotKiWTYASG4xGp3YJBSqWL78X6uOGMA+xgR/Pt3WCkb4Y4VLVA0ZqCgF8KDymnaUy J3Ng9xyA2t6U3ZksCwZqYyIukP7mClhMwkbwsI4icJYJBVWAVr2mclucBPpmhiyjh/ZS G12A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698797950; x=1699402750; 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=iQdBfGrxgT0Dp0rMc/ALsHZTaxuvWcxH/0MUqWK8IuU=; b=W30xrDweHtJPFj487uWJjrr1oOKEui9JlURkuolEyhxXU2He0hHWtT8MqM0E/v91ex 066wieie3FlH9s+rzuBTVoWV7+12CGRoOYlBjykpm9iP7twnlZUkfc/oCJpnKaPCKYq8 25mH53mppFeQSNqVi4i9gJO92ka+Ln9qbHxs4i+etatBPyPnp2fo3WsFBEEzidTwwH6v fjVxajmoMs6ieAEmLoIfRce7efRFYSA3Vo+imQT4FJ4q1lE6xY1fyxmPBTi3UD6TSfQi UfeawuT1YLfSlOuospg34M4vK+38rgNnn8O1G2l3lwO6Eg5HwCjF+Tb+bd6t6z1d7Gl8 PEyA== X-Gm-Message-State: AOJu0YzfROCFRLYbCcFrVTHF7edtzI7wBoNt4LOiyBq/kA+QtF5/aSs7 lZvVEc6lYgxfC+/V/TdBNQInTw== X-Received: by 2002:a05:6808:9b6:b0:3b2:ef9c:d1b1 with SMTP id e22-20020a05680809b600b003b2ef9cd1b1mr13418380oig.6.1698797949914; Tue, 31 Oct 2023 17:19:09 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id n21-20020aca2415000000b003af638fd8e4sm65309oic.55.2023.10.31.17.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 17:19:09 -0700 (PDT) From: Charlie Jenkins Date: Tue, 31 Oct 2023 17:18:51 -0700 Subject: [PATCH v9 1/5] asm-generic: Improve csum_fold MIME-Version: 1.0 Message-Id: <20231031-optimize_checksum-v9-1-ea018e69b229@rivosinc.com> References: <20231031-optimize_checksum-v9-0-ea018e69b229@rivosinc.com> In-Reply-To: <20231031-optimize_checksum-v9-0-ea018e69b229@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-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, 31 Oct 2023 17:19:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781318773702908455 X-GMAIL-MSGID: 1781318773702908455 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