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