#include "lp_bld_type.h"
+#include "lp_bld_const.h"
#include "lp_bld_conv.h"
#include "lp_bld_debug.h"
#include "lp_test.h"
double cycles_avg = 0.0;
unsigned num_srcs;
unsigned num_dsts;
+ double eps;
unsigned i, j;
if(verbose >= 1)
/* 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);
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;
}
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");
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) {
}
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;
*((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;
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);
}
+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)
{
fprintf(fp, "%f", value);
}
else {
- if(type.sign) {
+ if(type.sign && !type.norm) {
long long value;
const char *format;
switch(type.width) {
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);