buffer_is_zero: use vector optimizations if possible
RFC PATCH 4/9 buffer_is_zero: use vector optimizations if possible
performance gain on SSE2 is approx. 20-25%. altivec is not tested. performance for unsigned long arithmetic is unchanged.
--- util/cutils.c | 5 +++++ 1 file changed, 5 insertions(+)
util/cutils.c +5 -0
@@ -186,6 +186,11 @@ bool buffer_is_zero(const void *buf, size_t len)* latency. */ +if (((uintptr_t ) buf) %sizeof (VECTYPE ) ==0 + && len %8 *sizeof (VECTYPE ) ==0 ) { +return buffer_find_nonzero_offset (buf, len)==len; + } +size_t i;long d0, d1, d2, d3;const long *const data = buf;
Signature · 1 line
1.7.9.5
Quoted 14 lines · Peter Lieven
performance gain on SSE2 is approx. 20-25%. altivec is not tested. performance for unsigned long arithmetic is unchanged.
Signed-off-by Peter Lieven <[email protected]>--- util/cutils.c | 5 +++++ 1 file changed, 5 insertions(+)util/cutils.c +0
-0
util/cutils.c bool buffer_is_zero(const void *buf, size_t len) · line 190
Quoted 5 lines
util/cutils.c +2
-0@@ -186,6 +186,11 @@ bool buffer_is_zero(const void *buf, size_t len)* latency. */ +if (((uintptr_t ) buf) %sizeof (VECTYPE ) ==0 + && len %8 *sizeof (VECTYPE ) ==0 ) {
Space around binary operators. Use CHAR_BITS instead of a magic number
8. Also, did you mean:
len % (CHAR_BITS * sizeof(VECTYPE))
instead of what you wrote as '(len % 8) * sizeof(VECTYPE)'?
Quoted 6 lines
util/cutils.c +3
-0+return buffer_find_nonzero_offset (buf, len)==len; + } +size_t i;long d0, d1, d2, d3;const long *const data = buf;
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Am 12.03.2013 um 17:01 schrieb Eric Blake <[email protected]>:
Quoted 24 lines · Peter Lieven
Quoted 14 lines
performance gain on SSE2 is approx. 20-25%. altivec is not tested. performance for unsigned long arithmetic is unchanged.
Signed-off-by Peter Lieven <[email protected]>---
util/cutils.c| 5 +++++1 file changed, 5 insertions(+)util/cutils.c +0
-0util/cutils.c bool buffer_is_zero(const void *buf, size_t len) · line 190
Quoted 5 lines
util/cutils.c +2
-0@@ -186,6 +186,11 @@ bool buffer_is_zero(const void *buf, size_t len)* latency. */ +if (((uintptr_t ) buf) %sizeof (VECTYPE ) ==0 + && len %8 *sizeof (VECTYPE ) ==0 ) {Space around binary operators. Use
CHAR_BITSinstead of a magic number
8. Also, did you mean:
Quoted 3 lines
len % (
CHAR_BITS* sizeof(VECTYPE))instead of what you wrote as '(len % 8) * sizeof(VECTYPE)'?
the 8 is not BITS_PER_BYTE or CHAR_BITS its the number of vectors in one loop in buffer_find_nonzero_offset(). I will add a constant for this to make it clearer.
Peter
Quoted 12 lines
Quoted 7 lines
util/cutils.c +3
-0+return buffer_find_nonzero_offset (buf, len)==len; + } +size_t i;long d0, d1, d2, d3;const long *const data = buf;Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 9 lines · Peter Lieven
Quoted 5 lines
util/cutils.c bool buffer_is_zero(const void *buf, size_t len) · line 190
Quoted 2 lines
util/cutils.c +2
-0+if (((uintptr_t ) buf) %sizeof (VECTYPE ) ==0 + && len %8 *sizeof (VECTYPE ) ==0 ) {Space around binary operators. Use
CHAR_BITSinstead of a magic number 8.the 8 is not
BITS_PER_BYTEorCHAR_BITSits the number of vectors in one loop inbuffer_find_nonzero_offset(). I will add a constant for this to make it clearer.
Indeed, now I see it - 8 is the unroll factor. Well, all the more evidence that a named constant makes the code easier to read, compared to me mis-interpreting the magic number.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org