os/ossrv/genericopenlibs/liboil/src/i386/sad8x8avg_i386.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/i386/sad8x8avg_i386.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 + * POSSIBILITY OF SUCH DAMAGE.
    1.29 + */
    1.30 +//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    1.31 +
    1.32 +#ifdef HAVE_CONFIG_H
    1.33 +#include "config.h"
    1.34 +#endif
    1.35 +
    1.36 +#include <liboil/liboilfunction.h>
    1.37 +
    1.38 +OIL_DECLARE_CLASS (sad8x8_u8_avg);
    1.39 +
    1.40 +static void
    1.41 +sad8x8_u8_avg_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
    1.42 +{
    1.43 +#if !defined(__WINSCW__) && !defined(__WINS__)       
    1.44 +uint32_t diff;
    1.45 +
    1.46 +  __asm__ __volatile__ (
    1.47 +    "  pcmpeqd     %%mm5, %%mm5     \n\t"	/* fefefefefefefefe in mm5 */
    1.48 +    "  paddb       %%mm5, %%mm5     \n\t"
    1.49 +   
    1.50 +    "  pxor        %%mm6, %%mm6     \n\t"	/* zero out mm6 for unpack */
    1.51 +    "  pxor        %%mm7, %%mm7     \n\t" 	/* mm7 contains the result */
    1.52 +    "  mov         $8, %%edi        \n\t"	/* 8 rows */
    1.53 +    "1:                             \n\t"
    1.54 +    "  movq        (%1), %%mm0      \n\t"	/* take 8 bytes */
    1.55 +
    1.56 +    "  movq        (%2), %%mm2      \n\t"
    1.57 +    "  movq        (%3), %%mm3      \n\t"	/* take average of mm2 and mm3 */
    1.58 +    "  movq        %%mm2, %%mm1     \n\t"
    1.59 +    "  pand        %%mm3, %%mm1     \n\t"
    1.60 +    "  pxor        %%mm2, %%mm3     \n\t"
    1.61 +    "  pand        %%mm5, %%mm3     \n\t"
    1.62 +    "  psrlq       $1, %%mm3        \n\t"
    1.63 +    "  paddb       %%mm3, %%mm1     \n\t"
    1.64 +
    1.65 +    "  movq        %%mm0, %%mm2     \n\t"
    1.66 +
    1.67 +    "  psubusb     %%mm1, %%mm0     \n\t" 	/* A - B */
    1.68 +    "  psubusb     %%mm2, %%mm1     \n\t"	/* B - A */
    1.69 +    "  por         %%mm1, %%mm0     \n\t"    	/* and or gives abs difference */
    1.70 +    "  movq        %%mm0, %%mm1     \n\t"
    1.71 +
    1.72 +    "  punpcklbw   %%mm6, %%mm0     \n\t"	/* unpack to higher precision for accumulation */
    1.73 +    "  paddw       %%mm0, %%mm7     \n\t"	/* accumulate difference... */
    1.74 +    "  punpckhbw   %%mm6, %%mm1     \n\t"	/* unpack high four bytes to higher precision */
    1.75 +    "  add         %4, %1           \n\t"	/* Inc pointer into the new data */
    1.76 +    "  paddw       %%mm1, %%mm7     \n\t"	/* accumulate difference... */
    1.77 +    "  add         %5, %2           \n\t"	/* Inc pointer into ref data */
    1.78 +    "  add         %5, %3           \n\t"	/* Inc pointer into ref data */
    1.79 +
    1.80 +    "  dec         %%edi            \n\t"
    1.81 +    "  jnz 1b                       \n\t"
    1.82 +
    1.83 +    "  movq        %%mm7, %%mm0     \n\t"
    1.84 +    "  psrlq       $32, %%mm7       \n\t"
    1.85 +    "  paddw       %%mm0, %%mm7     \n\t"
    1.86 +    "  movq        %%mm7, %%mm0     \n\t"
    1.87 +    "  psrlq       $16, %%mm7       \n\t"
    1.88 +    "  paddw       %%mm0, %%mm7     \n\t"
    1.89 +    "  movd        %%mm7, %0        \n\t"
    1.90 +    "  andl        $0xffff, %0      \n\t"
    1.91 +    "  emms                         \n\t"
    1.92 +
    1.93 +     : "=m" (diff),
    1.94 +       "+r" (src1), 
    1.95 +       "+r" (src2), 
    1.96 +       "+r" (src3) 
    1.97 +     : "m" (ss1),
    1.98 +       "m" (ss2)
    1.99 +     : "edi", "memory"
   1.100 +  );
   1.101 +  *dest = diff;
   1.102 +#endif  
   1.103 +}
   1.104 +
   1.105 +OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmx, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX);
   1.106 +
   1.107 +static void
   1.108 +sad8x8_u8_avg_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
   1.109 +{
   1.110 +#if !defined(__WINSCW__) && !defined(__WINS__)      
   1.111 +  uint32_t  diff;
   1.112 +
   1.113 +  __asm__ __volatile__ (
   1.114 +    "  pxor %%mm7, %%mm7            \n\t" 	/* mm7 contains the result */
   1.115 +    "  mov $0x01010101, %%eax       \n\t"
   1.116 +    "  movd %%eax, %%mm6            \n\t"
   1.117 +    "  punpcklbw %%mm6, %%mm6       \n\t"
   1.118 +    "  mov $8, %%eax                \n\t"
   1.119 +    "1:                             \n\t"
   1.120 +    "  movq (%1), %%mm0             \n\t"	/* take 8 bytes */
   1.121 +    "  movq (%2), %%mm1             \n\t"
   1.122 +    "  movq (%3), %%mm2             \n\t"
   1.123 +    "  movq %%mm1, %%mm3            \n\t"
   1.124 +    "  pavgb %%mm2, %%mm1           \n\t"
   1.125 +    "  pxor %%mm2, %%mm3            \n\t"
   1.126 +    "  pand %%mm6, %%mm3            \n\t"
   1.127 +    "  psubb %%mm3, %%mm1           \n\t"
   1.128 +    "  psadbw %%mm1, %%mm0          \n\t"
   1.129 +
   1.130 +    "  add %4, %1                   \n\t"	/* Inc pointer into the new data */
   1.131 +    "  paddw %%mm0, %%mm7           \n\t"	/* accumulate difference... */
   1.132 +    "  add %5, %2                   \n\t"	/* Inc pointer into ref data */
   1.133 +    "  add %5, %3                   \n\t"	/* Inc pointer into ref data */
   1.134 +    "  decl %%eax                   \n\t"
   1.135 +    "  jnz 1b                       \n\t"
   1.136 +
   1.137 +    "  movd %%mm7, %0               \n\t"
   1.138 +    "  emms                         \n\t"
   1.139 +     : "=m" (diff),
   1.140 +       "+r" (src1), 
   1.141 +       "+r" (src2), 
   1.142 +       "+r" (src3) 
   1.143 +     : "m" (ss1),
   1.144 +       "m" (ss2)
   1.145 +     : "eax", "memory"
   1.146 +  );
   1.147 +  *dest = diff;
   1.148 +#endif
   1.149 +}
   1.150 +OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmxext, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT);
   1.151 +
   1.152 +
   1.153 +#ifdef	__SYMBIAN32__
   1.154 + 
   1.155 +OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg() {
   1.156 +		return &_oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg;
   1.157 +}
   1.158 +#endif
   1.159 +
   1.160 +#ifdef	__SYMBIAN32__
   1.161 + 
   1.162 +OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg() {
   1.163 +		return &_oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg;
   1.164 +}
   1.165 +#endif
   1.166 +