sl@0: /* sl@0: * LIBOIL - Library of Optimized Inner Loops sl@0: * Copyright (c) 2003,2004 David A. Schleef 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 sl@0: sl@0: OIL_DECLARE_CLASS (rowsad8x8_u8); sl@0: OIL_DECLARE_CLASS (colsad8x8_u8); sl@0: sl@0: static void sl@0: rowsad8x8_u8_mmx (uint32_t *dest, uint8_t *src1, uint8_t *src2) sl@0: { sl@0: uint32_t MaxSad; sl@0: #if !defined(__WINSCW__) && !defined(__WINS__) sl@0: __asm__ __volatile__ ( sl@0: " pxor %%mm6, %%mm6 \n\t" /* zero out mm6 for unpack */ sl@0: " pxor %%mm7, %%mm7 \n\t" /* zero out mm7 for unpack */ sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: " movq (%2), %%mm1 \n\t" sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" 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: sl@0: " movq %%mm0, %%mm1 \n\t" sl@0: sl@0: " punpcklbw %%mm6, %%mm0 \n\t" /* ; unpack low four bytes to higher precision */ sl@0: " punpckhbw %%mm7, %%mm1 \n\t" /* ; unpack high four bytes to higher precision */ sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" sl@0: " movq %%mm1, %%mm3 \n\t" sl@0: " psrlq $32, %%mm2 \n\t" /* fold and add */ sl@0: " psrlq $32, %%mm3 \n\t" sl@0: " paddw %%mm2, %%mm0 \n\t" sl@0: " paddw %%mm3, %%mm1 \n\t" sl@0: " movq %%mm0, %%mm2 \n\t" sl@0: " movq %%mm1, %%mm3 \n\t" sl@0: " psrlq $16, %%mm2 \n\t" sl@0: " psrlq $16, %%mm3 \n\t" sl@0: " paddw %%mm2, %%mm0 \n\t" sl@0: " paddw %%mm3, %%mm1 \n\t" sl@0: sl@0: " psubusw %%mm0, %%mm1 \n\t" sl@0: " paddw %%mm0, %%mm1 \n\t" /* mm1 = max(mm1, mm0) */ sl@0: " movd %%mm1, %0 \n\t" sl@0: " andl $0xffff, %0 \n\t" sl@0: " emms \n\t" sl@0: sl@0: : "=m" (MaxSad), sl@0: "+r" (src1), sl@0: "+r" (src2) sl@0: : sl@0: : "memory" sl@0: ); sl@0: *dest = MaxSad; sl@0: #endif sl@0: } sl@0: OIL_DEFINE_IMPL_FULL (rowsad8x8_u8_mmx, rowsad8x8_u8, OIL_IMPL_FLAG_MMX); sl@0: sl@0: static void sl@0: rowsad8x8_u8_mmxext (uint32_t *dest, uint8_t *src1, uint8_t *src2) sl@0: { sl@0: #if !defined(__WINSCW__) && !defined(__WINS__) sl@0: uint32_t MaxSad; sl@0: sl@0: __asm__ __volatile__ ( sl@0: " movd (%1), %%mm0 \n\t" sl@0: " movd (%2), %%mm1 \n\t" sl@0: " psadbw %%mm0, %%mm1 \n\t" sl@0: " movd 4(%1), %%mm2 \n\t" sl@0: " movd 4(%2), %%mm3 \n\t" sl@0: " psadbw %%mm2, %%mm3 \n\t" sl@0: sl@0: " pmaxsw %%mm1, %%mm3 \n\t" sl@0: " movd %%mm3, %0 \n\t" sl@0: " andl $0xffff, %0 \n\t" sl@0: " emms \n\t" sl@0: sl@0: : "=m" (MaxSad), sl@0: "+r" (src1), sl@0: "+r" (src2) sl@0: : sl@0: : "memory" sl@0: ); sl@0: *dest = MaxSad; sl@0: #endif sl@0: } sl@0: OIL_DEFINE_IMPL_FULL (rowsad8x8_u8_mmxext, rowsad8x8_u8, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT); sl@0: sl@0: static void sl@0: colsad8x8_u8_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, int ss2) sl@0: { sl@0: #if !defined(__WINSCW__) && !defined(__WINS__) sl@0: uint32_t MaxSad; sl@0: sl@0: __asm__ __volatile__ ( sl@0: " pxor %%mm3, %%mm3 \n\t" /* zero out mm3 for unpack */ sl@0: " pxor %%mm4, %%mm4 \n\t" /* mm4 low sum */ sl@0: " pxor %%mm5, %%mm5 \n\t" /* mm5 high sum */ sl@0: " pxor %%mm6, %%mm6 \n\t" /* mm6 low sum */ sl@0: " pxor %%mm7, %%mm7 \n\t" /* mm7 high sum */ sl@0: " mov $4, %%edi \n\t" /* 4 rows */ sl@0: "1: \n\t" sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: " movq (%2), %%mm1 \n\t" /* take 8 bytes */ sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" 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 %%mm3, %%mm0 \n\t" /* unpack to higher precision for accumulation */ sl@0: " paddw %%mm0, %%mm4 \n\t" /* accumulate difference... */ sl@0: " punpckhbw %%mm3, %%mm1 \n\t" /* unpack high four bytes to higher precision */ sl@0: " paddw %%mm1, %%mm5 \n\t" /* accumulate difference... */ sl@0: " add %3, %1 \n\t" /* Inc pointer into the new data */ sl@0: " add %3, %2 \n\t" /* Inc pointer into the new data */ sl@0: sl@0: " dec %%edi \n\t" sl@0: " jnz 1b \n\t" sl@0: sl@0: " mov $4, %%edi \n\t" /* 4 rows */ sl@0: "2: \n\t" sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: " movq (%2), %%mm1 \n\t" /* take 8 bytes */ sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" 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 %%mm3, %%mm0 \n\t" /* unpack to higher precision for accumulation */ sl@0: " paddw %%mm0, %%mm6 \n\t" /* accumulate difference... */ sl@0: " punpckhbw %%mm3, %%mm1 \n\t" /* unpack high four bytes to higher precision */ sl@0: " paddw %%mm1, %%mm7 \n\t" /* accumulate difference... */ sl@0: " add %3, %1 \n\t" /* Inc pointer into the new data */ sl@0: " add %3, %2 \n\t" /* Inc pointer into the new data */ sl@0: sl@0: " dec %%edi \n\t" sl@0: " jnz 2b \n\t" sl@0: sl@0: " psubusw %%mm6, %%mm7 \n\t" sl@0: " paddw %%mm6, %%mm7 \n\t" /* mm7 = max(mm7, mm6) */ sl@0: " psubusw %%mm4, %%mm5 \n\t" sl@0: " paddw %%mm4, %%mm5 \n\t" /* mm5 = max(mm5, mm4) */ sl@0: " psubusw %%mm5, %%mm7 \n\t" sl@0: " paddw %%mm5, %%mm7 \n\t" /* mm7 = max(mm5, mm7) */ sl@0: " movq %%mm7, %%mm6 \n\t" sl@0: " psrlq $32, %%mm6 \n\t" sl@0: " psubusw %%mm6, %%mm7 \n\t" sl@0: " paddw %%mm6, %%mm7 \n\t" /* mm7 = max(mm5, mm7) */ sl@0: " movq %%mm7, %%mm6 \n\t" sl@0: " psrlq $16, %%mm6 \n\t" sl@0: " psubusw %%mm6, %%mm7 \n\t" sl@0: " paddw %%mm6, %%mm7 \n\t" /* mm7 = max(mm5, mm7) */ sl@0: " movd %%mm7, %0 \n\t" sl@0: " andl $0xffff, %0 \n\t" sl@0: " emms \n\t" sl@0: sl@0: : "=r" (MaxSad), sl@0: "+r" (src1), sl@0: "+r" (src2) sl@0: : "r" (ss1) sl@0: : "memory", "edi" sl@0: ); sl@0: *dest = MaxSad; sl@0: #endif sl@0: } sl@0: OIL_DEFINE_IMPL_FULL (colsad8x8_u8_mmx, colsad8x8_u8, OIL_IMPL_FLAG_MMX); sl@0: sl@0: static void sl@0: colsad8x8_u8_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, int ss2) sl@0: { sl@0: #if !defined(__WINSCW__) && !defined(__WINS__) sl@0: uint32_t MaxSad; sl@0: sl@0: __asm__ __volatile__ ( sl@0: " pxor %%mm3, %%mm3 \n\t" /* zero out mm3 for unpack */ sl@0: " pxor %%mm4, %%mm4 \n\t" /* mm4 low sum */ sl@0: " pxor %%mm5, %%mm5 \n\t" /* mm5 high sum */ sl@0: " pxor %%mm6, %%mm6 \n\t" /* mm6 low sum */ sl@0: " pxor %%mm7, %%mm7 \n\t" /* mm7 high sum */ sl@0: " mov $4, %%edi \n\t" /* 4 rows */ sl@0: "1: \n\t" sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: " movq (%2), %%mm1 \n\t" /* take 8 bytes */ sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" 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 %%mm3, %%mm0 \n\t" /* unpack to higher precision for accumulation */ sl@0: " paddw %%mm0, %%mm4 \n\t" /* accumulate difference... */ sl@0: " punpckhbw %%mm3, %%mm1 \n\t" /* unpack high four bytes to higher precision */ sl@0: " paddw %%mm1, %%mm5 \n\t" /* accumulate difference... */ sl@0: " add %3, %1 \n\t" /* Inc pointer into the new data */ sl@0: " add %3, %2 \n\t" /* Inc pointer into the new data */ sl@0: sl@0: " dec %%edi \n\t" sl@0: " jnz 1b \n\t" sl@0: sl@0: " mov $4, %%edi \n\t" /* 4 rows */ sl@0: "2: \n\t" sl@0: " movq (%1), %%mm0 \n\t" /* take 8 bytes */ sl@0: " movq (%2), %%mm1 \n\t" /* take 8 bytes */ sl@0: sl@0: " movq %%mm0, %%mm2 \n\t" 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 %%mm3, %%mm0 \n\t" /* unpack to higher precision for accumulation */ sl@0: " paddw %%mm0, %%mm6 \n\t" /* accumulate difference... */ sl@0: " punpckhbw %%mm3, %%mm1 \n\t" /* unpack high four bytes to higher precision */ sl@0: " paddw %%mm1, %%mm7 \n\t" /* accumulate difference... */ sl@0: " add %3, %1 \n\t" /* Inc pointer into the new data */ sl@0: " add %3, %2 \n\t" /* Inc pointer into the new data */ sl@0: sl@0: " dec %%edi \n\t" sl@0: " jnz 2b \n\t" sl@0: sl@0: " pmaxsw %%mm6, %%mm7 \n\t" sl@0: " pmaxsw %%mm4, %%mm5 \n\t" sl@0: " pmaxsw %%mm5, %%mm7 \n\t" sl@0: " movq %%mm7, %%mm6 \n\t" sl@0: " psrlq $32, %%mm6 \n\t" sl@0: " pmaxsw %%mm6, %%mm7 \n\t" sl@0: " movq %%mm7, %%mm6 \n\t" sl@0: " psrlq $16, %%mm6 \n\t" sl@0: " pmaxsw %%mm6, %%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: : "=r" (MaxSad), sl@0: "+r" (src1), sl@0: "+r" (src2) sl@0: : "r" (ss1) sl@0: : "memory", "edi" sl@0: ); sl@0: sl@0: *dest = MaxSad; sl@0: #endif sl@0: } sl@0: OIL_DEFINE_IMPL_FULL (colsad8x8_u8_mmxext, colsad8x8_u8, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT); sl@0: sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_rowsad8x8_u8_mmx, rowsad8x8_u8() { sl@0: return &_oil_function_impl_rowsad8x8_u8_mmx, rowsad8x8_u8; sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_rowsad8x8_u8_mmxext, rowsad8x8_u8() { sl@0: return &_oil_function_impl_rowsad8x8_u8_mmxext, rowsad8x8_u8; sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_colsad8x8_u8_mmx, colsad8x8_u8() { sl@0: return &_oil_function_impl_colsad8x8_u8_mmx, colsad8x8_u8; sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_colsad8x8_u8_mmxext, colsad8x8_u8() { sl@0: return &_oil_function_impl_colsad8x8_u8_mmxext, colsad8x8_u8; sl@0: } sl@0: #endif sl@0: