From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7323B5A0274 for ; Mon, 5 Feb 2024 07:13:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707113625; bh=8kF8j6YWGWuw8AIcjEaHEZfKTPTUDIwpTJPReWPzZ/o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HEi+VAbIVEaUCggS1Yu9k1JE+SO6+5l+SLs5wgvI14+nZlMRRL2Z6pwP5lMgjWjfL Ca4nvKYgA9m1hawuwQsWhO02BqV82rUt2VSR90PBvtpCW0KTQP2NiZlq/MCqMnGQwr Nt91S4Vkve87XevHBm9abY1Ro8M2ugtgKSYcjTh4dUpg5/Vxqzde5D9aP4iTnaolMK I2ucA07satLG5JWa6DVHrZfGLirNvRVmv0NcsOenaKi2fw4jHyBQBzsKvx1QNXDO15 e2uelcQdCyGyRVCUQ3NRsfVeHio2RgOtTf5LcV+/rkpoST9evfoD6HHPFXXXNgxXoT osWPYO6gpP5OQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TSx091wZxz4wyf; Mon, 5 Feb 2024 17:13:45 +1100 (AEDT) Date: Mon, 5 Feb 2024 17:02:00 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 03/24] checksum: align buffers Message-ID: References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-4-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="JZY2Yz1i5dlytM7I" Content-Disposition: inline In-Reply-To: <20240202141151.3762941-4-lvivier@redhat.com> Message-ID-Hash: U2THNZBK2KC2Q4APW63YH7AHCELO4P2I X-Message-ID-Hash: U2THNZBK2KC2Q4APW63YH7AHCELO4P2I X-MailFrom: dgibson@gandalf.ozlabs.org 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: --JZY2Yz1i5dlytM7I Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > checksum.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) >=20 > 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 =3D ((intptr_t)buf + 0x1f) & ~(intptr_t)0x1f; Wonder if its worth adding an ALIGN_UP macro. > + unsigned int pad =3D align - (intptr_t)buf; > + > + if (len < pad) > + pad =3D len; > + > + if (pad) > + init +=3D sum_16b(buf, pad); > + > + if (len > pad) > + init =3D csum_avx2((void *)align, len - pad, init); > + > + return (uint16_t)~csum_fold(init); > } > =20 > #else /* __AVX2__ */ --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --JZY2Yz1i5dlytM7I Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXAedcACgkQzQJF27ox 2GcMQg//Uw6cmF7cysmEF9IzaI+YgtkwcpTpzrxm8ldoXuToVv7xWmZAcn+hD4+x xg9is8ifYc8iqFNkOvqCEIJlrKzpzUNyyp3L80YpJVUGpExEus5FVsoJEfZQBHES m8zXvYwxSXzHO+pQ3dHoqu/B+sbZPvBo0+eiy4hpw9DbSCyIyu8oiWEhPkr7O62z 5ANq00FsYVME/AGbJsdqCbPYPS69wsDi/QzYXlK3NQD43BiXq42Gcy6nAy6Zpkym CMENRm4WUWwNuKhb/i3TN4GIHie8WmWkl/PYLKyTv9UmH/H4bQj9P/UWgIpcvOvT LtRHSTUnSQMe4NudaaAiXYjIp2QLIJeXzeSk3WIeoa8pqO/nxMiFa2tTlSzCnM99 KUeAkgDcQb9R923BIp+ylpU5GE8t74n4TcYTviRhJCwTGPLFgJ3p45+ORG+1O/uJ 5bY+LsWJvgobkDdkGt6xIlHecj2isZkDp+sVCIzOG7xxpobNjKo1tZ+vKghJa4A9 bp6NqVGcUufm+tILEyN92H7/B2VG8gV+W3vwMnoDfLC/qcOUeW9ILUc5XgdqJkGo rRqfNv/d0mIonw0QM99jnFxbxC72VBRc90pOfTpOZoDRvsHFfiKsnslkoE9Ep27d 9NZeEWJgVOvW9cSRLq0RaDQXzENlDSFFAoM3B9fs9N3whU0qVW4= =8+/G -----END PGP SIGNATURE----- --JZY2Yz1i5dlytM7I--