text
stringlengths 0
2.2M
|
---|
#if defined(_MSC_VER) && defined(_M_X64)
|
#include <intrin.h>
|
#pragma intrinsic(_umul128)
|
#endif
|
using namespace BloombergLP;
|
// This was downloaded from
|
// https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
|
// which had been updated on September 14, 2021, last commit 166f352
|
// Many cosmetic changes have been made. There were also many functions not
|
// relevant to the hash function which have been removed.
|
// This is free and unencumbered software released into the public domain under
|
// The Unlicense (http://unlicense.org/)
|
// main repo: https://github.com/wangyi-fudan/wyhash
|
// author: Wang Yi <[email protected]>
|
// contributors: Reini Urban, Dietrich Epp, Joshua Haberman, Tommy Ettinger,
|
// Daniel Lemire, Otmar Ertl, cocowalla, leo-yuriev, Diego Barrios Romero,
|
// paulie-g, dumblob, Yann Collet, ivte-ms, hyb, James Z.M. Gao,
|
// easyaspi314 (Devin), TheOneric
|
// quick example:
|
// string s="fjsakfdsjkf";
|
// uint64_t hash=wyhash(s.c_str(), s.size(), 0, _wyp);
|
#define wyhash_final_version_3
|
//protections that produce different results:
|
//: 0 normal valid behavior
|
//:
|
//: 1 extra protection against entropy loss (probability=2^-63), aka. "blind
|
//: multiplication"
|
#undef U_WYMUM_XOR
|
#define U_WYMUM_XOR 0
|
//: 0 normal, real version of 64x64 -> 128 multiply, slow on 32 bit systems
|
//:
|
//: 1 not real multiply, faster on 32 bit systems but produces different
|
//: results
|
#undef U_WYMUM_PSEUDO_MULTIPLY
|
#define U_WYMUM_PSEUDO_MULTIPLY 0
|
//likely and unlikely macros
|
#undef U_LIKELY
|
#define U_LIKELY(x) BSLS_PERFORMANCEHINT_PREDICT_LIKELY(x)
|
#undef U_UNLIKELY
|
#define U_UNLIKELY(x) BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(x)
|
#undef U_UNLIKELY_HINT
|
#define U_UNLIKELY_HINT BSLS_PERFORMANCEHINT_UNLIKELY_HINT
|
static inline
|
uint64_t _wyrot(uint64_t x)
|
{
|
return (x >> 32) | (x << 32);
|
}
|
static inline
|
void _wymum(uint64_t *A, uint64_t *B)
|
// 128bit multiply function -- 64x64 -> 128,
|
// Result: *A is low 64 bits, *B is high 64 bits
|
{
|
#if U_WYMUM_PSEUDO_MULTIPLY
|
const uint64_t hh = (*A >> 32) * (*B >> 32);
|
const uint64_t hl = (*A >> 32) * (uint32_t) *B;
|
const uint64_t lh = (uint32_t)*A * (*B >> 32);
|
const uint64_t ll = (uint64_t) (uint32_t) *A * (uint32_t) *B;
|
# if U_WYMUM_XOR
|
// pseudo munge (not real multiply) -> xor
|
*A ^= _wyrot(hl) ^ hh;
|
*B ^= _wyrot(lh) ^ ll;
|
# else
|
// pseudo munge (not real multiply)
|
*A = _wyrot(hl) ^ hh;
|
*B = _wyrot(lh) ^ ll;
|
# endif
|
#elif defined(__SIZEOF_INT128__)
|
__uint128_t r = *A; r *= *B;
|
# if U_WYMUM_XOR
|
// multiply -> xor
|
*A ^= (uint64_t) r;
|
*B ^= (uint64_t) (r >> 64);
|
# else
|
// multiply
|
*A = (uint64_t) r;
|
*B = (uint64_t) (r >> 64);
|
# endif
|
#elif defined(_MSC_VER) && defined(_M_X64)
|
# if U_WYMUM_XOR
|
// multiply -> xor
|
uint64_t a, b;
|
a = _umul128(*A, *B, &b);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.