# HG changeset patch # User jbe # Date 1502628950 -7200 # Node ID 01f53490f26228b2eaf55e0ba560a4bb6869a0fc # Parent 5e6dbaa3e21995210d44d6f7fb24992fa8020232 moonhash library: determine endianess on FreeBSD, OpenBSD, NetBSD, and Linux diff -r 5e6dbaa3e219 -r 01f53490f262 libraries/moonhash/moonhash_sha3.c --- a/libraries/moonhash/moonhash_sha3.c Sun Aug 13 14:31:21 2017 +0200 +++ b/libraries/moonhash/moonhash_sha3.c Sun Aug 13 14:55:50 2017 +0200 @@ -2,6 +2,20 @@ #include +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#include +#if defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && _BYTE_ORDER == _LITTLE_ENDIAN +#define MOONHASH_LITTLE_ENDIAN +#endif +#elif defined(__linux__) +#include +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN +#define MOONHASH_LITTLE_ENDIAN +#endif +#else +#warning Could not determine endianess, revert to fail safe. +#endif + #define FOR(i,n) for(i=0; i>1; } #define ROL(a,o) ((((u64)a)<>(64-o))) +#ifdef MOONHASH_LITTLE_ENDIAN +#define load64(src) (*(uint64_t *)(src)) +#define store64(dst, src) do { *(uint64_t *)(dst) = src; } while (0) +#define xor64(dst, src) do { *(uint64_t *)(dst) ^= src; } while (0) +#else static u64 load64(const u8 *x) { ui i; u64 u=0; FOR(i,8) { u<<=8; u|=x[7-i]; } return u; } static void store64(u8 *x, u64 u) { ui i; FOR(i,8) { x[i]=u; u>>=8; } } static void xor64(u8 *x, u64 u) { ui i; FOR(i,8) { x[i]^=u; u>>=8; } } +#endif #define rL(x,y) load64((u8*)s+8*(x+5*y)) #define wL(x,y,l) store64((u8*)s+8*(x+5*y),l) #define XL(x,y,l) xor64((u8*)s+8*(x+5*y),l)