os/ossrv/genericopenlibs/liboil/src/composite_sse.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * Copyright (c) 2005
     3  *	Eric Anholt.  All rights reserved.
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions
     7  * are met:
     8  * 1. Redistributions of source code must retain the above copyright
     9  *    notice, this list of conditions and the following disclaimer.
    10  * 2. Redistributions in binary form must reproduce the above copyright
    11  *    notice, this list of conditions and the following disclaimer in the
    12  *    documentation and/or other materials provided with the distribution.
    13  *
    14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
    15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
    18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    24  * SUCH DAMAGE.
    25  */
    26 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    27 
    28 #ifdef HAVE_CONFIG_H
    29 #include "config.h"
    30 #endif
    31 #include <liboilclasses.h>
    32 #include <liboilfunction.h>
    33 #include <emmintrin.h>
    34 #include <liboilcolorspace.h>
    35 
    36 #define SSE_FUNCTION __attribute__((force_align_arg_pointer))
    37 
    38 #define COMPOSITE_ADD(d,s) oil_clamp_255((d) + (s))
    39 
    40 SSE_FUNCTION static void
    41 composite_add_argb_sse (uint32_t *dest, const uint32_t *src, int n)
    42 {
    43   /* Initial operations to align the destination pointer */
    44   for (; ((long)dest & 15) && (n > 0); n--) {
    45     uint32_t d = *dest, s = *src++;
    46 
    47     *dest++ = oil_argb(
    48 	COMPOSITE_ADD(oil_argb_A(d), oil_argb_A(s)),
    49 	COMPOSITE_ADD(oil_argb_R(d), oil_argb_R(s)),
    50 	COMPOSITE_ADD(oil_argb_G(d), oil_argb_G(s)),
    51 	COMPOSITE_ADD(oil_argb_B(d), oil_argb_B(s)));
    52   }
    53   for (; n >= 4; n -= 4) {
    54     __m128i s;
    55     s = _mm_loadu_si128((__m128i *)src);
    56     *(__m128i *)dest = _mm_adds_epu8(s, *(__m128i *)dest);
    57     src += 4;
    58     dest += 4;
    59   }
    60   for (; n > 0; n--) {
    61     uint32_t d = *dest, s = *src++;
    62 
    63     *dest++ = oil_argb(
    64 	COMPOSITE_ADD(oil_argb_A(d), oil_argb_A(s)),
    65 	COMPOSITE_ADD(oil_argb_R(d), oil_argb_R(s)),
    66 	COMPOSITE_ADD(oil_argb_G(d), oil_argb_G(s)),
    67 	COMPOSITE_ADD(oil_argb_B(d), oil_argb_B(s)));
    68   }
    69 }
    70 OIL_DEFINE_IMPL_FULL (composite_add_argb_sse, composite_add_argb,
    71     OIL_IMPL_FLAG_SSE2);
    72 
    73 SSE_FUNCTION static void
    74 composite_add_argb_const_src_sse (uint32_t *dest, const uint32_t *src_1, int n)
    75 {
    76   __m128i s;
    77   uint32_t val = *src_1;
    78 
    79   /* Initial operations to align the destination pointer */
    80   for (; ((long)dest & 15) && (n > 0); n--) {
    81     uint32_t d = *dest;
    82 
    83     *dest++ = oil_argb(
    84 	COMPOSITE_ADD(oil_argb_A(d), oil_argb_A(val)),
    85 	COMPOSITE_ADD(oil_argb_R(d), oil_argb_R(val)),
    86 	COMPOSITE_ADD(oil_argb_G(d), oil_argb_G(val)),
    87 	COMPOSITE_ADD(oil_argb_B(d), oil_argb_B(val)));
    88   }
    89   s = _mm_set1_epi32(val);
    90   for (; n >= 4; n -= 4) {
    91     __m128i xmm0;
    92     xmm0 = _mm_adds_epu8(s, *(__m128i *)dest);
    93     _mm_store_si128((__m128i *)dest, xmm0);
    94     dest += 4;
    95   }
    96   for (; n > 0; n--) {
    97     uint32_t d = *dest;
    98 
    99     *dest++ = oil_argb(
   100 	COMPOSITE_ADD(oil_argb_A(d), oil_argb_A(val)),
   101 	COMPOSITE_ADD(oil_argb_R(d), oil_argb_R(val)),
   102 	COMPOSITE_ADD(oil_argb_G(d), oil_argb_G(val)),
   103 	COMPOSITE_ADD(oil_argb_B(d), oil_argb_B(val)));
   104   }
   105 }
   106 OIL_DEFINE_IMPL_FULL (composite_add_argb_const_src_sse,
   107     composite_add_argb_const_src, OIL_IMPL_FLAG_SSE2);
   108 
   109 SSE_FUNCTION static void
   110 composite_add_u8_sse (uint8_t *dest, const uint8_t *src, int n)
   111 {
   112   /* Initial operations to align the destination pointer */
   113   for (; ((long)dest & 15) && (n > 0); n--) {
   114     int x = (int)*dest + *src++;
   115     if (x > 255) 
   116       x = 255;
   117     *dest++ = x;
   118   }
   119   for (; n >= 16; n -= 16) {
   120     __m128i d, s;
   121     s = _mm_loadu_si128((__m128i *)src);
   122     d = _mm_adds_epu8(s, *(__m128i *)dest);
   123     _mm_store_si128((__m128i *)dest, d);
   124     src += 16;
   125     dest += 16;
   126   }
   127   for (; n > 0; n--) {
   128     int x = (int)*dest + *src++;
   129     if (x > 255) 
   130       x = 255;
   131     *dest++ = x;
   132   }
   133 }
   134 OIL_DEFINE_IMPL_FULL (composite_add_u8_sse, composite_add_u8,
   135     OIL_IMPL_FLAG_SSE2);
   136 
   137 SSE_FUNCTION static void
   138 composite_add_u8_const_src_sse (uint8_t *dest, const uint8_t *src_1, int n)
   139 {
   140   __m128i s;
   141   int val = *src_1;
   142 
   143   /* Initial operations to align the destination pointer */
   144   for (; ((long)dest & 15) && (n > 0); n--) {
   145     int x = *dest + val;
   146     if (x > 255) 
   147       x = 255;
   148     *dest++ = x;
   149   }
   150   s = _mm_set1_epi8(val);
   151   for (; n >= 16; n -= 16) {
   152     __m128i d;
   153     d = _mm_adds_epu8(*(__m128i *)dest, s);
   154     _mm_store_si128((__m128i *)dest, d);
   155     dest += 16;
   156   }
   157   for (; n > 0; n--) {
   158     int x = *dest + val;
   159     if (x > 255) 
   160       x = 255;
   161     *dest++ = x;
   162   }
   163 }
   164 OIL_DEFINE_IMPL_FULL (composite_add_u8_const_src_sse,
   165     composite_add_u8_const_src, OIL_IMPL_FLAG_SSE2);
   166 
   167 
   168 #ifdef	__SYMBIAN32__
   169  
   170 OilFunctionImpl* __oil_function_impl_composite_add_argb_sse, composite_add_argb() {
   171 		return &_oil_function_impl_composite_add_argb_sse, composite_add_argb;
   172 }
   173 #endif
   174 
   175 #ifdef	__SYMBIAN32__
   176  
   177 OilFunctionImpl* __oil_function_impl_composite_add_argb_const_src_sse() {
   178 		return &_oil_function_impl_composite_add_argb_const_src_sse;
   179 }
   180 #endif
   181 
   182 #ifdef	__SYMBIAN32__
   183  
   184 OilFunctionImpl* __oil_function_impl_composite_add_u8_sse, composite_add_u8() {
   185 		return &_oil_function_impl_composite_add_u8_sse, composite_add_u8;
   186 }
   187 #endif
   188 
   189 #ifdef	__SYMBIAN32__
   190  
   191 OilFunctionImpl* __oil_function_impl_composite_add_u8_const_src_sse() {
   192 		return &_oil_function_impl_composite_add_u8_const_src_sse;
   193 }
   194 #endif
   195