Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboilfunction.h>
35 OIL_DECLARE_CLASS (sad8x8_u8_avg);
38 sad8x8_u8_avg_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
40 #if !defined(__WINSCW__) && !defined(__WINS__)
43 __asm__ __volatile__ (
44 " pcmpeqd %%mm5, %%mm5 \n\t" /* fefefefefefefefe in mm5 */
45 " paddb %%mm5, %%mm5 \n\t"
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 */
51 " movq (%1), %%mm0 \n\t" /* take 8 bytes */
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"
62 " movq %%mm0, %%mm2 \n\t"
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"
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 */
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"
102 OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmx, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX);
105 sad8x8_u8_avg_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
107 #if !defined(__WINSCW__) && !defined(__WINS__)
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"
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"
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 */
134 " movd %%mm7, %0 \n\t"
147 OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmxext, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT);
152 OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg() {
153 return &_oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg;
159 OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg() {
160 return &_oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg;