add some degree of endian detection to hashlittle.cpp

This commit is contained in:
Axel Kohlmeyer 2019-03-25 14:03:29 -04:00
parent 1ca0c78a2e
commit 1266b866e0
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 19 additions and 3 deletions

View File

@ -2,10 +2,26 @@
// from lookup3.c, by Bob Jenkins, May 2006, Public Domain
// bob_jenkins@burtleburtle.net
#include "stddef.h"
#include "stdint.h"
#include <cmath>
#include <stddef.h>
#include <stdint.h>
#define HASH_LITTLE_ENDIAN 1 // Intel and AMD are little endian
// if the system defines the __BYTE_ORDER__ define,
// we use it instead of guessing the platform
#if defined(__BYTE_ORDER__)
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define HASH_LITTLE_ENDIAN 1
# else
# define HASH_LITTLE_ENDIAN 0
# endif
#else // heuristic platform guess
# if defined(__bg__)
# define HASH_LITTLE_ENDIAN 0 // IBM BlueGene is big endian
# else
# define HASH_LITTLE_ENDIAN 1 // Intel and AMD x86 are little endian
# endif
#endif
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))