Line data Source code
1 : #ifndef HEADER_fd_src_ballet_murmur3_fd_murmur3_h 2 : #define HEADER_fd_src_ballet_murmur3_fd_murmur3_h 3 : 4 : /* fd_murmur3 provides APIs for Murmur3 hashing of messages. */ 5 : 6 : #include "../fd_ballet_base.h" 7 : 8 : FD_PROTOTYPES_BEGIN 9 : 10 : /* fd_murmur3_32 computes the Murmur3-32 hash given a hash seed and a 11 : contiguous memory region to serve as input of size sz. data points 12 : to the first byte of the input and may be freed on return. Returns 13 : the hash digest as a 32-bit integer. Is idempotent (Guaranteed to 14 : return the same hash given the same seed and input byte stream) */ 15 : 16 : FD_FN_PURE uint 17 : fd_murmur3_32( void const * data, 18 : ulong sz, 19 : uint seed ); 20 : 21 : /* fd_pchash computes the hash of a program counter suitable for use as 22 : the call instruction immediate. Equivalent to fd_murmur3_32 with 23 : zero seed and pc serialized to little-endian ulong. */ 24 : 25 : static inline uint 26 337848348 : fd_pchash( uint pc ) { 27 337848348 : uint x = pc; 28 337848348 : x *= 0xcc9e2d51U; 29 337848348 : x = fd_uint_rotate_left( x, 15 ); 30 337848348 : x *= 0x1b873593U; 31 337848348 : x = fd_uint_rotate_left( x, 13 ); 32 337848348 : x *= 5; 33 337848348 : x += 0xe6546b64U; 34 337848348 : x = fd_uint_rotate_left( x, 13 ); 35 337848348 : x *= 5; 36 337848348 : x += 0xe6546b64U; 37 337848348 : x ^= 8; 38 337848348 : x ^= x >> 16; 39 337848348 : x *= 0x85ebca6bU; 40 337848348 : x ^= x >> 13; 41 337848348 : x *= 0xc2b2ae35U; 42 337848348 : x ^= x >> 16; 43 337848348 : return x; 44 337848348 : } 45 : 46 : /* Inverse of the above. E.g.: 47 : fd_pchash_inverse( fd_pchash( (uint)x ) )==(uint)x 48 : and: 49 : fd_pchash( fd_pchash_inverse( (uint)x ) )==(uint)x */ 50 : 51 : static inline uint 52 304595976 : fd_pchash_inverse( uint hash ) { 53 304595976 : uint x = hash; 54 304595976 : x ^= x >> 16; 55 304595976 : x *= 0x7ed1b41dU; 56 304595976 : x ^= (x >> 13) ^ (x >> 26); 57 304595976 : x *= 0xa5cb9243U; 58 304595976 : x ^= x >> 16; 59 304595976 : x ^= 8; 60 304595976 : x -= 0xe6546b64U; 61 304595976 : x *= 0xcccccccdU; 62 304595976 : x = fd_uint_rotate_right( x, 13 ); 63 304595976 : x -= 0xe6546b64U; 64 304595976 : x *= 0xcccccccdU; 65 304595976 : x = fd_uint_rotate_right( x, 13 ); 66 304595976 : x *= 0x56ed309bU; 67 304595976 : x = fd_uint_rotate_right( x, 15 ); 68 304595976 : x *= 0xdee13bb1U; 69 304595976 : return x; 70 304595976 : } 71 : 72 : FD_PROTOTYPES_END 73 : 74 : #endif /* HEADER_fd_src_ballet_murmur3_fd_murmur3_h */