diff options
author | David Schleef <ds@schleef.org> | 2005-07-30 23:43:39 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2005-07-30 23:43:39 +0000 |
commit | 70d44fea4410f36e761450088c805757bb0e68f8 (patch) | |
tree | f4a554d61cec7d7e63af9861bbd25ed464ebf6e7 | |
parent | 9c444198c70e154f194c7a95cd3ccdf2620c4d3f (diff) | |
download | liboil-70d44fea4410f36e761450088c805757bb0e68f8.tar.gz |
* examples/report.c: (oil_print_class): Fix printing
* liboil/colorspace/Makefile.am:
* liboil/colorspace/composite.c: use colorspace header
* liboil/colorspace/composite_i386.c: new
* liboil/liboil.h: remove prefetch, it was a bad idea
* liboil/liboilcolorspace.h: new header
* liboil/liboilcpu.c: (oil_cpu_get_ticks_per_second):
* liboil/liboilcpu.h:
* liboil/liboiltest.c: (oil_test_init), (oil_test_check_function):
add oil_test_init() and reshuffle code
* liboil/liboiltest.h: ditto
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | examples/report.c | 2 | ||||
-rw-r--r-- | liboil/colorspace/Makefile.am | 3 | ||||
-rw-r--r-- | liboil/colorspace/composite.c | 268 | ||||
-rw-r--r-- | liboil/colorspace/composite_i386.c | 314 | ||||
-rw-r--r-- | liboil/liboil.h | 3 | ||||
-rw-r--r-- | liboil/liboilcolorspace.h | 63 | ||||
-rw-r--r-- | liboil/liboilcpu.c | 9 | ||||
-rw-r--r-- | liboil/liboilcpu.h | 2 | ||||
-rw-r--r-- | liboil/liboiltest.c | 33 | ||||
-rw-r--r-- | liboil/liboiltest.h | 4 |
11 files changed, 592 insertions, 123 deletions
@@ -1,3 +1,17 @@ +2005-07-30 David Schleef <ds@schleef.org> + + * examples/report.c: (oil_print_class): Fix printing + * liboil/colorspace/Makefile.am: + * liboil/colorspace/composite.c: use colorspace header + * liboil/colorspace/composite_i386.c: new + * liboil/liboil.h: remove prefetch, it was a bad idea + * liboil/liboilcolorspace.h: new header + * liboil/liboilcpu.c: (oil_cpu_get_ticks_per_second): + * liboil/liboilcpu.h: + * liboil/liboiltest.c: (oil_test_init), (oil_test_check_function): + add oil_test_init() and reshuffle code + * liboil/liboiltest.h: ditto + 2005-07-26 David Schleef <ds@schleef.org> * configure.ac: oops, compile fix diff --git a/examples/report.c b/examples/report.c index a9fe8bd..d6b3b07 100644 --- a/examples/report.c +++ b/examples/report.c @@ -162,7 +162,7 @@ oil_print_class (OilFunctionClass *klass, int verbose) n_impls = get_n_impls(klass); - printf ("%-20s,%d,%-10g,%-10g,%-10.3g,%s,%s\n", klass->name, + printf ("%-20s %d %-10g %-10g %-10.3g %s %s\n", klass->name, n_impls, klass->reference_impl->profile_ave, klass->chosen_impl->profile_ave, diff --git a/liboil/colorspace/Makefile.am b/liboil/colorspace/Makefile.am index 3dbf64f..2804da5 100644 --- a/liboil/colorspace/Makefile.am +++ b/liboil/colorspace/Makefile.am @@ -27,7 +27,8 @@ endif if HAVE_CPU_I386 i386_sources = \ ayuv2argb_i386.c \ - argb_paint_i386.c + argb_paint_i386.c \ + composite_i386.c else i386_sources = endif diff --git a/liboil/colorspace/composite.c b/liboil/colorspace/composite.c index 6cb2ef5..36fb354 100644 --- a/liboil/colorspace/composite.c +++ b/liboil/colorspace/composite.c @@ -31,43 +31,85 @@ #include <liboil/liboil.h> #include <liboil/liboilfunction.h> +#include <liboil/liboilcolorspace.h> +#include <liboil/liboiltest.h> +#include <liboil/liboildebug.h> -#define CLAMP_0(x) (((x)<0)?0:(x)) -#define CLAMP_255(x) (((x)>255)?255:(x)) -#define CLAMP(x) CLAMP_255(CLAMP_0(x)) +#define COMPOSITE_OVER(d,s,m) ((d) + (s) - oil_muldiv_255((d),(m))) +#define COMPOSITE_ADD(d,s) ((d) + (s)) +#define COMPOSITE_IN(s,m) oil_muldiv_255((s),(m)) + +static void +composite_test (OilTest *test) +{ + int i; + int n; + uint32_t *ptr; + int a; + OilParameter *p; + + p = &test->params[OIL_ARG_SRC1]; + if (p->src_data && p->type == OIL_TYPE_u32p) { + ptr = (uint32_t *)(p->src_data + OIL_TEST_HEADER); + n = p->post_n; + for(i=0;i<n;i++){ + a = oil_rand_u8(); + ptr[i] = oil_rand_rgba(a); + } + } -#define ARGB(a,r,g,b) ((CLAMP(a)<<24) | (CLAMP(r)<<16) | (CLAMP(g)<<8) | (CLAMP(b)<<0)) -#define ARGB_A(color) (((color)>>24)&0xff) -#define ARGB_R(color) (((color)>>16)&0xff) -#define ARGB_G(color) (((color)>>8)&0xff) -#define ARGB_B(color) (((color)>>0)&0xff) + p = &test->params[OIL_ARG_SRC2]; + if (p->src_data && p->type == OIL_TYPE_u32p) { + ptr = (uint32_t *)(p->src_data + OIL_TEST_HEADER); + n = p->post_n; + for(i=0;i<n;i++){ + a = oil_rand_u8(); + ptr[i] = oil_rand_rgba(a); + } + } -#define div255(x) (((x) + ((x)>>8))>>8) + p = &test->params[OIL_ARG_INPLACE1]; + if (p->src_data && p->type == OIL_TYPE_u32p) { + ptr = (uint32_t *)(p->src_data + OIL_TEST_HEADER); + n = p->post_n; + for(i=0;i<n;i++){ + a = oil_rand_u8(); + ptr[i] = oil_rand_rgba(a); + } + } -#define COMPOSITE_OVER(d,s,m) ((d) + (s) - div255((d)*(m))) -#define COMPOSITE_ADD(d,s) ((d) + (s)) -#define COMPOSITE_IN(s,m) (div255((s)*(m))) - -OIL_DEFINE_CLASS (composite_in_argb, - "uint32_t *d_n, uint32_t *s1_n, uint8_t *s2_n, int n"); -OIL_DEFINE_CLASS (composite_in_argb_const_src, - "uint32_t *d_n, uint32_t *s1_1, uint8_t *s2_n, int n"); -OIL_DEFINE_CLASS (composite_in_argb_const_mask, - "uint32_t *d_n, uint32_t *s1_n, uint8_t *s2_1, int n"); -OIL_DEFINE_CLASS (composite_over_argb, - "uint32_t *i_n, uint32_t *s1_n, int n"); -OIL_DEFINE_CLASS (composite_over_argb_const_src, - "uint32_t *i_n, uint32_t *s1_1, int n"); -OIL_DEFINE_CLASS (composite_add_argb, - "uint32_t *i_n, uint32_t *s1_n, int n"); -OIL_DEFINE_CLASS (composite_add_argb_const_src, - "uint32_t *i_n, uint32_t *s1_1, int n"); -OIL_DEFINE_CLASS (composite_in_over_argb, - "uint32_t *i_n, uint32_t *s1_n, uint8_t *s2_n, int n"); -OIL_DEFINE_CLASS (composite_in_over_argb_const_src, - "uint32_t *i_n, uint32_t *s1_1, uint8_t *s2_n, int n"); -OIL_DEFINE_CLASS (composite_in_over_argb_const_mask, - "uint32_t *i_n, uint32_t *s1_n, uint8_t *s2_1, int n"); +} + +OIL_DEFINE_CLASS_FULL (composite_in_argb, + "uint32_t *d_n, uint32_t *s1_n, uint8_t *s2_n, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_in_argb_const_src, + "uint32_t *d_n, uint32_t *s1_1, uint8_t *s2_n, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_in_argb_const_mask, + "uint32_t *d_n, uint32_t *s1_n, uint8_t *s2_1, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_over_argb, + "uint32_t *i_n, uint32_t *s1_n, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_over_argb_const_src, + "uint32_t *i_n, uint32_t *s1_1, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_add_argb, + "uint32_t *i_n, uint32_t *s1_n, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_add_argb_const_src, + "uint32_t *i_n, uint32_t *s1_1, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_in_over_argb, + "uint32_t *i_n, uint32_t *s1_n, uint8_t *s2_n, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_in_over_argb_const_src, + "uint32_t *i_n, uint32_t *s1_1, uint8_t *s2_n, int n", + composite_test); +OIL_DEFINE_CLASS_FULL (composite_in_over_argb_const_mask, + "uint32_t *i_n, uint32_t *s1_n, uint8_t *s2_1, int n", + composite_test); static void composite_in_argb_ref (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) @@ -75,11 +117,11 @@ composite_in_argb_ref (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) int i; for(i=0;i<n;i++){ - dest[i] = ARGB( - COMPOSITE_IN(ARGB_A(src[i]), mask[i]), - COMPOSITE_IN(ARGB_R(src[i]), mask[i]), - COMPOSITE_IN(ARGB_G(src[i]), mask[i]), - COMPOSITE_IN(ARGB_B(src[i]), mask[i])); + dest[i] = oil_argb( + COMPOSITE_IN(oil_argb_A(src[i]), mask[i]), + COMPOSITE_IN(oil_argb_R(src[i]), mask[i]), + COMPOSITE_IN(oil_argb_G(src[i]), mask[i]), + COMPOSITE_IN(oil_argb_B(src[i]), mask[i])); } } OIL_DEFINE_IMPL_REF (composite_in_argb_ref, composite_in_argb); @@ -90,11 +132,11 @@ composite_in_argb_const_src_ref (uint32_t *dest, uint32_t *src, uint8_t *mask, i int i; for(i=0;i<n;i++){ - dest[i] = ARGB( - COMPOSITE_IN(ARGB_A(src[0]), mask[i]), - COMPOSITE_IN(ARGB_R(src[0]), mask[i]), - COMPOSITE_IN(ARGB_G(src[0]), mask[i]), - COMPOSITE_IN(ARGB_B(src[0]), mask[i])); + dest[i] = oil_argb( + COMPOSITE_IN(oil_argb_A(src[0]), mask[i]), + COMPOSITE_IN(oil_argb_R(src[0]), mask[i]), + COMPOSITE_IN(oil_argb_G(src[0]), mask[i]), + COMPOSITE_IN(oil_argb_B(src[0]), mask[i])); } } OIL_DEFINE_IMPL_REF (composite_in_argb_const_src_ref, composite_in_argb_const_src); @@ -105,11 +147,11 @@ composite_in_argb_const_mask_ref (uint32_t *dest, uint32_t *src, uint8_t *mask, int i; for(i=0;i<n;i++){ - dest[i] = ARGB( - COMPOSITE_IN(ARGB_A(src[i]), mask[0]), - COMPOSITE_IN(ARGB_R(src[i]), mask[0]), - COMPOSITE_IN(ARGB_G(src[i]), mask[0]), - COMPOSITE_IN(ARGB_B(src[i]), mask[0])); + dest[i] = oil_argb( + COMPOSITE_IN(oil_argb_A(src[i]), mask[0]), + COMPOSITE_IN(oil_argb_R(src[i]), mask[0]), + COMPOSITE_IN(oil_argb_G(src[i]), mask[0]), + COMPOSITE_IN(oil_argb_B(src[i]), mask[0])); } } OIL_DEFINE_IMPL_REF (composite_in_argb_const_mask_ref, composite_in_argb_const_mask); @@ -121,12 +163,12 @@ composite_over_argb_ref (uint32_t *dest, uint32_t *src, int n) uint8_t a; for(i=0;i<n;i++){ - a = ARGB_A(src[i]); - dest[i] = ARGB( - COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(src[i]),a), - COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(src[i]),a), - COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(src[i]),a), - COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(src[i]),a)); + a = oil_argb_A(src[i]); + dest[i] = oil_argb( + COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(src[i]),a), + COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(src[i]),a), + COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(src[i]),a), + COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(src[i]),a)); } } @@ -138,13 +180,13 @@ composite_over_argb_const_src_ref (uint32_t *dest, uint32_t *src, int n) int i; uint8_t a; - a = ARGB_A(src[0]); + a = oil_argb_A(src[0]); for(i=0;i<n;i++){ - dest[i] = ARGB( - COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(src[0]),a), - COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(src[0]),a), - COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(src[0]),a), - COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(src[0]),a)); + dest[i] = oil_argb( + COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(src[0]),a), + COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(src[0]),a), + COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(src[0]),a), + COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(src[0]),a)); } } @@ -156,11 +198,11 @@ composite_add_argb_ref (uint32_t *dest, uint32_t *src, int n) int i; for(i=0;i<n;i++){ - dest[i] = ARGB( - COMPOSITE_ADD(ARGB_A(dest[i]),ARGB_A(src[i])), - COMPOSITE_ADD(ARGB_R(dest[i]),ARGB_R(src[i])), - COMPOSITE_ADD(ARGB_G(dest[i]),ARGB_G(src[i])), - COMPOSITE_ADD(ARGB_B(dest[i]),ARGB_B(src[i]))); + dest[i] = oil_argb( + COMPOSITE_ADD(oil_argb_A(dest[i]),oil_argb_A(src[i])), + COMPOSITE_ADD(oil_argb_R(dest[i]),oil_argb_R(src[i])), + COMPOSITE_ADD(oil_argb_G(dest[i]),oil_argb_G(src[i])), + COMPOSITE_ADD(oil_argb_B(dest[i]),oil_argb_B(src[i]))); } } @@ -172,11 +214,11 @@ composite_add_argb_const_src_ref (uint32_t *dest, uint32_t *src, int n) int i; for(i=0;i<n;i++){ - dest[i] = ARGB( - COMPOSITE_ADD(ARGB_A(dest[i]),ARGB_A(src[0])), - COMPOSITE_ADD(ARGB_R(dest[i]),ARGB_R(src[0])), - COMPOSITE_ADD(ARGB_G(dest[i]),ARGB_G(src[0])), - COMPOSITE_ADD(ARGB_B(dest[i]),ARGB_B(src[0]))); + dest[i] = oil_argb( + COMPOSITE_ADD(oil_argb_A(dest[i]),oil_argb_A(src[0])), + COMPOSITE_ADD(oil_argb_R(dest[i]),oil_argb_R(src[0])), + COMPOSITE_ADD(oil_argb_G(dest[i]),oil_argb_G(src[0])), + COMPOSITE_ADD(oil_argb_B(dest[i]),oil_argb_B(src[0]))); } } @@ -190,17 +232,17 @@ composite_in_over_argb_ref (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) uint32_t color; for(i=0;i<n;i++){ - color = ARGB( - COMPOSITE_IN(ARGB_A(src[i]), mask[i]), - COMPOSITE_IN(ARGB_R(src[i]), mask[i]), - COMPOSITE_IN(ARGB_G(src[i]), mask[i]), - COMPOSITE_IN(ARGB_B(src[i]), mask[i])); - a = ARGB_A(color); - dest[i] = ARGB( - COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(color),a), - COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(color),a), - COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(color),a), - COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(color),a)); + color = oil_argb( + COMPOSITE_IN(oil_argb_A(src[i]), mask[i]), + COMPOSITE_IN(oil_argb_R(src[i]), mask[i]), + COMPOSITE_IN(oil_argb_G(src[i]), mask[i]), + COMPOSITE_IN(oil_argb_B(src[i]), mask[i])); + a = oil_argb_A(color); + dest[i] = oil_argb( + COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(color),a), + COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(color),a), + COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(color),a), + COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(color),a)); } } @@ -214,17 +256,17 @@ composite_in_over_argb_const_src_ref (uint32_t *dest, uint32_t *src, uint8_t *ma uint32_t color; for(i=0;i<n;i++){ - color = ARGB( - COMPOSITE_IN(ARGB_A(src[0]), mask[i]), - COMPOSITE_IN(ARGB_R(src[0]), mask[i]), - COMPOSITE_IN(ARGB_G(src[0]), mask[i]), - COMPOSITE_IN(ARGB_B(src[0]), mask[i])); - a = ARGB_A(color); - dest[i] = ARGB( - COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(color),a), - COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(color),a), - COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(color),a), - COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(color),a)); + color = oil_argb( + COMPOSITE_IN(oil_argb_A(src[0]), mask[i]), + COMPOSITE_IN(oil_argb_R(src[0]), mask[i]), + COMPOSITE_IN(oil_argb_G(src[0]), mask[i]), + COMPOSITE_IN(oil_argb_B(src[0]), mask[i])); + a = oil_argb_A(color); + dest[i] = oil_argb( + COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(color),a), + COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(color),a), + COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(color),a), + COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(color),a)); } } @@ -238,19 +280,39 @@ composite_in_over_argb_const_mask_ref (uint32_t *dest, uint32_t *src, uint8_t *m uint32_t color; for(i=0;i<n;i++){ - color = ARGB( - COMPOSITE_IN(ARGB_A(src[i]), mask[0]), - COMPOSITE_IN(ARGB_R(src[i]), mask[0]), - COMPOSITE_IN(ARGB_G(src[i]), mask[0]), - COMPOSITE_IN(ARGB_B(src[i]), mask[0])); - a = ARGB_A(color); - dest[i] = ARGB( - COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(color),a), - COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(color),a), - COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(color),a), - COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(color),a)); + color = oil_argb( + COMPOSITE_IN(oil_argb_A(src[i]), mask[0]), + COMPOSITE_IN(oil_argb_R(src[i]), mask[0]), + COMPOSITE_IN(oil_argb_G(src[i]), mask[0]), + COMPOSITE_IN(oil_argb_B(src[i]), mask[0])); + a = oil_argb_A(color); + dest[i] = oil_argb( + COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(color),a), + COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(color),a), + COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(color),a), + COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(color),a)); } } OIL_DEFINE_IMPL_REF (composite_in_over_argb_const_mask_ref, composite_in_over_argb_const_mask); + + +static void +composite_over_argb_noclamp (uint32_t *dest, uint32_t *src, int n) +{ + int i; + uint8_t a; + + for(i=0;i<n;i++){ + a = oil_argb_A(src[i]); + dest[i] = oil_argb_noclamp( + COMPOSITE_OVER(oil_argb_A(dest[i]),oil_argb_A(src[i]),a), + COMPOSITE_OVER(oil_argb_R(dest[i]),oil_argb_R(src[i]),a), + COMPOSITE_OVER(oil_argb_G(dest[i]),oil_argb_G(src[i]),a), + COMPOSITE_OVER(oil_argb_B(dest[i]),oil_argb_B(src[i]),a)); + } + +} +OIL_DEFINE_IMPL (composite_over_argb_noclamp, composite_over_argb); + diff --git a/liboil/colorspace/composite_i386.c b/liboil/colorspace/composite_i386.c new file mode 100644 index 0000000..d48375e --- /dev/null +++ b/liboil/colorspace/composite_i386.c @@ -0,0 +1,314 @@ +/* + * LIBOIL - Library of Optimized Inner Loops + * Copyright (c) 2005 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/liboilfunction.h> + +OIL_DECLARE_CLASS (composite_in_argb); +OIL_DECLARE_CLASS (composite_in_argb_const_src); +OIL_DECLARE_CLASS (composite_in_argb_const_mask); +OIL_DECLARE_CLASS (composite_over_argb); +OIL_DECLARE_CLASS (composite_over_argb_const_src); +OIL_DECLARE_CLASS (composite_add_argb); +OIL_DECLARE_CLASS (composite_add_argb_const_src); +OIL_DECLARE_CLASS (composite_in_over_argb); +OIL_DECLARE_CLASS (composite_in_over_argb_const_src); +OIL_DECLARE_CLASS (composite_in_over_argb_const_mask); + +#if 0 +static void +composite_in_argb_mmx (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) +{ + int i; + + for(i=0;i<n;i++){ + dest[i] = ARGB( + COMPOSITE_IN(ARGB_A(src[i]), mask[i]), + COMPOSITE_IN(ARGB_R(src[i]), mask[i]), + COMPOSITE_IN(ARGB_G(src[i]), mask[i]), + COMPOSITE_IN(ARGB_B(src[i]), mask[i])); + } +} +OIL_DEFINE_IMPL_FULL (composite_in_argb_mmx, composite_in_argb); + +static void +composite_in_argb_const_src_mmx (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) +{ + int i; + + for(i=0;i<n;i++){ + dest[i] = ARGB( + COMPOSITE_IN(ARGB_A(src[0]), mask[i]), + COMPOSITE_IN(ARGB_R(src[0]), mask[i]), + COMPOSITE_IN(ARGB_G(src[0]), mask[i]), + COMPOSITE_IN(ARGB_B(src[0]), mask[i])); + } +} +OIL_DEFINE_IMPL_FULL (composite_in_argb_const_src_mmx, composite_in_argb_const_src); + +static void +composite_in_argb_const_mask_mmx (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) +{ + int i; + + for(i=0;i<n;i++){ + dest[i] = ARGB( + COMPOSITE_IN(ARGB_A(src[i]), mask[0]), + COMPOSITE_IN(ARGB_R(src[i]), mask[0]), + COMPOSITE_IN(ARGB_G(src[i]), mask[0]), + COMPOSITE_IN(ARGB_B(src[i]), mask[0])); + } +} +OIL_DEFINE_IMPL_FULL (composite_in_argb_const_mask_mmx, composite_in_argb_const_mask); +#endif + +static void +composite_over_argb_mmx (uint32_t *dest, uint32_t *src, int n) +{ + __asm__ __volatile__ (" pxor %%mm7, %%mm7\n" // mm7 = { 0, 0, 0, 0 } + " movl $0x80808080, %%eax\n" + " movd %%eax, %%mm6\n" // mm6 = { 128, 128, 128, 128 } + " punpcklbw %%mm7, %%mm6\n" + " movl $0xffffffff, %%eax\n" // mm5 = { 255, 255, 255, 255 } + " movd %%eax, %%mm5\n" + " punpcklbw %%mm7, %%mm5\n" + "1:\n" + " movl (%1), %%eax\n" + " testl $0xff000000, %%eax\n" + " jz 2f\n" + + " movd %%eax, %%mm1\n" + " punpcklbw %%mm7, %%mm1\n" + " pshufw $0xff, %%mm1, %%mm0\n" + " pxor %%mm5, %%mm0\n" + + " movd (%0), %%mm3\n" + " punpcklbw %%mm7, %%mm3\n" + " pmullw %%mm0, %%mm3\n" + " paddw %%mm6, %%mm3\n" + " movq %%mm3, %%mm2\n" + " psrlw $8, %%mm2\n" + " paddw %%mm2, %%mm3\n" + " psrlw $8, %%mm3\n" + + " paddw %%mm1, %%mm3\n" + " packuswb %%mm3, %%mm3\n" + + " movd %%mm3, %%eax\n" + " movl %%eax, (%0)\n" + "2:\n" + " addl $4, %0\n" + " addl $4, %1\n" + " decl %2\n" + " jnz 1b\n" + " emms\n" + :"+r" (dest), "+r" (src), "+r" (n) + : + :"eax"); + +} +OIL_DEFINE_IMPL_FULL (composite_over_argb_mmx, composite_over_argb, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT); + +static void +composite_over_argb_sse2 (uint32_t *dest, uint32_t *src, int n) +{ + __asm__ __volatile__ (" pxor %%xmm7, %%xmm7\n" // mm7 = { 0, 0, 0, 0 } + " movl $0x80808080, %%eax\n" + " movd %%eax, %%xmm6\n" // mm6 = { 128, 128, 128, 128 } + " punpcklbw %%xmm7, %%xmm6\n" + " movl $0xffffffff, %%eax\n" // mm5 = { 255, 255, 255, 255 } + " movd %%eax, %%xmm5\n" + " punpcklbw %%xmm7, %%xmm5\n" + "1:\n" + " movl (%1), %%eax\n" + " testl $0xff000000, %%eax\n" + " jz 2f\n" + + " movd %%eax, %%xmm1\n" + " punpcklbw %%xmm7, %%xmm1\n" + " pshuflw $0xff, %%xmm1, %%xmm0\n" +#if 1 + " pxor %%xmm5, %%xmm0\n" + + " movd (%0), %%xmm3\n" + " punpcklbw %%xmm7, %%xmm3\n" + " pmullw %%xmm0, %%xmm3\n" + " paddw %%xmm6, %%xmm3\n" + " movq %%xmm3, %%xmm2\n" + " psrlw $8, %%xmm2\n" + " paddw %%xmm2, %%xmm3\n" + " psrlw $8, %%xmm3\n" + + " paddw %%xmm1, %%xmm3\n" + " packuswb %%xmm3, %%xmm3\n" + " movd %%xmm3, %%eax\n" +#else + " packuswb %%xmm1, %%xmm1\n" + " movd %%xmm1, %%eax\n" +#endif + + " movl %%eax, (%0)\n" + "2:\n" + " addl $4, %0\n" + " addl $4, %1\n" + " decl %2\n" + " jnz 1b\n" + :"+r" (dest), "+r" (src), "+r" (n) + : + :"eax"); + +} +OIL_DEFINE_IMPL_FULL (composite_over_argb_sse2, composite_over_argb, OIL_IMPL_FLAG_SSE2); + +#if 0 +static void +composite_over_argb_const_src_mmx (uint32_t *dest, uint32_t *src, int n) +{ + int i; + uint8_t a; + + a = ARGB_A(src[0]); + for(i=0;i<n;i++){ + dest[i] = ARGB( + COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(src[0]),a), + COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(src[0]),a), + COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(src[0]),a), + COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(src[0]),a)); + } + +} +OIL_DEFINE_IMPL_FULL (composite_over_argb_const_src_mmx, composite_over_argb_const_src); + +static void +composite_add_argb_mmx (uint32_t *dest, uint32_t *src, int n) +{ + int i; + + for(i=0;i<n;i++){ + dest[i] = ARGB( + COMPOSITE_ADD(ARGB_A(dest[i]),ARGB_A(src[i])), + COMPOSITE_ADD(ARGB_R(dest[i]),ARGB_R(src[i])), + COMPOSITE_ADD(ARGB_G(dest[i]),ARGB_G(src[i])), + COMPOSITE_ADD(ARGB_B(dest[i]),ARGB_B(src[i]))); + } + +} +OIL_DEFINE_IMPL_FULL (composite_add_argb_mmx, composite_add_argb); + +static void +composite_add_argb_const_src_mmx (uint32_t *dest, uint32_t *src, int n) +{ + int i; + + for(i=0;i<n;i++){ + dest[i] = ARGB( + COMPOSITE_ADD(ARGB_A(dest[i]),ARGB_A(src[0])), + COMPOSITE_ADD(ARGB_R(dest[i]),ARGB_R(src[0])), + COMPOSITE_ADD(ARGB_G(dest[i]),ARGB_G(src[0])), + COMPOSITE_ADD(ARGB_B(dest[i]),ARGB_B(src[0]))); + } + +} +OIL_DEFINE_IMPL_FULL (composite_add_argb_const_src_mmx, composite_add_argb_const_src); + +static void +composite_in_over_argb_mmx (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) +{ + int i; + uint8_t a; + uint32_t color; + + for(i=0;i<n;i++){ + color = ARGB( + COMPOSITE_IN(ARGB_A(src[i]), mask[i]), + COMPOSITE_IN(ARGB_R(src[i]), mask[i]), + COMPOSITE_IN(ARGB_G(src[i]), mask[i]), + COMPOSITE_IN(ARGB_B(src[i]), mask[i])); + a = ARGB_A(color); + dest[i] = ARGB( + COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(color),a), + COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(color),a), + COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(color),a), + COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(color),a)); + } + +} +OIL_DEFINE_IMPL_FULL (composite_in_over_argb_mmx, composite_in_over_argb); + +static void +composite_in_over_argb_const_src_mmx (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) +{ + int i; + uint8_t a; + uint32_t color; + + for(i=0;i<n;i++){ + color = ARGB( + COMPOSITE_IN(ARGB_A(src[0]), mask[i]), + COMPOSITE_IN(ARGB_R(src[0]), mask[i]), + COMPOSITE_IN(ARGB_G(src[0]), mask[i]), + COMPOSITE_IN(ARGB_B(src[0]), mask[i])); + a = ARGB_A(color); + dest[i] = ARGB( + COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(color),a), + COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(color),a), + COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(color),a), + COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(color),a)); + } + +} +OIL_DEFINE_IMPL_FULL (composite_in_over_argb_const_src_mmx, composite_in_over_argb_const_src); + +static void +composite_in_over_argb_const_mask_mmx (uint32_t *dest, uint32_t *src, uint8_t *mask, int n) +{ + int i; + uint8_t a; + uint32_t color; + + for(i=0;i<n;i++){ + color = ARGB( + COMPOSITE_IN(ARGB_A(src[i]), mask[0]), + COMPOSITE_IN(ARGB_R(src[i]), mask[0]), + COMPOSITE_IN(ARGB_G(src[i]), mask[0]), + COMPOSITE_IN(ARGB_B(src[i]), mask[0])); + a = ARGB_A(color); + dest[i] = ARGB( + COMPOSITE_OVER(ARGB_A(dest[i]),ARGB_A(color),a), + COMPOSITE_OVER(ARGB_R(dest[i]),ARGB_R(color),a), + COMPOSITE_OVER(ARGB_G(dest[i]),ARGB_G(color),a), + COMPOSITE_OVER(ARGB_B(dest[i]),ARGB_B(color),a)); + } + +} +OIL_DEFINE_IMPL_FULL (composite_in_over_argb_const_mask_mmx, composite_in_over_argb_const_mask); + +#endif diff --git a/liboil/liboil.h b/liboil/liboil.h index b38a199..c19848a 100644 --- a/liboil/liboil.h +++ b/liboil/liboil.h @@ -34,9 +34,6 @@ void oil_init (void); -void oil_memory_prefetch_transient (void *ptr, int n_bytes); -void oil_memory_prefetch_local (void *ptr, int n_bytes); - #define oil_memcpy(dest,src,n_bytes) \ oil_copy_u8((void *)(dest),(void *)(src),(n_bytes)) diff --git a/liboil/liboilcolorspace.h b/liboil/liboilcolorspace.h new file mode 100644 index 0000000..cb5f297 --- /dev/null +++ b/liboil/liboilcolorspace.h @@ -0,0 +1,63 @@ +/* + * LIBOIL - Library of Optimized Inner Loops + * Copyright (c) 2005 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_COLORSPACE_H_ +#define _LIBOIL_COLORSPACE_H_ + +#include <liboil/liboilrandom.h> + +#define oil_max(x,y) ((x)>(y)?(x):(y)) +#define oil_min(x,y) ((x)<(y)?(x):(y)) + +#define oil_clamp_255(x) oil_max(0,oil_min((x),255)) + +#define oil_argb(a,r,g,b) \ + ((oil_clamp_255(a)<<24) | \ + (oil_clamp_255(r)<<16) | \ + (oil_clamp_255(g)<<8) | \ + (oil_clamp_255(b)<<0)) + +#define oil_argb_noclamp(a,r,g,b) \ + (((a)<<24) | ((r)<<16) | ((g)<<8) | ((b)<<0)) + +#define oil_argb_A(color) (((color)>>24)&0xff) +#define oil_argb_R(color) (((color)>>16)&0xff) +#define oil_argb_G(color) (((color)>>8)&0xff) +#define oil_argb_B(color) (((color)>>0)&0xff) + +#define oil_divide_255(x) ((((x)+128) + (((x)+128)>>8))>>8) +#define oil_muldiv_255(a,b) oil_divide_255((a)*(b)) + +#define oil_rand_rgba(a) \ + oil_argb_noclamp((a), \ + oil_muldiv_255((a),oil_rand_u8()), \ + oil_muldiv_255((a),oil_rand_u8()), \ + oil_muldiv_255((a),oil_rand_u8())) + +#endif + + diff --git a/liboil/liboilcpu.c b/liboil/liboilcpu.c index 14bf8b2..54968c4 100644 --- a/liboil/liboilcpu.c +++ b/liboil/liboilcpu.c @@ -396,6 +396,7 @@ oil_cpu_fault_check_disable (void) } } +#if 0 void oil_memory_prefetch_local (void *ptr, int n_bytes) { #ifdef __i386__ @@ -419,5 +420,13 @@ void oil_memory_prefetch_transient (void *ptr, int n_bytes) #endif } +#endif +#if 0 +double +oil_cpu_get_ticks_per_second (void) +{ + return _oil_ticks_per_second; +} +#endif diff --git a/liboil/liboilcpu.h b/liboil/liboilcpu.h index c15a509..7ff1fb5 100644 --- a/liboil/liboilcpu.h +++ b/liboil/liboilcpu.h @@ -36,5 +36,7 @@ void oil_cpu_fault_check_disable (void); int oil_cpu_fault_check_try (void (*func)(void *), void *priv); +double oil_cpu_get_ticks_per_second (void); + #endif diff --git a/liboil/liboiltest.c b/liboil/liboiltest.c index 82dbb70..c92de82 100644 --- a/liboil/liboiltest.c +++ b/liboil/liboiltest.c @@ -39,6 +39,7 @@ #include <stdio.h> #include <math.h> +static void oil_test_init_params (OilTest *test); 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, @@ -121,6 +122,24 @@ oil_test_set_iterations (OilTest *test, int iterations) test->iterations = iterations; } +void +oil_test_init (OilTest *test) +{ + if (test->inited) { + return; + } + + oil_test_init_params(test); + + test->params[OIL_ARG_N].value = test->n; + + test->inited = 1; + + if (test->klass->test_func) { + test->klass->test_func (test); + } +} + static void oil_test_check_function (void * priv) { @@ -130,17 +149,7 @@ oil_test_check_function (void * priv) unsigned long args[10]; unsigned int pointer_mask; - if (!test->inited) { - oil_test_init_params(test); - - test->params[OIL_ARG_N].value = test->n; - - test->inited = 1; - - if (test->klass->test_func) { - test->klass->test_func (test); - } - } + oil_test_init (test); OIL_LOG("calling function %s", test->impl->name); @@ -404,7 +413,7 @@ init_parameter (OilTest *test, OilParameter *p, OilParameter *ps) } } -void +static void oil_test_init_params (OilTest *test) { init_parameter (test, &test->params[OIL_ARG_DEST1], diff --git a/liboil/liboiltest.h b/liboil/liboiltest.h index 4b28723..2bc1722 100644 --- a/liboil/liboiltest.h +++ b/liboil/liboiltest.h @@ -63,9 +63,7 @@ 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); -void oil_test_init_dest_arrays (OilTest *test); -void oil_test_init_params (OilTest *test); +void oil_test_init (OilTest *test); void _oil_test_marshal_function (void *func, unsigned long *args, int n_args, unsigned int pointer_mask, OilProfile *prof); |