xxh3p.h 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. /*
  6. xxHash - Extremely Fast Hash algorithm
  7. Development source file for `xxh3`
  8. Copyright (C) 2019-present, Yann Collet.
  9. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are
  12. met:
  13. * Redistributions of source code must retain the above copyright
  14. notice, this list of conditions and the following disclaimer.
  15. * Redistributions in binary form must reproduce the above
  16. copyright notice, this list of conditions and the following disclaimer
  17. in the documentation and/or other materials provided with the
  18. distribution.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. You can contact the author at :
  31. - xxHash source repository : https://github.com/Cyan4973/xxHash
  32. */
  33. /* RocksDB Note: This file contains a preview release (xxhash repository
  34. version 0.7.2) of XXH3 that is unlikely to be compatible with the final
  35. version of XXH3. We have therefore renamed this XXH3p ("preview"), for
  36. clarity so that we can continue to use this version even after
  37. integrating a newer incompatible version.
  38. */
  39. /* Note :
  40. This file is separated for development purposes.
  41. It will be integrated into `xxhash.c` when development phase is complete.
  42. */
  43. #ifndef XXH3p_H
  44. #define XXH3p_H
  45. /* === Dependencies === */
  46. #undef XXH_INLINE_ALL /* in case it's already defined */
  47. #define XXH_INLINE_ALL
  48. #include "xxhash.h"
  49. /* === Compiler specifics === */
  50. #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* >= C99 */
  51. # define XXH_RESTRICT restrict
  52. #else
  53. /* note : it might be useful to define __restrict or __restrict__ for some C++ compilers */
  54. # define XXH_RESTRICT /* disable */
  55. #endif
  56. #if defined(__GNUC__)
  57. # if defined(__AVX2__)
  58. # include <immintrin.h>
  59. # elif defined(__SSE2__)
  60. # include <emmintrin.h>
  61. # elif defined(__ARM_NEON__) || defined(__ARM_NEON)
  62. # define inline __inline__ /* clang bug */
  63. # include <arm_neon.h>
  64. # undef inline
  65. # endif
  66. #elif defined(_MSC_VER)
  67. # include <intrin.h>
  68. #endif
  69. /*
  70. * Sanity check.
  71. *
  72. * XXH3 only requires these features to be efficient:
  73. *
  74. * - Usable unaligned access
  75. * - A 32-bit or 64-bit ALU
  76. * - If 32-bit, a decent ADC instruction
  77. * - A 32 or 64-bit multiply with a 64-bit result
  78. *
  79. * Almost all 32-bit and 64-bit targets meet this, except for Thumb-1, the
  80. * classic 16-bit only subset of ARM's instruction set.
  81. *
  82. * First of all, Thumb-1 lacks support for the UMULL instruction which
  83. * performs the important long multiply. This means numerous __aeabi_lmul
  84. * calls.
  85. *
  86. * Second of all, the 8 functional registers are just not enough.
  87. * Setup for __aeabi_lmul, byteshift loads, pointers, and all arithmetic need
  88. * Lo registers, and this shuffling results in thousands more MOVs than A32.
  89. *
  90. * A32 and T32 don't have this limitation. They can access all 14 registers,
  91. * do a 32->64 multiply with UMULL, and the flexible operand is helpful too.
  92. *
  93. * If compiling Thumb-1 for a target which supports ARM instructions, we
  94. * will give a warning.
  95. *
  96. * Usually, if this happens, it is because of an accident and you probably
  97. * need to specify -march, as you probably meant to compileh for a newer
  98. * architecture.
  99. */
  100. #if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM)
  101. # warning "XXH3 is highly inefficient without ARM or Thumb-2."
  102. #endif
  103. /* ==========================================
  104. * Vectorization detection
  105. * ========================================== */
  106. #define XXH_SCALAR 0
  107. #define XXH_SSE2 1
  108. #define XXH_AVX2 2
  109. #define XXH_NEON 3
  110. #define XXH_VSX 4
  111. #ifndef XXH_VECTOR /* can be defined on command line */
  112. # if defined(__AVX2__)
  113. # define XXH_VECTOR XXH_AVX2
  114. # elif defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2))
  115. # define XXH_VECTOR XXH_SSE2
  116. # elif defined(__GNUC__) /* msvc support maybe later */ \
  117. && (defined(__ARM_NEON__) || defined(__ARM_NEON)) \
  118. && (defined(__LITTLE_ENDIAN__) /* We only support little endian NEON */ \
  119. || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  120. # define XXH_VECTOR XXH_NEON
  121. # elif defined(__PPC64__) && defined(__POWER8_VECTOR__) && defined(__GNUC__)
  122. # define XXH_VECTOR XXH_VSX
  123. # else
  124. # define XXH_VECTOR XXH_SCALAR
  125. # endif
  126. #endif
  127. /* control alignment of accumulator,
  128. * for compatibility with fast vector loads */
  129. #ifndef XXH_ACC_ALIGN
  130. # if XXH_VECTOR == 0 /* scalar */
  131. # define XXH_ACC_ALIGN 8
  132. # elif XXH_VECTOR == 1 /* sse2 */
  133. # define XXH_ACC_ALIGN 16
  134. # elif XXH_VECTOR == 2 /* avx2 */
  135. # define XXH_ACC_ALIGN 32
  136. # elif XXH_VECTOR == 3 /* neon */
  137. # define XXH_ACC_ALIGN 16
  138. # elif XXH_VECTOR == 4 /* vsx */
  139. # define XXH_ACC_ALIGN 16
  140. # endif
  141. #endif
  142. /* xxh_u64 XXH_mult32to64(xxh_u32 a, xxh_u64 b) { return (xxh_u64)a * (xxh_u64)b; } */
  143. #if defined(_MSC_VER) && defined(_M_IX86)
  144. # include <intrin.h>
  145. # define XXH_mult32to64(x, y) __emulu(x, y)
  146. #else
  147. # define XXH_mult32to64(x, y) ((xxh_u64)((x) & 0xFFFFFFFF) * (xxh_u64)((y) & 0xFFFFFFFF))
  148. #endif
  149. /* VSX stuff. It's a lot because VSX support is mediocre across compilers and
  150. * there is a lot of mischief with endianness. */
  151. #if XXH_VECTOR == XXH_VSX
  152. # include <altivec.h>
  153. # undef vector
  154. typedef __vector unsigned long long U64x2;
  155. typedef __vector unsigned char U8x16;
  156. typedef __vector unsigned U32x4;
  157. #ifndef XXH_VSX_BE
  158. # if defined(__BIG_ENDIAN__) \
  159. || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  160. # define XXH_VSX_BE 1
  161. # elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__
  162. # warning "-maltivec=be is not recommended. Please use native endianness."
  163. # define XXH_VSX_BE 1
  164. # else
  165. # define XXH_VSX_BE 0
  166. # endif
  167. #endif
  168. /* We need some helpers for big endian mode. */
  169. #if XXH_VSX_BE
  170. /* A wrapper for POWER9's vec_revb. */
  171. # ifdef __POWER9_VECTOR__
  172. # define XXH_vec_revb vec_revb
  173. # else
  174. XXH_FORCE_INLINE U64x2 XXH_vec_revb(U64x2 val)
  175. {
  176. U8x16 const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
  177. 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 };
  178. return vec_perm(val, val, vByteSwap);
  179. }
  180. # endif
  181. /* Power8 Crypto gives us vpermxor which is very handy for
  182. * PPC64EB.
  183. *
  184. * U8x16 vpermxor(U8x16 a, U8x16 b, U8x16 mask)
  185. * {
  186. * U8x16 ret;
  187. * for (int i = 0; i < 16; i++) {
  188. * ret[i] = a[mask[i] & 0xF] ^ b[mask[i] >> 4];
  189. * }
  190. * return ret;
  191. * }
  192. *
  193. * Because both of the main loops load the key, swap, and xor it with input,
  194. * we can combine the key swap into this instruction.
  195. */
  196. # ifdef vec_permxor
  197. # define XXH_vec_permxor vec_permxor
  198. # else
  199. # define XXH_vec_permxor __builtin_crypto_vpermxor
  200. # endif
  201. #endif /* XXH_VSX_BE */
  202. /*
  203. * Because we reinterpret the multiply, there are endian memes: vec_mulo actually becomes
  204. * vec_mule.
  205. *
  206. * Additionally, the intrinsic wasn't added until GCC 8, despite existing for a while.
  207. * Clang has an easy way to control this, we can just use the builtin which doesn't swap.
  208. * GCC needs inline assembly. */
  209. #if __has_builtin(__builtin_altivec_vmuleuw)
  210. # define XXH_vec_mulo __builtin_altivec_vmulouw
  211. # define XXH_vec_mule __builtin_altivec_vmuleuw
  212. #else
  213. /* Adapted from https://github.com/google/highwayhash/blob/master/highwayhash/hh_vsx.h. */
  214. XXH_FORCE_INLINE U64x2 XXH_vec_mulo(U32x4 a, U32x4 b) {
  215. U64x2 result;
  216. __asm__("vmulouw %0, %1, %2" : "=v" (result) : "v" (a), "v" (b));
  217. return result;
  218. }
  219. XXH_FORCE_INLINE U64x2 XXH_vec_mule(U32x4 a, U32x4 b) {
  220. U64x2 result;
  221. __asm__("vmuleuw %0, %1, %2" : "=v" (result) : "v" (a), "v" (b));
  222. return result;
  223. }
  224. #endif /* __has_builtin(__builtin_altivec_vmuleuw) */
  225. #endif /* XXH_VECTOR == XXH_VSX */
  226. /* prefetch
  227. * can be disabled, by declaring XXH_NO_PREFETCH build macro */
  228. #if defined(XXH_NO_PREFETCH)
  229. # define XXH_PREFETCH(ptr) (void)(ptr) /* disabled */
  230. #else
  231. # if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
  232. # include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
  233. # define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
  234. # elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
  235. # define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
  236. # else
  237. # define XXH_PREFETCH(ptr) (void)(ptr) /* disabled */
  238. # endif
  239. #endif /* XXH_NO_PREFETCH */
  240. /* ==========================================
  241. * XXH3 default settings
  242. * ========================================== */
  243. #define XXH_SECRET_DEFAULT_SIZE 192 /* minimum XXH3p_SECRET_SIZE_MIN */
  244. #if (XXH_SECRET_DEFAULT_SIZE < XXH3p_SECRET_SIZE_MIN)
  245. # error "default keyset is not large enough"
  246. #endif
  247. XXH_ALIGN(64) static const xxh_u8 kSecret[XXH_SECRET_DEFAULT_SIZE] = {
  248. 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
  249. 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
  250. 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21,
  251. 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c,
  252. 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3,
  253. 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8,
  254. 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d,
  255. 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64,
  256. 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb,
  257. 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e,
  258. 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce,
  259. 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e,
  260. };
  261. /*
  262. * GCC for x86 has a tendency to use SSE in this loop. While it
  263. * successfully avoids swapping (as MUL overwrites EAX and EDX), it
  264. * slows it down because instead of free register swap shifts, it
  265. * must use pshufd and punpckl/hd.
  266. *
  267. * To prevent this, we use this attribute to shut off SSE.
  268. */
  269. #if defined(__GNUC__) && !defined(__clang__) && defined(__i386__)
  270. __attribute__((__target__("no-sse")))
  271. #endif
  272. static XXH128_hash_t
  273. XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs)
  274. {
  275. /*
  276. * GCC/Clang __uint128_t method.
  277. *
  278. * On most 64-bit targets, GCC and Clang define a __uint128_t type.
  279. * This is usually the best way as it usually uses a native long 64-bit
  280. * multiply, such as MULQ on x86_64 or MUL + UMULH on aarch64.
  281. *
  282. * Usually.
  283. *
  284. * Despite being a 32-bit platform, Clang (and emscripten) define this
  285. * type despite not having the arithmetic for it. This results in a
  286. * laggy compiler builtin call which calculates a full 128-bit multiply.
  287. * In that case it is best to use the portable one.
  288. * https://github.com/Cyan4973/xxHash/issues/211#issuecomment-515575677
  289. */
  290. #if defined(__GNUC__) && !defined(__wasm__) \
  291. && defined(__SIZEOF_INT128__) \
  292. || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128)
  293. __uint128_t product = (__uint128_t)lhs * (__uint128_t)rhs;
  294. XXH128_hash_t const r128 = { (xxh_u64)(product), (xxh_u64)(product >> 64) };
  295. return r128;
  296. /*
  297. * MSVC for x64's _umul128 method.
  298. *
  299. * xxh_u64 _umul128(xxh_u64 Multiplier, xxh_u64 Multiplicand, xxh_u64 *HighProduct);
  300. *
  301. * This compiles to single operand MUL on x64.
  302. */
  303. #elif defined(_M_X64) || defined(_M_IA64)
  304. #ifndef _MSC_VER
  305. # pragma intrinsic(_umul128)
  306. #endif
  307. xxh_u64 product_high;
  308. xxh_u64 const product_low = _umul128(lhs, rhs, &product_high);
  309. XXH128_hash_t const r128 = { product_low, product_high };
  310. return r128;
  311. #else
  312. /*
  313. * Portable scalar method. Optimized for 32-bit and 64-bit ALUs.
  314. *
  315. * This is a fast and simple grade school multiply, which is shown
  316. * below with base 10 arithmetic instead of base 0x100000000.
  317. *
  318. * 9 3 // D2 lhs = 93
  319. * x 7 5 // D2 rhs = 75
  320. * ----------
  321. * 1 5 // D2 lo_lo = (93 % 10) * (75 % 10)
  322. * 4 5 | // D2 hi_lo = (93 / 10) * (75 % 10)
  323. * 2 1 | // D2 lo_hi = (93 % 10) * (75 / 10)
  324. * + 6 3 | | // D2 hi_hi = (93 / 10) * (75 / 10)
  325. * ---------
  326. * 2 7 | // D2 cross = (15 / 10) + (45 % 10) + 21
  327. * + 6 7 | | // D2 upper = (27 / 10) + (45 / 10) + 63
  328. * ---------
  329. * 6 9 7 5
  330. *
  331. * The reasons for adding the products like this are:
  332. * 1. It avoids manual carry tracking. Just like how
  333. * (9 * 9) + 9 + 9 = 99, the same applies with this for
  334. * UINT64_MAX. This avoids a lot of complexity.
  335. *
  336. * 2. It hints for, and on Clang, compiles to, the powerful UMAAL
  337. * instruction available in ARMv6+ A32/T32, which is shown below:
  338. *
  339. * void UMAAL(xxh_u32 *RdLo, xxh_u32 *RdHi, xxh_u32 Rn, xxh_u32 Rm)
  340. * {
  341. * xxh_u64 product = (xxh_u64)*RdLo * (xxh_u64)*RdHi + Rn + Rm;
  342. * *RdLo = (xxh_u32)(product & 0xFFFFFFFF);
  343. * *RdHi = (xxh_u32)(product >> 32);
  344. * }
  345. *
  346. * This instruction was designed for efficient long multiplication,
  347. * and allows this to be calculated in only 4 instructions which
  348. * is comparable to some 64-bit ALUs.
  349. *
  350. * 3. It isn't terrible on other platforms. Usually this will be
  351. * a couple of 32-bit ADD/ADCs.
  352. */
  353. /* First calculate all of the cross products. */
  354. xxh_u64 const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF);
  355. xxh_u64 const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF);
  356. xxh_u64 const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32);
  357. xxh_u64 const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32);
  358. /* Now add the products together. These will never overflow. */
  359. xxh_u64 const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi;
  360. xxh_u64 const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi;
  361. xxh_u64 const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF);
  362. XXH128_hash_t r128 = { lower, upper };
  363. return r128;
  364. #endif
  365. }
  366. /*
  367. * We want to keep the attribute here because a target switch
  368. * disables inlining.
  369. *
  370. * Does a 64-bit to 128-bit multiply, then XOR folds it.
  371. * The reason for the separate function is to prevent passing
  372. * too many structs around by value. This will hopefully inline
  373. * the multiply, but we don't force it.
  374. */
  375. #if defined(__GNUC__) && !defined(__clang__) && defined(__i386__)
  376. __attribute__((__target__("no-sse")))
  377. #endif
  378. static xxh_u64
  379. XXH3p_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs)
  380. {
  381. XXH128_hash_t product = XXH_mult64to128(lhs, rhs);
  382. return product.low64 ^ product.high64;
  383. }
  384. static XXH64_hash_t XXH3p_avalanche(xxh_u64 h64)
  385. {
  386. h64 ^= h64 >> 37;
  387. h64 *= PRIME64_3;
  388. h64 ^= h64 >> 32;
  389. return h64;
  390. }
  391. /* ==========================================
  392. * Short keys
  393. * ========================================== */
  394. XXH_FORCE_INLINE XXH64_hash_t
  395. XXH3p_len_1to3_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  396. {
  397. XXH_ASSERT(input != NULL);
  398. XXH_ASSERT(1 <= len && len <= 3);
  399. XXH_ASSERT(secret != NULL);
  400. { xxh_u8 const c1 = input[0];
  401. xxh_u8 const c2 = input[len >> 1];
  402. xxh_u8 const c3 = input[len - 1];
  403. xxh_u32 const combined = ((xxh_u32)c1) | (((xxh_u32)c2) << 8) | (((xxh_u32)c3) << 16) | (((xxh_u32)len) << 24);
  404. xxh_u64 const keyed = (xxh_u64)combined ^ (XXH_readLE32(secret) + seed);
  405. xxh_u64 const mixed = keyed * PRIME64_1;
  406. return XXH3p_avalanche(mixed);
  407. }
  408. }
  409. XXH_FORCE_INLINE XXH64_hash_t
  410. XXH3p_len_4to8_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  411. {
  412. XXH_ASSERT(input != NULL);
  413. XXH_ASSERT(secret != NULL);
  414. XXH_ASSERT(4 <= len && len <= 8);
  415. { xxh_u32 const input_lo = XXH_readLE32(input);
  416. xxh_u32 const input_hi = XXH_readLE32(input + len - 4);
  417. xxh_u64 const input_64 = input_lo | ((xxh_u64)input_hi << 32);
  418. xxh_u64 const keyed = input_64 ^ (XXH_readLE64(secret) + seed);
  419. xxh_u64 const mix64 = len + ((keyed ^ (keyed >> 51)) * PRIME32_1);
  420. return XXH3p_avalanche((mix64 ^ (mix64 >> 47)) * PRIME64_2);
  421. }
  422. }
  423. XXH_FORCE_INLINE XXH64_hash_t
  424. XXH3p_len_9to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  425. {
  426. XXH_ASSERT(input != NULL);
  427. XXH_ASSERT(secret != NULL);
  428. XXH_ASSERT(9 <= len && len <= 16);
  429. { xxh_u64 const input_lo = XXH_readLE64(input) ^ (XXH_readLE64(secret) + seed);
  430. xxh_u64 const input_hi = XXH_readLE64(input + len - 8) ^ (XXH_readLE64(secret + 8) - seed);
  431. xxh_u64 const acc = len + (input_lo + input_hi) + XXH3p_mul128_fold64(input_lo, input_hi);
  432. return XXH3p_avalanche(acc);
  433. }
  434. }
  435. XXH_FORCE_INLINE XXH64_hash_t
  436. XXH3p_len_0to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  437. {
  438. XXH_ASSERT(len <= 16);
  439. { if (len > 8) return XXH3p_len_9to16_64b(input, len, secret, seed);
  440. if (len >= 4) return XXH3p_len_4to8_64b(input, len, secret, seed);
  441. if (len) return XXH3p_len_1to3_64b(input, len, secret, seed);
  442. /*
  443. * RocksDB modification from XXH3 preview: zero result for empty
  444. * string can be problematic for multiplication-based algorithms.
  445. * Return a hash of the seed instead.
  446. */
  447. return XXH3p_mul128_fold64(seed + XXH_readLE64(secret), PRIME64_2);
  448. }
  449. }
  450. /* === Long Keys === */
  451. #define STRIPE_LEN 64
  452. #define XXH_SECRET_CONSUME_RATE 8 /* nb of secret bytes consumed at each accumulation */
  453. #define ACC_NB (STRIPE_LEN / sizeof(xxh_u64))
  454. typedef enum { XXH3p_acc_64bits, XXH3p_acc_128bits } XXH3p_accWidth_e;
  455. XXH_FORCE_INLINE void
  456. XXH3p_accumulate_512( void* XXH_RESTRICT acc,
  457. const void* XXH_RESTRICT input,
  458. const void* XXH_RESTRICT secret,
  459. XXH3p_accWidth_e accWidth)
  460. {
  461. #if (XXH_VECTOR == XXH_AVX2)
  462. XXH_ASSERT((((size_t)acc) & 31) == 0);
  463. { XXH_ALIGN(32) __m256i* const xacc = (__m256i *) acc;
  464. const __m256i* const xinput = (const __m256i *) input; /* not really aligned, just for ptr arithmetic, and because _mm256_loadu_si256() requires this type */
  465. const __m256i* const xsecret = (const __m256i *) secret; /* not really aligned, just for ptr arithmetic, and because _mm256_loadu_si256() requires this type */
  466. size_t i;
  467. for (i=0; i < STRIPE_LEN/sizeof(__m256i); i++) {
  468. __m256i const data_vec = _mm256_loadu_si256 (xinput+i);
  469. __m256i const key_vec = _mm256_loadu_si256 (xsecret+i);
  470. __m256i const data_key = _mm256_xor_si256 (data_vec, key_vec); /* uint32 dk[8] = {d0+k0, d1+k1, d2+k2, d3+k3, ...} */
  471. __m256i const product = _mm256_mul_epu32 (data_key, _mm256_shuffle_epi32 (data_key, 0x31)); /* uint64 mul[4] = {dk0*dk1, dk2*dk3, ...} */
  472. if (accWidth == XXH3p_acc_128bits) {
  473. __m256i const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2));
  474. __m256i const sum = _mm256_add_epi64(xacc[i], data_swap);
  475. xacc[i] = _mm256_add_epi64(product, sum);
  476. } else { /* XXH3p_acc_64bits */
  477. __m256i const sum = _mm256_add_epi64(xacc[i], data_vec);
  478. xacc[i] = _mm256_add_epi64(product, sum);
  479. }
  480. } }
  481. #elif (XXH_VECTOR == XXH_SSE2)
  482. XXH_ASSERT((((size_t)acc) & 15) == 0);
  483. { XXH_ALIGN(16) __m128i* const xacc = (__m128i *) acc;
  484. const __m128i* const xinput = (const __m128i *) input; /* not really aligned, just for ptr arithmetic, and because _mm_loadu_si128() requires this type */
  485. const __m128i* const xsecret = (const __m128i *) secret; /* not really aligned, just for ptr arithmetic, and because _mm_loadu_si128() requires this type */
  486. size_t i;
  487. for (i=0; i < STRIPE_LEN/sizeof(__m128i); i++) {
  488. __m128i const data_vec = _mm_loadu_si128 (xinput+i);
  489. __m128i const key_vec = _mm_loadu_si128 (xsecret+i);
  490. __m128i const data_key = _mm_xor_si128 (data_vec, key_vec); /* uint32 dk[8] = {d0+k0, d1+k1, d2+k2, d3+k3, ...} */
  491. __m128i const product = _mm_mul_epu32 (data_key, _mm_shuffle_epi32 (data_key, 0x31)); /* uint64 mul[4] = {dk0*dk1, dk2*dk3, ...} */
  492. if (accWidth == XXH3p_acc_128bits) {
  493. __m128i const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2));
  494. __m128i const sum = _mm_add_epi64(xacc[i], data_swap);
  495. xacc[i] = _mm_add_epi64(product, sum);
  496. } else { /* XXH3p_acc_64bits */
  497. __m128i const sum = _mm_add_epi64(xacc[i], data_vec);
  498. xacc[i] = _mm_add_epi64(product, sum);
  499. }
  500. } }
  501. #elif (XXH_VECTOR == XXH_NEON)
  502. XXH_ASSERT((((size_t)acc) & 15) == 0);
  503. {
  504. XXH_ALIGN(16) uint64x2_t* const xacc = (uint64x2_t *) acc;
  505. /* We don't use a uint32x4_t pointer because it causes bus errors on ARMv7. */
  506. uint8_t const* const xinput = (const uint8_t *) input;
  507. uint8_t const* const xsecret = (const uint8_t *) secret;
  508. size_t i;
  509. for (i=0; i < STRIPE_LEN / sizeof(uint64x2_t); i++) {
  510. #if !defined(__aarch64__) && !defined(__arm64__) && defined(__GNUC__) /* ARM32-specific hack */
  511. /* vzip on ARMv7 Clang generates a lot of vmovs (technically vorrs) without this.
  512. * vzip on 32-bit ARM NEON will overwrite the original register, and I think that Clang
  513. * assumes I don't want to destroy it and tries to make a copy. This slows down the code
  514. * a lot.
  515. * aarch64 not only uses an entirely different syntax, but it requires three
  516. * instructions...
  517. * ext v1.16B, v0.16B, #8 // select high bits because aarch64 can't address them directly
  518. * zip1 v3.2s, v0.2s, v1.2s // first zip
  519. * zip2 v2.2s, v0.2s, v1.2s // second zip
  520. * ...to do what ARM does in one:
  521. * vzip.32 d0, d1 // Interleave high and low bits and overwrite. */
  522. /* data_vec = xsecret[i]; */
  523. uint8x16_t const data_vec = vld1q_u8(xinput + (i * 16));
  524. /* key_vec = xsecret[i]; */
  525. uint8x16_t const key_vec = vld1q_u8(xsecret + (i * 16));
  526. /* data_key = data_vec ^ key_vec; */
  527. uint32x4_t data_key;
  528. if (accWidth == XXH3p_acc_64bits) {
  529. /* Add first to prevent register swaps */
  530. /* xacc[i] += data_vec; */
  531. xacc[i] = vaddq_u64 (xacc[i], vreinterpretq_u64_u8(data_vec));
  532. } else { /* XXH3p_acc_128bits */
  533. /* xacc[i] += swap(data_vec); */
  534. /* can probably be optimized better */
  535. uint64x2_t const data64 = vreinterpretq_u64_u8(data_vec);
  536. uint64x2_t const swapped= vextq_u64(data64, data64, 1);
  537. xacc[i] = vaddq_u64 (xacc[i], swapped);
  538. }
  539. data_key = vreinterpretq_u32_u8(veorq_u8(data_vec, key_vec));
  540. /* Here's the magic. We use the quirkiness of vzip to shuffle data_key in place.
  541. * shuffle: data_key[0, 1, 2, 3] = data_key[0, 2, 1, 3] */
  542. __asm__("vzip.32 %e0, %f0" : "+w" (data_key));
  543. /* xacc[i] += (uint64x2_t) data_key[0, 1] * (uint64x2_t) data_key[2, 3]; */
  544. xacc[i] = vmlal_u32(xacc[i], vget_low_u32(data_key), vget_high_u32(data_key));
  545. #else
  546. /* On aarch64, vshrn/vmovn seems to be equivalent to, if not faster than, the vzip method. */
  547. /* data_vec = xsecret[i]; */
  548. uint8x16_t const data_vec = vld1q_u8(xinput + (i * 16));
  549. /* key_vec = xsecret[i]; */
  550. uint8x16_t const key_vec = vld1q_u8(xsecret + (i * 16));
  551. /* data_key = data_vec ^ key_vec; */
  552. uint64x2_t const data_key = vreinterpretq_u64_u8(veorq_u8(data_vec, key_vec));
  553. /* data_key_lo = (uint32x2_t) (data_key & 0xFFFFFFFF); */
  554. uint32x2_t const data_key_lo = vmovn_u64 (data_key);
  555. /* data_key_hi = (uint32x2_t) (data_key >> 32); */
  556. uint32x2_t const data_key_hi = vshrn_n_u64 (data_key, 32);
  557. if (accWidth == XXH3p_acc_64bits) {
  558. /* xacc[i] += data_vec; */
  559. xacc[i] = vaddq_u64 (xacc[i], vreinterpretq_u64_u8(data_vec));
  560. } else { /* XXH3p_acc_128bits */
  561. /* xacc[i] += swap(data_vec); */
  562. uint64x2_t const data64 = vreinterpretq_u64_u8(data_vec);
  563. uint64x2_t const swapped= vextq_u64(data64, data64, 1);
  564. xacc[i] = vaddq_u64 (xacc[i], swapped);
  565. }
  566. /* xacc[i] += (uint64x2_t) data_key_lo * (uint64x2_t) data_key_hi; */
  567. xacc[i] = vmlal_u32 (xacc[i], data_key_lo, data_key_hi);
  568. #endif
  569. }
  570. }
  571. #elif (XXH_VECTOR == XXH_VSX)
  572. U64x2* const xacc = (U64x2*) acc; /* presumed aligned */
  573. U64x2 const* const xinput = (U64x2 const*) input; /* no alignment restriction */
  574. U64x2 const* const xsecret = (U64x2 const*) secret; /* no alignment restriction */
  575. U64x2 const v32 = { 32, 32 };
  576. #if XXH_VSX_BE
  577. U8x16 const vXorSwap = { 0x07, 0x16, 0x25, 0x34, 0x43, 0x52, 0x61, 0x70,
  578. 0x8F, 0x9E, 0xAD, 0xBC, 0xCB, 0xDA, 0xE9, 0xF8 };
  579. #endif
  580. size_t i;
  581. for (i = 0; i < STRIPE_LEN / sizeof(U64x2); i++) {
  582. /* data_vec = xinput[i]; */
  583. /* key_vec = xsecret[i]; */
  584. #if XXH_VSX_BE
  585. /* byteswap */
  586. U64x2 const data_vec = XXH_vec_revb(vec_vsx_ld(0, xinput + i));
  587. U64x2 const key_raw = vec_vsx_ld(0, xsecret + i);
  588. /* See comment above. data_key = data_vec ^ swap(xsecret[i]); */
  589. U64x2 const data_key = (U64x2)XXH_vec_permxor((U8x16)data_vec, (U8x16)key_raw, vXorSwap);
  590. #else
  591. U64x2 const data_vec = vec_vsx_ld(0, xinput + i);
  592. U64x2 const key_vec = vec_vsx_ld(0, xsecret + i);
  593. U64x2 const data_key = data_vec ^ key_vec;
  594. #endif
  595. /* shuffled = (data_key << 32) | (data_key >> 32); */
  596. U32x4 const shuffled = (U32x4)vec_rl(data_key, v32);
  597. /* product = ((U64x2)data_key & 0xFFFFFFFF) * ((U64x2)shuffled & 0xFFFFFFFF); */
  598. U64x2 const product = XXH_vec_mulo((U32x4)data_key, shuffled);
  599. xacc[i] += product;
  600. if (accWidth == XXH3p_acc_64bits) {
  601. xacc[i] += data_vec;
  602. } else { /* XXH3p_acc_128bits */
  603. /* swap high and low halves */
  604. U64x2 const data_swapped = vec_xxpermdi(data_vec, data_vec, 2);
  605. xacc[i] += data_swapped;
  606. }
  607. }
  608. #else /* scalar variant of Accumulator - universal */
  609. XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64* const xacc = (xxh_u64*) acc; /* presumed aligned on 32-bytes boundaries, little hint for the auto-vectorizer */
  610. const xxh_u8* const xinput = (const xxh_u8*) input; /* no alignment restriction */
  611. const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */
  612. size_t i;
  613. XXH_ASSERT(((size_t)acc & (XXH_ACC_ALIGN-1)) == 0);
  614. for (i=0; i < ACC_NB; i++) {
  615. xxh_u64 const data_val = XXH_readLE64(xinput + 8*i);
  616. xxh_u64 const data_key = data_val ^ XXH_readLE64(xsecret + i*8);
  617. if (accWidth == XXH3p_acc_64bits) {
  618. xacc[i] += data_val;
  619. } else {
  620. xacc[i ^ 1] += data_val; /* swap adjacent lanes */
  621. }
  622. xacc[i] += XXH_mult32to64(data_key & 0xFFFFFFFF, data_key >> 32);
  623. }
  624. #endif
  625. }
  626. XXH_FORCE_INLINE void
  627. XXH3p_scrambleAcc(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret)
  628. {
  629. #if (XXH_VECTOR == XXH_AVX2)
  630. XXH_ASSERT((((size_t)acc) & 31) == 0);
  631. { XXH_ALIGN(32) __m256i* const xacc = (__m256i*) acc;
  632. const __m256i* const xsecret = (const __m256i *) secret; /* not really aligned, just for ptr arithmetic, and because _mm256_loadu_si256() requires this argument type */
  633. const __m256i prime32 = _mm256_set1_epi32((int)PRIME32_1);
  634. size_t i;
  635. for (i=0; i < STRIPE_LEN/sizeof(__m256i); i++) {
  636. /* xacc[i] ^= (xacc[i] >> 47) */
  637. __m256i const acc_vec = xacc[i];
  638. __m256i const shifted = _mm256_srli_epi64 (acc_vec, 47);
  639. __m256i const data_vec = _mm256_xor_si256 (acc_vec, shifted);
  640. /* xacc[i] ^= xsecret; */
  641. __m256i const key_vec = _mm256_loadu_si256 (xsecret+i);
  642. __m256i const data_key = _mm256_xor_si256 (data_vec, key_vec);
  643. /* xacc[i] *= PRIME32_1; */
  644. __m256i const data_key_hi = _mm256_shuffle_epi32 (data_key, 0x31);
  645. __m256i const prod_lo = _mm256_mul_epu32 (data_key, prime32);
  646. __m256i const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32);
  647. xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32));
  648. }
  649. }
  650. #elif (XXH_VECTOR == XXH_SSE2)
  651. XXH_ASSERT((((size_t)acc) & 15) == 0);
  652. { XXH_ALIGN(16) __m128i* const xacc = (__m128i*) acc;
  653. const __m128i* const xsecret = (const __m128i *) secret; /* not really aligned, just for ptr arithmetic, and because _mm_loadu_si128() requires this argument type */
  654. const __m128i prime32 = _mm_set1_epi32((int)PRIME32_1);
  655. size_t i;
  656. for (i=0; i < STRIPE_LEN/sizeof(__m128i); i++) {
  657. /* xacc[i] ^= (xacc[i] >> 47) */
  658. __m128i const acc_vec = xacc[i];
  659. __m128i const shifted = _mm_srli_epi64 (acc_vec, 47);
  660. __m128i const data_vec = _mm_xor_si128 (acc_vec, shifted);
  661. /* xacc[i] ^= xsecret; */
  662. __m128i const key_vec = _mm_loadu_si128 (xsecret+i);
  663. __m128i const data_key = _mm_xor_si128 (data_vec, key_vec);
  664. /* xacc[i] *= PRIME32_1; */
  665. __m128i const data_key_hi = _mm_shuffle_epi32 (data_key, 0x31);
  666. __m128i const prod_lo = _mm_mul_epu32 (data_key, prime32);
  667. __m128i const prod_hi = _mm_mul_epu32 (data_key_hi, prime32);
  668. xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32));
  669. }
  670. }
  671. #elif (XXH_VECTOR == XXH_NEON)
  672. XXH_ASSERT((((size_t)acc) & 15) == 0);
  673. { uint64x2_t* const xacc = (uint64x2_t*) acc;
  674. uint8_t const* const xsecret = (uint8_t const*) secret;
  675. uint32x2_t const prime = vdup_n_u32 (PRIME32_1);
  676. size_t i;
  677. for (i=0; i < STRIPE_LEN/sizeof(uint64x2_t); i++) {
  678. /* data_vec = xacc[i] ^ (xacc[i] >> 47); */
  679. uint64x2_t const acc_vec = xacc[i];
  680. uint64x2_t const shifted = vshrq_n_u64 (acc_vec, 47);
  681. uint64x2_t const data_vec = veorq_u64 (acc_vec, shifted);
  682. /* key_vec = xsecret[i]; */
  683. uint32x4_t const key_vec = vreinterpretq_u32_u8(vld1q_u8(xsecret + (i * 16)));
  684. /* data_key = data_vec ^ key_vec; */
  685. uint32x4_t const data_key = veorq_u32 (vreinterpretq_u32_u64(data_vec), key_vec);
  686. /* shuffled = { data_key[0, 2], data_key[1, 3] }; */
  687. uint32x2x2_t const shuffled = vzip_u32 (vget_low_u32(data_key), vget_high_u32(data_key));
  688. /* data_key *= PRIME32_1 */
  689. /* prod_hi = (data_key >> 32) * PRIME32_1; */
  690. uint64x2_t const prod_hi = vmull_u32 (shuffled.val[1], prime);
  691. /* xacc[i] = prod_hi << 32; */
  692. xacc[i] = vshlq_n_u64(prod_hi, 32);
  693. /* xacc[i] += (prod_hi & 0xFFFFFFFF) * PRIME32_1; */
  694. xacc[i] = vmlal_u32(xacc[i], shuffled.val[0], prime);
  695. } }
  696. #elif (XXH_VECTOR == XXH_VSX)
  697. U64x2* const xacc = (U64x2*) acc;
  698. const U64x2* const xsecret = (const U64x2*) secret;
  699. /* constants */
  700. U64x2 const v32 = { 32, 32 };
  701. U64x2 const v47 = { 47, 47 };
  702. U32x4 const prime = { PRIME32_1, PRIME32_1, PRIME32_1, PRIME32_1 };
  703. size_t i;
  704. #if XXH_VSX_BE
  705. /* endian swap */
  706. U8x16 const vXorSwap = { 0x07, 0x16, 0x25, 0x34, 0x43, 0x52, 0x61, 0x70,
  707. 0x8F, 0x9E, 0xAD, 0xBC, 0xCB, 0xDA, 0xE9, 0xF8 };
  708. #endif
  709. for (i = 0; i < STRIPE_LEN / sizeof(U64x2); i++) {
  710. U64x2 const acc_vec = xacc[i];
  711. U64x2 const data_vec = acc_vec ^ (acc_vec >> v47);
  712. /* key_vec = xsecret[i]; */
  713. #if XXH_VSX_BE
  714. /* swap bytes words */
  715. U64x2 const key_raw = vec_vsx_ld(0, xsecret + i);
  716. U64x2 const data_key = (U64x2)XXH_vec_permxor((U8x16)data_vec, (U8x16)key_raw, vXorSwap);
  717. #else
  718. U64x2 const key_vec = vec_vsx_ld(0, xsecret + i);
  719. U64x2 const data_key = data_vec ^ key_vec;
  720. #endif
  721. /* data_key *= PRIME32_1 */
  722. /* prod_lo = ((U64x2)data_key & 0xFFFFFFFF) * ((U64x2)prime & 0xFFFFFFFF); */
  723. U64x2 const prod_even = XXH_vec_mule((U32x4)data_key, prime);
  724. /* prod_hi = ((U64x2)data_key >> 32) * ((U64x2)prime >> 32); */
  725. U64x2 const prod_odd = XXH_vec_mulo((U32x4)data_key, prime);
  726. xacc[i] = prod_odd + (prod_even << v32);
  727. }
  728. #else /* scalar variant of Scrambler - universal */
  729. XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64* const xacc = (xxh_u64*) acc; /* presumed aligned on 32-bytes boundaries, little hint for the auto-vectorizer */
  730. const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */
  731. size_t i;
  732. XXH_ASSERT((((size_t)acc) & (XXH_ACC_ALIGN-1)) == 0);
  733. for (i=0; i < ACC_NB; i++) {
  734. xxh_u64 const key64 = XXH_readLE64(xsecret + 8*i);
  735. xxh_u64 acc64 = xacc[i];
  736. acc64 ^= acc64 >> 47;
  737. acc64 ^= key64;
  738. acc64 *= PRIME32_1;
  739. xacc[i] = acc64;
  740. }
  741. #endif
  742. }
  743. #define XXH_PREFETCH_DIST 384
  744. /* assumption : nbStripes will not overflow secret size */
  745. XXH_FORCE_INLINE void
  746. XXH3p_accumulate( xxh_u64* XXH_RESTRICT acc,
  747. const xxh_u8* XXH_RESTRICT input,
  748. const xxh_u8* XXH_RESTRICT secret,
  749. size_t nbStripes,
  750. XXH3p_accWidth_e accWidth)
  751. {
  752. size_t n;
  753. for (n = 0; n < nbStripes; n++ ) {
  754. const xxh_u8* const in = input + n*STRIPE_LEN;
  755. XXH_PREFETCH(in + XXH_PREFETCH_DIST);
  756. XXH3p_accumulate_512(acc,
  757. in,
  758. secret + n*XXH_SECRET_CONSUME_RATE,
  759. accWidth);
  760. }
  761. }
  762. /* note : clang auto-vectorizes well in SS2 mode _if_ this function is `static`,
  763. * and doesn't auto-vectorize it at all if it is `FORCE_INLINE`.
  764. * However, it auto-vectorizes better AVX2 if it is `FORCE_INLINE`
  765. * Pretty much every other modes and compilers prefer `FORCE_INLINE`.
  766. */
  767. #if defined(__clang__) && (XXH_VECTOR==0) && !defined(__AVX2__) && !defined(__arm__) && !defined(__thumb__)
  768. static void
  769. #else
  770. XXH_FORCE_INLINE void
  771. #endif
  772. XXH3p_hashLong_internal_loop( xxh_u64* XXH_RESTRICT acc,
  773. const xxh_u8* XXH_RESTRICT input, size_t len,
  774. const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
  775. XXH3p_accWidth_e accWidth)
  776. {
  777. size_t const nb_rounds = (secretSize - STRIPE_LEN) / XXH_SECRET_CONSUME_RATE;
  778. size_t const block_len = STRIPE_LEN * nb_rounds;
  779. size_t const nb_blocks = len / block_len;
  780. size_t n;
  781. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN);
  782. for (n = 0; n < nb_blocks; n++) {
  783. XXH3p_accumulate(acc, input + n*block_len, secret, nb_rounds, accWidth);
  784. XXH3p_scrambleAcc(acc, secret + secretSize - STRIPE_LEN);
  785. }
  786. /* last partial block */
  787. XXH_ASSERT(len > STRIPE_LEN);
  788. { size_t const nbStripes = (len - (block_len * nb_blocks)) / STRIPE_LEN;
  789. XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE));
  790. XXH3p_accumulate(acc, input + nb_blocks*block_len, secret, nbStripes, accWidth);
  791. /* last stripe */
  792. if (len & (STRIPE_LEN - 1)) {
  793. const xxh_u8* const p = input + len - STRIPE_LEN;
  794. #define XXH_SECRET_LASTACC_START 7 /* do not align on 8, so that secret is different from scrambler */
  795. XXH3p_accumulate_512(acc, p, secret + secretSize - STRIPE_LEN - XXH_SECRET_LASTACC_START, accWidth);
  796. } }
  797. }
  798. XXH_FORCE_INLINE xxh_u64
  799. XXH3p_mix2Accs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret)
  800. {
  801. return XXH3p_mul128_fold64(
  802. acc[0] ^ XXH_readLE64(secret),
  803. acc[1] ^ XXH_readLE64(secret+8) );
  804. }
  805. static XXH64_hash_t
  806. XXH3p_mergeAccs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, xxh_u64 start)
  807. {
  808. xxh_u64 result64 = start;
  809. result64 += XXH3p_mix2Accs(acc+0, secret + 0);
  810. result64 += XXH3p_mix2Accs(acc+2, secret + 16);
  811. result64 += XXH3p_mix2Accs(acc+4, secret + 32);
  812. result64 += XXH3p_mix2Accs(acc+6, secret + 48);
  813. return XXH3p_avalanche(result64);
  814. }
  815. #define XXH3p_INIT_ACC { PRIME32_3, PRIME64_1, PRIME64_2, PRIME64_3, \
  816. PRIME64_4, PRIME32_2, PRIME64_5, PRIME32_1 };
  817. XXH_FORCE_INLINE XXH64_hash_t
  818. XXH3p_hashLong_internal(const xxh_u8* XXH_RESTRICT input, size_t len,
  819. const xxh_u8* XXH_RESTRICT secret, size_t secretSize)
  820. {
  821. XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[ACC_NB] = XXH3p_INIT_ACC;
  822. XXH3p_hashLong_internal_loop(acc, input, len, secret, secretSize, XXH3p_acc_64bits);
  823. /* converge into final hash */
  824. XXH_STATIC_ASSERT(sizeof(acc) == 64);
  825. #define XXH_SECRET_MERGEACCS_START 11 /* do not align on 8, so that secret is different from accumulator */
  826. XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
  827. return XXH3p_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * PRIME64_1);
  828. }
  829. XXH_NO_INLINE XXH64_hash_t /* It's important for performance that XXH3p_hashLong is not inlined. Not sure why (uop cache maybe ?), but difference is large and easily measurable */
  830. XXH3p_hashLong_64b_defaultSecret(const xxh_u8* XXH_RESTRICT input, size_t len)
  831. {
  832. return XXH3p_hashLong_internal(input, len, kSecret, sizeof(kSecret));
  833. }
  834. XXH_NO_INLINE XXH64_hash_t /* It's important for performance that XXH3p_hashLong is not inlined. Not sure why (uop cache maybe ?), but difference is large and easily measurable */
  835. XXH3p_hashLong_64b_withSecret(const xxh_u8* XXH_RESTRICT input, size_t len,
  836. const xxh_u8* XXH_RESTRICT secret, size_t secretSize)
  837. {
  838. return XXH3p_hashLong_internal(input, len, secret, secretSize);
  839. }
  840. XXH_FORCE_INLINE void XXH_writeLE64(void* dst, xxh_u64 v64)
  841. {
  842. if (!XXH_CPU_LITTLE_ENDIAN) v64 = XXH_swap64(v64);
  843. memcpy(dst, &v64, sizeof(v64));
  844. }
  845. /* XXH3p_initCustomSecret() :
  846. * destination `customSecret` is presumed allocated and same size as `kSecret`.
  847. */
  848. XXH_FORCE_INLINE void XXH3p_initCustomSecret(xxh_u8* customSecret, xxh_u64 seed64)
  849. {
  850. int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16;
  851. int i;
  852. XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0);
  853. for (i=0; i < nbRounds; i++) {
  854. XXH_writeLE64(customSecret + 16*i, XXH_readLE64(kSecret + 16*i) + seed64);
  855. XXH_writeLE64(customSecret + 16*i + 8, XXH_readLE64(kSecret + 16*i + 8) - seed64);
  856. }
  857. }
  858. /* XXH3p_hashLong_64b_withSeed() :
  859. * Generate a custom key,
  860. * based on alteration of default kSecret with the seed,
  861. * and then use this key for long mode hashing.
  862. * This operation is decently fast but nonetheless costs a little bit of time.
  863. * Try to avoid it whenever possible (typically when seed==0).
  864. */
  865. XXH_NO_INLINE XXH64_hash_t /* It's important for performance that XXH3p_hashLong is not inlined. Not sure why (uop cache maybe ?), but difference is large and easily measurable */
  866. XXH3p_hashLong_64b_withSeed(const xxh_u8* input, size_t len, XXH64_hash_t seed)
  867. {
  868. XXH_ALIGN(8) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
  869. if (seed==0) return XXH3p_hashLong_64b_defaultSecret(input, len);
  870. XXH3p_initCustomSecret(secret, seed);
  871. return XXH3p_hashLong_internal(input, len, secret, sizeof(secret));
  872. }
  873. XXH_FORCE_INLINE xxh_u64 XXH3p_mix16B(const xxh_u8* XXH_RESTRICT input,
  874. const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64)
  875. {
  876. xxh_u64 const input_lo = XXH_readLE64(input);
  877. xxh_u64 const input_hi = XXH_readLE64(input+8);
  878. return XXH3p_mul128_fold64(
  879. input_lo ^ (XXH_readLE64(secret) + seed64),
  880. input_hi ^ (XXH_readLE64(secret+8) - seed64) );
  881. }
  882. XXH_FORCE_INLINE XXH64_hash_t
  883. XXH3p_len_17to128_64b(const xxh_u8* XXH_RESTRICT input, size_t len,
  884. const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
  885. XXH64_hash_t seed)
  886. {
  887. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN); (void)secretSize;
  888. XXH_ASSERT(16 < len && len <= 128);
  889. { xxh_u64 acc = len * PRIME64_1;
  890. if (len > 32) {
  891. if (len > 64) {
  892. if (len > 96) {
  893. acc += XXH3p_mix16B(input+48, secret+96, seed);
  894. acc += XXH3p_mix16B(input+len-64, secret+112, seed);
  895. }
  896. acc += XXH3p_mix16B(input+32, secret+64, seed);
  897. acc += XXH3p_mix16B(input+len-48, secret+80, seed);
  898. }
  899. acc += XXH3p_mix16B(input+16, secret+32, seed);
  900. acc += XXH3p_mix16B(input+len-32, secret+48, seed);
  901. }
  902. acc += XXH3p_mix16B(input+0, secret+0, seed);
  903. acc += XXH3p_mix16B(input+len-16, secret+16, seed);
  904. return XXH3p_avalanche(acc);
  905. }
  906. }
  907. #define XXH3p_MIDSIZE_MAX 240
  908. XXH_NO_INLINE XXH64_hash_t
  909. XXH3p_len_129to240_64b(const xxh_u8* XXH_RESTRICT input, size_t len,
  910. const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
  911. XXH64_hash_t seed)
  912. {
  913. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN); (void)secretSize;
  914. XXH_ASSERT(128 < len && len <= XXH3p_MIDSIZE_MAX);
  915. #define XXH3p_MIDSIZE_STARTOFFSET 3
  916. #define XXH3p_MIDSIZE_LASTOFFSET 17
  917. { xxh_u64 acc = len * PRIME64_1;
  918. int const nbRounds = (int)len / 16;
  919. int i;
  920. for (i=0; i<8; i++) {
  921. acc += XXH3p_mix16B(input+(16*i), secret+(16*i), seed);
  922. }
  923. acc = XXH3p_avalanche(acc);
  924. XXH_ASSERT(nbRounds >= 8);
  925. for (i=8 ; i < nbRounds; i++) {
  926. acc += XXH3p_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3p_MIDSIZE_STARTOFFSET, seed);
  927. }
  928. /* last bytes */
  929. acc += XXH3p_mix16B(input + len - 16, secret + XXH3p_SECRET_SIZE_MIN - XXH3p_MIDSIZE_LASTOFFSET, seed);
  930. return XXH3p_avalanche(acc);
  931. }
  932. }
  933. /* === Public entry point === */
  934. XXH_PUBLIC_API XXH64_hash_t XXH3p_64bits(const void* input, size_t len)
  935. {
  936. if (len <= 16) return XXH3p_len_0to16_64b((const xxh_u8*)input, len, kSecret, 0);
  937. if (len <= 128) return XXH3p_len_17to128_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0);
  938. if (len <= XXH3p_MIDSIZE_MAX) return XXH3p_len_129to240_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0);
  939. return XXH3p_hashLong_64b_defaultSecret((const xxh_u8*)input, len);
  940. }
  941. XXH_PUBLIC_API XXH64_hash_t
  942. XXH3p_64bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize)
  943. {
  944. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN);
  945. /* if an action must be taken should `secret` conditions not be respected,
  946. * it should be done here.
  947. * For now, it's a contract pre-condition.
  948. * Adding a check and a branch here would cost performance at every hash */
  949. if (len <= 16) return XXH3p_len_0to16_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, 0);
  950. if (len <= 128) return XXH3p_len_17to128_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0);
  951. if (len <= XXH3p_MIDSIZE_MAX) return XXH3p_len_129to240_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0);
  952. return XXH3p_hashLong_64b_withSecret((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize);
  953. }
  954. XXH_PUBLIC_API XXH64_hash_t
  955. XXH3p_64bits_withSeed(const void* input, size_t len, XXH64_hash_t seed)
  956. {
  957. if (len <= 16) return XXH3p_len_0to16_64b((const xxh_u8*)input, len, kSecret, seed);
  958. if (len <= 128) return XXH3p_len_17to128_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed);
  959. if (len <= XXH3p_MIDSIZE_MAX) return XXH3p_len_129to240_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed);
  960. return XXH3p_hashLong_64b_withSeed((const xxh_u8*)input, len, seed);
  961. }
  962. /* === XXH3 streaming === */
  963. XXH_PUBLIC_API XXH3p_state_t* XXH3p_createState(void)
  964. {
  965. return (XXH3p_state_t*)XXH_malloc(sizeof(XXH3p_state_t));
  966. }
  967. XXH_PUBLIC_API XXH_errorcode XXH3p_freeState(XXH3p_state_t* statePtr)
  968. {
  969. XXH_free(statePtr);
  970. return XXH_OK;
  971. }
  972. XXH_PUBLIC_API void
  973. XXH3p_copyState(XXH3p_state_t* dst_state, const XXH3p_state_t* src_state)
  974. {
  975. memcpy(dst_state, src_state, sizeof(*dst_state));
  976. }
  977. static void
  978. XXH3p_64bits_reset_internal(XXH3p_state_t* statePtr,
  979. XXH64_hash_t seed,
  980. const xxh_u8* secret, size_t secretSize)
  981. {
  982. XXH_ASSERT(statePtr != NULL);
  983. memset(statePtr, 0, sizeof(*statePtr));
  984. statePtr->acc[0] = PRIME32_3;
  985. statePtr->acc[1] = PRIME64_1;
  986. statePtr->acc[2] = PRIME64_2;
  987. statePtr->acc[3] = PRIME64_3;
  988. statePtr->acc[4] = PRIME64_4;
  989. statePtr->acc[5] = PRIME32_2;
  990. statePtr->acc[6] = PRIME64_5;
  991. statePtr->acc[7] = PRIME32_1;
  992. statePtr->seed = seed;
  993. XXH_ASSERT(secret != NULL);
  994. statePtr->secret = secret;
  995. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN);
  996. statePtr->secretLimit = (XXH32_hash_t)(secretSize - STRIPE_LEN);
  997. statePtr->nbStripesPerBlock = statePtr->secretLimit / XXH_SECRET_CONSUME_RATE;
  998. }
  999. XXH_PUBLIC_API XXH_errorcode
  1000. XXH3p_64bits_reset(XXH3p_state_t* statePtr)
  1001. {
  1002. if (statePtr == NULL) return XXH_ERROR;
  1003. XXH3p_64bits_reset_internal(statePtr, 0, kSecret, XXH_SECRET_DEFAULT_SIZE);
  1004. return XXH_OK;
  1005. }
  1006. XXH_PUBLIC_API XXH_errorcode
  1007. XXH3p_64bits_reset_withSecret(XXH3p_state_t* statePtr, const void* secret, size_t secretSize)
  1008. {
  1009. if (statePtr == NULL) return XXH_ERROR;
  1010. XXH3p_64bits_reset_internal(statePtr, 0, (const xxh_u8*)secret, secretSize);
  1011. if (secret == NULL) return XXH_ERROR;
  1012. if (secretSize < XXH3p_SECRET_SIZE_MIN) return XXH_ERROR;
  1013. return XXH_OK;
  1014. }
  1015. XXH_PUBLIC_API XXH_errorcode
  1016. XXH3p_64bits_reset_withSeed(XXH3p_state_t* statePtr, XXH64_hash_t seed)
  1017. {
  1018. if (statePtr == NULL) return XXH_ERROR;
  1019. XXH3p_64bits_reset_internal(statePtr, seed, kSecret, XXH_SECRET_DEFAULT_SIZE);
  1020. XXH3p_initCustomSecret(statePtr->customSecret, seed);
  1021. statePtr->secret = statePtr->customSecret;
  1022. return XXH_OK;
  1023. }
  1024. XXH_FORCE_INLINE void
  1025. XXH3p_consumeStripes( xxh_u64* acc,
  1026. XXH32_hash_t* nbStripesSoFarPtr, XXH32_hash_t nbStripesPerBlock,
  1027. const xxh_u8* input, size_t totalStripes,
  1028. const xxh_u8* secret, size_t secretLimit,
  1029. XXH3p_accWidth_e accWidth)
  1030. {
  1031. XXH_ASSERT(*nbStripesSoFarPtr < nbStripesPerBlock);
  1032. if (nbStripesPerBlock - *nbStripesSoFarPtr <= totalStripes) {
  1033. /* need a scrambling operation */
  1034. size_t const nbStripes = nbStripesPerBlock - *nbStripesSoFarPtr;
  1035. XXH3p_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, accWidth);
  1036. XXH3p_scrambleAcc(acc, secret + secretLimit);
  1037. XXH3p_accumulate(acc, input + nbStripes * STRIPE_LEN, secret, totalStripes - nbStripes, accWidth);
  1038. *nbStripesSoFarPtr = (XXH32_hash_t)(totalStripes - nbStripes);
  1039. } else {
  1040. XXH3p_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, totalStripes, accWidth);
  1041. *nbStripesSoFarPtr += (XXH32_hash_t)totalStripes;
  1042. }
  1043. }
  1044. XXH_FORCE_INLINE XXH_errorcode
  1045. XXH3p_update(XXH3p_state_t* state, const xxh_u8* input, size_t len, XXH3p_accWidth_e accWidth)
  1046. {
  1047. if (input==NULL)
  1048. #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
  1049. return XXH_OK;
  1050. #else
  1051. return XXH_ERROR;
  1052. #endif
  1053. { const xxh_u8* const bEnd = input + len;
  1054. state->totalLen += len;
  1055. if (state->bufferedSize + len <= XXH3p_INTERNALBUFFER_SIZE) { /* fill in tmp buffer */
  1056. XXH_memcpy(state->buffer + state->bufferedSize, input, len);
  1057. state->bufferedSize += (XXH32_hash_t)len;
  1058. return XXH_OK;
  1059. }
  1060. /* input now > XXH3p_INTERNALBUFFER_SIZE */
  1061. #define XXH3p_INTERNALBUFFER_STRIPES (XXH3p_INTERNALBUFFER_SIZE / STRIPE_LEN)
  1062. XXH_STATIC_ASSERT(XXH3p_INTERNALBUFFER_SIZE % STRIPE_LEN == 0); /* clean multiple */
  1063. if (state->bufferedSize) { /* some input within internal buffer: fill then consume it */
  1064. size_t const loadSize = XXH3p_INTERNALBUFFER_SIZE - state->bufferedSize;
  1065. XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize);
  1066. input += loadSize;
  1067. XXH3p_consumeStripes(state->acc,
  1068. &state->nbStripesSoFar, state->nbStripesPerBlock,
  1069. state->buffer, XXH3p_INTERNALBUFFER_STRIPES,
  1070. state->secret, state->secretLimit,
  1071. accWidth);
  1072. state->bufferedSize = 0;
  1073. }
  1074. /* consume input by full buffer quantities */
  1075. if (input+XXH3p_INTERNALBUFFER_SIZE <= bEnd) {
  1076. const xxh_u8* const limit = bEnd - XXH3p_INTERNALBUFFER_SIZE;
  1077. do {
  1078. XXH3p_consumeStripes(state->acc,
  1079. &state->nbStripesSoFar, state->nbStripesPerBlock,
  1080. input, XXH3p_INTERNALBUFFER_STRIPES,
  1081. state->secret, state->secretLimit,
  1082. accWidth);
  1083. input += XXH3p_INTERNALBUFFER_SIZE;
  1084. } while (input<=limit);
  1085. }
  1086. if (input < bEnd) { /* some remaining input input : buffer it */
  1087. XXH_memcpy(state->buffer, input, (size_t)(bEnd-input));
  1088. state->bufferedSize = (XXH32_hash_t)(bEnd-input);
  1089. }
  1090. }
  1091. return XXH_OK;
  1092. }
  1093. XXH_PUBLIC_API XXH_errorcode
  1094. XXH3p_64bits_update(XXH3p_state_t* state, const void* input, size_t len)
  1095. {
  1096. return XXH3p_update(state, (const xxh_u8*)input, len, XXH3p_acc_64bits);
  1097. }
  1098. XXH_FORCE_INLINE void
  1099. XXH3p_digest_long (XXH64_hash_t* acc, const XXH3p_state_t* state, XXH3p_accWidth_e accWidth)
  1100. {
  1101. memcpy(acc, state->acc, sizeof(state->acc)); /* digest locally, state remains unaltered, and can continue ingesting more input afterwards */
  1102. if (state->bufferedSize >= STRIPE_LEN) {
  1103. size_t const totalNbStripes = state->bufferedSize / STRIPE_LEN;
  1104. XXH32_hash_t nbStripesSoFar = state->nbStripesSoFar;
  1105. XXH3p_consumeStripes(acc,
  1106. &nbStripesSoFar, state->nbStripesPerBlock,
  1107. state->buffer, totalNbStripes,
  1108. state->secret, state->secretLimit,
  1109. accWidth);
  1110. if (state->bufferedSize % STRIPE_LEN) { /* one last partial stripe */
  1111. XXH3p_accumulate_512(acc,
  1112. state->buffer + state->bufferedSize - STRIPE_LEN,
  1113. state->secret + state->secretLimit - XXH_SECRET_LASTACC_START,
  1114. accWidth);
  1115. }
  1116. } else { /* bufferedSize < STRIPE_LEN */
  1117. if (state->bufferedSize) { /* one last stripe */
  1118. xxh_u8 lastStripe[STRIPE_LEN];
  1119. size_t const catchupSize = STRIPE_LEN - state->bufferedSize;
  1120. memcpy(lastStripe, state->buffer + sizeof(state->buffer) - catchupSize, catchupSize);
  1121. memcpy(lastStripe + catchupSize, state->buffer, state->bufferedSize);
  1122. XXH3p_accumulate_512(acc,
  1123. lastStripe,
  1124. state->secret + state->secretLimit - XXH_SECRET_LASTACC_START,
  1125. accWidth);
  1126. } }
  1127. }
  1128. XXH_PUBLIC_API XXH64_hash_t XXH3p_64bits_digest (const XXH3p_state_t* state)
  1129. {
  1130. if (state->totalLen > XXH3p_MIDSIZE_MAX) {
  1131. XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[ACC_NB];
  1132. XXH3p_digest_long(acc, state, XXH3p_acc_64bits);
  1133. return XXH3p_mergeAccs(acc, state->secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)state->totalLen * PRIME64_1);
  1134. }
  1135. /* len <= XXH3p_MIDSIZE_MAX : short code */
  1136. if (state->seed)
  1137. return XXH3p_64bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed);
  1138. return XXH3p_64bits_withSecret(state->buffer, (size_t)(state->totalLen), state->secret, state->secretLimit + STRIPE_LEN);
  1139. }
  1140. /* ==========================================
  1141. * XXH3 128 bits (=> XXH128)
  1142. * ========================================== */
  1143. XXH_FORCE_INLINE XXH128_hash_t
  1144. XXH3p_len_1to3_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  1145. {
  1146. XXH_ASSERT(input != NULL);
  1147. XXH_ASSERT(1 <= len && len <= 3);
  1148. XXH_ASSERT(secret != NULL);
  1149. { xxh_u8 const c1 = input[0];
  1150. xxh_u8 const c2 = input[len >> 1];
  1151. xxh_u8 const c3 = input[len - 1];
  1152. xxh_u32 const combinedl = ((xxh_u32)c1) + (((xxh_u32)c2) << 8) + (((xxh_u32)c3) << 16) + (((xxh_u32)len) << 24);
  1153. xxh_u32 const combinedh = XXH_swap32(combinedl);
  1154. xxh_u64 const keyed_lo = (xxh_u64)combinedl ^ (XXH_readLE32(secret) + seed);
  1155. xxh_u64 const keyed_hi = (xxh_u64)combinedh ^ (XXH_readLE32(secret+4) - seed);
  1156. xxh_u64 const mixedl = keyed_lo * PRIME64_1;
  1157. xxh_u64 const mixedh = keyed_hi * PRIME64_5;
  1158. XXH128_hash_t const h128 = { XXH3p_avalanche(mixedl) /*low64*/, XXH3p_avalanche(mixedh) /*high64*/ };
  1159. return h128;
  1160. }
  1161. }
  1162. XXH_FORCE_INLINE XXH128_hash_t
  1163. XXH3p_len_4to8_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  1164. {
  1165. XXH_ASSERT(input != NULL);
  1166. XXH_ASSERT(secret != NULL);
  1167. XXH_ASSERT(4 <= len && len <= 8);
  1168. { xxh_u32 const input_lo = XXH_readLE32(input);
  1169. xxh_u32 const input_hi = XXH_readLE32(input + len - 4);
  1170. xxh_u64 const input_64_lo = input_lo + ((xxh_u64)input_hi << 32);
  1171. xxh_u64 const input_64_hi = XXH_swap64(input_64_lo);
  1172. xxh_u64 const keyed_lo = input_64_lo ^ (XXH_readLE64(secret) + seed);
  1173. xxh_u64 const keyed_hi = input_64_hi ^ (XXH_readLE64(secret + 8) - seed);
  1174. xxh_u64 const mix64l1 = len + ((keyed_lo ^ (keyed_lo >> 51)) * PRIME32_1);
  1175. xxh_u64 const mix64l2 = (mix64l1 ^ (mix64l1 >> 47)) * PRIME64_2;
  1176. xxh_u64 const mix64h1 = ((keyed_hi ^ (keyed_hi >> 47)) * PRIME64_1) - len;
  1177. xxh_u64 const mix64h2 = (mix64h1 ^ (mix64h1 >> 43)) * PRIME64_4;
  1178. { XXH128_hash_t const h128 = { XXH3p_avalanche(mix64l2) /*low64*/, XXH3p_avalanche(mix64h2) /*high64*/ };
  1179. return h128;
  1180. } }
  1181. }
  1182. XXH_FORCE_INLINE XXH128_hash_t
  1183. XXH3p_len_9to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  1184. {
  1185. XXH_ASSERT(input != NULL);
  1186. XXH_ASSERT(secret != NULL);
  1187. XXH_ASSERT(9 <= len && len <= 16);
  1188. { xxh_u64 const input_lo = XXH_readLE64(input) ^ (XXH_readLE64(secret) + seed);
  1189. xxh_u64 const input_hi = XXH_readLE64(input + len - 8) ^ (XXH_readLE64(secret+8) - seed);
  1190. XXH128_hash_t m128 = XXH_mult64to128(input_lo ^ input_hi, PRIME64_1);
  1191. xxh_u64 const lenContrib = XXH_mult32to64(len, PRIME32_5);
  1192. m128.low64 += lenContrib;
  1193. m128.high64 += input_hi * PRIME64_1;
  1194. m128.low64 ^= (m128.high64 >> 32);
  1195. { XXH128_hash_t h128 = XXH_mult64to128(m128.low64, PRIME64_2);
  1196. h128.high64 += m128.high64 * PRIME64_2;
  1197. h128.low64 = XXH3p_avalanche(h128.low64);
  1198. h128.high64 = XXH3p_avalanche(h128.high64);
  1199. return h128;
  1200. } }
  1201. }
  1202. /* Assumption : `secret` size is >= 16
  1203. * Note : it should be >= XXH3p_SECRET_SIZE_MIN anyway */
  1204. XXH_FORCE_INLINE XXH128_hash_t
  1205. XXH3p_len_0to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed)
  1206. {
  1207. XXH_ASSERT(len <= 16);
  1208. { if (len > 8) return XXH3p_len_9to16_128b(input, len, secret, seed);
  1209. if (len >= 4) return XXH3p_len_4to8_128b(input, len, secret, seed);
  1210. if (len) return XXH3p_len_1to3_128b(input, len, secret, seed);
  1211. { XXH128_hash_t const h128 = { 0, 0 };
  1212. return h128;
  1213. } }
  1214. }
  1215. XXH_FORCE_INLINE XXH128_hash_t
  1216. XXH3p_hashLong_128b_internal(const xxh_u8* XXH_RESTRICT input, size_t len,
  1217. const xxh_u8* XXH_RESTRICT secret, size_t secretSize)
  1218. {
  1219. XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[ACC_NB] = XXH3p_INIT_ACC;
  1220. XXH3p_hashLong_internal_loop(acc, input, len, secret, secretSize, XXH3p_acc_128bits);
  1221. /* converge into final hash */
  1222. XXH_STATIC_ASSERT(sizeof(acc) == 64);
  1223. XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
  1224. { xxh_u64 const low64 = XXH3p_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * PRIME64_1);
  1225. xxh_u64 const high64 = XXH3p_mergeAccs(acc, secret + secretSize - sizeof(acc) - XXH_SECRET_MERGEACCS_START, ~((xxh_u64)len * PRIME64_2));
  1226. XXH128_hash_t const h128 = { low64, high64 };
  1227. return h128;
  1228. }
  1229. }
  1230. XXH_NO_INLINE XXH128_hash_t /* It's important for performance that XXH3p_hashLong is not inlined. Not sure why (uop cache maybe ?), but difference is large and easily measurable */
  1231. XXH3p_hashLong_128b_defaultSecret(const xxh_u8* input, size_t len)
  1232. {
  1233. return XXH3p_hashLong_128b_internal(input, len, kSecret, sizeof(kSecret));
  1234. }
  1235. XXH_NO_INLINE XXH128_hash_t /* It's important for performance that XXH3p_hashLong is not inlined. Not sure why (uop cache maybe ?), but difference is large and easily measurable */
  1236. XXH3p_hashLong_128b_withSecret(const xxh_u8* input, size_t len,
  1237. const xxh_u8* secret, size_t secretSize)
  1238. {
  1239. return XXH3p_hashLong_128b_internal(input, len, secret, secretSize);
  1240. }
  1241. XXH_NO_INLINE XXH128_hash_t /* It's important for performance that XXH3p_hashLong is not inlined. Not sure why (uop cache maybe ?), but difference is large and easily measurable */
  1242. XXH3p_hashLong_128b_withSeed(const xxh_u8* input, size_t len, XXH64_hash_t seed)
  1243. {
  1244. XXH_ALIGN(8) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE];
  1245. if (seed == 0) return XXH3p_hashLong_128b_defaultSecret(input, len);
  1246. XXH3p_initCustomSecret(secret, seed);
  1247. return XXH3p_hashLong_128b_internal(input, len, secret, sizeof(secret));
  1248. }
  1249. XXH_FORCE_INLINE XXH128_hash_t
  1250. XXH128_mix32B(XXH128_hash_t acc, const xxh_u8* input_1, const xxh_u8* input_2, const xxh_u8* secret, XXH64_hash_t seed)
  1251. {
  1252. acc.low64 += XXH3p_mix16B (input_1, secret+0, seed);
  1253. acc.low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8);
  1254. acc.high64 += XXH3p_mix16B (input_2, secret+16, seed);
  1255. acc.high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8);
  1256. return acc;
  1257. }
  1258. XXH_NO_INLINE XXH128_hash_t
  1259. XXH3p_len_129to240_128b(const xxh_u8* XXH_RESTRICT input, size_t len,
  1260. const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
  1261. XXH64_hash_t seed)
  1262. {
  1263. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN); (void)secretSize;
  1264. XXH_ASSERT(128 < len && len <= XXH3p_MIDSIZE_MAX);
  1265. { XXH128_hash_t acc;
  1266. int const nbRounds = (int)len / 32;
  1267. int i;
  1268. acc.low64 = len * PRIME64_1;
  1269. acc.high64 = 0;
  1270. for (i=0; i<4; i++) {
  1271. acc = XXH128_mix32B(acc, input+(32*i), input+(32*i)+16, secret+(32*i), seed);
  1272. }
  1273. acc.low64 = XXH3p_avalanche(acc.low64);
  1274. acc.high64 = XXH3p_avalanche(acc.high64);
  1275. XXH_ASSERT(nbRounds >= 4);
  1276. for (i=4 ; i < nbRounds; i++) {
  1277. acc = XXH128_mix32B(acc, input+(32*i), input+(32*i)+16, secret+XXH3p_MIDSIZE_STARTOFFSET+(32*(i-4)), seed);
  1278. }
  1279. /* last bytes */
  1280. acc = XXH128_mix32B(acc, input + len - 16, input + len - 32, secret + XXH3p_SECRET_SIZE_MIN - XXH3p_MIDSIZE_LASTOFFSET - 16, 0ULL - seed);
  1281. { xxh_u64 const low64 = acc.low64 + acc.high64;
  1282. xxh_u64 const high64 = (acc.low64 * PRIME64_1) + (acc.high64 * PRIME64_4) + ((len - seed) * PRIME64_2);
  1283. XXH128_hash_t const h128 = { XXH3p_avalanche(low64), (XXH64_hash_t)0 - XXH3p_avalanche(high64) };
  1284. return h128;
  1285. }
  1286. }
  1287. }
  1288. XXH_FORCE_INLINE XXH128_hash_t
  1289. XXH3p_len_17to128_128b(const xxh_u8* XXH_RESTRICT input, size_t len,
  1290. const xxh_u8* XXH_RESTRICT secret, size_t secretSize,
  1291. XXH64_hash_t seed)
  1292. {
  1293. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN); (void)secretSize;
  1294. XXH_ASSERT(16 < len && len <= 128);
  1295. { XXH128_hash_t acc;
  1296. acc.low64 = len * PRIME64_1;
  1297. acc.high64 = 0;
  1298. if (len > 32) {
  1299. if (len > 64) {
  1300. if (len > 96) {
  1301. acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed);
  1302. }
  1303. acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed);
  1304. }
  1305. acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed);
  1306. }
  1307. acc = XXH128_mix32B(acc, input, input+len-16, secret, seed);
  1308. { xxh_u64 const low64 = acc.low64 + acc.high64;
  1309. xxh_u64 const high64 = (acc.low64 * PRIME64_1) + (acc.high64 * PRIME64_4) + ((len - seed) * PRIME64_2);
  1310. XXH128_hash_t const h128 = { XXH3p_avalanche(low64), (XXH64_hash_t)0 - XXH3p_avalanche(high64) };
  1311. return h128;
  1312. }
  1313. }
  1314. }
  1315. XXH_PUBLIC_API XXH128_hash_t XXH3p_128bits(const void* input, size_t len)
  1316. {
  1317. if (len <= 16) return XXH3p_len_0to16_128b((const xxh_u8*)input, len, kSecret, 0);
  1318. if (len <= 128) return XXH3p_len_17to128_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0);
  1319. if (len <= XXH3p_MIDSIZE_MAX) return XXH3p_len_129to240_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0);
  1320. return XXH3p_hashLong_128b_defaultSecret((const xxh_u8*)input, len);
  1321. }
  1322. XXH_PUBLIC_API XXH128_hash_t
  1323. XXH3p_128bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize)
  1324. {
  1325. XXH_ASSERT(secretSize >= XXH3p_SECRET_SIZE_MIN);
  1326. /* if an action must be taken should `secret` conditions not be respected,
  1327. * it should be done here.
  1328. * For now, it's a contract pre-condition.
  1329. * Adding a check and a branch here would cost performance at every hash */
  1330. if (len <= 16) return XXH3p_len_0to16_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, 0);
  1331. if (len <= 128) return XXH3p_len_17to128_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0);
  1332. if (len <= XXH3p_MIDSIZE_MAX) return XXH3p_len_129to240_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0);
  1333. return XXH3p_hashLong_128b_withSecret((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize);
  1334. }
  1335. XXH_PUBLIC_API XXH128_hash_t
  1336. XXH3p_128bits_withSeed(const void* input, size_t len, XXH64_hash_t seed)
  1337. {
  1338. if (len <= 16) return XXH3p_len_0to16_128b((const xxh_u8*)input, len, kSecret, seed);
  1339. if (len <= 128) return XXH3p_len_17to128_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed);
  1340. if (len <= XXH3p_MIDSIZE_MAX) return XXH3p_len_129to240_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed);
  1341. return XXH3p_hashLong_128b_withSeed((const xxh_u8*)input, len, seed);
  1342. }
  1343. XXH_PUBLIC_API XXH128_hash_t
  1344. XXH128(const void* input, size_t len, XXH64_hash_t seed)
  1345. {
  1346. return XXH3p_128bits_withSeed(input, len, seed);
  1347. }
  1348. /* === XXH3 128-bit streaming === */
  1349. /* all the functions are actually the same as for 64-bit streaming variant,
  1350. just the reset one is different (different initial acc values for 0,5,6,7),
  1351. and near the end of the digest function */
  1352. static void
  1353. XXH3p_128bits_reset_internal(XXH3p_state_t* statePtr,
  1354. XXH64_hash_t seed,
  1355. const xxh_u8* secret, size_t secretSize)
  1356. {
  1357. XXH3p_64bits_reset_internal(statePtr, seed, secret, secretSize);
  1358. }
  1359. XXH_PUBLIC_API XXH_errorcode
  1360. XXH3p_128bits_reset(XXH3p_state_t* statePtr)
  1361. {
  1362. if (statePtr == NULL) return XXH_ERROR;
  1363. XXH3p_128bits_reset_internal(statePtr, 0, kSecret, XXH_SECRET_DEFAULT_SIZE);
  1364. return XXH_OK;
  1365. }
  1366. XXH_PUBLIC_API XXH_errorcode
  1367. XXH3p_128bits_reset_withSecret(XXH3p_state_t* statePtr, const void* secret, size_t secretSize)
  1368. {
  1369. if (statePtr == NULL) return XXH_ERROR;
  1370. XXH3p_128bits_reset_internal(statePtr, 0, (const xxh_u8*)secret, secretSize);
  1371. if (secret == NULL) return XXH_ERROR;
  1372. if (secretSize < XXH3p_SECRET_SIZE_MIN) return XXH_ERROR;
  1373. return XXH_OK;
  1374. }
  1375. XXH_PUBLIC_API XXH_errorcode
  1376. XXH3p_128bits_reset_withSeed(XXH3p_state_t* statePtr, XXH64_hash_t seed)
  1377. {
  1378. if (statePtr == NULL) return XXH_ERROR;
  1379. XXH3p_128bits_reset_internal(statePtr, seed, kSecret, XXH_SECRET_DEFAULT_SIZE);
  1380. XXH3p_initCustomSecret(statePtr->customSecret, seed);
  1381. statePtr->secret = statePtr->customSecret;
  1382. return XXH_OK;
  1383. }
  1384. XXH_PUBLIC_API XXH_errorcode
  1385. XXH3p_128bits_update(XXH3p_state_t* state, const void* input, size_t len)
  1386. {
  1387. return XXH3p_update(state, (const xxh_u8*)input, len, XXH3p_acc_128bits);
  1388. }
  1389. XXH_PUBLIC_API XXH128_hash_t XXH3p_128bits_digest (const XXH3p_state_t* state)
  1390. {
  1391. if (state->totalLen > XXH3p_MIDSIZE_MAX) {
  1392. XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[ACC_NB];
  1393. XXH3p_digest_long(acc, state, XXH3p_acc_128bits);
  1394. XXH_ASSERT(state->secretLimit + STRIPE_LEN >= sizeof(acc) + XXH_SECRET_MERGEACCS_START);
  1395. { xxh_u64 const low64 = XXH3p_mergeAccs(acc, state->secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)state->totalLen * PRIME64_1);
  1396. xxh_u64 const high64 = XXH3p_mergeAccs(acc, state->secret + state->secretLimit + STRIPE_LEN - sizeof(acc) - XXH_SECRET_MERGEACCS_START, ~((xxh_u64)state->totalLen * PRIME64_2));
  1397. XXH128_hash_t const h128 = { low64, high64 };
  1398. return h128;
  1399. }
  1400. }
  1401. /* len <= XXH3p_MIDSIZE_MAX : short code */
  1402. if (state->seed)
  1403. return XXH3p_128bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed);
  1404. return XXH3p_128bits_withSecret(state->buffer, (size_t)(state->totalLen), state->secret, state->secretLimit + STRIPE_LEN);
  1405. }
  1406. /* 128-bit utility functions */
  1407. #include <string.h> /* memcmp */
  1408. /* return : 1 is equal, 0 if different */
  1409. XXH_PUBLIC_API int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2)
  1410. {
  1411. /* note : XXH128_hash_t is compact, it has no padding byte */
  1412. return !(memcmp(&h1, &h2, sizeof(h1)));
  1413. }
  1414. /* This prototype is compatible with stdlib's qsort().
  1415. * return : >0 if *h128_1 > *h128_2
  1416. * <0 if *h128_1 < *h128_2
  1417. * =0 if *h128_1 == *h128_2 */
  1418. XXH_PUBLIC_API int XXH128_cmp(const void* h128_1, const void* h128_2)
  1419. {
  1420. XXH128_hash_t const h1 = *(const XXH128_hash_t*)h128_1;
  1421. XXH128_hash_t const h2 = *(const XXH128_hash_t*)h128_2;
  1422. int const hcmp = (h1.high64 > h2.high64) - (h2.high64 > h1.high64);
  1423. /* note : bets that, in most cases, hash values are different */
  1424. if (hcmp) return hcmp;
  1425. return (h1.low64 > h2.low64) - (h2.low64 > h1.low64);
  1426. }
  1427. /*====== Canonical representation ======*/
  1428. XXH_PUBLIC_API void
  1429. XXH128_canonicalFromHash(XXH128_canonical_t* dst, XXH128_hash_t hash)
  1430. {
  1431. XXH_STATIC_ASSERT(sizeof(XXH128_canonical_t) == sizeof(XXH128_hash_t));
  1432. if (XXH_CPU_LITTLE_ENDIAN) {
  1433. hash.high64 = XXH_swap64(hash.high64);
  1434. hash.low64 = XXH_swap64(hash.low64);
  1435. }
  1436. memcpy(dst, &hash.high64, sizeof(hash.high64));
  1437. memcpy((char*)dst + sizeof(hash.high64), &hash.low64, sizeof(hash.low64));
  1438. }
  1439. XXH_PUBLIC_API XXH128_hash_t
  1440. XXH128_hashFromCanonical(const XXH128_canonical_t* src)
  1441. {
  1442. XXH128_hash_t h;
  1443. h.high64 = XXH_readBE64(src);
  1444. h.low64 = XXH_readBE64(src->digest + 8);
  1445. return h;
  1446. }
  1447. #endif /* XXH3p_H */