summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-03-30 17:34:15 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-03-30 17:34:15 (GMT)
commit6c69dc176c318fba721fa8adade53f3e413cac52 (patch)
tree2c1d73f7ae359a035d2d9ad11611535a29a4d5a7
parent44793b8be9f18bb51f524b3a210de11bb0df6654 (diff)
downloadlz4-6c69dc176c318fba721fa8adade53f3e413cac52.zip
lz4-6c69dc176c318fba721fa8adade53f3e413cac52.tar.gz
lz4-6c69dc176c318fba721fa8adade53f3e413cac52.tar.bz2
faster compression in 64 bits mode
-rw-r--r--lib/lz4.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 881d1af..2a1ae57 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -464,7 +464,24 @@ static U32 LZ4_hashSequence(U32 sequence, tableType_t const tableType)
return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG));
}
-static U32 LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(LZ4_read32(p), tableType); }
+static const U64 prime5bytes = 889523592379ULL;
+static U32 LZ4_hashSequence64(size_t sequence, tableType_t const tableType)
+{
+ const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG;
+ const U32 hashMask = (1<<hashLog) - 1;
+ return ((sequence * prime5bytes) >> (40 - hashLog)) & hashMask;
+}
+
+static U32 LZ4_hashSequenceT(size_t sequence, tableType_t const tableType)
+{
+ if (LZ4_64bits())
+ return LZ4_hashSequence64(sequence, tableType);
+ return LZ4_hashSequence((U32)sequence, tableType);
+}
+
+static U32 LZ4_hashPosition(const void* p, tableType_t tableType) { return LZ4_hashSequenceT(LZ4_read_ARCH(p), tableType); }
+
+//static U32 LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(LZ4_read32(p), tableType); }
static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase)
{