Article View: linux.kernel.netdev
Article #10683Re: [PATCH 0/2] arm64: csum: Add fused copy and Internet checksum
From: David Laight
Date: Tue, 03 Nov 2026 22:38
Date: Tue, 03 Nov 2026 22:38
113 lines
15969 bytes
15969 bytes
On Tue, 3 Nov 2026 16:47:29 +0100
Demian Shulhan <demyansh@gmail.com> wrote:
> > .L4:
> > ldr x1, [x0, x4]
> > adds x2, x2, x1
> > cinc x3, x3, cs # adc $0,%rxx on x86
> > adds x4, x4, 8
> > bne .L4
> Agreed, that is a nice loop for the sum-only case, one dependent op on
> the sum chain and no builtin needed.
> For the copy case I tried the same form on x86 (Zen 3, GCC 15, Clang
> 19-22, -O2) with a store added, against csum-copy_64.S, as posted it ran
> at 0.85x of the asm with GCC and 0.73-0.76x with Clang (which rewrites
> it into setb/adc), and ~0.8x unrolled 2x/4x - a bit slower than the
> posted 4-accumulator loop (0.88-0.95x).
I just added *(u64 *)(dest + count) = val to one of my loops.
gcc just replaces the 'add from memory' with mov/mov/add.
I'm now confused though, I seem to be getting different output from earlier.
With -Os (which I didn't think I was passing) clang is refusing to do the
'offset from end of buffer' loop.
With -O2 it bloats everything by unrolling 4 times and adding lots of
extra instructions.
(AFAICT the optimiser has a completely incorrect cpu model.)
If the compiler doesn't generate the expected code it is all pointless.
The xor parity code loop had to be in the asm block to stop the compiler
changing it to a much slower form.
For the checksum code I have managed to work out how many bytes/clock
the code was generating and getting it to (reasonably) match the expected
values.
But you have to use relatively short buffers to avoid D-cache effects.
David
>
> пн, 2 лист. 2026 р. о 17:14 David Laight <david.laight.linux@gmail.com> пише:
>
>
> >
> > On Mon, 2 Nov 2026 16:14:06 +0100
> > Demian Shulhan <demyansh@gmail.com> wrote:
> >
> > > > The scalar path seems like generic C code and not restricted to arm64,
> > > > curious how that performs against existing (e.g. x86) assembly
> > > > optimized implementation.
> > > Depends. I think __builtin_addcll() is needed to get roughly the same
> > > performance as the asm version. In my tests GCC on arm64 turns it
> > > into adds + cset instead of adcs like on x86.
> > > But I will look at it, thanks!
> >
> > The C version I posted earlier has the loop:
> > buf += count;
> > count = -count;
> > sum = carry = 0;
> > do {
> > val = *(u64 *)(buf + count);
> > sum += val;
> > carry += sum < val;
> > } while ((count += 8));
> >
> > for aarch64 you get:
> > .L4:
> > ldr x1, [x0, x4]
> > adds x2, x2, x1
> > cinc x3, x3, cs # adc $0,%rxx on x86
> > adds x4, x4, 8
> > bne .L4
> >
> > I suspect that is close to optimal - especially for fast cpu with
> > out of order execution.
> >
> > https://godbolt.org/z/eso79K7Wq
> >
> > David
> >
> > >
> > > пн, 2 лист. 2026 р. о 12:44 saeed bishara <saeed.bishara.os@gmail.com> пише:
> > > >
> > > > On Sun, Nov 1, 2026 at 3:34 PM Demian Shulhan <demyansh@gmail.com> wrote:
> > > > >
> > > > > I would prefer to keep only the scalar version of the fused copy+csum.
> > > > > It reads the data once instead of twice, and on real Armv9 hardware it
> > > > > cuts end-to-end cycles/byte for bulk TCP over WireGuard by 3-12%
> > > > > depending on the core (+6-8% throughput). It uses only general-purpose
> > > > > registers, so there is no FPSIMD state to save and it is safe in any
> > > > > context.
> > > > >
> > > > > If you are OK with the scalar path, I can send v2 with NEON dropped,
> > > > > the scalar path only, and the KUnit fix for the x86 zero-length case
> > > > > Jakub reported.
> > > > >
> > > > The scalar path seems like generic C code and not restricted to arm64,
> > > > curious how that performs against existing (e.g. x86) assembly
> > > > optimized implementation.
> > > > saeed
> >
Technical Details
Message-ID:
<20261103223846.5e6a1dfc@pumpkin>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356040-linux-kernel-netdev=dewy.ruReferences:
<20260927131838.6774-1-demyansh@gmail.com> <20260927184414.6c0c8867@pumpkin> <CAOLeWCt+yFs29yWg6DrRH42HD9ConLgTEbW=wMKtEoTW5ROHvw@mail.gmail.com> <CAHfVqdX4AmqXs_oD5OCjU8R5ts=98=RmgCmJ3D5gLyk=Xtrfkw@mail.gmail.com> <CAOLeWCu4NiedyXmoLwwnTvJitRwgg6PQq9LApO=k36ktN3-XWA@mail.gmail.com> <20261102161426.2403d308@pumpkin> <CAOLeWCviRtGMhGJQx3HHFQOze439576PQqr4tmvjGkMMfYfcog@mail.gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356040-linux-kernel-netdev=dewy.ru
From: david.laight.linux@gmail.com (David Laight)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 0/2] arm64: csum: Add fused copy and Internet checksum
Date: Tue, 3 Nov 2026 22:38:46 +0000
Organization: Usenet Network
Message-ID: <20261103223846.5e6a1dfc@pumpkin>
References: <20260927131838.6774-1-demyansh@gmail.com>
<20260927184414.6c0c8867@pumpkin>
<CAOLeWCt+yFs29yWg6DrRH42HD9ConLgTEbW=wMKtEoTW5ROHvw@mail.gmail.com>
<CAHfVqdX4AmqXs_oD5OCjU8R5ts=98=RmgCmJ3D5gLyk=Xtrfkw@mail.gmail.com>
<CAOLeWCu4NiedyXmoLwwnTvJitRwgg6PQq9LApO=k36ktN3-XWA@mail.gmail.com>
<20261102161426.2403d308@pumpkin>
<CAOLeWCviRtGMhGJQx3HHFQOze439576PQqr4tmvjGkMMfYfcog@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3277853"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:1UJUBhIjg93k4phB7R4Iey+tfdk= sha256:NTDYXhcR9/SejeEO/iKAdaX8VH9GSIMq/tywo81ET0g=
sha1:U+J1JlZiMWO5StJEDW7m3QphiZQ= sha256:a/jh3Rv3ZwrBIAACs1Ufm7pTRBW/gixJoyyaBFGvHXo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id C8E44112A5E; Wed, 4 Nov 2026 01:40:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id lYJgfY-29MkB;
Wed, 4 Nov 2026 01:40:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-356040-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id 278551129A0; Wed, 4 Nov 2026 01:40:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sin.lore.kernel.org (Postfix) with ESMTP id BEDC1273F9; Tue, 3 Nov 2026 22:38:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793745531;
b=T/smJyLh9Pm3IQD3VHicXtANR3u4kUQN799l/yFh+iJC+xxG9UlGxYzX/OP96YukwCh5
5i4mxk0nE6l/qXjkDEe/ui225GGhXDH1b/Q6feKoVmB0Cx5jQ5RgTnqXgB1uXtIyGAMbJ
JxO0Mre+c9xl53iVzh9qm0h9WdhSCGwUSzwMMjS/dX6dnylAaHhkxn1Y8z7g2VJ30P37D
qwFlqZIxlzckSkzXJLa1XfX+j0+hgUnvHEyO5AR6fVInLrzpDqBwD+5VFBHLXxGEobpZZ
YnEAqsb3U+1sznhyXq+TGoWBqernPz3ZIdTdOp0ST4qiS6PNO6Vm01m4cvknldbEAyA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793745531;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:Date:From:To:Cc:Subject:Message-ID:
In-Reply-To:References:X-Mailer:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=7Y4hWEy3KCqBGcgLZyC88t/BtG1nVv31oLpGNCBZoVw=;
b=FlxK4g4AT83Fjup59fcdJSc6gVP7QRdwDVJqG2tpwxmMYjsPrED3UbSRwJuCXdWBCaFc
xTMFkK4NO33nucsVW6VNuACP2vu0g97bOO9ErHwQsg1C2e9AHRR86uQwrURcsSVYDVUOQ
BBcjtln75ZNv0c+yHlVaXF7isQaBqoBxunFtOHxwzTrXdStsoZ12M6bDFgZK+NhV3l3g/
6Rc5bVkUQL4cVciVEaQDZ3CGx+aw2JorxH8BgHckx9pfonsLngtyVERcq6Z6aGAm6jVjb
cLDL0tn6xI6j8nnc70mBXCM6m6Uza7C/PWtD26H6pTYqY+g349jQgCSph7AB8EVynUw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=q83QGk6Z;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 676C8606A330;
Tue, 3 Nov 2026 22:38:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=q83QGk6Z
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793745530;
b=iZ9MJaMEmiXKOLE5zaWcvQ6cGh9e/bzmTPPp+Cx2Dq+OwlWbL5WatoacDyohIVRwMblA
h/79WxXZIVviLPoLAS1OuXekPFNkDoXLUvxoRkkRuUoNZXGKfF9BpSiwZ10x5wWgLUkXI
YnewNy5YU+0cI7ZPBE3UgTOz8v3PAW1MIOI1+GcCpeE7sdgQ3oQ0zm/Rc5ZDgPnX9HvQz
Xw3g+58pHbLF3avEfl+frJwywZNnnmrSCoQ6fJAmZZg6igmkHbK2TZpL3H6a5aF5vggZ7
kt6PLu4oSrZkk7/If8nIWxnkMfpASWQH0bxQTGu6/CL48WY011DhW6FvKaiJkLKmCEg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793745530;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer:
MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=7Y4hWEy3KCqBGcgLZyC88t/BtG1nVv31oLpGNCBZoVw=;
b=xItPrSKeZSslft2QBAcWtw6cTMUCRwxzbBQHi6YhmT8+YfdxG0Kzymb9Otn2K2/Emypf
Z0TDVzSJv98gm9dZfy7JuavhWb4aPxLMLZ58yfi9f9q5TlZW/xAoj/uBK4ylwMMOT3RAu
oGoxKmwC72TjRqkz7Utl2YhaMKF/wEBVG0pzo4/DdSJvST4kUl/G2TRNUQU1lmnpL+ofe
zUwDeMye6eUSq5pNIdEMWmYq70b4Yjc+Ge0sZANiI/5hV+QITVjh9fNAIbZEMVvc/EifF
VK0JkTqP61hCdUIl+AqVWEsB2DZ9iLzRm1sy+1QW87nKlAPhlHPOTgUb4e85M+/FY7Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=q83QGk6Z;
arc=none smtp.remote-ip=209.85.128.44
X-Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 313A6606A324
for <netdev@vger.kernel.org>; Tue, 3 Nov 2026 22:38:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 313A6606A324
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a549cd7fd2so66915e9.0
for <netdev@vger.kernel.org>; Tue, 03 Nov 2026 14:38:50 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793745529; x=1794350329; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=7Y4hWEy3KCqBGcgLZyC88t/BtG1nVv31oLpGNCBZoVw=;
b=q83QGk6ZlvK41Xnj9VYjDJsaU/LVIlKY/O3UTOsd7cHawXlaokPl1p1agoBY/5nwQg
uPzkJbtm0E91Y8sCbX76cPRL3i6SSTUKoXzttrTc/gWurMr2GWS0k5ylOm8PFozwb36o
OS3bFPXf8wE9XoVm/Dw9eCQmeqCwK0ijKk3mbqWteVs9IzoU8g54pTAHJRaxm52hAkiu
7twTSt9UNnEzbw5wK5y4pN3/8W+5ruU9wDD555aCgwBySzZ9UMbSQ/4Vj2g+AHO5WIHz
uHru3TjxC9/+VhraivLgz3IWOjs2cfBPVSktUTxcdqSG/kW/hrbRL1LEOapw9UlMVR/o
lXTw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793745529; x=1794350329;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=7Y4hWEy3KCqBGcgLZyC88t/BtG1nVv31oLpGNCBZoVw=;
b=vI4Dp6fT2QmniK0L6umQHTpyRkAizQTwuos01BwPRCt9yq42AWRW4MBn+L139TsTSn
1rX9oT12OnAWLgsCerOD4ggkGJ7Jzj+pLxT/SauAyXnoO9FTEPYYheHB8BvcOjtEdWpi
VJRPBxURweSNIQ9DOo8k60LEuJxGXUQIacGKqPDim5B1a83mXW/OYLdLCJueoGu33IOf
U6WIG61nj9qntfQCc2rUT2iEDTt/KmZYpNhfwHYsDylhYOpQkN0OA1klsPGsXb2rS2VL
IkPXqlAyCUmjG+Tb/dgS4FJodkRnZ0S9o1TD70rdwNl9h3wSoVD34d4sxm9EjOumEohC
I/DQ==
X-Forwarded-Encrypted: i=1; AKwUvBzG3zpS2KXxV/poQZYiE20d9FvcYD6ut8n+bMaKmDEE4pfxo788VS+nGK2vtcTy9Mlq24bFsWU=@vger.kernel.org
X-Gm-Message-State: APuU4Z/pJEzo8mfDZwuIPOHoZ01TohhoGgdfHvf21NuDIYQytskhhorZ
vceRbZOVCG0ANjvQQHLv1jGl1kwuqV4q2mCQN4Q3hilymXjgisL1hwDj
X-Gm-Gg: AYBFou3Mdmq15NvDThQzIi4VWAsMTZ22/mz53VOajuEYAggQA9SMuTaMePkPhtpy86T
9oyvxjYmf/cqhZFI0b01r9/gDpwj3QcOQKHn0YVe6tbKuNbkkRv3D5El+rCtiLAboyRqpT05bn+
yUTKXIDa2Kyef+8j0f4GT+DoYljIPdUeEWqsEZJQkm4ewaVPflscXfX6YWKQMEUTDxxlJ4DBGWj
jlUCcI6H3hvtB+wv9k9ZiQndrpC1upHpTaA2WAORX42B6sTSA9+by0j5WK73e88nij2taYP7Oq7
TAGhkIYNrrQWPEh3Bz/8YF6Nu5xMhqG0igRFyVQe8sGrpEiqhvAyi5Y9mao8lUAcnxWU0rG6fNs
pfrhULvIANI/U7LrBNohbnEkPvn+Wz6ciTiHpvTOhQnwH0xguPYxYRDM9VeNXJMYjF/k8zRgw7p
Csk877KwYCb/wONtD+o7Xmjj7X/atOFKUiAotFKn6K0L2Qh6MzWQN7ru9vkHWRLVJzjrIu0pa6j
igYBZdqs7WU9MnrQOOTyGW6qzJUApkPBO0krJd9A10TAqeCwCvoceNSmqFCES6vv5IMXBhLEeET
weShfEM/X9woPUKxIJH2tbL/fC4RE1AQa4jLMMiqpQh1jLTjglZvn+ipW81+G2gQT5k0bvU43MR
2XMyVwMUHyQ==
X-Received: by 2002:a05:600c:6555:b0:4a1:d45a:3ae9 with SMTP id 5b1f17b1804b1-4aa8b05fa4bmr341420665e9.15.1793745528451;
Tue, 03 Nov 2026 14:38:48 -0800 (PST)
X-Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48fea18104bsm467832f8f.6.2026.11.03.14.38.47
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 03 Nov 2026 14:38:48 -0800 (PST)
X-Cc: saeed bishara <saeed.bishara.os@gmail.com>, Catalin Marinas
<catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Mark Rutland
<mark.rutland@arm.com>, Eric Biggers <ebiggers@kernel.org>, Andrew Morton
<akpm@linux-foundation.org>, Marco Elver <elver@google.com>, Ard Biesheuvel
<ardb@kernel.org>, Robin Murphy <robin.murphy@arm.com>, David Gow
<davidgow@google.com>, Brendan Higgins <brendan.higgins@linux.dev>, Nathan
Chancellor <nathan@kernel.org>, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com,
netdev@vger.kernel.org, llvm@lists.linux.dev
X-In-Reply-To: <CAOLeWCviRtGMhGJQx3HHFQOze439576PQqr4tmvjGkMMfYfcog@mail.gmail.com>
X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list