summaryrefslogtreecommitdiff
path: root/snappy.cc
diff options
context:
space:
mode:
authorSnappy Team <no-reply@google.com>2020-07-10 22:21:23 +0000
committerVictor Costan <costan@google.com>2020-07-11 01:54:52 +0000
commit4dd277fed475de4898e0eea12124e14033636041 (patch)
treefebed2769c1f20696ae74699390f827c399085db /snappy.cc
parentf16eda3466633b88d0a55199deb00aa5429c6219 (diff)
downloadsnappy-git-4dd277fed475de4898e0eea12124e14033636041.tar.gz
Replace the division with a constant table in IncrementalCopy
PiperOrigin-RevId: 320686580
Diffstat (limited to 'snappy.cc')
-rw-r--r--snappy.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/snappy.cc b/snappy.cc
index 790ae7e..5d3263c 100644
--- a/snappy.cc
+++ b/snappy.cc
@@ -177,6 +177,9 @@ alignas(16) const char pshufb_fill_patterns[7][16] = {
{0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1},
};
+// j * (16 / j) for all j from 0 to 7. 0 is not actually used.
+const uint8_t pattern_size_table[8] = {0, 16, 16, 15, 16, 15, 12, 14};
+
#endif // SNAPPY_HAVE_SSSE3
// 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,
// Uninitialized bytes are masked out by the shuffle mask.
// TODO: remove annotation and macro defs once MSan is fixed.
SNAPPY_ANNOTATE_MEMORY_IS_INITIALIZED(&pattern, sizeof(pattern));
- pattern_size *= 16 / pattern_size;
+ pattern_size = pattern_size_table[pattern_size];
char* op_end = std::min(op_limit, buf_limit - 15);
while (op < op_end) {
_mm_storeu_si128(reinterpret_cast<__m128i*>(op), pattern);