From 36e75c3efec08b1e9bdb9c1f69a5b0018abd8ac7 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Fri, 5 Sep 2014 13:33:04 +0200 Subject: use posix_memalign to align memory for SIMD region tests Properly emulate aligned allocation if posix_memalign is not available. --- tools/gf_time.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/gf_time.c b/tools/gf_time.c index d17a7c2..7402ab5 100644 --- a/tools/gf_time.c +++ b/tools/gf_time.c @@ -8,6 +8,14 @@ * Performs timing for gf arithmetic */ +#include "config.h" + +#ifdef HAVE_POSIX_MEMALIGN +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 +#endif +#endif + #include #include #include @@ -95,6 +103,9 @@ int main(int argc, char **argv) time_t t0; uint8_t *ra, *rb; gf_general_t a; +#ifndef HAVE_POSIX_MEMALIGN + uint8_t *malloc_ra, *malloc_rb; +#endif if (argc < 6) usage(NULL); @@ -155,8 +166,17 @@ int main(int argc, char **argv) printf("Seed: %ld\n", t0); - ra = (uint8_t *) malloc(size); - rb = (uint8_t *) malloc(size); +#ifdef HAVE_POSIX_MEMALIGN + if (posix_memalign((void **) &ra, 16, size)) + ra = NULL; + if (posix_memalign((void **) &rb, 16, size)) + rb = NULL; +#else + malloc_ra = (uint8_t *) malloc(size + 15); + malloc_rb = (uint8_t *) malloc(size + 15); + ra = (uint8_t *) (((uintptr_t) malloc_ra + 15) & ~((uintptr_t) 0xf)); + rb = (uint8_t *) (((uintptr_t) malloc_rb + 15) & ~((uintptr_t) 0xf)); +#endif if (ra == NULL || rb == NULL) { perror("malloc"); exit(1); } -- cgit v1.2.1