sl@0: /* sl@0: * LIBOIL - Library of Optimized Inner Loops sl@0: * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org> sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, sl@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES sl@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR sl@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING sl@0: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE sl@0: * POSSIBILITY OF SUCH DAMAGE. sl@0: */ sl@0: //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: #ifdef HAVE_CONFIG_H sl@0: #include "config.h" sl@0: #endif sl@0: sl@0: #include <liboil/liboilfunction.h> sl@0: sl@0: OIL_DECLARE_CLASS (sad8x8_u8_avg); sl@0: sl@0: static void sl@0: sad8x8_u8_avg_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2) sl@0: { sl@0: #if !defined(__WINSCW__) && !defined(__WINS__) sl@0: uint32_t diff; sl@0: sl@0: __asm__ __volatile__ ( sl@0: " pcmpeqd %%mm5, %%mm5 \n\t" /* fefefefefefefefe in mm5 */ sl@0: " paddb %%mm5, %%mm5 \n\t" sl@0: sl@0: " pxor %%mm6, %%mm6 \n\t" /* zero out mm6 for unpack */ sl@0: " pxor %%mm7, %%mm7 \n\t" /* mm7 contains the result */ sl@0: " mov $8, %%edi \n\t" /* 8 rows */ sl@0: "1: \n\t" sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: sl@0: " movq (%2), %%mm2 \n\t" sl@0: " movq (%3), %%mm3 \n\t" /* take average of mm2 and mm3 */ sl@0: " movq %%mm2, %%mm1 \n\t" sl@0: " pand %%mm3, %%mm1 \n\t" sl@0: " pxor %%mm2, %%mm3 \n\t" sl@0: " pand %%mm5, %%mm3 \n\t" sl@0: " psrlq $1, %%mm3 \n\t" sl@0: " paddb %%mm3, %%mm1 \n\t" sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" sl@0: sl@0: " psubusb %%mm1, %%mm0 \n\t" /* A - B */ sl@0: " psubusb %%mm2, %%mm1 \n\t" /* B - A */ sl@0: " por %%mm1, %%mm0 \n\t" /* and or gives abs difference */ sl@0: " movq %%mm0, %%mm1 \n\t" sl@0: sl@0: " punpcklbw %%mm6, %%mm0 \n\t" /* unpack to higher precision for accumulation */ sl@0: " paddw %%mm0, %%mm7 \n\t" /* accumulate difference... */ sl@0: " punpckhbw %%mm6, %%mm1 \n\t" /* unpack high four bytes to higher precision */ sl@0: " add %4, %1 \n\t" /* Inc pointer into the new data */ sl@0: " paddw %%mm1, %%mm7 \n\t" /* accumulate difference... */ sl@0: " add %5, %2 \n\t" /* Inc pointer into ref data */ sl@0: " add %5, %3 \n\t" /* Inc pointer into ref data */ sl@0: sl@0: " dec %%edi \n\t" sl@0: " jnz 1b \n\t" sl@0: sl@0: " movq %%mm7, %%mm0 \n\t" sl@0: " psrlq $32, %%mm7 \n\t" sl@0: " paddw %%mm0, %%mm7 \n\t" sl@0: " movq %%mm7, %%mm0 \n\t" sl@0: " psrlq $16, %%mm7 \n\t" sl@0: " paddw %%mm0, %%mm7 \n\t" sl@0: " movd %%mm7, %0 \n\t" sl@0: " andl $0xffff, %0 \n\t" sl@0: " emms \n\t" sl@0: sl@0: : "=m" (diff), sl@0: "+r" (src1), sl@0: "+r" (src2), sl@0: "+r" (src3) sl@0: : "m" (ss1), sl@0: "m" (ss2) sl@0: : "edi", "memory" sl@0: ); sl@0: *dest = diff; sl@0: #endif sl@0: } sl@0: sl@0: OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmx, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX); sl@0: sl@0: static void sl@0: sad8x8_u8_avg_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2) sl@0: { sl@0: #if !defined(__WINSCW__) && !defined(__WINS__) sl@0: uint32_t diff; sl@0: sl@0: __asm__ __volatile__ ( sl@0: " pxor %%mm7, %%mm7 \n\t" /* mm7 contains the result */ sl@0: " mov $0x01010101, %%eax \n\t" sl@0: " movd %%eax, %%mm6 \n\t" sl@0: " punpcklbw %%mm6, %%mm6 \n\t" sl@0: " mov $8, %%eax \n\t" sl@0: "1: \n\t" sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: " movq (%2), %%mm1 \n\t" sl@0: " movq (%3), %%mm2 \n\t" sl@0: " movq %%mm1, %%mm3 \n\t" sl@0: " pavgb %%mm2, %%mm1 \n\t" sl@0: " pxor %%mm2, %%mm3 \n\t" sl@0: " pand %%mm6, %%mm3 \n\t" sl@0: " psubb %%mm3, %%mm1 \n\t" sl@0: " psadbw %%mm1, %%mm0 \n\t" sl@0: sl@0: " add %4, %1 \n\t" /* Inc pointer into the new data */ sl@0: " paddw %%mm0, %%mm7 \n\t" /* accumulate difference... */ sl@0: " add %5, %2 \n\t" /* Inc pointer into ref data */ sl@0: " add %5, %3 \n\t" /* Inc pointer into ref data */ sl@0: " decl %%eax \n\t" sl@0: " jnz 1b \n\t" sl@0: sl@0: " movd %%mm7, %0 \n\t" sl@0: " emms \n\t" sl@0: : "=m" (diff), sl@0: "+r" (src1), sl@0: "+r" (src2), sl@0: "+r" (src3) sl@0: : "m" (ss1), sl@0: "m" (ss2) sl@0: : "eax", "memory" sl@0: ); sl@0: *dest = diff; sl@0: #endif sl@0: } sl@0: OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmxext, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT); sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg() { sl@0: return &_oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg; sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg() { sl@0: return &_oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg; sl@0: } sl@0: #endif sl@0: