summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJanne Grunau <j@jannau.net>2014-09-05 13:33:04 +0200
committerJanne Grunau <j@jannau.net>2014-10-09 23:22:34 +0200
commit36e75c3efec08b1e9bdb9c1f69a5b0018abd8ac7 (patch)
tree7deb8e00964e43ed5d5ac71a78540b20cafe25b7 /tools
parenteb5ce0ca4206ed4f74009c1b9a3a72407693448b (diff)
downloadgf-complete-36e75c3efec08b1e9bdb9c1f69a5b0018abd8ac7.tar.gz
use posix_memalign to align memory for SIMD region tests
Properly emulate aligned allocation if posix_memalign is not available.
Diffstat (limited to 'tools')
-rw-r--r--tools/gf_time.c24
1 files changed, 22 insertions, 2 deletions
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 <stdio.h>
#include <getopt.h>
#include <stdint.h>
@@ -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); }