Patchwork [PATCHv4,3/9] buffer_is_zero: use vector optimizations if possible

login
register
mail settings
Submitter Peter Lieven
Date March 22, 2013, 12:46 p.m.
Message ID <1363956370-23681-4-git-send-email-pl@kamp.de>
Download mbox | patch
Permalink /patch/229998/
State New
Headers show

Comments

Peter Lieven - March 22, 2013, 12:46 p.m.
performance gain on SSE2 is approx. 20-25%. altivec
is not tested. performance for unsigned long arithmetic
is unchanged.

Signed-off-by: Peter Lieven <pl@kamp.de>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 util/cutils.c |    5 +++++
 1 file changed, 5 insertions(+)
Orit Wasserman - March 25, 2013, 8:53 a.m.
On 03/22/2013 02:46 PM, Peter Lieven wrote:
> performance gain on SSE2 is approx. 20-25%. altivec
> is not tested. performance for unsigned long arithmetic
> is unchanged.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  util/cutils.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/util/cutils.c b/util/cutils.c
> index 41c627e..0f43c22 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -205,6 +205,11 @@ bool buffer_is_zero(const void *buf, size_t len)
>      long d0, d1, d2, d3;
>      const long * const data = buf;
>  
> +    /* use vector optimized zero check if possible */
> +    if (can_use_buffer_find_nonzero_offset(buf, len)) {
> +        return buffer_find_nonzero_offset(buf, len) == len;
> +    }
> +
>      assert(len % (4 * sizeof(long)) == 0);
>      len /= sizeof(long);
>  
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>

Patch

diff --git a/util/cutils.c b/util/cutils.c
index 41c627e..0f43c22 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -205,6 +205,11 @@  bool buffer_is_zero(const void *buf, size_t len)
     long d0, d1, d2, d3;
     const long * const data = buf;
 
+    /* use vector optimized zero check if possible */
+    if (can_use_buffer_find_nonzero_offset(buf, len)) {
+        return buffer_find_nonzero_offset(buf, len) == len;
+    }
+
     assert(len % (4 * sizeof(long)) == 0);
     len /= sizeof(long);