From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqJyH-0000yb-06 for qemu-devel@nongnu.org; Sun, 25 Oct 2015 08:00:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqJyD-0002UB-Pa for qemu-devel@nongnu.org; Sun, 25 Oct 2015 08:00:20 -0400 Received: from mail1.vodafone.ie ([213.233.128.43]:11158) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqJyD-0002Rv-KP for qemu-devel@nongnu.org; Sun, 25 Oct 2015 08:00:17 -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> <56293D5D.2030107@redhat.com> <562A16BB.6080006@draigBrady.com> <562AEBDD.7070701@draigBrady.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <562CC44E.80208@draigBrady.com> Date: Sun, 25 Oct 2015 12:00:14 +0000 MIME-Version: 1.0 In-Reply-To: <562AEBDD.7070701@draigBrady.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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 , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Cc: Rusty Russell , coreutils@gnu.org, "qemu-devel@nongnu.org" On 24/10/15 03:24, Pádraig Brady wrote: > On 23/10/15 12:15, Pádraig Brady wrote: >> On 22/10/15 20:47, Paolo Bonzini wrote: >>> >>> >>> On 22/10/2015 19:39, Radim Krčmář 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. :) >>>> >>>> It rather seems that you don't want spoilers, :) >>>> >>>> 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:-) >> >> For completeness this should address the bugs I think? >> >> bool memeqzero4_paolo(const void *data, size_t length) >> { >> const unsigned char *p = data; >> unsigned long word; > > Note the original coreutils code accessed a word at a time, > but only on aligned buffers. The code below may generate > unaligned accesses for unaligned sizes or buffers. > You can avoid that by auto degenerating back to byte > at a time access using: > > #if _STRING_ARCH_unaligned > unsigned long word; > #else > unsigned char word; > #endif Note _STRING_ARCH_unaligned being defined at the glibc level doesn't guarantee the compiler wont do something "defined" when vectorizing code, or perhaps removing sanity checks like: #define ALIGNED_POINTER(ptr, type) ((size_t) (ptr) % alignof (type) == 0) by assuming that the lower bits of the pointer are zero as that's the only defined operation? One gets stronger guarantees from a compiler define, like __ARM_FEATURE_UNALIGNED which gcc -munaligned-access defines for arm, though we're still in undefined territory and -fsanitize=undefined will warn about such accesses. You'd have to explicitly avoid such warnings with something like: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=5760532 Given coreutils only uses is_nul for relatively large buffers, I'm going to avoid the above complexity, since the focus of this coreutils patch was simplification, and only enable the byte at a time access. cheers, Pádraig.