From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 9BAD15A0272 for ; Wed, 7 Feb 2024 10:02:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707296554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wvVF2EnXTYromOlXFpR1xsDz0WF1R83eJHziKwsPrd0=; b=d3iocqVwmDcqxvoVUaI1/OiHtVQZceQj/Bac20Fy/60aD90q6owq9J6jqque4DUcor4o+q wNEkLHW7OSBixOw5ysSQ5pQ2/2ZM6kIHRnEEuU+SUAgt/VrmbLlVFRb54GBNrluj9sA4E4 7gnKG35I+bUbVzfZQfuwAHcdhEeJuH0= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-370-quH15F3xNeuHXkv9U970HA-1; Wed, 07 Feb 2024 04:02:33 -0500 X-MC-Unique: quH15F3xNeuHXkv9U970HA-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2d0a4e18689so3886931fa.0 for ; Wed, 07 Feb 2024 01:02:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707296551; x=1707901351; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wvVF2EnXTYromOlXFpR1xsDz0WF1R83eJHziKwsPrd0=; b=owicDQXeSkv/TSlUZLy1NEbNjAd5+poUassAFfbCv9WR68KVhX0n0IC7JJwODafYqX jIqD1Ct49Q1DmrUs1+kHRD/7bNOKZ/3zJSOloqGyE9K85dBu+vZvZBUbBeTbwF/J1B9P yjSpV3zON94o+u6m5dQ5ZsUonA0fD82OoVZ0Piw6OF0gg8qHkSXR2ZM3fgBmrjPSObA8 iiFZijeltw6gmAipE4mrkCPbFmZCp04iuxKZEvqq8HeAICJyZNHC6GmODIecEG49IZNV C0O8xsHSl6icf4uMj7rec/I5xo915WXLoUSYHNEpynJ3KzW2hc8qZk3YVofDT/35aczW 8QpA== X-Gm-Message-State: AOJu0Yz+ulGcZxZGaPvEKD7tL0Lhz0GI7r5WT8qvh5X6ob1CAgUdFjaf esLOYzhvTM8U6GVxgARYChVCgY5ELUBA9aIq5DK0TGgDXGTc11fNK9rNR7klJBv9j0W473zwgHM OFveuJx4NZ7cB5F2mUcxUP580BkGYoibdLoNpu7qfiOd1pb/hsw== X-Received: by 2002:ac2:5216:0:b0:511:6436:66c7 with SMTP id a22-20020ac25216000000b00511643666c7mr1214174lfl.43.1707296551745; Wed, 07 Feb 2024 01:02:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFK7xh8JJ8ZHFOHy+sTwa7rYvMF0vtBSQxqTFuWN/QrwXBXD9bHocUeW7kD1QcScbOgHvgIfA== X-Received: by 2002:ac2:5216:0:b0:511:6436:66c7 with SMTP id a22-20020ac25216000000b00511643666c7mr1214151lfl.43.1707296551213; Wed, 07 Feb 2024 01:02:31 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUh4OhrMvg2IE6fDVtNIR7Wa93G7zb0k/mRdfef+mf2fRS1B+jVatXeba7WfQRphZx3eOd9BsdytqCix8GnDwpcpao= Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id eo15-20020a056402530f00b00560b0b707adsm452075edb.73.2024.02.07.01.02.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2024 01:02:30 -0800 (PST) Date: Wed, 7 Feb 2024 10:01:56 +0100 From: Stefano Brivio To: David Gibson , Laurent Vivier Subject: Re: [PATCH 03/24] checksum: align buffers Message-ID: <20240207100156.5113d7de@elisabeth> In-Reply-To: References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-4-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.1.1 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: UNO6D3BNWCMIGZJPJCDL367NGCEKMVWB X-Message-ID-Hash: UNO6D3BNWCMIGZJPJCDL367NGCEKMVWB X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon, 5 Feb 2024 17:02:00 +1100 David Gibson wrote: > On Fri, Feb 02, 2024 at 03:11:30PM +0100, Laurent Vivier wrote: > > if buffer is not aligned use sum_16b() only on the not aligned > > part, and then use csum() on the remaining part > > > > Signed-off-by: Laurent Vivier > > Reviewed-by: David Gibson > > > --- > > checksum.c | 14 +++++++++++++- > > 1 file changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/checksum.c b/checksum.c > > index f21c9b7a14d1..c94980771c63 100644 > > --- a/checksum.c > > +++ b/checksum.c > > @@ -407,7 +407,19 @@ less_than_128_bytes: > > __attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */ > > uint16_t csum(const void *buf, size_t len, uint32_t init) > > { > > - return (uint16_t)~csum_fold(csum_avx2(buf, len, init)); > > + intptr_t align = ((intptr_t)buf + 0x1f) & ~(intptr_t)0x1f; > > Wonder if its worth adding an ALIGN_UP macro. Actually, we have it, it's called ROUND_UP (see util.h). This could be: intptr_t align = ROUND_UP(buf, 0x20); ...and maybe we could use sizeof(__m256i) or similar instead of 0x20. > > > + unsigned int pad = align - (intptr_t)buf; > > + > > + if (len < pad) > > + pad = len; > > + > > + if (pad) > > + init += sum_16b(buf, pad); > > + > > + if (len > pad) > > + init = csum_avx2((void *)align, len - pad, init); > > + > > + return (uint16_t)~csum_fold(init); > > } > > > > #else /* __AVX2__ */ > -- Stefano