diff options
author | José Fonseca <jfonseca@vmware.com> | 2009-08-21 07:34:15 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2009-08-21 07:34:15 +0100 |
commit | 4946909361ca2a6420f27c841e6da04c00012cd5 (patch) | |
tree | 4a27d100e1499191d5f05416527ec7eaf6789344 | |
parent | 20c5d3782c456fc6af544de3e3b66ba5ff7956bc (diff) |
llvmpipe: Several fixes of the conversion test.
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_bld_const.c | 22 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_bld_const.h | 4 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_test_conv.c | 10 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_test_main.c | 53 |
4 files changed, 55 insertions, 34 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_const.c b/src/gallium/drivers/llvmpipe/lp_bld_const.c index 20f0d3c40b..991cf24a9e 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_const.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_const.c @@ -33,6 +33,7 @@ * @author Jose Fonseca <jfonseca@vmware.com> */ +#include <float.h> #include "util/u_debug.h" @@ -92,6 +93,27 @@ lp_const_scale(union lp_type type) } +double +lp_const_eps(union lp_type type) +{ + if (type.floating) { + switch(type.width) { + case 32: + return FLT_EPSILON; + case 64: + return DBL_EPSILON; + default: + assert(0); + return 0.0; + } + } + else { + double scale = lp_const_scale(type); + return 1.0/scale; + } +} + + LLVMValueRef lp_build_undef(union lp_type type) { diff --git a/src/gallium/drivers/llvmpipe/lp_bld_const.h b/src/gallium/drivers/llvmpipe/lp_bld_const.h index 854b729ee6..fb0e70ad19 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_const.h +++ b/src/gallium/drivers/llvmpipe/lp_bld_const.h @@ -57,6 +57,10 @@ double lp_const_scale(union lp_type type); +double +lp_const_eps(union lp_type type); + + LLVMValueRef lp_build_undef(union lp_type type); diff --git a/src/gallium/drivers/llvmpipe/lp_test_conv.c b/src/gallium/drivers/llvmpipe/lp_test_conv.c index 91815509b7..e8b0b56d96 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_conv.c +++ b/src/gallium/drivers/llvmpipe/lp_test_conv.c @@ -35,6 +35,7 @@ #include "lp_bld_type.h" +#include "lp_bld_const.h" #include "lp_bld_conv.h" #include "lp_bld_debug.h" #include "lp_test.h" @@ -160,6 +161,7 @@ test_one(unsigned verbose, double cycles_avg = 0.0; unsigned num_srcs; unsigned num_dsts; + double eps; unsigned i, j; if(verbose >= 1) @@ -179,6 +181,8 @@ test_one(unsigned verbose, /* We must not loose or gain channels. Only precision */ assert(src_type.length * num_srcs == dst_type.length * num_dsts); + eps = MAX2(lp_const_eps(src_type), lp_const_eps(dst_type)); + module = LLVMModuleCreateWithName("test"); func = add_conv_test(module, src_type, num_srcs, dst_type, num_dsts); @@ -248,7 +252,7 @@ test_one(unsigned verbose, cycles[i] = end_counter - start_counter; for(j = 0; j < num_dsts; ++j) { - if(!compare_vec(dst_type, dst + j*dst_stride, ref + j*dst_stride)) + if(!compare_vec_with_eps(dst_type, dst + j*dst_stride, ref + j*dst_stride, eps)) success = FALSE; } @@ -263,8 +267,8 @@ test_one(unsigned verbose, fprintf(stderr, "\n"); } -#if 0 - fprintf(stderr, " Ref: ", j); +#if 1 + fprintf(stderr, " Ref: "); for(j = 0; j < src_type.length*num_srcs; ++j) fprintf(stderr, " %f", fref[j]); fprintf(stderr, "\n"); diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c index 32ed0f6da3..49213fb4f0 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_main.c +++ b/src/gallium/drivers/llvmpipe/lp_test_main.c @@ -120,6 +120,8 @@ write_elem(union lp_type type, void *dst, unsigned index, double value) assert(index < type.length); if(!type.sign && value < 0.0) value = 0.0; + if(type.norm && value < -1.0) + value = -1.0; if(type.norm && value > 1.0) value = 1.0; if (type.floating) { @@ -136,9 +138,10 @@ write_elem(union lp_type type, void *dst, unsigned index, double value) } else { double scale = lp_const_scale(type); - long long lvalue = (long long)round(value*scale); + value = round(value*scale); if(type.sign) { - lvalue = MIN2(lvalue, (1 << (type.width - 1)) - 1); + long long lvalue = (long long)value; + lvalue = MIN2(lvalue, ((long long)1 << (type.width - 1)) - 1); switch(type.width) { case 8: *((int8_t *)dst + index) = (int8_t)lvalue; @@ -150,14 +153,15 @@ write_elem(union lp_type type, void *dst, unsigned index, double value) *((int32_t *)dst + index) = (int32_t)lvalue; break; case 64: - *((int64_t *)dst + index) = (int32_t)lvalue; + *((int64_t *)dst + index) = (int64_t)lvalue; break; default: assert(0); } } else { - lvalue = MIN2(lvalue, (1 << type.width) - 1); + unsigned long long lvalue = (long long)value; + lvalue = MIN2(lvalue, ((unsigned long long)1 << type.width) - 1); switch(type.width) { case 8: *((uint8_t *)dst + index) = (uint8_t)lvalue; @@ -239,30 +243,9 @@ random_vec(union lp_type type, void *dst) boolean -compare_vec(union lp_type type, const void *res, const void *ref) +compare_vec_with_eps(union lp_type type, const void *res, const void *ref, double eps) { - double eps; unsigned i; - - if (type.floating) { - switch(type.width) { - case 32: - eps = FLT_EPSILON; - break; - case 64: - eps = DBL_EPSILON; - break; - default: - assert(0); - eps = 0.0; - break; - } - } - else { - double scale = lp_const_scale(type); - eps = 1.0/scale; - } - for (i = 0; i < type.length; ++i) { double res_elem = read_elem(type, res, i); double ref_elem = read_elem(type, ref, i); @@ -275,6 +258,14 @@ compare_vec(union lp_type type, const void *res, const void *ref) } +boolean +compare_vec(union lp_type type, const void *res, const void *ref) +{ + double eps = lp_const_eps(type); + return compare_vec_with_eps(type, res, ref, eps); +} + + void dump_vec(FILE *fp, union lp_type type, const void *src) { @@ -298,7 +289,7 @@ dump_vec(FILE *fp, union lp_type type, const void *src) fprintf(fp, "%f", value); } else { - if(type.sign) { + if(type.sign && !type.norm) { long long value; const char *format; switch(type.width) { @@ -331,19 +322,19 @@ dump_vec(FILE *fp, union lp_type type, const void *src) switch(type.width) { case 8: value = *((const uint8_t *)src + i); - format = "%4llu"; + format = type.norm ? "%2x" : "%4llu"; break; case 16: value = *((const uint16_t *)src + i); - format = "%6llu"; + format = type.norm ? "%4x" : "%6llx"; break; case 32: value = *((const uint32_t *)src + i); - format = "%11llu"; + format = type.norm ? "%8x" : "%11llx"; break; case 64: value = *((const uint64_t *)src + i); - format = "%21llu"; + format = type.norm ? "%16x" : "%21llx"; break; default: assert(0); |