From: "Pádraig Brady" <P@draigBrady.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
coreutils@gnu.org,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detection
Date: Fri, 23 Oct 2015 12:15:07 +0100 [thread overview]
Message-ID: <562A16BB.6080006@draigBrady.com> (raw)
In-Reply-To: <56293D5D.2030107@redhat.com>
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;
if (!length)
return true;
/* Check len bytes not aligned on a word. */
while (__builtin_expect(length & (sizeof(word) - 1), 0)) {
if (*p)
return false;
p++;
length--;
if (!length)
return true;
}
/* Check up to 16 bytes a word at a time. */
for (;;) {
memcpy(&word, p, sizeof(word));
if (word)
return false;
p += sizeof(word);
length -= sizeof(word);
if (!length)
return true;
if (__builtin_expect(length & 15, 0) == 0)
break;
}
/* Now we know that's zero, memcmp with self. */
return memcmp(data, p, length) == 0;
}
compiled with gcc 5.1.1 -march=native -O2 on an i3-2310M
we get these timings:
bytes 1 8 16 512 65536
---------------------------------------------
Rusty: 10 28 59 114 6510
Paolo: 9 9 12 75 6495
It's also smaller, especially at -O3:
$ nm -S a.out | grep memeqzero4
... 000000000000005b t memeqzero4_paolo
... 0000000000000063 t memeqzero4_rusty
$ gcc -march=native -O3 memeqzero.c
$ nm -S a.out | grep memeqzero4
... 000000000000005b t memeqzero4_paolo
... 0000000000000133 t memeqzero4_rusty
cheers,
Pádraig.
next prev parent reply other threads:[~2015-10-23 11:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1445522453-14450-1-git-send-email-P@draigBrady.com>
2015-10-22 14:37 ` [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detection Eric Blake
2015-10-22 14:44 ` Paolo Bonzini
2015-10-22 15:17 ` Pádraig Brady
2015-10-22 15:31 ` Paolo Bonzini
2015-10-22 16:02 ` Eric Blake
2015-10-22 16:14 ` Paolo Bonzini
2015-10-22 17:39 ` Radim Krčmář
2015-10-22 19:47 ` Paolo Bonzini
2015-10-23 11:12 ` Pádraig Brady
2015-10-23 11:14 ` Paolo Bonzini
2015-10-23 11:15 ` Pádraig Brady [this message]
2015-10-24 2:24 ` Pádraig Brady
2015-10-25 12:00 ` Pádraig Brady
2015-10-22 15:47 ` Bernhard Voelker
2015-10-22 15:52 ` Paolo Bonzini
2015-10-22 15:55 ` Eric Blake
2015-10-23 10:59 ` Bernhard Voelker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=562A16BB.6080006@draigBrady.com \
--to=p@draigbrady.com \
--cc=coreutils@gnu.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkrcmar@redhat.com \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.