X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhash%2Fhash.c;h=59c4d24b3b989013a6ef7004f99e62151dc6ebfc;hp=9b3f58b2b20a649785b7f053c4c7828413610148;hb=233190071e5834e1a701d6d2ef4bc0a46cecc537;hpb=142afe327024262a0eaa0731bcf31def91c146e0 diff --git a/ccan/hash/hash.c b/ccan/hash/hash.c index 9b3f58b2..59c4d24b 100644 --- a/ccan/hash/hash.c +++ b/ccan/hash/hash.c @@ -40,9 +40,7 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #include /* defines time_t for timings in the test */ #include /* defines uint32_t etc */ #include /* attempt to define endianness */ -#endif -#include "hash.h" #ifdef linux # include /* attempt to define endianness */ #endif @@ -54,7 +52,8 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ __BYTE_ORDER == __LITTLE_ENDIAN) || \ (defined(i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) + defined(__i586__) || defined(__i686__) || defined(__x86_64) || \ + defined(vax) || defined(MIPSEL)) # define HASH_LITTLE_ENDIAN 1 # define HASH_BIG_ENDIAN 0 #elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \ @@ -65,6 +64,19 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #else # error Unknown endian #endif +#endif /* old hash.c headers. */ + +#include "hash.h" + +#if HAVE_LITTLE_ENDIAN +#define HASH_LITTLE_ENDIAN 1 +#define HASH_BIG_ENDIAN 0 +#elif HAVE_BIG_ENDIAN +#define HASH_LITTLE_ENDIAN 0 +#define HASH_BIG_ENDIAN 1 +#else +#error Unknown endian +#endif #define hashsize(n) ((uint32_t)1<<(n)) #define hashmask(n) (hashsize(n)-1) @@ -247,9 +259,7 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t *val2 ) u.ptr = key; if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ -#ifdef VALGRIND const uint8_t *k8; -#endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) @@ -271,9 +281,10 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t *val2 ) * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). + * + * Not on my testing with gcc 4.5 on an intel i5 CPU, at least --RR. */ -#ifndef VALGRIND - +#if 0 switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; @@ -425,9 +436,7 @@ static uint32_t hashbig( const void *key, size_t length, uint32_t *val2) u.ptr = key; if (HASH_BIG_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ -#ifdef VALGRIND const uint8_t *k8; -#endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) @@ -449,9 +458,10 @@ static uint32_t hashbig( const void *key, size_t length, uint32_t *val2) * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). + * + * Not on my testing with gcc 4.5 on an intel i5 CPU, at least --RR. */ -#ifndef VALGRIND - +#if 0 switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; @@ -741,7 +751,7 @@ void driver2() { for (j=0; j<8; ++j) /*------------------------ for each input bit, */ { - for (m=1; m<8; ++m) /*------------ for serveral possible initvals, */ + for (m=1; m<8; ++m) /*------------ for several possible initvals, */ { for (l=0; l