diff options
author | Yves Orton <demerphq@gmail.com> | 2013-03-17 15:20:20 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2013-03-19 00:23:11 +0100 |
commit | b716320d9d4e3483bbddcbf6c6977a2a6a0efa1e (patch) | |
tree | a9449244eed722e2ef4e9bb0e9cf459c6183dfba | |
parent | 8dafa723e1a85f9bfb12b62414c660009b085761 (diff) | |
download | perl-b716320d9d4e3483bbddcbf6c6977a2a6a0efa1e.tar.gz |
rework ROTL definitions (and add ROTL_UV)
-rw-r--r-- | hv_func.h | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -127,16 +127,36 @@ #define UNALIGNED_SAFE #endif -/* Find best way to ROTL32 */ +#ifdef HAS_QUAD +#ifndef U64TYPE +/* This probably isn't going to work, but failing with a compiler error due to + lack of uint64_t is no worse than failing right now with an #error. */ +#define U64TYPE uint64_t +#endif +#endif + +/* Find best way to ROTL32/ROTL64 */ #if defined(_MSC_VER) #include <stdlib.h> /* Microsoft put _rotl declaration in here */ #define ROTL32(x,r) _rotl(x,r) + #ifdef HAS_QUAD + #define ROTL64(x,r) _rotl64(x,r) + #endif #else /* gcc recognises this code and generates a rotate instruction for CPUs with one */ #define ROTL32(x,r) (((U32)x << r) | ((U32)x >> (32 - r))) + #ifdef HAS_QUAD + #define ROTL64(x,r) (((U64TYPE)x << r) | ((U64TYPE)x >> (64 - r))) + #endif #endif +#ifdef UV_IS_QUAD +#define ROTL_UV(x,r) ROTL64(x,r) +#else +#define ROTL_UV(x,r) ROTL32(x,r) +#endif + /* This is SipHash by Jean-Philippe Aumasson and Daniel J. Bernstein. * The authors claim it is relatively secure compared to the alternatives * and that performance wise it is a suitable hash for languages like Perl. @@ -153,15 +173,6 @@ #ifdef HAS_QUAD -#ifndef U64TYPE -/* This probably isn't going to work, but failing with a compiler error due to - lack of uint64_t is no worse than failing right now with an #error. */ -#define U64TYPE uint64_t -#endif - - -#define ROTL64(x,b) (U64TYPE)( ((x) << (b)) | ( (x) >> (64 - (b))) ) - #define U8TO64_LE(p) \ (((U64TYPE)((p)[0]) ) | \ ((U64TYPE)((p)[1]) << 8) | \ |