X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fllvmpipe%2Flp_test_main.c;h=4c6109231464bbbf1aa16109d732a5b9c4337d81;hb=351d3c59f2a1153047d45fcdb23cc487f231683d;hp=34e6bf31fcf9aae3da0d387af75b7fbd11bb498d;hpb=b19cb0080cbc9877993e76f6cbd6bc170d3d2851;p=mesa.git diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c index 34e6bf31fcf..4c610923146 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_main.c +++ b/src/gallium/drivers/llvmpipe/lp_test_main.c @@ -34,16 +34,22 @@ */ -#include "lp_bld_const.h" +#include "util/u_cpu_detect.h" +#include "util/u_math.h" + +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_debug.h" #include "lp_test.h" void dump_type(FILE *fp, - union lp_type type) + struct lp_type type) { - fprintf(fp, "%s%u%sx%u", - type.floating ? "f" : (type.fixed ? "h" : (type.sign ? "s" : "u")), + fprintf(fp, "%s%s%u%sx%u", + type.sign ? (type.floating || type.fixed ? "" : "s") : "u", + type.floating ? "f" : (type.fixed ? "h" : "i"), type.width, type.norm ? "n" : "", type.length); @@ -51,7 +57,7 @@ dump_type(FILE *fp, double -read_elem(union lp_type type, const void *src, unsigned index) +read_elem(struct lp_type type, const void *src, unsigned index) { double scale = lp_const_scale(type); double value; @@ -114,11 +120,15 @@ read_elem(union lp_type type, const void *src, unsigned index) void -write_elem(union lp_type type, void *dst, unsigned index, double src) +write_elem(struct lp_type type, void *dst, unsigned index, double value) { - double scale = lp_const_scale(type); - double value = scale*src; 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) { switch(type.width) { case 32: @@ -132,37 +142,43 @@ write_elem(union lp_type type, void *dst, unsigned index, double src) } } else { + double scale = lp_const_scale(type); + value = round(value*scale); if(type.sign) { + 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)round(value); + *((int8_t *)dst + index) = (int8_t)lvalue; break; case 16: - *((int16_t *)dst + index) = (int16_t)round(value); + *((int16_t *)dst + index) = (int16_t)lvalue; break; case 32: - *((int32_t *)dst + index) = (int32_t)round(value); + *((int32_t *)dst + index) = (int32_t)lvalue; break; case 64: - *((int64_t *)dst + index) = (int32_t)round(value); + *((int64_t *)dst + index) = (int64_t)lvalue; break; default: assert(0); } } else { + 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)round(value); + *((uint8_t *)dst + index) = (uint8_t)lvalue; break; case 16: - *((uint16_t *)dst + index) = (uint16_t)round(value); + *((uint16_t *)dst + index) = (uint16_t)lvalue; break; case 32: - *((uint32_t *)dst + index) = (uint32_t)round(value); + *((uint32_t *)dst + index) = (uint32_t)lvalue; break; case 64: - *((uint64_t *)dst + index) = (uint64_t)round(value); + *((uint64_t *)dst + index) = (uint64_t)lvalue; break; default: assert(0); @@ -173,50 +189,35 @@ write_elem(union lp_type type, void *dst, unsigned index, double src) void -random_elem(union lp_type type, void *dst, unsigned index) +random_elem(struct lp_type type, void *dst, unsigned index) { + double value; assert(index < type.length); - if (type.floating) { - double value = (double)random()/(double)RAND_MAX; - if(!type.norm) { - value += (double)random(); - if(random() & 1) - value = -value; - } - switch(type.width) { - case 32: - *((float *)dst + index) = (float)value; - break; - case 64: - *((double *)dst + index) = value; - break; - default: - assert(0); + value = (double)rand()/(double)RAND_MAX; + if(!type.norm) { + if (type.floating) { + value *= 2.0; } - } - else { - switch(type.width) { - case 8: - *((uint8_t *)dst + index) = (uint8_t)random(); - break; - case 16: - *((uint16_t *)dst + index) = (uint16_t)random(); - break; - case 32: - *((uint32_t *)dst + index) = (uint32_t)random(); - break; - case 64: - *((uint64_t *)dst + index) = (uint64_t)random(); - break; - default: - assert(0); + else { + unsigned long long mask; + if (type.fixed) + mask = ((unsigned long long)1 << (type.width / 2)) - 1; + else if (type.sign) + mask = ((unsigned long long)1 << (type.width - 1)) - 1; + else + mask = ((unsigned long long)1 << type.width) - 1; + value += (double)(mask & rand()); } } + if(!type.sign) + if(rand() & 1) + value = -value; + write_elem(type, dst, index, value); } void -read_vec(union lp_type type, const void *src, double *dst) +read_vec(struct lp_type type, const void *src, double *dst) { unsigned i; for (i = 0; i < type.length; ++i) @@ -225,7 +226,7 @@ read_vec(union lp_type type, const void *src, double *dst) void -write_vec(union lp_type type, void *dst, const double *src) +write_vec(struct lp_type type, void *dst, const double *src) { unsigned i; for (i = 0; i < type.length; ++i) @@ -236,12 +237,12 @@ write_vec(union lp_type type, void *dst, const double *src) float random_float(void) { - return (float)((double)random()/(double)RAND_MAX); + return (float)((double)rand()/(double)RAND_MAX); } void -random_vec(union lp_type type, void *dst) +random_vec(struct lp_type type, void *dst) { unsigned i; for (i = 0; i < type.length; ++i) @@ -250,44 +251,37 @@ 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(struct 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; - } - + eps *= type.floating ? 8.0 : 2.0; for (i = 0; i < type.length; ++i) { double res_elem = read_elem(type, res, i); double ref_elem = read_elem(type, ref, i); - double delta = fabs(res_elem - ref_elem); - if(delta >= 2.0*eps) + double delta = res_elem - ref_elem; + if (ref_elem < -1.0 || ref_elem > 1.0) { + delta /= ref_elem; + } + delta = fabs(delta); + if (delta >= eps) { return FALSE; + } } return TRUE; } +boolean +compare_vec(struct 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) +dump_vec(FILE *fp, struct lp_type type, const void *src) { unsigned i; for (i = 0; i < type.length; ++i) { @@ -309,7 +303,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) { @@ -342,19 +336,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); @@ -375,16 +369,30 @@ int main(int argc, char **argv) unsigned long n = 1000; unsigned i; boolean success; + boolean single = FALSE; for(i = 1; i < argc; ++i) { if(strcmp(argv[i], "-v") == 0) ++verbose; + else if(strcmp(argv[i], "-s") == 0) + single = TRUE; else if(strcmp(argv[i], "-o") == 0) fp = fopen(argv[++i], "wt"); else n = atoi(argv[i]); } + lp_build_init(); + +#ifdef DEBUG + if (verbose >= 2) { + gallivm_debug |= GALLIVM_DEBUG_IR; + gallivm_debug |= GALLIVM_DEBUG_ASM; + } +#endif + + util_cpu_detect(); + if(fp) { /* Warm up the caches */ test_some(0, NULL, 100); @@ -392,7 +400,9 @@ int main(int argc, char **argv) write_tsv_header(fp); } - if(n) + if (single) + success = test_single(verbose, fp); + else if (n) success = test_some(verbose, fp, n); else success = test_all(verbose, fp);