genericopenlibs/liboil/src/simdpack/mix_u8.c
branchRCL_3
changeset 56 acd3cd4aaceb
equal deleted inserted replaced
54:4332f0f7be53 56:acd3cd4aaceb
       
     1 /*
       
     2  * LIBOIL - Library of Optimized Inner Loops
       
     3  * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
       
     4  * All rights reserved.
       
     5  *
       
     6  * Redistribution and use in source and binary forms, with or without
       
     7  * modification, are permitted provided that the following conditions
       
     8  * are met:
       
     9  * 1. Redistributions of source code must retain the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer.
       
    11  * 2. Redistributions in binary form must reproduce the above copyright
       
    12  *    notice, this list of conditions and the following disclaimer in the
       
    13  *    documentation and/or other materials provided with the distribution.
       
    14  * 
       
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
       
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
       
    19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
       
    21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
       
    22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
       
    23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
       
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    25  * POSSIBILITY OF SUCH DAMAGE.
       
    26  */
       
    27 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
       
    28 
       
    29 #ifdef HAVE_CONFIG_H
       
    30 #include "config.h"
       
    31 #endif
       
    32 
       
    33 #include <liboil/liboilfunction.h>
       
    34 #include "liboil/simdpack/simdpack.h"
       
    35 #include <math.h>
       
    36 
       
    37 static void mix_u8_fast(uint8_t *dest, uint8_t *src1, uint8_t *src2, uint8_t *scale, int n)
       
    38 {
       
    39 	while(n>0){
       
    40 		*dest++ = (*src1 * *scale + *src2 * (255 - *scale))>>8;
       
    41 		src1++;
       
    42 		src2++;
       
    43 		scale++;
       
    44 		n--;
       
    45 	}
       
    46 }
       
    47 OIL_DEFINE_IMPL (mix_u8_fast, mix_u8);
       
    48 
       
    49 static void
       
    50 mix_u8_fast2 (uint8_t *dest, uint8_t *src1, uint8_t *src2, uint8_t *scale, int n)
       
    51 {
       
    52 	while(n>0){
       
    53 		*dest++ = ((*src1 - *src2) * *scale + *src2 * 255)>>8;
       
    54 		src1++;
       
    55 		src2++;
       
    56 		scale++;
       
    57 		n--;
       
    58 	}
       
    59 }
       
    60 OIL_DEFINE_IMPL (mix_u8_fast2, mix_u8);
       
    61 
       
    62 /* PowerPC likes this one */
       
    63 static void
       
    64 mix_u8_fast3(uint8_t *dest, uint8_t *src1, uint8_t *src2, uint8_t *scale, int n)
       
    65 {
       
    66 	int i;
       
    67 
       
    68 	for(i=0;i<n;i++){
       
    69 		dest[i] = ((src1[i] - src2[i]) * scale[i] + src2[i] * 255)>>8;
       
    70 	}
       
    71 }
       
    72 OIL_DEFINE_IMPL (mix_u8_fast3, mix_u8);
       
    73 
       
    74 static void
       
    75 mix_u8_unroll4(uint8_t *dest, uint8_t *src1, uint8_t *src2, uint8_t *scale, int n)
       
    76 {
       
    77 	while(n&0x3){
       
    78 		*dest++ = (*src1 * *scale + *src2 * (255 - *scale))>>8;
       
    79 		src1++;
       
    80 		src2++;
       
    81 		scale++;
       
    82 		n--;
       
    83 	}
       
    84 	while(n>0){
       
    85 		*dest++ = (*src1 * *scale + *src2 * (255 - *scale))>>8;
       
    86 		src1++;
       
    87 		src2++;
       
    88 		scale++;
       
    89 		*dest++ = (*src1 * *scale + *src2 * (255 - *scale))>>8;
       
    90 		src1++;
       
    91 		src2++;
       
    92 		scale++;
       
    93 		*dest++ = (*src1 * *scale + *src2 * (255 - *scale))>>8;
       
    94 		src1++;
       
    95 		src2++;
       
    96 		scale++;
       
    97 		*dest++ = (*src1 * *scale + *src2 * (255 - *scale))>>8;
       
    98 		src1++;
       
    99 		src2++;
       
   100 		scale++;
       
   101 		n-=4;
       
   102 	}
       
   103 }
       
   104 OIL_DEFINE_IMPL (mix_u8_unroll4, mix_u8);
       
   105 
       
   106 
       
   107 
       
   108 #ifdef	__SYMBIAN32__
       
   109  
       
   110 OilFunctionImpl* __oil_function_impl_mix_u8_fast() {
       
   111 		return &_oil_function_impl_mix_u8_fast;
       
   112 }
       
   113 #endif
       
   114 
       
   115 #ifdef	__SYMBIAN32__
       
   116  
       
   117 OilFunctionImpl* __oil_function_impl_mix_u8_fast2() {
       
   118 		return &_oil_function_impl_mix_u8_fast2;
       
   119 }
       
   120 #endif
       
   121 
       
   122 #ifdef	__SYMBIAN32__
       
   123  
       
   124 OilFunctionImpl* __oil_function_impl_mix_u8_fast3() {
       
   125 		return &_oil_function_impl_mix_u8_fast3;
       
   126 }
       
   127 #endif
       
   128 
       
   129 #ifdef	__SYMBIAN32__
       
   130  
       
   131 OilFunctionImpl* __oil_function_impl_mix_u8_unroll4() {
       
   132 		return &_oil_function_impl_mix_u8_unroll4;
       
   133 }
       
   134 #endif
       
   135