qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detec


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detection
Date: Thu, 22 Oct 2015 09:55:09 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 10/22/2015 09:47 AM, Bernhard Voelker wrote:

>> 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);

Won't work over the whole bufsize for anything larger than 16 unless you
do repeated memcmp()s.

Or are you suggesting that the first 16-byte head validation be done
against a static buffer via one memcmp(), followed by the other
overlap-self memcmp() for the rest of the buffer?  But I suspect that
for short lengths, it is more efficient to do an unrolled loop than to
make a function call (where the function call itself will probably just
do an unrolled loop on the short length).  You want the short case to be
fast, and the real speedup comes by delegating as much of the long case
as possible to the system memcmp() optimizations.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]