From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpLq0-0000Sz-VC for qemu-devel@nongnu.org; Thu, 22 Oct 2015 15:47:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpLpy-00035h-9v for qemu-devel@nongnu.org; Thu, 22 Oct 2015 15:47:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54985) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpLpy-00035U-5W for qemu-devel@nongnu.org; Thu, 22 Oct 2015 15:47:46 -0400 References: <1445522453-14450-1-git-send-email-P@draigBrady.com> <5628F4BC.2040502@redhat.com> <5628F634.6040809@redhat.com> <5628FE20.80802@draigBrady.com> <56290152.7010408@redhat.com> <562908A6.3000307@redhat.com> <56290B55.2000703@redhat.com> <20151022173919.GC14789@potion.brq.redhat.com> From: Paolo Bonzini Message-ID: <56293D5D.2030107@redhat.com> Date: Thu, 22 Oct 2015 21:47:41 +0200 MIME-Version: 1.0 In-Reply-To: <20151022173919.GC14789@potion.brq.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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?B?UmFkaW0gS3LEjW3DocWZ?= Cc: =?UTF-8?Q?P=c3=a1draig_Brady?= , Rusty Russell , coreutils@gnu.org, "qemu-devel@nongnu.org" On 22/10/2015 19:39, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > 2015-10-22 18:14+0200, Paolo Bonzini: >> On 22/10/2015 18:02, Eric Blake wrote: >>> I see a bug in there: >> >> Of course. You shouldn't have told me what the bug was, I deserved >> to look for it myself. :) >=20 > It rather seems that you don't want spoilers, :) >=20 > I see two bugs now. Me too. :) But Rusty surely has some testcases in case he wants to adopt some of the ideas here. O:-) Paolo >> bool memeqzero4_paolo(const void *data, size_t length) >> { >> const unsigned char *p =3D data; >> unsigned long word; >> >> while (__builtin_expect(length & (sizeof(word) - 1), 0)) { >> if (*p) >> return false; >> p++; >> length--; >> if (!length) >> return true; >> } >> >> /* We must always read one byte or word, even if everything is ali= gned! >> * Otherwise, memcmp(data, data, length) is trivially true. >> */ >> for (;;) { >> memcpy(&word, p, sizeof(word)); >> if (word) >> return false; >> if (__builtin_expect(length & (16 - sizeof(word)), 0) =3D=3D 0= ) >> break; >> p +=3D sizeof(word); >> length -=3D sizeof(word); >> if (!length) >> return true; >> } >> >> /* Now we know that's zero, memcmp with self. */ >> return memcmp(data, p, length) =3D=3D 0; >> }