mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-23 00:00:51 -05:00
Merge pull request #496 from banburybill/master
Use build system endianness if available, otherwise try to work it out.
This commit is contained in:
commit
d116c9711a
1 changed files with 58 additions and 44 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue