From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpJpo-0008Qt-Un for qemu-devel@nongnu.org; Thu, 22 Oct 2015 13:39:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpJpl-0006Af-LP for qemu-devel@nongnu.org; Thu, 22 Oct 2015 13:39:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39635) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpJpl-0006AR-Fb for qemu-devel@nongnu.org; Thu, 22 Oct 2015 13:39:25 -0400 Date: Thu, 22 Oct 2015 19:39:20 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20151022173919.GC14789@potion.brq.redhat.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56290B55.2000703@redhat.com> 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: Paolo Bonzini Cc: =?utf-8?Q?P=C3=A1draig?= Brady , Rusty Russell , coreutils@gnu.org, "qemu-devel@nongnu.org" 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. :) It rather seems that you don't want spoilers, :) I see two bugs now. > bool memeqzero4_paolo(const void *data, size_t length) > { > const unsigned char *p = 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 aligned! > * 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) == 0) > break; > p += sizeof(word); > length -= sizeof(word); > if (!length) > return true; > } > > /* Now we know that's zero, memcmp with self. */ > return memcmp(data, p, length) == 0; > }