diff --git a/ChangeLog b/ChangeLog index 8ecfb343e235e7e722f7bfa34acfd93e7ab49a02..971b6d708103cba7089b7e91d7fe719ec6160f62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ * memxor.c (memxor_common_alignment, memxor_different_alignment) (memxor): Change loop order, iterate from the end. (memxor3_common_alignment): Unroll twice. + (word_t): On x86_64, unconditionally define as uint64_t, to get 64 + bits also in M$ windows. Replaced all uses of SIZEOF_LONG. * examples/nettle-benchmark.c (time_memxor): Allocate buffers as arrays of unsigned long, for more reliable alignment. diff --git a/memxor.c b/memxor.c index 0e60e35d0a1ed43fc683a53fbfaf0f09391b4a75..940da0205962254c6908b49e5ac6758be25d5d02 100644 --- a/memxor.c +++ b/memxor.c @@ -44,10 +44,11 @@ /* For uintptr_t */ #include "nettle-types.h" +#if defined(__x86_64__) || defined(__arch64__) +/* Including on M$ windows, where unsigned long is only 32 bits */ +typedef uint64_t word_t; +#else typedef unsigned long int word_t; - -#if SIZEOF_LONG & (SIZEOF_LONG - 1) -#error Word size must be a power of two #endif #define ALIGN_OFFSET(p) ((uintptr_t) (p) % sizeof(word_t)) @@ -95,7 +96,7 @@ memxor_different_alignment (word_t *dst, const char *src, size_t n) shl = CHAR_BIT * offset; shr = CHAR_BIT * (sizeof(word_t) - offset); - src_word = (const word_t *) ((uintptr_t) src & -SIZEOF_LONG); + src_word = (const word_t *) ((uintptr_t) src & -sizeof(word_t)); if (n & 1) { @@ -191,7 +192,7 @@ memxor3_different_alignment_b (word_t *dst, shl = CHAR_BIT * offset; shr = CHAR_BIT * (sizeof(word_t) - offset); - b_word = (const word_t *) ((uintptr_t) b & -SIZEOF_LONG); + b_word = (const word_t *) ((uintptr_t) b & -sizeof(word_t)); if (n & 1) { @@ -227,8 +228,8 @@ memxor3_different_alignment_ab (word_t *dst, shl = CHAR_BIT * offset; shr = CHAR_BIT * (sizeof(word_t) - offset); - a_word = (const word_t *) ((uintptr_t) a & -SIZEOF_LONG); - b_word = (const word_t *) ((uintptr_t) b & -SIZEOF_LONG); + a_word = (const word_t *) ((uintptr_t) a & -sizeof(word_t)); + b_word = (const word_t *) ((uintptr_t) b & -sizeof(word_t)); if (n & 1) { @@ -267,8 +268,8 @@ memxor3_different_alignment_all (word_t *dst, bl = CHAR_BIT * b_offset; br = CHAR_BIT * (sizeof(word_t) - b_offset); - a_word = (const word_t *) ((uintptr_t) a & -SIZEOF_LONG); - b_word = (const word_t *) ((uintptr_t) b & -SIZEOF_LONG); + a_word = (const word_t *) ((uintptr_t) a & -sizeof(word_t)); + b_word = (const word_t *) ((uintptr_t) b & -sizeof(word_t)); if (n & 1) {