summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2004-12-30 05:48:48 +0000
committerDavid Schleef <ds@schleef.org>2004-12-30 05:48:48 +0000
commitd63de3b79237c4cb63be64063f82b39cbe741e3b (patch)
tree423d86c7cb1b862940c0030ca044339cf88ea416
parentee6786e10ddaafc2566f182595e4005db1b7a612 (diff)
downloadliboil-d63de3b79237c4cb63be64063f82b39cbe741e3b.tar.gz
Add support for checking the output of functions and comparing
it to the reference function. * examples/oil-inspect.c: (oil_print_impl), (oil_print_class): * examples/work/Makefile.am: * examples/work/work.c: (test), (main): * liboil/copy/permute.c: (permute_test): * liboil/liboilfuncs.h: * liboil/liboilfunction.c: (oil_class_optimize), (oil_class_register_impl_by_name): * liboil/liboilfunction.h: * liboil/liboilparameter.h: * liboil/liboilprototype.c: (oil_param_from_string): * liboil/liboiltest.c: (oil_test_free), (_oil_test_marshal_function), (oil_test_check_function), (oil_test_check_ref), (oil_test_check_impl), (init_parameter), (fill_array), (check_array): * liboil/liboiltest.h: * testsuite/test1.c: (main):
-rw-r--r--ChangeLog21
-rw-r--r--examples/oil-inspect.c16
-rw-r--r--examples/work/Makefile.am2
-rw-r--r--examples/work/work.c52
-rw-r--r--liboil/copy/permute.c3
-rw-r--r--liboil/liboilfuncs.h6
-rw-r--r--liboil/liboilfunction.c23
-rw-r--r--liboil/liboilfunction.h3
-rw-r--r--liboil/liboilparameter.h9
-rw-r--r--liboil/liboilprototype.c6
-rw-r--r--liboil/liboiltest.c330
-rw-r--r--liboil/liboiltest.h8
-rw-r--r--testsuite/test1.c3
13 files changed, 364 insertions, 118 deletions
diff --git a/ChangeLog b/ChangeLog
index 58c9abf..a3b28e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
2004-12-29 David Schleef <ds@schleef.org>
+ Add support for checking the output of functions and comparing
+ it to the reference function.
+ * examples/oil-inspect.c: (oil_print_impl), (oil_print_class):
+ * examples/work/Makefile.am:
+ * examples/work/work.c: (test), (main):
+ * liboil/copy/permute.c: (permute_test):
+ * liboil/liboilfuncs.h:
+ * liboil/liboilfunction.c: (oil_class_optimize),
+ (oil_class_register_impl_by_name):
+ * liboil/liboilfunction.h:
+ * liboil/liboilparameter.h:
+ * liboil/liboilprototype.c: (oil_param_from_string):
+ * liboil/liboiltest.c: (oil_test_free),
+ (_oil_test_marshal_function), (oil_test_check_function),
+ (oil_test_check_ref), (oil_test_check_impl), (init_parameter),
+ (fill_array), (check_array):
+ * liboil/liboiltest.h:
+ * testsuite/test1.c: (main):
+
+2004-12-29 David Schleef <ds@schleef.org>
+
* liboil/colorspace/Makefile.am: some new classes
* liboil/colorspace/argb_paint.c: (argb_paint_u8_ref),
(argb_paint_u8_fast):
diff --git a/examples/oil-inspect.c b/examples/oil-inspect.c
index c37aee7..4432e7d 100644
--- a/examples/oil-inspect.c
+++ b/examples/oil-inspect.c
@@ -32,6 +32,7 @@
#include <liboil/liboil.h>
#include <liboil/liboilfunction.h>
#include <liboil/liboilcpu.h>
+#include <liboil/liboiltest.h>
#include <stdio.h>
#include <stdlib.h>
@@ -99,11 +100,13 @@ oil_flags_to_string (unsigned int flags)
}
static void
-oil_print_impl (OilFunctionImpl *impl, char* prefix)
+oil_print_impl (OilFunctionImpl *impl, OilTest *test, char* prefix)
{
char *c;
unsigned int cpu_flags = oil_cpu_get_flags();
+ oil_test_check_impl (test, impl);
+
printf ("%s%s\n", prefix, impl->name);
c = oil_flags_to_string (impl->flags);
if (c) {
@@ -114,6 +117,10 @@ oil_print_impl (OilFunctionImpl *impl, char* prefix)
printf ("%s profile: %g ticks (st.dev. %g)\n", prefix, impl->profile_ave,
impl->profile_std);
}
+ if (test && !(impl->flags & OIL_IMPL_FLAG_REF)) {
+ printf ("%s sum abs difference: %g (n=%d)\n", prefix,
+ test->sum_abs_diff, test->n_points);
+ }
if ((impl->flags & OIL_CPU_FLAG_MASK) & (~cpu_flags)) {
printf ("%s disabled\n", prefix);
}
@@ -137,6 +144,7 @@ oil_print_class (OilFunctionClass *klass, int verbose)
OilFunctionImpl **list;
int n;
int i;
+ OilTest *test;
if (!verbose) {
printf ("%s\n", klass->name);
@@ -158,6 +166,8 @@ oil_print_class (OilFunctionClass *klass, int verbose)
qsort (list, n, sizeof(OilFunctionImpl *), impl_compare);
+ test = oil_test_new (klass);
+
for (i=0;i<n;i++){
impl = list[i];
if ((impl->flags & OIL_IMPL_FLAG_REF) &&
@@ -165,12 +175,14 @@ oil_print_class (OilFunctionClass *klass, int verbose)
printerr ("warning: function %s is not reference implementation for class %s\n",
impl->name, klass->name);
}
- oil_print_impl (impl, " ");
+ oil_print_impl (impl, test, " ");
if (klass->chosen_impl == impl) {
printf (" currently chosen\n");
}
}
+ oil_test_free (test);
+
free(list);
}
diff --git a/examples/work/Makefile.am b/examples/work/Makefile.am
index 7de314f..9aa9766 100644
--- a/examples/work/Makefile.am
+++ b/examples/work/Makefile.am
@@ -1,6 +1,8 @@
noinst_PROGRAMS = work
+work_SOURCES = work.c argb_paint.c
+
AM_LDFLAGS = $(LIBOIL_LIBS) $(GLIB_LIBS)
AM_CFLAGS = $(LIBOIL_CFLAGS) $(GLIB_CFLAGS)
diff --git a/examples/work/work.c b/examples/work/work.c
index 3abca6c..e4addd4 100644
--- a/examples/work/work.c
+++ b/examples/work/work.c
@@ -37,30 +37,32 @@
#include <string.h>
#include <math.h>
+void register_impls(void);
+
void test(void)
{
- double src[12];
- double dest[6];
- double d2[12];
+ uint8_t dest[100*4];
+ uint8_t color[4];
+ uint8_t alpha[100];
int i;
- for(i=0;i<12;i++){
- src[i] = oil_rand_f64_0_1();
- }
-
- oil_mdct12_f64 (dest, src);
-
- for(i=0;i<6;i++){
- g_print("%4g ",dest[i]);
+ for(i=0;i<16;i++){
+ dest[i*4+0] = 0;
+ dest[i*4+1] = 0;
+ dest[i*4+2] = 0;
+ dest[i*4+3] = 255;
+ alpha[i]=i*16;
}
- g_print("\n");
+ color[0] = 255;
+ color[1] = 128;
+ color[2] = 10;
+ color[3] = 128;
- oil_imdct12_f64 (d2, dest);
+ oil_argb_paint_u8 (dest, color, alpha, 16);
- for(i=0;i<12;i++){
- g_print("%4g ",d2[i]/6.0);
+ for(i=0;i<4*16;i+=4){
+ g_print("%d %d %d %d\n",dest[i+0],dest[i+1],dest[i+2],dest[i+3]);
}
- g_print("\n");
}
@@ -71,14 +73,18 @@ int main (int argc, char *argv[])
oil_init ();
- klass = oil_class_get ("mdct12_f64");
+ register_impls();
+
+ klass = oil_class_get ("argb_paint_u8");
+ oil_class_optimize (klass);
- oil_class_choose_by_name (klass, "imdct12_f64_ref");
- impl = klass->chosen_impl;
- g_print("chosen=%p\n", impl);
- impl = klass->reference_impl;
- g_print("ref=%p\n", impl);
- test();
+ for (impl = klass->first_impl; impl; impl = impl->next) {
+ klass->chosen_impl = impl;
+ klass->func = impl->func;
+ g_print("impl %s %g %g\n", impl->name, impl->profile_ave,
+ impl->profile_std);
+ test();
+ }
return 0;
}
diff --git a/liboil/copy/permute.c b/liboil/copy/permute.c
index 4797edb..1d5618d 100644
--- a/liboil/copy/permute.c
+++ b/liboil/copy/permute.c
@@ -40,7 +40,8 @@ permute_test (OilTest *test)
int i;
int n = test->n;
int stride = test->params[OIL_ARG_SSTR2].value;
- void *ptr = (void *)test->params[OIL_ARG_SRC2].value;
+ uint8_t *ptr = (uint8_t *)test->params[OIL_ARG_SRC2].src_data +
+ OIL_TEST_HEADER;
for(i=0;i<n;i++){
/* FIXME */
diff --git a/liboil/liboilfuncs.h b/liboil/liboilfuncs.h
index 067f6db..d11cae0 100644
--- a/liboil/liboilfuncs.h
+++ b/liboil/liboilfuncs.h
@@ -51,9 +51,15 @@ typedef void (*_oil_type_abs_u32_s32)(uint32_t * dest, int dstr, const int32_t *
extern OilFunctionClass *oil_function_class_ptr_abs_u8_s8;
typedef void (*_oil_type_abs_u8_s8)(uint8_t * dest, int dstr, const int8_t * src, int sstr, int n);
#define oil_abs_u8_s8 ((_oil_type_abs_u8_s8)(*(void **)oil_function_class_ptr_abs_u8_s8))
+extern OilFunctionClass *oil_function_class_ptr_argb_paint_u8;
+typedef void (*_oil_type_argb_paint_u8)(uint8_t * i_4xn, const uint8_t * s1_4, const uint8_t * s2_n, int n);
+#define oil_argb_paint_u8 ((_oil_type_argb_paint_u8)(*(void **)oil_function_class_ptr_argb_paint_u8))
extern OilFunctionClass *oil_function_class_ptr_average2_u8;
typedef void (*_oil_type_average2_u8)(uint8_t * dest, int dstr, const uint8_t * src1, int sstr1, const uint8_t * src2, int sstr2, int n);
#define oil_average2_u8 ((_oil_type_average2_u8)(*(void **)oil_function_class_ptr_average2_u8))
+extern OilFunctionClass *oil_function_class_ptr_ayuv2argb_u8;
+typedef void (*_oil_type_ayuv2argb_u8)(uint8_t * d_4xn, const uint8_t * s_4xn, int n);
+#define oil_ayuv2argb_u8 ((_oil_type_ayuv2argb_u8)(*(void **)oil_function_class_ptr_ayuv2argb_u8))
extern OilFunctionClass *oil_function_class_ptr_clip_f32;
typedef void (*_oil_type_clip_f32)(float * dest, int dstr, const float * src, int sstr, int n, const float * s2_1, const float * s3_1);
#define oil_clip_f32 ((_oil_type_clip_f32)(*(void **)oil_function_class_ptr_clip_f32))
diff --git a/liboil/liboilfunction.c b/liboil/liboilfunction.c
index b9bf930..ef0d6fd 100644
--- a/liboil/liboilfunction.c
+++ b/liboil/liboilfunction.c
@@ -174,9 +174,7 @@ oil_class_optimize (OilFunctionClass * klass)
if ((impl->flags & OIL_CPU_FLAG_MASK) & (~oil_cpu_flags))
continue;
- oil_test_set_impl (test, impl);
-
- ret = oil_test_go (test);
+ ret = oil_test_check_impl (test, impl);
if (ret) {
OIL_LOG ("impl %s ave=%g std=%g", impl->name, impl->profile_ave,
impl->profile_std);
@@ -234,3 +232,22 @@ oil_init_structs (void)
}
}
}
+
+void
+oil_class_register_impl_by_name (const char *klass_name, OilFunctionImpl *impl)
+{
+ OilFunctionClass *klass;
+
+ klass = oil_class_get (klass_name);
+ if (klass == NULL) return;
+
+ impl->klass = klass;
+ impl->next = impl->klass->first_impl;
+ klass->first_impl = impl;
+ if (impl->flags & OIL_IMPL_FLAG_REF) {
+ impl->klass->reference_impl = impl;
+ impl->klass->chosen_impl = impl;
+ impl->klass->func = impl->func;
+ }
+}
+
diff --git a/liboil/liboilfunction.h b/liboil/liboilfunction.h
index 8c322bc..52a0092 100644
--- a/liboil/liboilfunction.h
+++ b/liboil/liboilfunction.h
@@ -151,5 +151,8 @@ OilFunctionImpl * oil_impl_get_by_index (int i);
void oil_class_choose_by_name (OilFunctionClass * klass, const char *name);
+void oil_class_register_impl_by_name (const char *klass_name,
+ OilFunctionImpl *impl);
+
#endif
diff --git a/liboil/liboilparameter.h b/liboil/liboilparameter.h
index 5cb6ba6..8679cd5 100644
--- a/liboil/liboilparameter.h
+++ b/liboil/liboilparameter.h
@@ -85,6 +85,7 @@ struct _OilParameter {
OilType type;
int direction;
+ int is_pointer;
int is_stride;
int index;
int prestride_length;
@@ -94,8 +95,14 @@ struct _OilParameter {
OilArgType parameter_type;
- void *ptr;
+ void *src_data;
+ void *ref_data;
+ void *test_data;
unsigned long value;
+
+ int pre_n;
+ int post_n;
+ int stride;
int size;
};
diff --git a/liboil/liboilprototype.c b/liboil/liboilprototype.c
index 89f80b6..0a61400 100644
--- a/liboil/liboilprototype.c
+++ b/liboil/liboilprototype.c
@@ -465,11 +465,15 @@ oil_param_from_string (OilParameter *p, char *s)
if (s[0] == 'n' && s[1] == 0) {
p->direction = *s;
+ p->is_stride = 0;
+ p->is_pointer = 0;
p->parameter_type = OIL_ARG_N;
return 1;
}
if (s[0] == 'm' && s[1] == 0) {
p->direction = *s;
+ p->is_stride = 0;
+ p->is_pointer = 0;
p->parameter_type = OIL_ARG_M;
return 1;
}
@@ -496,9 +500,11 @@ oil_param_from_string (OilParameter *p, char *s)
if (*s == 's') {
p->is_stride = 1;
+ p->is_pointer = 0;
s++;
} else {
p->is_stride = 0;
+ p->is_pointer = 1;
}
if (isdigit (*s)) {
diff --git a/liboil/liboiltest.c b/liboil/liboiltest.c
index cc2b057..ad885f6 100644
--- a/liboil/liboiltest.c
+++ b/liboil/liboiltest.c
@@ -35,8 +35,13 @@
#include <liboil/liboilprofile.h>
#include <stdlib.h>
#include <string.h>
-
#include <stdio.h>
+#include <math.h>
+
+static void fill_array (void *ptr, OilType type, int pre_n, int stride,
+ int post_n);
+static double check_array (void *data, void *ref, OilType type, int pre_n,
+ int stride, int post_n);
OilTest *
oil_test_new (OilFunctionClass *klass)
@@ -82,8 +87,14 @@ oil_test_free (OilTest *test)
}
for(i=0;i<OIL_ARG_LAST;i++){
- if (test->params[i].ptr) {
- free (test->params[i].ptr);
+ if (test->params[i].src_data) {
+ free (test->params[i].src_data);
+ }
+ if (test->params[i].ref_data) {
+ free (test->params[i].ref_data);
+ }
+ if (test->params[i].test_data) {
+ free (test->params[i].test_data);
}
}
@@ -102,14 +113,24 @@ oil_test_set_iterations (OilTest *test, int iterations)
test->iterations = iterations;
}
-int
-oil_test_go (OilTest *test)
+static void
+_oil_test_marshal_function (void *func, unsigned long *args, int n_args,
+ unsigned int pointer_mask, OilProfile *prof)
+{
+ oil_profile_start (prof);
+ ((void (*)(int,int,int,int,int,int,int,int,int,int))func)
+ (args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],
+ args[8],args[9]);
+ oil_profile_stop (prof);
+}
+
+static void
+oil_test_check_function (OilTest *test)
{
int i;
int j;
- int args[10];
-
- if (test->proto->n_params > 10) return 0;
+ unsigned long args[10];
+ unsigned int pointer_mask;
if (!test->inited) {
oil_test_init_params(test);
@@ -117,33 +138,117 @@ oil_test_go (OilTest *test)
test->params[OIL_ARG_N].value = test->n;
test->inited = 1;
- }
- if (test->klass->test_func) {
- test->klass->test_func (test);
+ if (test->klass->test_func) {
+ test->klass->test_func (test);
+ }
}
- OIL_LOG("calling test function %s", test->impl->name);
+ OIL_LOG("calling reference function %s", test->impl->name);
+
+ pointer_mask = 0;
for(i=0;i<test->proto->n_params;i++){
+ OilParameter *p;
j = test->proto->params[i].parameter_type;
- OIL_LOG(" %s: 0x%08lx (%ld)",
- oil_arg_type_name (j),
- test->params[j].value,
- test->params[j].value);
- args[i] = test->params[j].value;
+ p = &test->params[j];
+
+ pointer_mask <<= 1;
+ OIL_LOG(" %s: 0x%08lx (%ld)", oil_arg_type_name (j), p->value, p->value);
+ if (p->is_pointer) {
+ pointer_mask |= 1;
+ if (p->direction == 's') {
+ args[i] = (unsigned long)p->src_data + OIL_TEST_HEADER;
+ } else if (p->direction == 'i') {
+ memcpy (p->test_data, p->src_data, p->size);
+ args[i] = (unsigned long)p->test_data + OIL_TEST_HEADER;
+ } else if (p->direction == 'd') {
+ memset (p->test_data, 0, p->size);
+ args[i] = (unsigned long)p->test_data + OIL_TEST_HEADER;
+ } else {
+ OIL_ERROR ("not reached");
+ }
+ } else {
+ args[i] = p->value;
+ }
}
oil_profile_init (&test->prof);
for(i=0;i<test->iterations;i++){
- oil_profile_start (&test->prof);
- ((void (*)(int,int,int,int,int,int,int,int,int,int))test->impl->func)
- (args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],
- args[8],args[9]);
- oil_profile_stop (&test->prof);
+ _oil_test_marshal_function (test->impl->func, args, test->proto->n_params,
+ pointer_mask, &test->prof);
}
oil_profile_get_ave_std (&test->prof, &test->impl->profile_ave,
&test->impl->profile_std);
+}
+
+void
+oil_test_check_ref (OilTest *test)
+{
+ int i;
+
+ if (test->proto->n_params > 10) {
+ OIL_ERROR ("function has too many parameters");
+ return;
+ }
+
+ test->impl = test->klass->reference_impl;
+
+ oil_test_check_function (test);
+
+ for(i=0;i<OIL_ARG_LAST;i++){
+ OilParameter *p = &test->params[i];
+
+ if (p->is_pointer) {
+ if (p->direction == 'i' || p->direction == 'd') {
+ memcpy (p->ref_data, p->test_data, p->size);
+ }
+ }
+ }
+
+ test->tested_ref = 1;
+}
+
+int
+oil_test_check_impl (OilTest *test, OilFunctionImpl *impl)
+{
+ double x;
+ int i;
+ int n;
+
+ if (test->proto->n_params > 10) {
+ OIL_ERROR ("function has too many parameters");
+ return 0;
+ }
+
+ if (!test->tested_ref) {
+ oil_test_check_ref(test);
+ }
+
+ test->impl = impl;
+ oil_test_check_function (test);
+
+ x = 0;
+ n = 0;
+ for(i=0;i<OIL_ARG_LAST;i++){
+ OilParameter *p = &test->params[i];
+
+ if (p->is_pointer) {
+ if (p->direction == 'i' || p->direction == 'd') {
+ x += check_array (p->ref_data, p->test_data, p->type, p->pre_n,
+ p->stride, p->post_n);
+ n += p->pre_n * p->post_n;
+ }
+ }
+ }
+ OIL_DEBUG("sum of absolute differences %g for %d values", x, n);
+ if (x > n) {
+ OIL_ERROR ("function %s in class %s failed check (%g > %d)",
+ test->impl->name, test->klass->name, x, n);
+ }
+
+ test->sum_abs_diff = x;
+ test->n_points = n;
return 1;
}
@@ -191,97 +296,58 @@ oil_test_cleanup (OilTest *test)
}
-static void
-fill_array (void *ptr, OilType type, int pre_n, int stride, int post_n)
-{
- int i;
- int j;
- int s2 = oil_type_sizeof (type);
-
- for(i=0;i<post_n;i++){
- for(j=0;j<pre_n;j++){
- switch (type) {
- case OIL_TYPE_s8p:
- OIL_GET(ptr, i*stride + j*s2, int8_t) = oil_rand_s8();
- break;
- case OIL_TYPE_u8p:
- OIL_GET(ptr, i*stride + j*s2, uint8_t) = oil_rand_u8();
- break;
- case OIL_TYPE_s16p:
- OIL_GET(ptr, i*stride + j*s2, int16_t) = oil_rand_s16();
- break;
- case OIL_TYPE_u16p:
- OIL_GET(ptr, i*stride + j*s2, uint16_t) = oil_rand_u16();
- break;
- case OIL_TYPE_s32p:
- OIL_GET(ptr, i*stride + j*s2, int32_t) = oil_rand_s32();
- break;
- case OIL_TYPE_u32p:
- OIL_GET(ptr, i*stride + j*s2, uint32_t) = oil_rand_u32();
- break;
- case OIL_TYPE_f32p:
- OIL_GET(ptr, i*stride + j*s2, float) = oil_rand_f32_0_1();
- break;
- case OIL_TYPE_f64p:
- OIL_GET(ptr, i*stride + j*s2, double) = oil_rand_f64_0_1();
- break;
- default:
- OIL_ERROR ("should not be reached (type == %d)", type);
- return;
- break;
- }
- }
- }
-}
static void
init_parameter (OilTest *test, OilParameter *p, OilParameter *ps)
{
- int stride;
- void *ptr;
- int pre_n;
- int post_n;
-
if (!p->type) return;
if (p->prestride_length) {
- pre_n = p->prestride_length;
+ p->pre_n = p->prestride_length;
} else {
if (p->prestride_var == 1) {
- pre_n = test->n;
+ p->pre_n = test->n;
} else {
- pre_n = test->m;
+ p->pre_n = test->m;
}
}
if (ps->value) {
- stride = ps->value;
+ p->stride = ps->value;
} else {
- stride = oil_type_sizeof (p->type) * pre_n;
- ps->value = stride;
+ p->stride = oil_type_sizeof (p->type) * p->pre_n;
+ ps->value = p->stride;
}
if (p->poststride_length) {
- post_n = p->poststride_length;
+ p->post_n = p->poststride_length;
} else {
if (p->poststride_var == 1) {
- post_n = test->n;
+ p->post_n = test->n;
} else {
- post_n = test->m;
+ p->post_n = test->m;
}
}
- ptr = malloc (stride * post_n + OIL_TEST_HEADER + OIL_TEST_FOOTER);
- memset (ptr, 0, stride * post_n + OIL_TEST_HEADER + OIL_TEST_FOOTER);
- p->ptr = ptr;
- p->value = (unsigned long) ptr + OIL_TEST_HEADER;
+ p->size = p->stride * p->post_n + OIL_TEST_HEADER + OIL_TEST_FOOTER;
if (p->direction == 'i' || p->direction == 's') {
- fill_array (ptr, p->type, pre_n, stride, post_n);
+ if (p->src_data) free (p->src_data);
+ p->src_data = malloc (p->size);
+ memset (p->src_data, 0, p->size);
+ fill_array (p->src_data, p->type, p->pre_n, p->stride, p->post_n);
}
-}
+ if (p->direction == 'i' || p->direction == 'd') {
+ if (p->ref_data) free (p->ref_data);
+ p->ref_data = malloc (p->size);
+ memset (p->ref_data, 0, p->size);
+ if (p->test_data) free (p->ref_data);
+ p->test_data = malloc (p->size);
+ memset (p->test_data, 0, p->size);
+ }
+}
void
oil_test_init_params (OilTest *test)
@@ -308,3 +374,99 @@ oil_test_init_params (OilTest *test)
&test->params[OIL_ARG_ISTR2]);
}
+static void
+fill_array (void *data, OilType type, int pre_n, int stride, int post_n)
+{
+ int i;
+ int j;
+ int s2 = oil_type_sizeof (type);
+
+#define FILL(type,func) do {\
+ for(i=0;i<post_n;i++){ \
+ for(j=0;j<pre_n;j++){ \
+ OIL_GET(data, i*stride + j*s2, type) = func ; \
+ } \
+ } \
+}while(0)
+
+ switch (type) {
+ case OIL_TYPE_s8p:
+ FILL(int8_t,oil_rand_s8());
+ break;
+ case OIL_TYPE_u8p:
+ FILL(uint8_t,oil_rand_u8());
+ break;
+ case OIL_TYPE_s16p:
+ FILL(int16_t,oil_rand_s16());
+ break;
+ case OIL_TYPE_u16p:
+ FILL(uint16_t,oil_rand_u16());
+ break;
+ case OIL_TYPE_s32p:
+ FILL(int32_t,oil_rand_s32());
+ break;
+ case OIL_TYPE_u32p:
+ FILL(uint32_t,oil_rand_u32());
+ break;
+ case OIL_TYPE_f32p:
+ FILL(float,oil_rand_f32_0_1());
+ break;
+ case OIL_TYPE_f64p:
+ FILL(double,oil_rand_f64_0_1());
+ break;
+ default:
+ OIL_ERROR ("should not be reached (type == %d)", type);
+ return;
+ break;
+ }
+}
+
+static double
+check_array (void *data, void *ref, OilType type, int pre_n, int stride, int post_n)
+{
+ int i;
+ int j;
+ int s2 = oil_type_sizeof (type);
+ double x = 0;
+
+#define CHECK(type) do {\
+ for(i=0;i<post_n;i++){ \
+ for(j=0;j<pre_n;j++){ \
+ x += fabs((double)OIL_GET(data, i*stride + j*s2, type) - \
+ (double)OIL_GET(ref, i*stride + j*s2, type)); \
+ } \
+ } \
+}while(0)
+
+ switch (type) {
+ case OIL_TYPE_s8p:
+ CHECK(int8_t);
+ break;
+ case OIL_TYPE_u8p:
+ CHECK(uint8_t);
+ break;
+ case OIL_TYPE_s16p:
+ CHECK(int16_t);
+ break;
+ case OIL_TYPE_u16p:
+ CHECK(uint16_t);
+ break;
+ case OIL_TYPE_s32p:
+ CHECK(int32_t);
+ break;
+ case OIL_TYPE_u32p:
+ CHECK(uint32_t);
+ break;
+ case OIL_TYPE_f32p:
+ CHECK(float);
+ break;
+ case OIL_TYPE_f64p:
+ CHECK(double);
+ break;
+ default:
+ OIL_ERROR ("should not be reached (type == %d)", type);
+ return INFINITY;
+ break;
+ }
+ return x;
+}
diff --git a/liboil/liboiltest.h b/liboil/liboiltest.h
index a6f12e1..dd97e7a 100644
--- a/liboil/liboiltest.h
+++ b/liboil/liboiltest.h
@@ -45,6 +45,10 @@ struct _OilTest {
int m;
int inited;
+ int tested_ref;
+
+ double sum_abs_diff;
+ int n_points;
};
#define OIL_TEST_HEADER 256
@@ -53,10 +57,10 @@ struct _OilTest {
OilTest *oil_test_new (OilFunctionClass *klass);
void oil_test_free (OilTest *test);
-void oil_test_set_impl (OilTest *test, OilFunctionImpl *impl);
void oil_test_set_iterations (OilTest *test, int iterations);
-int oil_test_go (OilTest *test);
+void oil_test_check_ref (OilTest *test);
+int oil_test_check_impl (OilTest *test, OilFunctionImpl *impl);
void oil_test_cleanup (OilTest *test);
void oil_test_init_src_arrays (OilTest *test);
diff --git a/testsuite/test1.c b/testsuite/test1.c
index 9bf32da..a2828db 100644
--- a/testsuite/test1.c
+++ b/testsuite/test1.c
@@ -70,11 +70,10 @@ int main (int argc, char *argv[])
if ((impl->flags & OIL_CPU_FLAG_MASK) & ~cpu_flags) {
printf(" not supported\n");
} else {
- oil_test_set_impl (test, impl);
test->n = 1600;
- ret = oil_test_go (test);
+ ret = oil_test_check_impl (test, impl);
if (ret) {
#if 0
printf(" %lu %g\n",test->prof.min,