Flip the hot loops to do-while.
Change-Id: I4b33af6aa4c433a3c6b49bd39511ddfdfbb828a6
Reviewed-on: https://code-review.googlesource.com/c/re2/+/58932
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/prog.cc b/re2/prog.cc
index 3979bd2..a4b70bd 100644
--- a/re2/prog.cc
+++ b/re2/prog.cc
@@ -1035,7 +1035,7 @@
if (size >= 8) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(data);
const uint8_t* endp = p + (size&~7);
- while (p != endp) {
+ do {
uint8_t b0 = p[0];
uint8_t b1 = p[1];
uint8_t b2 = p[2];
@@ -1080,7 +1080,7 @@
curr = curr7;
p += 8;
- }
+ } while (p != endp);
data = p;
size = size&7;
}
@@ -1139,7 +1139,7 @@
const __m256i* endfp = fp + size/sizeof(__m256i);
const __m256i f_set1 = _mm256_set1_epi8(prefix_front_);
const __m256i b_set1 = _mm256_set1_epi8(prefix_back_);
- while (fp != endfp) {
+ do {
const __m256i f_loadu = _mm256_loadu_si256(fp++);
const __m256i b_loadu = _mm256_loadu_si256(bp++);
const __m256i f_cmpeq = _mm256_cmpeq_epi8(f_set1, f_loadu);
@@ -1151,7 +1151,7 @@
const int fb_ctz = FindLSBSet(fb_movemask);
return reinterpret_cast<const char*>(fp-1) + fb_ctz;
}
- }
+ } while (fp != endfp);
data = fp;
size = size%sizeof(__m256i);
}