From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpH0F-0001rk-Kv for qemu-devel@nongnu.org; Thu, 22 Oct 2015 10:38:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpH09-0003Y4-BF for qemu-devel@nongnu.org; Thu, 22 Oct 2015 10:38:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpH09-0003Xw-5c for qemu-devel@nongnu.org; Thu, 22 Oct 2015 10:37:57 -0400 References: <1445522453-14450-1-git-send-email-P@draigBrady.com> From: Eric Blake Message-ID: <5628F4BC.2040502@redhat.com> Date: Thu, 22 Oct 2015 08:37:48 -0600 MIME-Version: 1.0 In-Reply-To: <1445522453-14450-1-git-send-email-P@draigBrady.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4Qw5bToXXRhPOWpIcCwq6twqjhqtVdGEi" Subject: Re: [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?P=c3=a1draig_Brady?= , coreutils@gnu.org Cc: Rusty Russell , "qemu-devel@nongnu.org" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --4Qw5bToXXRhPOWpIcCwq6twqjhqtVdGEi Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [adding qemu] On 10/22/2015 08:00 AM, P=C3=A1draig Brady wrote: > * src/system.h (is_nul): Reimplement with a version > that doesn't require a sentinel after the buffer, > and which calls down to (the system optimized) memcmp. > Performance analyzed at http://rusty.ozlabs.org/?p=3D560 > /* Return whether the buffer consists entirely of NULs. > - Note the word after the buffer must be non NUL. */ > + From CCAN by Rusty Russell > + released under CC0 (Public domain). */ > =20 > static inline bool _GL_ATTRIBUTE_PURE > is_nul (void const *buf, size_t bufsize) > { > + const unsigned char *p =3D buf; > + size_t len; > + > + /* Check first 16 bytes manually. */ > + for (len =3D 0; len < 16; len++) > + { > + if (! bufsize) > + return true; > + if (*p) > + return false; > + p++; > + bufsize--; > + } > + > + /* Now we know that's zero, memcmp with self. */ > + return memcmp (buf, p, bufsize) =3D=3D 0; > } Cool trick of using a suitably-aligned overlap-to-self check to then trigger platform-specific speedups without having to rewrite them by hand! qemu is doing a similar check in util/cutils.c:buffer_is_zero() that could probably benefit from the same idea. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --4Qw5bToXXRhPOWpIcCwq6twqjhqtVdGEi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWKPS8AAoJEKeha0olJ0Nq0RUH/2rhDneHEZCCP/l9YaQ4OV1z 6TMu5qt0MFoBnObkOV6Egj0S2zCdxYwjCfZbcmqwPuZ7DXhgHHrsfgNvUrhlCOkn wSgJI+3+q22aqCTZA0GvjT3ZPRorFmmQ1zmOCius1hseoSX+ABv0Vlw67nfkEd2c pd+0DcQCfUJofmuIZpmxaK/aS3h34YayODlgssRAdzZtQD/rifu/RveONTFSFYsB DDDQUp4xNfXyMTqY0PO/eHrd9y/hrwYRQb8BvP6ISKsAMuzkZGUx4X6LPuFp/iJK N+Guod63xJfgWDwheJflplWIcsAlFgj6pG9vRlfwAhdoPOKti3g8jR0aESjwGOE= =Q0L2 -----END PGP SIGNATURE----- --4Qw5bToXXRhPOWpIcCwq6twqjhqtVdGEi--