aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/Xxh64Reg.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common/Xxh64Reg.cpp
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-24.05.tar.gz
7zip-24.05.tar.bz2
7zip-24.05.zip
24.0524.05
Diffstat (limited to 'CPP/Common/Xxh64Reg.cpp')
-rw-r--r--CPP/Common/Xxh64Reg.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/CPP/Common/Xxh64Reg.cpp b/CPP/Common/Xxh64Reg.cpp
new file mode 100644
index 0000000..8abd15e
--- /dev/null
+++ b/CPP/Common/Xxh64Reg.cpp
@@ -0,0 +1,97 @@
1// Xxh64Reg.cpp
2
3#include "StdAfx.h"
4
5#include "../../C/Xxh64.h"
6#include "../../C/CpuArch.h"
7
8// #define Z7_USE_HHX64_ORIGINAL
9#ifdef Z7_USE_HHX64_ORIGINAL
10#ifdef __clang__
11#include "../../C/zstd7z/7z_zstd_cmpl.h"
12#pragma GCC diagnostic ignored "-Wlanguage-extension-token"
13#endif
14#define XXH_STATIC_LINKING_ONLY
15#include "../../C/zstd7z/common/xxhash.h"
16#endif
17
18#include "../Common/MyCom.h"
19
20#include "../7zip/Common/RegisterCodec.h"
21
22Z7_CLASS_IMP_COM_1(
23 CXxh64Hasher
24 , IHasher
25)
26 CXxh64 _state;
27public:
28 Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field
29 CXxh64Hasher() { Init(); }
30};
31
32Z7_COM7F_IMF2(void, CXxh64Hasher::Init())
33{
34 Xxh64_Init(&_state);
35}
36
37Z7_COM7F_IMF2(void, CXxh64Hasher::Update(const void *data, UInt32 size))
38{
39#if 1
40 Xxh64_Update(&_state, data, size);
41#else // for debug:
42 for (;;)
43 {
44 if (size == 0)
45 return;
46 UInt32 size2 = (size * 0x85EBCA87) % size / 8;
47 if (size2 == 0)
48 size2 = 1;
49 Xxh64_Update(&_state, data, size2);
50 data = (const void *)((const Byte *)data + size2);
51 size -= size2;
52 }
53#endif
54}
55
56Z7_COM7F_IMF2(void, CXxh64Hasher::Final(Byte *digest))
57{
58 const UInt64 val = Xxh64_Digest(&_state);
59 SetUi64(digest, val)
60}
61
62REGISTER_HASHER(CXxh64Hasher, 0x211, "XXH64", 8)
63
64
65
66#ifdef Z7_USE_HHX64_ORIGINAL
67namespace NOriginal
68{
69Z7_CLASS_IMP_COM_1(
70 CXxh64Hasher
71 , IHasher
72)
73 XXH64_state_t _state;
74public:
75 Byte _mtDummy[1 << 7]; // it's public to eliminate clang warning: unused private field
76 CXxh64Hasher() { Init(); }
77};
78
79Z7_COM7F_IMF2(void, CXxh64Hasher::Init())
80{
81 XXH64_reset(&_state, 0);
82}
83
84Z7_COM7F_IMF2(void, CXxh64Hasher::Update(const void *data, UInt32 size))
85{
86 XXH64_update(&_state, data, size);
87}
88
89Z7_COM7F_IMF2(void, CXxh64Hasher::Final(Byte *digest))
90{
91 const UInt64 val = XXH64_digest(&_state);
92 SetUi64(digest, val)
93}
94
95REGISTER_HASHER(CXxh64Hasher, 0x212, "XXH64a", 8)
96}
97#endif