From 221ec1ffbcbc282d64643e191f3271285b87b0d9 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sat, 21 Aug 2010 13:45:18 -0700 Subject: [PATCH] tests: Add show_parse --- testsuite/Makefile.am | 3 +- testsuite/show_parse.c | 365 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 testsuite/show_parse.c diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index c89eee5..d6beddc 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -17,7 +17,8 @@ noinst_PROGRAMS = $(TESTS) generate_xml_table generate_xml_table2 \ perf_opcodes_sys_compare perf_parse_compare \ exec_parse \ compile_opcodes_sys_c \ - compile_opcodes_sys + compile_opcodes_sys \ + show_parse EXTRA_DIST = test.orc diff --git a/testsuite/show_parse.c b/testsuite/show_parse.c new file mode 100644 index 0000000..1e8e3ff --- /dev/null +++ b/testsuite/show_parse.c @@ -0,0 +1,365 @@ + +#define ORC_ENABLE_UNSTABLE_API + +#include +#include +#include +#include + +#include +#include +#include +#include + +static char * read_file (const char *filename); +void output_code (OrcProgram *p, FILE *output); +void output_code_header (OrcProgram *p, FILE *output); +void output_code_test (OrcProgram *p, FILE *output); + +void show (OrcProgram *p); + +int error = FALSE; + +enum { + FORMAT_SIGNED, + FORMAT_UNSIGNED, + FORMAT_HEX, + FORMAT_FLOAT +}; + +int format = FORMAT_SIGNED; + +int +main (int argc, char *argv[]) +{ + char *code; + int n = 0; + int i; + OrcProgram **programs; + const char *filename = NULL; + + orc_init (); + orc_test_init (); + + for(i=1;i|opcode)\n"); + exit(1); + } + } + + for(i=0;idata, + i*array->element_size + j*array->stride); + + switch (array->element_size) { + case 1: + printf(" %4d", *(orc_int8 *)ptr); + return *(orc_int8 *)ptr; + case 2: + printf(" %5d", *(orc_int16 *)ptr); + return *(orc_int16 *)ptr; + case 4: + printf(" %10d", *(orc_int32 *)ptr); + return *(orc_int32 *)ptr; + case 8: + printf(" %20lld", (long long)*(orc_int64 *)ptr); + return *(orc_int64 *)ptr; + default: + return -1; + } +} + +int +print_array_val_unsigned (OrcArray *array, int i, int j) +{ + void *ptr = ORC_PTR_OFFSET (array->data, + i*array->element_size + j*array->stride); + + switch (array->element_size) { + case 1: + printf(" %4u", *(orc_uint8 *)ptr); + return *(orc_int8 *)ptr; + case 2: + printf(" %5u", *(orc_uint16 *)ptr); + return *(orc_int16 *)ptr; + case 4: + printf(" %10u", *(orc_uint32 *)ptr); + return *(orc_int32 *)ptr; + case 8: + printf(" %20llu", (long long)*(orc_uint64 *)ptr); + return *(orc_int64 *)ptr; + default: + return -1; + } +} + +int +print_array_val_hex (OrcArray *array, int i, int j) +{ + void *ptr = ORC_PTR_OFFSET (array->data, + i*array->element_size + j*array->stride); + + switch (array->element_size) { + case 1: + printf(" %02x", *(orc_uint8 *)ptr); + return *(orc_int8 *)ptr; + case 2: + printf(" %04x", *(orc_uint16 *)ptr); + return *(orc_int16 *)ptr; + case 4: + printf(" %08x", *(orc_uint32 *)ptr); + return *(orc_int32 *)ptr; + case 8: + printf(" %016llx", (long long)*(orc_uint64 *)ptr); + return *(orc_int64 *)ptr; + default: + return -1; + } +} + +int +print_array_val_float (OrcArray *array, int i, int j) +{ + void *ptr = ORC_PTR_OFFSET (array->data, + i*array->element_size + j*array->stride); + + switch (array->element_size) { + case 4: + if (isnan(*(float *)ptr)) { + printf(" nan %08x", *(orc_uint32 *)ptr); + /* This is to get around signaling/non-signaling nans in the output */ + return (*(orc_uint32 *)ptr) & 0xffbfffff; + } else { + printf(" %12.5g", *(float *)ptr); + return *(orc_int32 *)ptr; + } + case 8: + printf(" %12.5g", *(double *)ptr); + return *(orc_int64 *)ptr; + default: + printf(" ERROR"); + return -1; + } +} + + +void +show (OrcProgram *program) +{ + OrcCompileResult result; + OrcTarget *target; + const char *target_name; + unsigned int target_flags; + int n, m; + OrcExecutor *ex; + OrcArray *dest[4] = { NULL, NULL, NULL, NULL }; + OrcArray *src[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + int i,j; + OrcRandomContext rand_context = { 0 }; + + + target_name = NULL; + target = orc_target_get_by_name (target_name); + + target_flags = orc_target_get_default_flags (target); + + result = orc_program_compile_full (program, target, target_flags); + if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) { + printf("%s: compile failed\n", program->name); + return; + } + + printf("%s:\n", program->name); + + if (program->constant_n > 0) { + n = program->constant_n; + } else { + n = 10; + } + + ex = orc_executor_new (program); + orc_executor_set_n (ex, n); + if (program->is_2d) { + if (program->constant_m > 0) { + m = program->constant_m; + } else { + m = 2; + } + } else { + m = 1; + } + orc_executor_set_m (ex, m); + + for(i=0;ivars[i].name == NULL) continue; + + if (program->vars[i].vartype == ORC_VAR_TYPE_SRC) { + src[i-ORC_VAR_S1] = orc_array_new (n, m, program->vars[i].size, 0); + orc_array_set_random (src[i-ORC_VAR_S1], &rand_context); + } else if (program->vars[i].vartype == ORC_VAR_TYPE_DEST) { + dest[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size, 0); + orc_array_set_pattern (dest[i], ORC_OOB_VALUE); + } else if (program->vars[i].vartype == ORC_VAR_TYPE_PARAM) { + orc_executor_set_param (ex, i, 2); + } + } + + orc_executor_set_n (ex, n); + orc_executor_set_m (ex, m); + for(j=0;jvars[j].vartype == ORC_VAR_TYPE_DEST) { + orc_executor_set_array (ex, j, dest[j-ORC_VAR_D1]->data); + orc_executor_set_stride (ex, j, dest[j-ORC_VAR_D1]->stride); + } + if (program->vars[j].vartype == ORC_VAR_TYPE_SRC) { + orc_executor_set_array (ex, j, src[j-ORC_VAR_S1]->data); + orc_executor_set_stride (ex, j, src[j-ORC_VAR_S1]->stride); + } + } + + orc_executor_run (ex); + + { + int i,j; + + for(j=0;jvars[l].size > 0) { + switch (format) { + case FORMAT_FLOAT: + print_array_val_float (src[l-ORC_VAR_S1], i, j); + break; + case FORMAT_HEX: + print_array_val_hex (src[l-ORC_VAR_S1], i, j); + break; + case FORMAT_SIGNED: + print_array_val_signed (src[l-ORC_VAR_S1], i, j); + break; + case FORMAT_UNSIGNED: + print_array_val_unsigned (src[l-ORC_VAR_S1], i, j); + break; + } + } + } + + printf(" ->"); + for(l=ORC_VAR_D1;lvars[l].size > 0) { + switch (format) { + case FORMAT_FLOAT: + print_array_val_float (dest[l-ORC_VAR_D1], i, j); + break; + case FORMAT_HEX: + print_array_val_hex (dest[l-ORC_VAR_D1], i, j); + break; + case FORMAT_SIGNED: + print_array_val_signed (dest[l-ORC_VAR_D1], i, j); + break; + case FORMAT_UNSIGNED: + print_array_val_unsigned (dest[l-ORC_VAR_D1], i, j); + break; + } + } + } + + printf("\n"); + } + } + } + + + + for(i=0;i<4;i++){ + if (dest[i]) orc_array_free (dest[i]); + } + for(i=0;i<8;i++){ + if (src[i]) orc_array_free (src[i]); + } + + orc_executor_free (ex); + +} + -- 2.7.4