diff options
author | David Schleef <ds@schleef.org> | 2009-09-29 20:15:34 -0700 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2009-09-29 20:15:34 -0700 |
commit | 22bdbfc7aeddd66dc8e719f3a019387ddbf33b4e (patch) | |
tree | 16d048dff0900631ceed00672799bd8ed768dbd8 /orc-test | |
parent | efc3d0d1952313b233f179d9d50e9d015e98e684 (diff) |
Move 32-bit float ops to core library
Diffstat (limited to 'orc-test')
-rw-r--r-- | orc-test/orcarray.c | 25 | ||||
-rw-r--r-- | orc-test/orcarray.h | 2 | ||||
-rw-r--r-- | orc-test/orcrandom.c | 10 | ||||
-rw-r--r-- | orc-test/orcrandom.h | 1 | ||||
-rw-r--r-- | orc-test/orctest.c | 62 | ||||
-rw-r--r-- | orc-test/orctest.h | 3 |
6 files changed, 76 insertions, 27 deletions
diff --git a/orc-test/orcarray.c b/orc-test/orcarray.c index ba100ec..2c20f4c 100644 --- a/orc-test/orcarray.c +++ b/orc-test/orcarray.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> +#include <math.h> #define EXTEND_ROWS 16 #define EXTEND_STRIDE 256 @@ -57,11 +58,29 @@ orc_array_set_random (OrcArray *array, OrcRandom *context) int -orc_array_compare (OrcArray *array1, OrcArray *array2) +orc_array_compare (OrcArray *array1, OrcArray *array2, int flags) { - if (memcmp (array1->alloc_data, array2->alloc_data, - array1->alloc_len) == 0) { + if (flags & ORC_TEST_FLAGS_FLOAT && array1->element_size == 4) { + int j; + for(j=0;j<array1->m;j++){ + float *a, *b; + int i; + + a = ORC_PTR_OFFSET (array1->data, j*array1->stride); + b = ORC_PTR_OFFSET (array2->data, j*array2->stride); + + for (i=0;i<array1->n;i++){ + if (!((isnan(a[i]) && isnan(b[i])) || a[i] == b[i])) { + return FALSE; + } + } + } return TRUE; + } else { + if (memcmp (array1->alloc_data, array2->alloc_data, + array1->alloc_len) == 0) { + return TRUE; + } } return FALSE; diff --git a/orc-test/orcarray.h b/orc-test/orcarray.h index b8f323a..d8c89cb 100644 --- a/orc-test/orcarray.h +++ b/orc-test/orcarray.h @@ -24,7 +24,7 @@ void orc_array_free (OrcArray *array); void orc_array_set_pattern (OrcArray *array, int value); void orc_array_set_random (OrcArray *array, OrcRandom *context); -int orc_array_compare (OrcArray *array1, OrcArray *array2); +int orc_array_compare (OrcArray *array1, OrcArray *array2, int flags); int orc_array_check_out_of_bounds (OrcArray *array); #endif diff --git a/orc-test/orcrandom.c b/orc-test/orcrandom.c index 3b6d5fb..7ada96d 100644 --- a/orc-test/orcrandom.c +++ b/orc-test/orcrandom.c @@ -29,6 +29,16 @@ orc_random_bits (OrcRandom *context, void *data, int n_bytes) } } +void +orc_random_floats (OrcRandom *context, float *data, int n) +{ + int i; + for(i=0;i<n;i++){ + context->x = 1103515245*context->x + 12345; + data[i] = (double)(context->x>>16) / 32768.0 - 1.0; + } +} + unsigned int orc_random (OrcRandom *context) { diff --git a/orc-test/orcrandom.h b/orc-test/orcrandom.h index ce7be74..838d267 100644 --- a/orc-test/orcrandom.h +++ b/orc-test/orcrandom.h @@ -13,6 +13,7 @@ struct _OrcRandom { void orc_random_init (OrcRandom *context, int seed); void orc_random_bits (OrcRandom *context, void *data, int n_bytes); +void orc_random_floats (OrcRandom *context, float *data, int n); unsigned int orc_random (OrcRandom *context); ORC_END_DECLS diff --git a/orc-test/orctest.c b/orc-test/orctest.c index 7f07990..8eba583 100644 --- a/orc-test/orctest.c +++ b/orc-test/orctest.c @@ -11,6 +11,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <math.h> OrcRandom rand_context; @@ -244,24 +245,25 @@ print_array_val_hex (void *array, int size, int i) } } -float -print_array_val_float (void *array, int size, int i) +int +print_array_val_float (OrcArray *array, int i, int j) { - switch (size) { + void *ptr = ORC_PTR_OFFSET (array->data, + i*array->element_size + j*array->stride); + + switch (array->element_size) { case 4: - { - float *a = array; - printf(" %g", a[i]); - return a[i]; + if (isnan(*(float *)ptr)) { + printf(" nan %08x", *(uint32_t *)ptr); + /* This is to get around signaling/non-signaling nans in the output */ + return (*(uint32_t *)ptr) & 0xffbfffff; + } else { + printf(" %12.5g", *(float *)ptr); + return *(int32_t *)ptr; } - break; case 8: - { - double *a = array; - printf(" %g", a[i]); - return a[i]; - } - break; + printf(" %12.5g", *(double *)ptr); + return *(int64_t *)ptr; default: printf(" ERROR"); return -1; @@ -269,7 +271,7 @@ print_array_val_float (void *array, int size, int i) } static OrcTestResult orc_test_compare_output_full (OrcProgram *program, - int backup); + int flags); OrcTestResult orc_test_compare_output (OrcProgram *program) @@ -280,12 +282,12 @@ orc_test_compare_output (OrcProgram *program) OrcTestResult orc_test_compare_output_backup (OrcProgram *program) { - return orc_test_compare_output_full (program, 1); + return orc_test_compare_output_full (program, ORC_TEST_FLAGS_BACKUP); } OrcTestResult -orc_test_compare_output_full (OrcProgram *program, int backup) +orc_test_compare_output_full (OrcProgram *program, int flags) { OrcExecutor *ex; int n = 64 + (orc_random(&rand_context)&0xf); @@ -304,7 +306,8 @@ orc_test_compare_output_full (OrcProgram *program, int backup) ORC_DEBUG ("got here"); - if (!backup) { +flags |= ORC_TEST_FLAGS_FLOAT; + if (!(flags & ORC_TEST_FLAGS_BACKUP)) { OrcTarget *target; unsigned int flags; @@ -384,7 +387,7 @@ orc_test_compare_output_full (OrcProgram *program, int backup) for(k=0;k<ORC_N_VARIABLES;k++){ if (program->vars[k].vartype == ORC_VAR_TYPE_DEST) { - if (!orc_array_compare (dest_exec[k], dest_emul[k])) { + if (!orc_array_compare (dest_exec[k], dest_emul[k], flags)) { for(j=0;j<m;j++){ for(i=0;i<n;i++){ int a,b; @@ -396,13 +399,22 @@ orc_test_compare_output_full (OrcProgram *program, int backup) if (program->vars[l].name == NULL) continue; if (program->vars[l].vartype == ORC_VAR_TYPE_SRC && program->vars[l].size > 0) { - print_array_val_signed (src[l-ORC_VAR_S1], i, j); + if (flags & ORC_TEST_FLAGS_FLOAT) { + print_array_val_float (src[l-ORC_VAR_S1], i, j); + } else { + print_array_val_signed (src[l-ORC_VAR_S1], i, j); + } } } printf(" ->"); - a = print_array_val_signed (dest_emul[k], i, j); - b = print_array_val_signed (dest_exec[k], i, j); + if (flags & ORC_TEST_FLAGS_FLOAT) { + a = print_array_val_float (dest_emul[k], i, j); + b = print_array_val_float (dest_exec[k], i, j); + } else { + a = print_array_val_signed (dest_emul[k], i, j); + b = print_array_val_signed (dest_exec[k], i, j); + } if (a != b) { printf(" *"); @@ -433,7 +445,11 @@ orc_test_compare_output_full (OrcProgram *program, int backup) if (program->vars[k].name == NULL) continue; if (program->vars[k].vartype == ORC_VAR_TYPE_SRC && program->vars[k].size > 0) { - print_array_val_signed (src[k-ORC_VAR_S1], i, j); + if (flags & ORC_TEST_FLAGS_FLOAT) { + print_array_val_float (src[k-ORC_VAR_S1], i, j); + } else { + print_array_val_signed (src[k-ORC_VAR_S1], i, j); + } } } diff --git a/orc-test/orctest.h b/orc-test/orctest.h index f0c1409..7f087ab 100644 --- a/orc-test/orctest.h +++ b/orc-test/orctest.h @@ -13,6 +13,9 @@ typedef enum { ORC_TEST_OK = 2 } OrcTestResult; +#define ORC_TEST_FLAGS_BACKUP (1<<0) +#define ORC_TEST_FLAGS_FLOAT (1<<1) + void orc_test_init (void); OrcTestResult orc_test_gcc_compile (OrcProgram *p); void orc_test_random_bits (void *data, int n_bytes); |