qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Konishchev <konishchev@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
	Dmitry Konishchev <konishchev@gmail.com>,
	qemu-devel@nongnu.org,
	Stanislav Ievlev <stanislav.ievlev@gmail.com>
Subject: [Qemu-devel] [PATCH] is_not_zero() optimization in qemu-img
Date: Wed, 18 May 2011 15:03:59 +0400	[thread overview]
Message-ID: <1305716639-27846-1-git-send-email-konishchev@gmail.com> (raw)
In-Reply-To: <4DD391FC.6070101@redhat.com>

Please sorry - I've sent the previous email via Thunderbird which promised that won't wrap the lines but it did. :(
Sending this via git send-email.

Signed-off-by: Dmitry Konishchev <konishchev@gmail.com>
---
 qemu-img.c |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index e825123..c849c6f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -496,14 +496,37 @@ static int img_commit(int argc, char **argv)
     return 0;
 }
 
+/*
+ * Checks whether the sector is not a zero sector.
+ *
+ * Attention! The len must be a multiple of 4 * sizeof(long) due to
+ * restriction of optimizations in this function.
+ */
 static int is_not_zero(const uint8_t *sector, int len)
 {
+    /*
+     * Use long as the biggest available internal data type that fits into the
+     * CPU register and unroll the loop to smooth out the effect of memory
+     * latency.
+     */
+
     int i;
-    len >>= 2;
-    for(i = 0;i < len; i++) {
-        if (((uint32_t *)sector)[i] != 0)
+    long d0, d1, d2, d3;
+    const long * const data = (const long *) sector;
+
+    len /= sizeof(long);
+
+    for(i = 0; i < len; i += 4) {
+        d0 = data[i + 0];
+        d1 = data[i + 1];
+        d2 = data[i + 2];
+        d3 = data[i + 3];
+
+        if (d0 || d1 || d2 || d3) {
             return 1;
+        }
     }
+
     return 0;
 }
 
-- 
1.7.4.1

  parent reply	other threads:[~2011-05-18 11:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-17 14:33 [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization Dmitry Konishchev
2011-05-17 15:35 ` Stefan Hajnoczi
2011-05-18  6:55   ` Dmitry Konishchev
2011-05-18  7:57     ` Stefan Hajnoczi
2011-05-18  8:05       ` Kevin Wolf
2011-05-18  9:18       ` Dmitry Konishchev
2011-05-18  9:31         ` Kevin Wolf
2011-05-18 10:27           ` Dmitry Konishchev
2011-05-18 11:03           ` Dmitry Konishchev [this message]
2011-05-18 12:14             ` [Qemu-devel] [PATCH] is_not_zero() optimization in qemu-img Kevin Wolf
2011-05-18  9:40         ` [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization Peter Maydell
2011-05-18  9:40           ` Peter Maydell
2011-05-18 10:27           ` Dmitry Konishchev

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=1305716639-27846-1-git-send-email-konishchev@gmail.com \
    --to=konishchev@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stanislav.ievlev@gmail.com \
    --cc=stefanha@gmail.com \
    /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).