Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4785921rdb; Fri, 15 Sep 2023 12:09:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPQ0cmK6Vi3/wGsFcIezVLx3zC5wYBHgXqgyYou69rENkajPyQZKuuLBekGfJiH/UrK631 X-Received: by 2002:a05:6a20:1608:b0:15a:7d2:a418 with SMTP id l8-20020a056a20160800b0015a07d2a418mr3092778pzj.19.1694804996928; Fri, 15 Sep 2023 12:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694804996; cv=none; d=google.com; s=arc-20160816; b=iz4Q0kPhesP1fM/ZigNCMxCLTBYom4Q8+dvJGxBiTZ8XRopQQF2cvqixpRYaDy7rR5 TUi1OarCZEEgXZJteCFgCfU7W1ig3o11vciqmAbZ9BMvt0lzryGX2Fff1yX8MF4KXnUR OHXrKiecwPJtKRpOuh1cPnL81J6qqZfJU2SsrOUdU2NlVym6Bqmh+ePENQd9nDelO1aF o1a+un6myFeq69Q1hSOaHWYDWrbGvUb+vdC4ncGRiN+wQEMniyrOAya65fu6VRa5Peii 8LNToGpZQ/ClK/Y9Eeh169YyL81exeQWkwPH7DvgMKE8OtP1+uSePBwV+Jmreqhc2vAy xu+w== 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=bFaSlC1Eanb+aGEVXbnD8fQMHZ9ukouqu1oCkaPSAho=; fh=Y565EP4XCbbHzyjsLQMNVA5sHkqrC9GPqaO5xfn/wHs=; b=taBTuis38GnU2WRATEQViFoz6xabuaEOAkEIT0hhQoexUrDjw9JKtXIh2UcZPt980X R2Hn5TA0AafqRdKArhcxfActldExMbfjz6LtbIuUPe1FsxpdKzNhVq545i239J62GVFA +9h8fPdPYRCR6Aq7fCQr6WltVES89HOCiSVb/FRZgBfIsJ+kegWeZk/PUQ8PW8t4rN/d vr2b9p6T8KoYwrVwTcsi1xvrx+nTi653YB0TbTUZmQ6hTCJZAWt93R5YmjKt61ERBzoi gbUA1c3n86ygIUXmhW9k87puyk0iErqwgf26Ou4AagvT0sNdOqwP3pCGI6e6TOLhPu9D MDUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AMqGV4LW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id f22-20020aa782d6000000b0068bc3b540b0si3501817pfn.390.2023.09.15.12.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AMqGV4LW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 5398E8377277; Fri, 15 Sep 2023 10:03:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234978AbjIORDA (ORCPT + 99 others); Fri, 15 Sep 2023 13:03:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235452AbjIORCh (ORCPT ); Fri, 15 Sep 2023 13:02:37 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B52FF2703 for ; Fri, 15 Sep 2023 10:02:31 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bf1935f6c2so17526365ad.1 for ; Fri, 15 Sep 2023 10:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694797351; x=1695402151; 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=bFaSlC1Eanb+aGEVXbnD8fQMHZ9ukouqu1oCkaPSAho=; b=AMqGV4LWYluMA2CXitPG5LrXIL/L6LC7fUq3EO4giRqbZN018okEFAaIYpemNHDDBY WmBl+BUrU3/6lqgqGvakoUB1V87JzbpqtyKGysUVwDJmJi7W0wq0LyNqXViFSty478oB tdgh8cSNkqSsbO3zT8h3tlyPvR1rAc+L1OyoFgae2kHF7LwaGYdci815ZMYt98lG/RY7 Kq7a08DJZM0Ea6gATUq2tJ1w3Rq6ojpOf7mNw+o7egSfGyWIKN5FxJA4eEf9ngdsSUge 060tzEBP4/t/lche3fdU1PzqekIgK9OaH+Y7UfoeSnP9LV34E9S/wBqpe1lvMD5wdfIc i+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694797351; x=1695402151; 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=bFaSlC1Eanb+aGEVXbnD8fQMHZ9ukouqu1oCkaPSAho=; b=DDTjQ9/jnKkFZ9OnmJycHGnpZtfAigtmlUex9duObADmt+5xnxNyPCAFT2G3UhLYuU TGnLOyrV6yLlsSlRZsG6MoAfv614DzIyn9P2o+OA/0DJC6WCq5GSOos8CgXgIis7dSBy yP5C0TX3kJo8LMP/w9/ZNC7PCflUCNuS56EcqGZFa4mtljbzqGaJSx1v7/AJsvk0Rn95 CeiM+mKriWv+U0W9bwvGVgp/8ieEj08hfUXhM9TGb276CqXpJZBf2fGUBXE/nBkS8XZ/ wE/ctzaXrwhwrFNY26PeGIK5IAn2y9nsdCttZeF+4H7h2KyXHozk8WFFuJK4fvXH49mn KXtA== X-Gm-Message-State: AOJu0YzkazsMS0b1vHxgYX5Nls9LHk9oU1V0wlu/PxfFbSZOsZXH3uuS edO/SNx+sLujgJVuklmWZw1tgA== X-Received: by 2002:a17:902:dacb:b0:1c0:bcbc:d67 with SMTP id q11-20020a170902dacb00b001c0bcbc0d67mr8332563plx.22.1694797351144; Fri, 15 Sep 2023 10:02:31 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id g22-20020a1709029f9600b001c44c8d857esm34299plq.120.2023.09.15.10.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:02:30 -0700 (PDT) From: Charlie Jenkins Date: Fri, 15 Sep 2023 10:01:17 -0700 Subject: [PATCH v6 1/4] asm-generic: Improve csum_fold MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230915-optimize_checksum-v6-1-14a6cf61c618@rivosinc.com> References: <20230915-optimize_checksum-v6-0-14a6cf61c618@rivosinc.com> In-Reply-To: <20230915-optimize_checksum-v6-0-14a6cf61c618@rivosinc.com> To: Charlie Jenkins , Palmer Dabbelt , Conor Dooley , Samuel Holland , David Laight , 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=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 10:03:31 -0700 (PDT) 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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/asm-generic/checksum.h b/include/asm-generic/checksum.h index 43e18db89c14..37f5ec70ac93 100644 --- a/include/asm-generic/checksum.h +++ b/include/asm-generic/checksum.h @@ -31,9 +31,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.42.0