sl@0
|
1 |
/*
|
sl@0
|
2 |
* LIBOIL - Library of Optimized Inner Loops
|
sl@0
|
3 |
* Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
10 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
13 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
sl@0
|
16 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
sl@0
|
17 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
sl@0
|
19 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
sl@0
|
20 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
sl@0
|
21 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
23 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
sl@0
|
24 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
sl@0
|
25 |
* POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
//Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
28 |
|
sl@0
|
29 |
#ifdef HAVE_CONFIG_H
|
sl@0
|
30 |
#include "config.h"
|
sl@0
|
31 |
#endif
|
sl@0
|
32 |
|
sl@0
|
33 |
#include <liboil/liboilfunction.h>
|
sl@0
|
34 |
|
sl@0
|
35 |
OIL_DECLARE_CLASS (sad8x8_u8_avg);
|
sl@0
|
36 |
|
sl@0
|
37 |
static void
|
sl@0
|
38 |
sad8x8_u8_avg_mmx (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
#if !defined(__WINSCW__) && !defined(__WINS__)
|
sl@0
|
41 |
uint32_t diff;
|
sl@0
|
42 |
|
sl@0
|
43 |
__asm__ __volatile__ (
|
sl@0
|
44 |
" pcmpeqd %%mm5, %%mm5 \n\t" /* fefefefefefefefe in mm5 */
|
sl@0
|
45 |
" paddb %%mm5, %%mm5 \n\t"
|
sl@0
|
46 |
|
sl@0
|
47 |
" pxor %%mm6, %%mm6 \n\t" /* zero out mm6 for unpack */
|
sl@0
|
48 |
" pxor %%mm7, %%mm7 \n\t" /* mm7 contains the result */
|
sl@0
|
49 |
" mov $8, %%edi \n\t" /* 8 rows */
|
sl@0
|
50 |
"1: \n\t"
|
sl@0
|
51 |
" movq (%1), %%mm0 \n\t" /* take 8 bytes */
|
sl@0
|
52 |
|
sl@0
|
53 |
" movq (%2), %%mm2 \n\t"
|
sl@0
|
54 |
" movq (%3), %%mm3 \n\t" /* take average of mm2 and mm3 */
|
sl@0
|
55 |
" movq %%mm2, %%mm1 \n\t"
|
sl@0
|
56 |
" pand %%mm3, %%mm1 \n\t"
|
sl@0
|
57 |
" pxor %%mm2, %%mm3 \n\t"
|
sl@0
|
58 |
" pand %%mm5, %%mm3 \n\t"
|
sl@0
|
59 |
" psrlq $1, %%mm3 \n\t"
|
sl@0
|
60 |
" paddb %%mm3, %%mm1 \n\t"
|
sl@0
|
61 |
|
sl@0
|
62 |
" movq %%mm0, %%mm2 \n\t"
|
sl@0
|
63 |
|
sl@0
|
64 |
" psubusb %%mm1, %%mm0 \n\t" /* A - B */
|
sl@0
|
65 |
" psubusb %%mm2, %%mm1 \n\t" /* B - A */
|
sl@0
|
66 |
" por %%mm1, %%mm0 \n\t" /* and or gives abs difference */
|
sl@0
|
67 |
" movq %%mm0, %%mm1 \n\t"
|
sl@0
|
68 |
|
sl@0
|
69 |
" punpcklbw %%mm6, %%mm0 \n\t" /* unpack to higher precision for accumulation */
|
sl@0
|
70 |
" paddw %%mm0, %%mm7 \n\t" /* accumulate difference... */
|
sl@0
|
71 |
" punpckhbw %%mm6, %%mm1 \n\t" /* unpack high four bytes to higher precision */
|
sl@0
|
72 |
" add %4, %1 \n\t" /* Inc pointer into the new data */
|
sl@0
|
73 |
" paddw %%mm1, %%mm7 \n\t" /* accumulate difference... */
|
sl@0
|
74 |
" add %5, %2 \n\t" /* Inc pointer into ref data */
|
sl@0
|
75 |
" add %5, %3 \n\t" /* Inc pointer into ref data */
|
sl@0
|
76 |
|
sl@0
|
77 |
" dec %%edi \n\t"
|
sl@0
|
78 |
" jnz 1b \n\t"
|
sl@0
|
79 |
|
sl@0
|
80 |
" movq %%mm7, %%mm0 \n\t"
|
sl@0
|
81 |
" psrlq $32, %%mm7 \n\t"
|
sl@0
|
82 |
" paddw %%mm0, %%mm7 \n\t"
|
sl@0
|
83 |
" movq %%mm7, %%mm0 \n\t"
|
sl@0
|
84 |
" psrlq $16, %%mm7 \n\t"
|
sl@0
|
85 |
" paddw %%mm0, %%mm7 \n\t"
|
sl@0
|
86 |
" movd %%mm7, %0 \n\t"
|
sl@0
|
87 |
" andl $0xffff, %0 \n\t"
|
sl@0
|
88 |
" emms \n\t"
|
sl@0
|
89 |
|
sl@0
|
90 |
: "=m" (diff),
|
sl@0
|
91 |
"+r" (src1),
|
sl@0
|
92 |
"+r" (src2),
|
sl@0
|
93 |
"+r" (src3)
|
sl@0
|
94 |
: "m" (ss1),
|
sl@0
|
95 |
"m" (ss2)
|
sl@0
|
96 |
: "edi", "memory"
|
sl@0
|
97 |
);
|
sl@0
|
98 |
*dest = diff;
|
sl@0
|
99 |
#endif
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmx, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX);
|
sl@0
|
103 |
|
sl@0
|
104 |
static void
|
sl@0
|
105 |
sad8x8_u8_avg_mmxext (uint32_t *dest, uint8_t *src1, int ss1, uint8_t *src2, uint8_t *src3, int ss2)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
#if !defined(__WINSCW__) && !defined(__WINS__)
|
sl@0
|
108 |
uint32_t diff;
|
sl@0
|
109 |
|
sl@0
|
110 |
__asm__ __volatile__ (
|
sl@0
|
111 |
" pxor %%mm7, %%mm7 \n\t" /* mm7 contains the result */
|
sl@0
|
112 |
" mov $0x01010101, %%eax \n\t"
|
sl@0
|
113 |
" movd %%eax, %%mm6 \n\t"
|
sl@0
|
114 |
" punpcklbw %%mm6, %%mm6 \n\t"
|
sl@0
|
115 |
" mov $8, %%eax \n\t"
|
sl@0
|
116 |
"1: \n\t"
|
sl@0
|
117 |
" movq (%1), %%mm0 \n\t" /* take 8 bytes */
|
sl@0
|
118 |
" movq (%2), %%mm1 \n\t"
|
sl@0
|
119 |
" movq (%3), %%mm2 \n\t"
|
sl@0
|
120 |
" movq %%mm1, %%mm3 \n\t"
|
sl@0
|
121 |
" pavgb %%mm2, %%mm1 \n\t"
|
sl@0
|
122 |
" pxor %%mm2, %%mm3 \n\t"
|
sl@0
|
123 |
" pand %%mm6, %%mm3 \n\t"
|
sl@0
|
124 |
" psubb %%mm3, %%mm1 \n\t"
|
sl@0
|
125 |
" psadbw %%mm1, %%mm0 \n\t"
|
sl@0
|
126 |
|
sl@0
|
127 |
" add %4, %1 \n\t" /* Inc pointer into the new data */
|
sl@0
|
128 |
" paddw %%mm0, %%mm7 \n\t" /* accumulate difference... */
|
sl@0
|
129 |
" add %5, %2 \n\t" /* Inc pointer into ref data */
|
sl@0
|
130 |
" add %5, %3 \n\t" /* Inc pointer into ref data */
|
sl@0
|
131 |
" decl %%eax \n\t"
|
sl@0
|
132 |
" jnz 1b \n\t"
|
sl@0
|
133 |
|
sl@0
|
134 |
" movd %%mm7, %0 \n\t"
|
sl@0
|
135 |
" emms \n\t"
|
sl@0
|
136 |
: "=m" (diff),
|
sl@0
|
137 |
"+r" (src1),
|
sl@0
|
138 |
"+r" (src2),
|
sl@0
|
139 |
"+r" (src3)
|
sl@0
|
140 |
: "m" (ss1),
|
sl@0
|
141 |
"m" (ss2)
|
sl@0
|
142 |
: "eax", "memory"
|
sl@0
|
143 |
);
|
sl@0
|
144 |
*dest = diff;
|
sl@0
|
145 |
#endif
|
sl@0
|
146 |
}
|
sl@0
|
147 |
OIL_DEFINE_IMPL_FULL (sad8x8_u8_avg_mmxext, sad8x8_u8_avg, OIL_IMPL_FLAG_MMX | OIL_IMPL_FLAG_MMXEXT);
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
#ifdef __SYMBIAN32__
|
sl@0
|
151 |
|
sl@0
|
152 |
OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg() {
|
sl@0
|
153 |
return &_oil_function_impl_sad8x8_u8_avg_mmx, sad8x8_u8_avg;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
#endif
|
sl@0
|
156 |
|
sl@0
|
157 |
#ifdef __SYMBIAN32__
|
sl@0
|
158 |
|
sl@0
|
159 |
OilFunctionImpl* __oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg() {
|
sl@0
|
160 |
return &_oil_function_impl_sad8x8_u8_avg_mmxext, sad8x8_u8_avg;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
#endif
|
sl@0
|
163 |
|