diff options
author | David Schleef <ds@schleef.org> | 2005-03-01 23:29:52 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2005-03-01 23:29:52 +0000 |
commit | 06413ff9f05be868bb5dbbf3565afa2a0c027cdd (patch) | |
tree | e15d624abceb3db1475f58a28fc0767aca199111 | |
parent | 5533b305d3f81ab510f4e46bd70480563517ec95 (diff) | |
download | liboil-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
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | examples/work/work.c | 142 | ||||
-rw-r--r-- | liboil/Makefile.am | 3 | ||||
-rw-r--r-- | liboil/liboilfuncs.h | 3 | ||||
-rw-r--r-- | liboil/liboilfunction.c | 2 | ||||
-rw-r--r-- | liboil/utf8/Makefile.am | 33 | ||||
-rw-r--r-- | liboil/utf8/utf8.c | 89 | ||||
-rw-r--r-- | liboil/utf8/utf8.h | 36 | ||||
-rw-r--r-- | testsuite/dso_check.c | 2 |
10 files changed, 309 insertions, 15 deletions
@@ -1,3 +1,16 @@ +2005-03-01 David Schleef <ds@schleef.org> + + * 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 + 2005-02-13 David Schleef <ds@schleef.org> * testsuite/dso_check.c: (main): Add diff --git a/configure.ac b/configure.ac index d37ed44..256de4d 100644 --- a/configure.ac +++ b/configure.ac @@ -184,6 +184,7 @@ liboil/dct/Makefile liboil/md5/Makefile liboil/jpeg/Makefile liboil/simdpack/Makefile +liboil/utf8/Makefile testsuite/Makefile examples/Makefile examples/jpeg/Makefile 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); } } diff --git a/liboil/Makefile.am b/liboil/Makefile.am index 4a36149..5c4e3d5 100644 --- a/liboil/Makefile.am +++ b/liboil/Makefile.am @@ -1,7 +1,7 @@ pkgincludedir = $(includedir)/liboil-@LIBOIL_MAJORMINOR@/liboil -SUBDIRS = colorspace conv copy dct jpeg simdpack md5 +SUBDIRS = colorspace conv copy dct jpeg simdpack md5 utf8 lib_LTLIBRARIES = liboiltmp1.la liboil-@LIBOIL_MAJORMINOR@.la @@ -26,6 +26,7 @@ liboilfunctions_la_LIBADD = \ jpeg/libjpeg.la \ md5/libmd5.la \ simdpack/libsimdpack.la \ + utf8/libutf8.la \ -lm liboiltmp1_la_SOURCES = diff --git a/liboil/liboilfuncs.h b/liboil/liboilfuncs.h index 5cd83ca..dac4856 100644 --- a/liboil/liboilfuncs.h +++ b/liboil/liboilfuncs.h @@ -534,6 +534,9 @@ typedef void (*_oil_type_trans8x8_u8)(uint8_t * d_8x8, int ds, const uint8_t * s extern OilFunctionClass *oil_function_class_ptr_unzigzag8x8_s16; typedef void (*_oil_type_unzigzag8x8_s16)(int16_t * d_8x8, int ds, const int16_t * s_8x8, int ss); #define oil_unzigzag8x8_s16 ((_oil_type_unzigzag8x8_s16)(*(void **)oil_function_class_ptr_unzigzag8x8_s16)) +extern OilFunctionClass *oil_function_class_ptr_utf8_validate; +typedef void (*_oil_type_utf8_validate)(int32_t * d_1, const uint8_t * s, int n); +#define oil_utf8_validate ((_oil_type_utf8_validate)(*(void **)oil_function_class_ptr_utf8_validate)) extern OilFunctionClass *oil_function_class_ptr_vectoradd_f32; typedef void (*_oil_type_vectoradd_f32)(float * dest, int dstr, const float * src1, int sstr1, const float * src2, int sstr2, int n, const float * s3_1, const float * s4_1); #define oil_vectoradd_f32 ((_oil_type_vectoradd_f32)(*(void **)oil_function_class_ptr_vectoradd_f32)) diff --git a/liboil/liboilfunction.c b/liboil/liboilfunction.c index 9181816..58cb8cf 100644 --- a/liboil/liboilfunction.c +++ b/liboil/liboilfunction.c @@ -280,6 +280,8 @@ oil_class_optimize (OilFunctionClass * klass) } klass->chosen_impl = min_impl; klass->func = min_impl->func; + + oil_test_free (test); } static void diff --git a/liboil/utf8/Makefile.am b/liboil/utf8/Makefile.am new file mode 100644 index 0000000..163f592 --- /dev/null +++ b/liboil/utf8/Makefile.am @@ -0,0 +1,33 @@ + +if USE_ALT_OPT +opt_libs = libutf8_opt.la +else +opt_libs = +endif + +noinst_LTLIBRARIES = libutf8.la $(opt_libs) + +noinst_HEADERS = utf8.h + +c_sources = utf8.c + +if HAVE_CPU_I386 +#i386_sources = utf8_i386.c +else +#i386_sources = +endif + +if HAVE_CPU_POWERPC +#powerpc_sources = utf8_powerpc.c +else +#powerpc_sources = +endif + +libutf8_la_SOURCES = \ + $(c_sources) $(i386_sources) $(powerpc_sources) +libutf8_la_LIBADD = $(opt_libs) +libutf8_la_CFLAGS = $(LIBOIL_CFLAGS) + +libutf8_opt_la_SOURCES = $(c_sources) +libutf8_opt_la_CFLAGS = $(LIBOIL_CFLAGS) $(LIBOIL_OPT_CFLAGS) + diff --git a/liboil/utf8/utf8.c b/liboil/utf8/utf8.c new file mode 100644 index 0000000..885d9e4 --- /dev/null +++ b/liboil/utf8/utf8.c @@ -0,0 +1,89 @@ +/* + * LIBOIL - Library of Optimized Inner Loops + * Copyright (c) 2004 David A. Schleef <ds@schleef.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <liboil/liboil.h> +#include <liboil/liboiltest.h> +#include <liboil/liboilrandom.h> +#include "utf8.h" + + +static void +utf8_validate_test (OilTest *test) +{ + int i; + int n = test->n; + uint8_t *ptr = (uint8_t *)test->params[OIL_ARG_SRC1].src_data + + OIL_TEST_HEADER; + + for (i=0;i<n;i++){ + OIL_GET(ptr, i, uint8_t) = oil_rand_u8() & 0x7f; + } + +} + +OIL_DEFINE_CLASS_FULL (utf8_validate, "int32_t *d_1, uint8_t *s, int n", + utf8_validate_test); + + +static void +utf8_validate_ref (int32_t *d_1, uint8_t *s, int n) +{ + int i; + int extra_bytes; + int mask; + + for(i=0;i<n;i++){ + if (s[i] < 128) continue; + if ((s[i] & 0xe0) == 0xc0) { + extra_bytes = 1; + mask = 0x7f; + } else if ((s[i] & 0xf0) == 0xe0) { + extra_bytes = 2; + mask = 0x1f; + } else if ((s[i] & 0xf8) == 0xf0) { + extra_bytes = 3; + mask = 0x0f; + } else { + goto error; + } + if (i + extra_bytes >= n) goto error; + while(extra_bytes--) { + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + } + } + +error: + d_1[0] = i; +} + +OIL_DEFINE_IMPL_REF (utf8_validate_ref, utf8_validate); + diff --git a/liboil/utf8/utf8.h b/liboil/utf8/utf8.h new file mode 100644 index 0000000..2145461 --- /dev/null +++ b/liboil/utf8/utf8.h @@ -0,0 +1,36 @@ +/* + * LIBOIL - Library of Optimized Inner Loops + * Copyright (c) 2004 David A. Schleef <ds@schleef.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LIBOIL_MD5_H_ +#define _LIBOIL_MD5_H_ + +#include <liboil/liboilfunction.h> + +OIL_DECLARE_CLASS(utf8_validate); + +#endif + diff --git a/testsuite/dso_check.c b/testsuite/dso_check.c index abb3163..adcaa99 100644 --- a/testsuite/dso_check.c +++ b/testsuite/dso_check.c @@ -42,7 +42,7 @@ int main (int argc, char *argv[]) oil_init (); - printf("null is at %p\n", &oil_function_class_null); + printf("null is at %p\n", &oil_function_class_ptr_null); oil_null (); n = oil_class_get_n_classes (); |