From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpIAN-0003J8-OI for qemu-devel@nongnu.org; Thu, 22 Oct 2015 11:52:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpIAJ-0007vT-JB for qemu-devel@nongnu.org; Thu, 22 Oct 2015 11:52:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpIAJ-0007vA-Eh for qemu-devel@nongnu.org; Thu, 22 Oct 2015 11:52:31 -0400 References: <1445522453-14450-1-git-send-email-P@draigBrady.com> <5628F4BC.2040502@redhat.com> <5628F634.6040809@redhat.com> <5628FE20.80802@draigBrady.com> <5629050C.20607@bernhard-voelker.de> From: Paolo Bonzini Message-ID: <5629063A.2080308@redhat.com> Date: Thu, 22 Oct 2015 17:52:26 +0200 MIME-Version: 1.0 In-Reply-To: <5629050C.20607@bernhard-voelker.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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: Bernhard Voelker , =?UTF-8?Q?P=c3=a1draig_Brady?= , Eric Blake , coreutils@gnu.org Cc: Rusty Russell , "qemu-devel@nongnu.org" On 22/10/2015 17:47, Bernhard Voelker wrote: >> Note the above does break early if non zero detected in first 16 bytes. >> >> Also I suspect the extra conditions involved in using longs >> for just the first 16 bytes would outweigh the benefits? >> I.E. the first simple loop probably breaks early, and if not >> has the added benefit of "priming the pumps" for the subsequent memcmp(). > > what about spending some 16 bytes of memory and do the memcmp on the whole > buffer? > > static unsigned char p[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; > return 0 == memcmp (p, buf, bufsize); memcmp has high setup costs, because the compiler doesn't know it as well as memcpy, so no. :( Nerd sniping at its best! Paolo