aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrotli <no-reply@google.com>2024-05-31 09:10:52 -0700
committerCopybara-Service <copybara-worker@google.com>2024-05-31 09:11:23 -0700
commita528bce9f65be7515a47cec2cbdcd8023822b99b (patch)
treecac86faefa8a58c4b14211d527032ca5fc98c166
parentfe754f3459f4fd60d41aae7e87b5053b2ab3a7a3 (diff)
downloadbrotli-a528bce9f65be7515a47cec2cbdcd8023822b99b.zip
brotli-a528bce9f65be7515a47cec2cbdcd8023822b99b.tar.gz
brotli-a528bce9f65be7515a47cec2cbdcd8023822b99b.tar.bz2
Hoist the static bounds check out of the combined if check.HEADmaster
PiperOrigin-RevId: 639054702
-rw-r--r--c/enc/hash_longest_match64_inc.h12
-rw-r--r--c/enc/hash_longest_match64_simd_inc.h12
-rw-r--r--c/enc/hash_longest_match_inc.h12
-rw-r--r--c/enc/hash_longest_match_simd_inc.h12
4 files changed, 32 insertions, 16 deletions
diff --git a/c/enc/hash_longest_match64_inc.h b/c/enc/hash_longest_match64_inc.h
index 7e0b2f5..bdbb30a 100644
--- a/c/enc/hash_longest_match64_inc.h
+++ b/c/enc/hash_longest_match64_inc.h
@@ -192,8 +192,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@@ -239,8 +241,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
break;
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
/* compare 4 bytes ending at best_len + 1 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
diff --git a/c/enc/hash_longest_match64_simd_inc.h b/c/enc/hash_longest_match64_simd_inc.h
index cd4e7b1..12bd8cf 100644
--- a/c/enc/hash_longest_match64_simd_inc.h
+++ b/c/enc/hash_longest_match64_simd_inc.h
@@ -209,8 +209,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@@ -263,8 +265,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
break;
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
/* compare 4 bytes ending at best_len + 1 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
diff --git a/c/enc/hash_longest_match_inc.h b/c/enc/hash_longest_match_inc.h
index b744f4d..58e88b3 100644
--- a/c/enc/hash_longest_match_inc.h
+++ b/c/enc/hash_longest_match_inc.h
@@ -192,8 +192,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@@ -234,8 +236,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
break;
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
/* compare 4 bytes ending at best_len + 1 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {
diff --git a/c/enc/hash_longest_match_simd_inc.h b/c/enc/hash_longest_match_simd_inc.h
index 2bf9b6c..79b341a 100644
--- a/c/enc/hash_longest_match_simd_inc.h
+++ b/c/enc/hash_longest_match_simd_inc.h
@@ -184,8 +184,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@@ -235,8 +237,10 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
break;
}
prev_ix &= ring_buffer_mask;
- if (cur_ix_masked + best_len > ring_buffer_mask ||
- prev_ix + best_len > ring_buffer_mask ||
+ if (cur_ix_masked + best_len > ring_buffer_mask) {
+ break;
+ }
+ if (prev_ix + best_len > ring_buffer_mask ||
/* compare 4 bytes ending at best_len + 1 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {