qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Pádraig Brady" <P@draigBrady.com>, coreutils@gnu.org
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detection
Date: Thu, 22 Oct 2015 08:37:48 -0600	[thread overview]
Message-ID: <5628F4BC.2040502@redhat.com> (raw)
In-Reply-To: <1445522453-14450-1-git-send-email-P@draigBrady.com>

[-- Attachment #1: Type: text/plain, Size: 1388 bytes --]

[adding qemu]

On 10/22/2015 08:00 AM, Pádraig Brady wrote:
> * src/system.h (is_nul): Reimplement with a version
> that doesn't require a sentinel after the buffer,
> and which calls down to (the system optimized) memcmp.
> Performance analyzed at http://rusty.ozlabs.org/?p=560

>  /* Return whether the buffer consists entirely of NULs.
> -   Note the word after the buffer must be non NUL. */
> +   From CCAN by Rusty Russell <rusty@rustcorp.com.au>
> +   released under CC0 (Public domain).  */
>  
>  static inline bool _GL_ATTRIBUTE_PURE
>  is_nul (void const *buf, size_t bufsize)
>  {

> +  const unsigned char *p = buf;
> +  size_t len;
> +
> +  /* Check first 16 bytes manually.  */
> +  for (len = 0; len < 16; len++)
> +    {
> +      if (! bufsize)
> +        return true;
> +      if (*p)
> +        return false;
> +      p++;
> +      bufsize--;
> +    }
> +
> +  /* Now we know that's zero, memcmp with self.  */
> +  return memcmp (buf, p, bufsize) == 0;
>  }

Cool trick of using a suitably-aligned overlap-to-self check to then
trigger platform-specific speedups without having to rewrite them by
hand!  qemu is doing a similar check in util/cutils.c:buffer_is_zero()
that could probably benefit from the same idea.

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

       reply	other threads:[~2015-10-22 14:38 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 ` Eric Blake [this message]
2015-10-22 14:44   ` [Qemu-devel] [PATCH] copy, dd: simplify and optimize NUL bytes detection 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
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=5628F4BC.2040502@redhat.com \
    --to=eblake@redhat.com \
    --cc=P@draigBrady.com \
    --cc=coreutils@gnu.org \
    --cc=qemu-devel@nongnu.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).