os/ossrv/genericopenlibs/liboil/src/sad8x8_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 
    27 #ifdef HAVE_CONFIG_H
    28 #include "config.h"
    29 #endif
    30 #include <liboil/liboilclasses.h>
    31 #include <liboil/liboilfunction.h>
    32 #include <emmintrin.h>
    33 
    34 #define SSE_FUNCTION __attribute__((force_align_arg_pointer))
    35 
    36 #ifdef ENABLE_BROKEN_IMPLS
    37 union m128_int {
    38   __m128i m128;
    39   uint32_t i[4];
    40   uint16_t s[8];
    41 };
    42 
    43 SSE_FUNCTION static void
    44 sad8x8_u8_sse (uint32_t *dest, uint8_t *src1, int sstr1, uint8_t *src2,
    45     int sstr2)
    46 {
    47   int i;
    48   __m128i sum = _mm_setzero_si128();
    49   union m128_int sumi;
    50 
    51   for (i = 0; i < 4; i++) {
    52     __m128i xmm0, xmm1, xmm2, xmm3;
    53     xmm0 = _mm_loadl_epi64((__m128i *)src1);
    54     xmm1 = _mm_loadl_epi64((__m128i *)(src1 + sstr1));
    55     xmm2 = _mm_loadl_epi64((__m128i *)src2);
    56     xmm3 = _mm_loadl_epi64((__m128i *)(src2 + sstr2));
    57     xmm0 = _mm_unpacklo_epi8(xmm0, xmm1);
    58     xmm2 = _mm_unpacklo_epi8(xmm2, xmm3);
    59     sum = _mm_add_epi64(sum, _mm_sad_epu8(xmm0, xmm2));
    60     src1 += 2 * sstr1;
    61     src2 += 2 * sstr2;
    62   }
    63   sumi.m128 = sum;
    64   *dest = sumi.i[0] + sumi.i[2];
    65 }
    66 OIL_DEFINE_IMPL_FULL_WRAPPER(sad8x8_u8_sse, sad8x8_u8, OIL_IMPL_FLAG_SSE2);
    67 #endif
    68