os/ossrv/genericopenlibs/liboil/src/i386/sad8x8avg_i386.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 
    35 OIL_DECLARE_CLASS (sad8x8_u8_avg);
    36 
    37 static void
    38 sad8x8_u8_avg_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
    39 {
    40 #if !defined(__WINSCW__) && !defined(__WINS__)       
    41 uint32_t diff;
    42 
    43   __asm__ __volatile__ (
    44     "  pcmpeqd     %%mm5, %%mm5     \n\t"	/* fefefefefefefefe in mm5 */
    45     "  paddb       %%mm5, %%mm5     \n\t"
    46    
    47     "  pxor        %%mm6, %%mm6     \n\t"	/* zero out mm6 for unpack */
    48     "  pxor        %%mm7, %%mm7     \n\t" 	/* mm7 contains the result */
    49     "  mov         $8, %%edi        \n\t"	/* 8 rows */
    50     "1:                             \n\t"
    51     "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
    52 
    53     "  movq        (%2), %%mm2      \n\t"
    54     "  movq        (%3), %%mm3      \n\t"	/* take average of mm2 and mm3 */
    55     "  movq        %%mm2, %%mm1     \n\t"
    56     "  pand        %%mm3, %%mm1     \n\t"
    57     "  pxor        %%mm2, %%mm3     \n\t"
    58     "  pand        %%mm5, %%mm3     \n\t"
    59     "  psrlq       $1, %%mm3        \n\t"
    60     "  paddb       %%mm3, %%mm1     \n\t"
    61 
    62     "  movq        %%mm0, %%mm2     \n\t"
    63 
    64     "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
    65     "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
    66     "  por         %%mm1, %%mm0     \n\t"    	/* and or gives abs difference */
    67     "  movq        %%mm0, %%mm1     \n\t"
    68 
    69     "  punpcklbw   %%mm6, %%mm0     \n\t"	/* unpack to higher precision for accumulation */
    70     "  paddw       %%mm0, %%mm7     \n\t"	/* accumulate difference... */
    71     "  punpckhbw   %%mm6, %%mm1     \n\t"	/* unpack high four bytes to higher precision */
    72     "  add         %4, %1           \n\t"	/* Inc pointer into the new data */
    73     "  paddw       %%mm1, %%mm7     \n\t"	/* accumulate difference... */
    74     "  add         %5, %2           \n\t"	/* Inc pointer into ref data */
    75     "  add         %5, %3           \n\t"	/* Inc pointer into ref data */
    76 
    77     "  dec         %%edi            \n\t"
    78     "  jnz 1b                       \n\t"
    79 
    80     "  movq        %%mm7, %%mm0     \n\t"
    81     "  psrlq       $32, %%mm7       \n\t"
    82     "  paddw       %%mm0, %%mm7     \n\t"
    83     "  movq        %%mm7, %%mm0     \n\t"
    84     "  psrlq       $16, %%mm7       \n\t"
    85     "  paddw       %%mm0, %%mm7     \n\t"
    86     "  movd        %%mm7, %0        \n\t"
    87     "  andl        $0xffff, %0      \n\t"
    88     "  emms                         \n\t"
    89 
    90      : "=m" (diff),
    91        "+r" (src1), 
    92        "+r" (src2), 
    93        "+r" (src3) 
    94      : "m" (ss1),
    95        "m" (ss2)
    96      : "edi", "memory"
    97   );
    98   *dest = diff;
    99 #endif  
   100 }
   101 
   102 OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmx, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX);
   103 
   104 static void
   105 sad8x8_u8_avg_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
   106 {
   107 #if !defined(__WINSCW__) && !defined(__WINS__)      
   108   uint32_t  diff;
   109 
   110   __asm__ __volatile__ (
   111     "  pxor %%mm7, %%mm7            \n\t" 	/* mm7 contains the result */
   112     "  mov $0x01010101, %%eax       \n\t"
   113     "  movd %%eax, %%mm6            \n\t"
   114     "  punpcklbw %%mm6, %%mm6       \n\t"
   115     "  mov $8, %%eax                \n\t"
   116     "1:                             \n\t"
   117     "  movq (%1), %%mm0             \n\t"	/* take 8 bytes */
   118     "  movq (%2), %%mm1             \n\t"
   119     "  movq (%3), %%mm2             \n\t"
   120     "  movq %%mm1, %%mm3            \n\t"
   121     "  pavgb %%mm2, %%mm1           \n\t"
   122     "  pxor %%mm2, %%mm3            \n\t"
   123     "  pand %%mm6, %%mm3            \n\t"
   124     "  psubb %%mm3, %%mm1           \n\t"
   125     "  psadbw %%mm1, %%mm0          \n\t"
   126 
   127     "  add %4, %1                   \n\t"	/* Inc pointer into the new data */
   128     "  paddw %%mm0, %%mm7           \n\t"	/* accumulate difference... */
   129     "  add %5, %2                   \n\t"	/* Inc pointer into ref data */
   130     "  add %5, %3                   \n\t"	/* Inc pointer into ref data */
   131     "  decl %%eax                   \n\t"
   132     "  jnz 1b                       \n\t"
   133 
   134     "  movd %%mm7, %0               \n\t"
   135     "  emms                         \n\t"
   136      : "=m" (diff),
   137        "+r" (src1), 
   138        "+r" (src2), 
   139        "+r" (src3) 
   140      : "m" (ss1),
   141        "m" (ss2)
   142      : "eax", "memory"
   143   );
   144   *dest = diff;
   145 #endif
   146 }
   147 OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmxext, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT);
   148 
   149 
   150 #ifdef	__SYMBIAN32__
   151  
   152 OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg() {
   153 		return &_oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg;
   154 }
   155 #endif
   156 
   157 #ifdef	__SYMBIAN32__
   158  
   159 OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg() {
   160 		return &_oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg;
   161 }
   162 #endif
   163