Skip to contentSkip to conversation

util/bufferiszero: assign length_to_accel value for each accelerator case

PATCH In review Robert Hoo 4 participants 7 messages Mar 25, 2020 – Mar 26, 2020

lore
Share & tools
lore

Robert Hoo

author
#0 lore raw

PATCH 1/2 util/bufferiszero: assign length_to_accel value for each accelerator case

Because in unit test, init_accel() will be called several times, each with different accelerator type.

---
 util/bufferiszero.c | 3 +++
 1 file changed, 3 insertions(+)
util/bufferiszero.c +3 -0
index 6639035..b801253 100644
@@ -254,13 +254,16 @@ static void init_accel(unsigned cache)
     bool (*fn)(const void *, size_t) = buffer_zero_int;
     if (cache & CACHE_SSE2) {
         fn = buffer_zero_sse2;
+        length_to_accel = 64;
     }
 #ifdef CONFIG_AVX2_OPT
     if (cache & CACHE_SSE4) {
         fn = buffer_zero_sse4;
+        length_to_accel = 64;
     }
     if (cache & CACHE_AVX2) {
         fn = buffer_zero_avx2;
+        length_to_accel = 64;
     }
 #endif
 #ifdef CONFIG_AVX512F_OPT
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 util/bufferiszero: improve avx2 accelerator

By increasing avx2 length_to_accel to 128, we can simplify its logic and reduce a branch.

The authorship of this patch actually belongs to Richard Henderson <[email protected]>, I just fix a boudary case on his original patch.

---
 util/bufferiszero.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
util/bufferiszero.c +9 -17
index b801253..695bb4c 100644
@@ -158,27 +158,19 @@ buffer_zero_avx2(const void *buf, size_t len)
     __m256i *p = (__m256i *)(((uintptr_t)buf + 5 * 32) & -32);
     __m256i *e = (__m256i *)(((uintptr_t)buf + len) & -32);
 
-    if (likely(p <= e)) {
-        /* Loop over 32-byte aligned blocks of 128.  */
-        do {
-            __builtin_prefetch(p);
-            if (unlikely(!_mm256_testz_si256(t, t))) {
-                return false;
-            }
-            t = p[-4] | p[-3] | p[-2] | p[-1];
-            p += 4;
-        } while (p <= e);
-    } else {
-        t |= _mm256_loadu_si256(buf + 32);
-        if (len <= 128) {
-            goto last2;
+    /* Loop over 32-byte aligned blocks of 128.  */
+    while (p <= e) {
+        __builtin_prefetch(p);
+        if (unlikely(!_mm256_testz_si256(t, t))) {
+            return false;
         }
-    }
+        t = p[-4] | p[-3] | p[-2] | p[-1];
+        p += 4;
+    } ;
 
     /* Finish the last block of 128 unaligned.  */
     t |= _mm256_loadu_si256(buf + len - 4 * 32);
     t |= _mm256_loadu_si256(buf + len - 3 * 32);
- last2:
     t |= _mm256_loadu_si256(buf + len - 2 * 32);
     t |= _mm256_loadu_si256(buf + len - 1 * 32);
 
@@ -263,7 +255,7 @@ static void init_accel(unsigned cache)
     }
     if (cache & CACHE_AVX2) {
         fn = buffer_zero_avx2;
-        length_to_accel = 64;
+        length_to_accel = 128;
     }
 #endif
 #ifdef CONFIG_AVX512F_OPT
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 2/2] util/bufferiszero: improve avx2 accelerator

Quoted 4 lines · Robert Hoo

By increasing avx2 length_to_accel to 128, we can simplify its logic and reduce a branch.

The authorship of this patch actually belongs to Richard Henderson <[email protected]>,

Long line; it's nice to wrap commit messages around column 70 or so (because reading 'git log' in an 80-column window adds indentation).

Quoted 1 line

I just fix a boudary case on his original patch.

boundary

Quoted 7 lines
---
  util/bufferiszero.c | 26 +++++++++-----------------
  1 file changed, 9 insertions(+), 17 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

RE: [PATCH 2/2] util/bufferiszero: improve avx2 accelerator

(Don't know why my Linux-Evolution missed this mail.)

Quoted 9 lines

-----Original Message-----
From: Eric Blake <[email protected]>
Sent: Wednesday, March 25, 2020 20:54
To: Robert Hoo <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Hu, Robert <[email protected]>
Subject: Re: [PATCH 2/2] util/bufferiszero: improve avx2 accelerator

On 3/25/20 1:50 AM, Robert Hoo wrote:

Quoted 9 lines
Quoted 5 lines

By increasing avx2 length_to_accel to 128, we can simplify its logic and reduce a branch.

The authorship of this patch actually belongs to Richard Henderson <[email protected]>,

Long line; it's nice to wrap commit messages around column 70 or so (because reading 'git log' in an 80-column window adds indentation).

[Hu, Robert]
I think I set my vim on wrap. This probably escaped by paste.
I ran checkpatch.pl on the patches before sending. It escaped check but didn't escaped your eagle eye😊 Thank you.

Quoted 3 lines
Quoted 1 line

I just fix a boudary case on his original patch.

boundary

[Hu, Robert]
Emm... again spell error. Usually I would paste descriptions into some editors with spell check, but forgot this time.
Vim doesn't have spell check I think. What editor would you suggest me to integrate with git editing?

BTW, do I need to resend these 2 patches?

Quoted 14 lines
Quoted 8 lines
---
  util/bufferiszero.c | 26 +++++++++-----------------
  1 file changed, 9 insertions(+), 17 deletions(-)

--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org

#4 lore raw

Re: [PATCH 2/2] util/bufferiszero: improve avx2 accelerator

Quoted 1 line · Robert

BTW, do I need to resend these 2 patches?

No, thanks! I have queued them.

Paolo

#5 lore raw

Re: [PATCH 2/2] util/bufferiszero: improve avx2 accelerator

In reply to Hu, Robert
Quoted 10 lines · Robert

(Don't know why my Linux-Evolution missed this mail.)

Quoted 5 lines

-----Original Message-----

Long line; it's nice to wrap commit messages around column 70 or so (because reading 'git log' in an 80-column window adds indentation).

[Hu, Robert]
I think I set my vim on wrap. This probably escaped by paste.
I ran checkpatch.pl on the patches before sending. It escaped check but didn't escaped your eagle eye😊 Thank you.

checkpatch doesn't flag commit message long lines. Maybe it could be patched to do so, but it's not at the top of my list to write that patch.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

I just fix a boudary case on his original patch.

boundary

[Hu, Robert]
Emm... again spell error. Usually I would paste descriptions into some editors with spell check, but forgot this time.
Vim doesn't have spell check I think. What editor would you suggest me to integrate with git editing?

I'm an emacs user, so I have no suggestions for vim, but I'd be very surprised if there were not some vim expert online that could figure out how to wire in a spell-checker to vim. Google quickly finds: https://www.ostechnix.com/use-spell-check-feature-vim-text-editor/

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
author
#6 lore raw

Re: [PATCH 2/2] util/bufferiszero: improve avx2 accelerator

Quoted 32 lines · Eric Blake
Quoted 7 lines · Robert

(Don't know why my Linux-Evolution missed this mail.)

Quoted 5 lines

-----Original Message-----
Long line; it's nice to wrap commit messages around column 70 or so (because
reading 'git log' in an 80-column window adds indentation).

Quoted 5 lines

[Hu, Robert]
I think I set my vim on wrap. This probably escaped by paste. I ran checkpatch.pl on the patches before sending. It escaped check but didn't
escaped your eagle eye😊 Thank you.

checkpatch doesn't flag commit message long lines. Maybe it could be
patched to do so, but it's not at the top of my list to write that patch.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

I just fix a boudary case on his original patch.

boundary

Quoted 7 lines

[Hu, Robert]
Emm... again spell error. Usually I would paste descriptions into some editors
with spell check, but forgot this time.
Vim doesn't have spell check I think. What editor would you suggest me to
integrate with git editing?

Quoted 6 lines

I'm an emacs user, so I have no suggestions for vim, but I'd be very surprised if there were not some vim expert online that could figure out
how to wire in a spell-checker to vim. Google quickly finds:
https://www.ostechnix.com/use-spell-check-feature-vim-text-editor/

nice, thanks:)