xref: /aosp_15_r20/external/lzma/CPP/Common/Xxh64Reg.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
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 
22 Z7_CLASS_IMP_COM_1(
23   CXxh64Hasher
24   , IHasher
25 )
26   CXxh64 _state;
27 public:
28   Byte _mtDummy[1 << 7];  // it's public to eliminate clang warning: unused private field
29   CXxh64Hasher() { Init(); }
30 };
31 
32 Z7_COM7F_IMF2(void, CXxh64Hasher::Init())
33 {
34   Xxh64_Init(&_state);
35 }
36 
37 Z7_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 
56 Z7_COM7F_IMF2(void, CXxh64Hasher::Final(Byte *digest))
57 {
58   const UInt64 val = Xxh64_Digest(&_state);
59   SetUi64(digest, val)
60 }
61 
62 REGISTER_HASHER(CXxh64Hasher, 0x211, "XXH64", 8)
63 
64 
65 
66 #ifdef Z7_USE_HHX64_ORIGINAL
67 namespace NOriginal
68 {
69 Z7_CLASS_IMP_COM_1(
70   CXxh64Hasher
71   , IHasher
72 )
73   XXH64_state_t _state;
74 public:
75   Byte _mtDummy[1 << 7];  // it's public to eliminate clang warning: unused private field
76   CXxh64Hasher() { Init(); }
77 };
78 
79 Z7_COM7F_IMF2(void, CXxh64Hasher::Init())
80 {
81   XXH64_reset(&_state, 0);
82 }
83 
84 Z7_COM7F_IMF2(void, CXxh64Hasher::Update(const void *data, UInt32 size))
85 {
86   XXH64_update(&_state, data, size);
87 }
88 
89 Z7_COM7F_IMF2(void, CXxh64Hasher::Final(Byte *digest))
90 {
91   const UInt64 val = XXH64_digest(&_state);
92   SetUi64(digest, val)
93 }
94 
95 REGISTER_HASHER(CXxh64Hasher, 0x212, "XXH64a", 8)
96 }
97 #endif
98