From 93a9b686b6b66310d2bd132f13a665279749b907 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 13 Jan 2014 18:16:09 +0100 Subject: [PATCH] erasure-code: use uintptr_t instead of long long Checking the pointer alignment using a cast to long long raises a warning when --Wpointer-to-int-cast is given. Signed-off-by: Loic Dachary --- src/osd/ErasureCodePluginJerasure/galois.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/osd/ErasureCodePluginJerasure/galois.c b/src/osd/ErasureCodePluginJerasure/galois.c index f1ec347fadc0b..9981353969861 100644 --- a/src/osd/ErasureCodePluginJerasure/galois.c +++ b/src/osd/ErasureCodePluginJerasure/galois.c @@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "galois.h" #include "vectorop.h" @@ -741,6 +742,8 @@ void galois_w32_region_multiply(char *region, /* Region to multiply */ return; } +#define is_aligned(POINTER, BYTE_COUNT) \ + (((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0) void galois_region_xor( char *r1, /* Region 1 */ char *r2, /* Region 2 */ @@ -748,9 +751,9 @@ void galois_region_xor( char *r1, /* Region 1 */ int nbytes) /* Number of bytes in region */ { if (nbytes%VECTOR_WORDSIZE) { - assert(!((long long)r1%sizeof(long))); - assert(!((long long)r2%sizeof(long))); - assert(!((long long)r3%sizeof(long))); + assert(is_aligned(r1, sizeof(long))); + assert(is_aligned(r2, sizeof(long))); + assert(is_aligned(r3, sizeof(long))); long* l1 = (long*)r1; long* l2 = (long*)r2; long* l3 = (long*)r3; @@ -760,9 +763,9 @@ void galois_region_xor( char *r1, /* Region 1 */ *l3++ = ((*l1++) ^ (*l2++)); } } else { - assert(!((long long)r1%VECTOR_WORDSIZE)); - assert(!((long long)r2%VECTOR_WORDSIZE)); - assert(!((long long)r3%VECTOR_WORDSIZE)); + assert(is_aligned(r1, VECTOR_WORDSIZE)); + assert(is_aligned(r2, VECTOR_WORDSIZE)); + assert(is_aligned(r3, VECTOR_WORDSIZE)); vector_op_t* l1 = (vector_op_t*)r1; vector_op_t* l2 = (vector_op_t*)r2; vector_op_t* l3 = (vector_op_t*)r3; -- 2.39.5