Merge pull request #496 from banburybill/master

Use build system endianness if available, otherwise try to work it out.
This commit is contained in:
Wouter Wijngaards 2021-05-27 13:29:08 +02:00 committed by GitHub
commit d116c9711a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -53,7 +53,21 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
#include "util/storage/lookup3.h"
#include <stdio.h> /* defines printf for tests */
#include <time.h> /* defines time_t for timings in the test */
/*#include <stdint.h> defines uint32_t etc (from config.h) */
/*
* If our build system provides endianness info, signalled by
* HAVE_TARGET_ENDIANNESS and the presence or absence of TARGET_IS_BIG_ENDIAN,
* use that. Otherwise try to work out the endianness.
*/
#if defined(HAVE_TARGET_ENDIANNESS)
# if defined(TARGET_IS_BIG_ENDIAN)
# define HASH_LITTLE_ENDIAN 0
# define HASH_BIG_ENDIAN 1
# else
# define HASH_LITTLE_ENDIAN 1
# define HASH_BIG_ENDIAN 0
# endif
#else
# include <sys/param.h> /* attempt to define endianness */
# ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> /* attempt to define endianness (solaris) */
@ -68,16 +82,6 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
# include <sys/endian.h> /* attempt to define endianness */
# endif
/* random initial value */
static uint32_t raninit = (uint32_t)0xdeadbeef;
void
hash_set_raninit(uint32_t v)
{
raninit = v;
}
/*
* My best guess at if you are big-endian or little-endian. This may
* need adjustment.
@ -107,11 +111,21 @@ hash_set_raninit(uint32_t v)
# define HASH_LITTLE_ENDIAN 0
# define HASH_BIG_ENDIAN 0
# endif
#endif /* defined(HAVE_TARGET_ENDIANNESS) */
#define hashsize(n) ((uint32_t)1<<(n))
#define hashmask(n) (hashsize(n)-1)
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
/* random initial value */
static uint32_t raninit = (uint32_t)0xdeadbeef;
void
hash_set_raninit(uint32_t v)
{
raninit = v;
}
/*
-------------------------------------------------------------------------------
mix -- mix 3 32-bit values reversibly.