Skip to content

Commit 4dd277f

Browse files
Snappy Teampwnall
Snappy Team
authored andcommitted
Replace the division with a constant table in IncrementalCopy
PiperOrigin-RevId: 320686580
1 parent f16eda3 commit 4dd277f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

snappy.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ alignas(16) const char pshufb_fill_patterns[7][16] = {
177177
{0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1},
178178
};
179179

180+
// j * (16 / j) for all j from 0 to 7. 0 is not actually used.
181+
const uint8_t pattern_size_table[8] = {0, 16, 16, 15, 16, 15, 12, 14};
182+
180183
#endif // SNAPPY_HAVE_SSSE3
181184

182185
// Copy [src, src+(op_limit-op)) to [op, (op_limit-op)) but faster than
@@ -248,7 +251,7 @@ inline char* IncrementalCopy(const char* src, char* op, char* const op_limit,
248251
// Uninitialized bytes are masked out by the shuffle mask.
249252
// TODO: remove annotation and macro defs once MSan is fixed.
250253
SNAPPY_ANNOTATE_MEMORY_IS_INITIALIZED(&pattern, sizeof(pattern));
251-
pattern_size *= 16 / pattern_size;
254+
pattern_size = pattern_size_table[pattern_size];
252255
char* op_end = std::min(op_limit, buf_limit - 15);
253256
while (op < op_end) {
254257
_mm_storeu_si128(reinterpret_cast<__m128i*>(op), pattern);

0 commit comments

Comments
 (0)