summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2005-03-01 23:29:52 +0000
committerDavid Schleef <ds@schleef.org>2005-03-01 23:29:52 +0000
commit06413ff9f05be868bb5dbbf3565afa2a0c027cdd (patch)
treee15d624abceb3db1475f58a28fc0767aca199111 /examples
parent5533b305d3f81ab510f4e46bd70480563517ec95 (diff)
downloadliboil-06413ff9f05be868bb5dbbf3565afa2a0c027cdd.tar.gz
* configure.ac: add utf8
* examples/work/work.c: (test), (dump_array), (dump_test), (dump_source), (main): improve things a bit * liboil/Makefile.am: add utf8 * liboil/liboilfuncs.h: add utf8 * liboil/liboilfunction.c: (oil_class_optimize): Fix memleak. * liboil/utf8/Makefile.am: utf8 functions * liboil/utf8/utf8.c: (utf8_validate_test), (utf8_validate_ref): * liboil/utf8/utf8.h: same * testsuite/dso_check.c: (main): fix compilation
Diffstat (limited to 'examples')
-rw-r--r--examples/work/work.c142
1 files changed, 129 insertions, 13 deletions
diff --git a/examples/work/work.c b/examples/work/work.c
index 4f7882d..6dba338 100644
--- a/examples/work/work.c
+++ b/examples/work/work.c
@@ -25,6 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#define KLASS_NAME "conv_s16_f32"
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -32,6 +33,7 @@
#include <liboil/liboil.h>
#include <liboil/liboilfunction.h>
+#include <liboil/liboiltest.h>
#include <liboil/liboilrandom.h>
#include <liboil/liboilcpu.h>
#include <glib.h>
@@ -42,42 +44,156 @@ void register_impls(void);
void test(void)
{
- int16_t dest[100];
- float src[100];
+ int32_t dest[1];
+ uint8_t src[100];
int i;
for(i=0;i<100;i++){
- src[i] = oil_rand_s16();
- dest[i] = 0;
+ src[i] = oil_rand_u8() & 0x7f;
}
+ dest[0] = 0;
- oil_conv_s16_f32 (dest, 2, src, 4, 100);
+ oil_utf8_validate (dest, src, 100);
+#if 0
for(i=0;i<100;i++){
- g_print("%d %g\n",dest[i],src[i]);
+ g_print("%d %d\n",dest[i],src[i]);
}
+#endif
+ g_print("%d\n", dest[0]);
+
+}
+void
+dump_array (void *data, void *ref_data, OilType type, int pre_n, int stride,
+ int post_n)
+{
+ int i, j;
+ int s2 = oil_type_sizeof (type);
+ double x;
+
+#define DUMP(type, format) do { \
+ for(i=0;i<post_n;i++){ \
+ g_print(" "); \
+ for(j=0;j<pre_n;j++){ \
+ x = fabs(OIL_GET(data, i*stride + j*s2, type) - \
+ OIL_GET(data, i*stride + j*s2, type)); \
+ if (x >= 1.0) { \
+ g_print("[" format "] ", OIL_GET(data, i*stride + j*s2, type)); \
+ } else { \
+ g_print(format " ", OIL_GET(data, i*stride + j*s2, type)); \
+ } \
+ } \
+ g_print("\n"); \
+ } \
+} while(0)
+
+ switch(type) {
+ case OIL_TYPE_s8p:
+ DUMP(int8_t, "%d");
+ break;
+ case OIL_TYPE_u8p:
+ DUMP(uint8_t, "%d");
+ break;
+ case OIL_TYPE_s16p:
+ DUMP(int16_t, "%d");
+ break;
+ case OIL_TYPE_u16p:
+ DUMP(uint16_t, "%d");
+ break;
+ case OIL_TYPE_s32p:
+ DUMP(int32_t, "%d");
+ break;
+ case OIL_TYPE_u32p:
+ DUMP(uint32_t, "%u");
+ break;
+ case OIL_TYPE_f32p:
+ DUMP(float, "%g");
+ break;
+ case OIL_TYPE_f64p:
+ DUMP(double, "%g");
+ break;
+ default:
+ break;
+ }
+}
+
+void
+dump_test (OilTest *test)
+{
+ int i;
+ for(i=0;i<OIL_ARG_LAST;i++){
+ OilParameter *p = &test->params[i];
+ if (p->is_pointer) {
+ if (p->direction == 'i' || p->direction == 'd') {
+ g_print (" %s:\n", p->parameter_name);
+ dump_array (p->test_data + OIL_TEST_HEADER,
+ p->ref_data + OIL_TEST_HEADER,
+ p->type, p->pre_n, p->stride, p->post_n);
+ }
+ }
+ }
+}
+
+void
+dump_source (OilTest *test)
+{
+ int i;
+ for(i=0;i<OIL_ARG_LAST;i++){
+ OilParameter *p = &test->params[i];
+ if (p->is_pointer) {
+ if (p->direction == 'i' || p->direction == 's') {
+ g_print (" %s:\n", p->parameter_name);
+ dump_array (p->src_data + OIL_TEST_HEADER,
+ p->src_data + OIL_TEST_HEADER,
+ p->type, p->pre_n, p->stride, p->post_n);
+ }
+ }
+ }
}
int main (int argc, char *argv[])
{
OilFunctionClass *klass;
OilFunctionImpl *impl;
+ OilTest *test;
+ //const char *klass_name = "utf8_validate";
+ const char *klass_name = KLASS_NAME;
+ double ave, std;
oil_init ();
- //register_impls();
+ register_impls();
- klass = oil_class_get ("conv_s16_f32");
+ klass = oil_class_get (klass_name);
+ if (klass == NULL) {
+ g_print("class not found: %s\n", klass_name);
+ exit(0);
+ }
oil_class_optimize (klass);
+ test = oil_test_new(klass);
+ oil_test_set_iterations(test, 1);
+ test->n = 10;
+ test->m = 10;
+
+ impl = klass->reference_impl;
+ ave = impl->profile_ave;
+ std = impl->profile_std;
+ oil_test_check_impl (test, impl);
+ g_print ("source array\n");
+ dump_source(test);
+ g_print ("reference impl %s\n", impl->name);
+ g_print(" ave=%g std=%g\n", ave, std);
+ dump_test(test);
+
for (impl = klass->first_impl; impl; impl = impl->next) {
+ if (impl == klass->reference_impl) continue;
+ g_print ("impl %s\n", impl->name);
if (oil_impl_is_runnable (impl)) {
- klass->chosen_impl = impl;
- klass->func = impl->func;
- g_print("impl %s %g %g\n", impl->name, impl->profile_ave,
- impl->profile_std);
- test();
+ g_print(" ave=%g std=%g\n", impl->profile_ave, impl->profile_std);
+ oil_test_check_impl (test, impl);
+ dump_test(test);
}
}