Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp16963rdb; Mon, 4 Dec 2023 18:26:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkwzly+QCLUMmzMOC1JNgraxTko6erBx3TBWsOOkR2vQ1ACpW9a3oF7HWQ/p4hdGPFKEh5 X-Received: by 2002:a05:6a20:4326:b0:187:4e8c:ac5c with SMTP id h38-20020a056a20432600b001874e8cac5cmr1080301pzk.1.1701743185778; Mon, 04 Dec 2023 18:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743185; cv=none; d=google.com; s=arc-20160816; b=HmLqFMcKGRPhtBGJpYwBXF1C0o8w7U3maWUMYvUg+mHcdsA3UGOmOCiHFoV5GUeIKE kunPXl43r0jbKJ8xTP2Hqdmxhhs3P+Vyje6JZryBEQNWED4o4EjEil9pT1soEq96r9o4 hgVCmnMKxCEdiHY7tYZjVJaQm2rT+0GWZywA0RZoBS+LCd41bIPccoAFswxrfTvUHwCd EAe8aGrQcbC/woyJzad6hTB0D3/s+/+gQP4djk0JqAQ+TJE+ODq8z8ta1f/HVEHzxL/f CMGpHbYQwT6UFNpA72ROyFNL02BnOUCvDEIJD08icgFFheU9bC1cLzF/tF5tJQtC5oks HVPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Lz9jDx1K1J1PVs+5ELGTz3x5GcPqr4KZv94HVfgzNvM=; fh=DgGXwGbnyiv1Rvt/NkXbEKOXDvWVLBCb4IpCdacEJoI=; b=CWB7DBskGJ6CiCHnqYFpgFV+RLlO3jX0bjNc3PvV2ooaaSCMUsnMiqJedxWk5Kcq+2 Fx+bqXAZf+jV6arqqUCtSxLkkAE7IpnDYYlFxFw6/qVvfdIS17AQTMvhrw3bUShlqvnN DDeax5yIIxLhj6jhIwtWlgYD8/uplIZWbHu/pIxM7dfkeOuifZtbl0cDTCMAaJ8CWf5V efqNUQ4wrEe1ML4Rho53u/mXsuMHZzELkzn/LpDrR0AqkhqJVH7KJDlNVvsalVbdLK5A K9pt+ugUI1qE3FrLLCI30w6TqW6az2fKMQMsIz42l/b9Mh2vh9dmuSJY9eqpcBkqjx7m t0JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=UJDauNpR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id b7-20020a655cc7000000b005c6034ba3f4si8915353pgt.419.2023.12.04.18.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:26:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=UJDauNpR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 705C5807D401; Mon, 4 Dec 2023 18:25:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346400AbjLECYm (ORCPT + 99 others); Mon, 4 Dec 2023 21:24:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344040AbjLECYU (ORCPT ); Mon, 4 Dec 2023 21:24:20 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F14E3134; Mon, 4 Dec 2023 18:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Lz9jDx1K1J1PVs+5ELGTz3x5GcPqr4KZv94HVfgzNvM=; b=UJDauNpRs2sWRFoqxzYw4pL6kX kvCaUzHAkNfC9Xk2cC4LSbtif0CXS9TFXcA1qBHhoEXGpDQaALJu8QLQh2R0JclzfpfMYvz4BQVbm Vb5plQmEVC6PzpbB16Qdnf2xzresMHr8kppWJpbGbVNjXPv8OyPuXagNLk2OFDSoZ6Hv417zHn3TT /lzijk8PybhTEqV4023qhQoPgKWI7Yo4hHNg0aZRyJvVMZITEOOQLSf9Z3yy+1VfhH/2aK2ljyqJv I0pmXBHrlD/1TJ63VFrrVFBf2zPhNOyUznkbY8dNxqIIZxd+TbhYKF45TC21Sku0XjkffGP3ljHbj Kz13T9ow==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1rAL6l-00793x-14; Tue, 05 Dec 2023 02:24:23 +0000 From: Al Viro To: linux-arch@vger.kernel.org Cc: gus Gusenleitner Klaus , Al Viro , Thomas Gleixner , lkml , Ingo Molnar , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "David S. Miller" , "dsahern@kernel.org" , "kuba@kernel.org" , Paolo Abeni , Eric Dumazet Subject: [PATCH v2 15/18] x86: optimized csum_add() is the same for 32bit and 64bit Date: Tue, 5 Dec 2023 02:24:15 +0000 Message-Id: <20231205022418.1703007-24-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231205022418.1703007-1-viro@zeniv.linux.org.uk> References: <20231205022100.GB1674809@ZenIV> <20231205022418.1703007-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro 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,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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:25:47 -0800 (PST) ... and when gcc-8 becomes a requirement, we could simply switch to generic version. Signed-off-by: Al Viro --- arch/x86/include/asm/checksum.h | 18 ++++++++++++++++++ arch/x86/include/asm/checksum_64.h | 16 ---------------- arch/x86/um/asm/checksum.h | 17 +++++++++++++++++ arch/x86/um/asm/checksum_64.h | 9 --------- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/arch/x86/include/asm/checksum.h b/arch/x86/include/asm/checksum.h index c66fa797703a..5c0a730c7316 100644 --- a/arch/x86/include/asm/checksum.h +++ b/arch/x86/include/asm/checksum.h @@ -1,6 +1,24 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef _ASM_X86_CHECKSUM_H #define _ASM_X86_CHECKSUM_H + +static inline unsigned add32_with_carry(unsigned a, unsigned b) +{ + asm("addl %2,%0\n\t" + "adcl $0,%0" + : "=r" (a) + : "0" (a), "rm" (b)); + return a; +} + +/* note: with gcc-8 or later generic csum_add() yields the same code */ +#define HAVE_ARCH_CSUM_ADD +static inline __wsum csum_add(__wsum csum, __wsum addend) +{ + return (__force __wsum)add32_with_carry((__force unsigned)csum, + (__force unsigned)addend); +} + #ifdef CONFIG_GENERIC_CSUM # include #else diff --git a/arch/x86/include/asm/checksum_64.h b/arch/x86/include/asm/checksum_64.h index e225a12cec68..c86db605c0fd 100644 --- a/arch/x86/include/asm/checksum_64.h +++ b/arch/x86/include/asm/checksum_64.h @@ -52,20 +52,4 @@ extern __sum16 csum_ipv6_magic(const struct in6_addr *saddr, const struct in6_addr *daddr, __u32 len, __u8 proto, __wsum sum); -static inline unsigned add32_with_carry(unsigned a, unsigned b) -{ - asm("addl %2,%0\n\t" - "adcl $0,%0" - : "=r" (a) - : "0" (a), "rm" (b)); - return a; -} - -#define HAVE_ARCH_CSUM_ADD -static inline __wsum csum_add(__wsum csum, __wsum addend) -{ - return (__force __wsum)add32_with_carry((__force unsigned)csum, - (__force unsigned)addend); -} - #endif /* _ASM_X86_CHECKSUM_64_H */ diff --git a/arch/x86/um/asm/checksum.h b/arch/x86/um/asm/checksum.h index 9ef8ef4291f4..0986c19e5ff0 100644 --- a/arch/x86/um/asm/checksum.h +++ b/arch/x86/um/asm/checksum.h @@ -6,6 +6,23 @@ #include #include +static inline unsigned add32_with_carry(unsigned a, unsigned b) +{ + asm("addl %2,%0\n\t" + "adcl $0,%0" + : "=r" (a) + : "0" (a), "rm" (b)); + return a; +} + +/* note: with gcc-8 or later generic csum_add() yields the same code */ +#define HAVE_ARCH_CSUM_ADD +static inline __wsum csum_add(__wsum csum, __wsum addend) +{ + return (__force __wsum)add32_with_carry((__force unsigned)csum, + (__force unsigned)addend); +} + /* * computes the checksum of a memory block at buff, length len, * and adds in "sum" (32-bit) diff --git a/arch/x86/um/asm/checksum_64.h b/arch/x86/um/asm/checksum_64.h index fd1ab07e4a4c..17228e4c26b6 100644 --- a/arch/x86/um/asm/checksum_64.h +++ b/arch/x86/um/asm/checksum_64.h @@ -7,13 +7,4 @@ #define _HAVE_IP_COMPUTE_CSUM -static inline unsigned add32_with_carry(unsigned a, unsigned b) -{ - asm("addl %2,%0\n\t" - "adcl $0,%0" - : "=r" (a) - : "0" (a), "r" (b)); - return a; -} - #endif -- 2.39.2