First public contribution.
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>
34 #include "liboil/simdpack/simdpack.h"
36 #define ABS(x) ((x)>0 ? (x) : -(x))
40 abs_u16_s16_i386asm (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
42 __asm__ __volatile__ ("\n"
44 "1: movswl (%0), %%eax \n"
46 " movl %%eax, %%edx \n"
49 " cmovle %%edx, %%eax \n"
54 " jg 1b \n":"+r" (src), "+r" (dest), "+r" (n)
58 OIL_DEFINE_IMPL_FULL (abs_u16_s16_i386asm, abs_u16_s16, OIL_IMPL_FLAG_CMOV);
62 /* The previous function after running through uberopt */
64 abs_u16_s16_i386asm_uber4 (uint16_t * dest, int dstr, int16_t * src,
67 __asm__ __volatile__ ("\n"
70 " movswl (%0), %%eax \n" /* UBER 0: */
71 " addl $2, %0 \n" /* UBER 1: 0 */
72 " movl %%eax, %%edx \n" /* UBER 2: 0 */
73 " decl %2 \n" /* UBER 7: */
74 " negl %%edx \n" /* UBER 3: 2 */
75 " cmpl $-1, %%eax ; cmovle %%edx, %%eax \n" /* UBER 4: 3 */
76 " movw %%ax, (%1) \n" /* UBER 5: 4 */
77 " addl $2, %1 \n" /* UBER 6: 5 */
80 :"+r" (src), "+r" (dest), "+r" (n)
83 OIL_DEFINE_IMPL_FULL (abs_u16_s16_i386asm_uber4, abs_u16_s16, OIL_IMPL_FLAG_CMOV);
88 abs_u16_s16_i386asm2 (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
90 __asm__ __volatile__ ("\n"
92 " movl %%eax, %%ebp \n"
94 "1: movswl (%%edi), %%eax \n"
96 " movl %%eax, %%edx \n"
99 " cmovle %%edx, %%eax \n"
100 " movw %%ax, (%%ebp) \n"
105 " popl %%ebp \n":"+D" (src), "+a" (dest), "+S" (n)
108 OIL_DEFINE_IMPL_FULL (abs_u16_s16_i386asm2, abs_u16_s16, OIL_IMPL_FLAG_CMOV);
112 abs_u16_s16_i386asm3 (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
114 #if !defined(__WINSCW__) && !defined(__WINS__)
115 __asm__ __volatile__ ("\n"
117 "1: movswl (%1), %%eax \n"
119 " mov %%eax, %%edx \n"
121 " and %%edx, %%eax \n"
122 " add %%eax, %%eax \n"
123 " sub %%eax, %%edx \n"
128 : "+r" (dest), "+r" (src), "+m" (n)
129 : "m" (dstr), "m" (sstr)
133 OIL_DEFINE_IMPL_ASM (abs_u16_s16_i386asm3, abs_u16_s16);
138 abs_u16_s16_mmx (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
140 #if !defined(__WINSCW__) && !defined(__WINS__)
141 static const int16_t p[][4] = {
142 { -32768, -32768, -32768, -32768 },
143 { 32767, 32767, 32767, 32767 }
149 OIL_INCREMENT (dest, dstr);
150 OIL_INCREMENT (src, sstr);
155 __asm__ __volatile__ ("\n"
156 " movq (%0), %%mm2 \n"
157 " movq 8(%0), %%mm3 \n"
162 OIL_INCREMENT (src, sstr);
164 OIL_INCREMENT (src, sstr);
166 OIL_INCREMENT (src, sstr);
168 OIL_INCREMENT (src, sstr);
169 __asm__ __volatile__ ("\n"
170 " movq (%0), %%mm1 \n"
171 " movq %%mm1, %%mm0 \n"
172 " paddsw %%mm2, %%mm0 \n"
173 " paddsw %%mm3, %%mm1 \n"
174 " psubsw %%mm2, %%mm0 \n"
175 " psubsw %%mm3, %%mm1 \n"
176 " psubw %%mm1, %%mm0 \n"
177 " movq %%mm0, (%0) \n"
181 OIL_INCREMENT (dest, dstr);
183 OIL_INCREMENT (dest, dstr);
185 OIL_INCREMENT (dest, dstr);
187 OIL_INCREMENT (dest, dstr);
189 asm volatile ("emms");
193 OIL_DEFINE_IMPL_FULL (abs_u16_s16_mmx, abs_u16_s16, OIL_IMPL_FLAG_MMX);
197 abs_u16_s16_mmxx (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
199 short p[] = { -32768, -32768, -32768, -32768,
200 32767, 32767, 32767, 32767
205 OIL_INCREMENT (dest, dstr);
206 OIL_INCREMENT (src, sstr);
210 __asm__ __volatile__ ("\n"
211 " movq (%3), %%mm2 \n"
212 " movq 8(%3), %%mm3 \n"
214 "1: movq (%%edi), %%mm0 \n"
215 " movq (%%edi), %%mm1 \n"
216 " paddsw %%mm2, %%mm0 \n"
217 " paddsw %%mm3, %%mm1 \n"
218 " psubsw %%mm2, %%mm0 \n"
219 " psubsw %%mm3, %%mm1 \n"
220 " psubw %%mm1, %%mm0 \n"
221 " movq %%mm0, (%%eax) \n"
222 " movq 8(%%edi), %%mm4 \n"
223 " movq 8(%%edi), %%mm5 \n"
224 " addl $16, %%edi \n"
225 " paddsw %%mm2, %%mm4 \n"
226 " paddsw %%mm3, %%mm5 \n"
227 " psubsw %%mm2, %%mm4 \n"
228 " psubsw %%mm3, %%mm5 \n"
229 " psubw %%mm5, %%mm4 \n"
230 " movq %%mm4, 8(%%eax) \n"
231 " addl $16, %%eax \n"
234 " jg 1b \n":"+D" (src), "+a" (dest), "+S" (n)
236 asm volatile ("emms");
238 OIL_DEFINE_IMPL_FULL (abs_u16_s16_mmxx, abs_u16_s16, OIL_IMPL_FLAG_MMX);
241 #ifdef ENABLE_BROKEN_IMPLS
243 abs_u16_s16_mmx2 (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
247 OIL_INCREMENT (dest, dstr);
248 OIL_INCREMENT (src, sstr);
252 __asm__ __volatile__ ("\n"
254 " movl %%eax, %%ebp \n"
256 "1: movq (%%edi), %%mm0 \n"
257 " pxor %%mm1, %%mm1 \n"
258 " movq 8(%%edi), %%mm2 \n"
259 " addl $16, %%edi \n"
260 " psubw %%mm0, %%mm1 \n"
261 " pxor %%mm3, %%mm3 \n"
262 " pmaxsw %%mm0, %%mm1 \n"
263 " psubw %%mm2, %%mm3 \n"
264 " movq %%mm1, (%%ebp) \n"
265 " pmaxsw %%mm2, %%mm3 \n"
266 " movq %%mm3, 8(%%ebp) \n"
267 " addl $16, %%ebp \n"
271 " popl %%ebp \n":"+D" (src), "+a" (dest), "+S" (n)
273 asm volatile ("emms");
275 OIL_DEFINE_IMPL_FULL (abs_u16_s16_mmx2, abs_u16_s16, OIL_IMPL_FLAG_MMXEXT);
278 #ifdef ENABLE_BROKEN_IMPLS
280 abs_u16_s16_sse2 (uint16_t * dest, int dstr, int16_t * src, int sstr, int n)
284 OIL_INCREMENT (dest, dstr);
285 OIL_INCREMENT (src, sstr);
289 __asm__ __volatile__ ("\n"
291 " movl %%eax, %%ebp \n"
293 "1: movq (%%edi), %%xmm0 \n"
294 " addl $16, %%edi \n"
295 " pxor %%xmm1, %%xmm1 \n"
296 " psubw %%xmm0, %%xmm1 \n"
297 " pmaxsw %%xmm0, %%xmm1 \n"
298 " movq %%xmm1, (%%ebp) \n"
299 " addl $16, %%ebp \n"
303 " popl %%ebp \n":"+D" (src), "+a" (dest), "+S" (n)
306 OIL_DEFINE_IMPL_FULL (abs_u16_s16_sse2, abs_u16_s16, OIL_IMPL_FLAG_SSE2);
313 OilFunctionImpl* __oil_function_impl_abs_u16_s16_i386asm, abs_u16_s16() {
314 return &_oil_function_impl_abs_u16_s16_i386asm, abs_u16_s16;
320 OilFunctionImpl* __oil_function_impl_abs_u16_s16_i386asm_uber4, abs_u16_s16() {
321 return &_oil_function_impl_abs_u16_s16_i386asm_uber4, abs_u16_s16;
327 OilFunctionImpl* __oil_function_impl_abs_u16_s16_i386asm2, abs_u16_s16() {
328 return &_oil_function_impl_abs_u16_s16_i386asm2, abs_u16_s16;
334 OilFunctionImpl* __oil_function_impl_abs_u16_s16_mmx, abs_u16_s16() {
335 return &_oil_function_impl_abs_u16_s16_mmx, abs_u16_s16;
341 OilFunctionImpl* __oil_function_impl_abs_u16_s16_mmxx, abs_u16_s16() {
342 return &_oil_function_impl_abs_u16_s16_mmxx, abs_u16_s16;
348 OilFunctionImpl* __oil_function_impl_abs_u16_s16_mmx2, abs_u16_s16() {
349 return &_oil_function_impl_abs_u16_s16_mmx2, abs_u16_s16;
355 OilFunctionImpl* __oil_function_impl_abs_u16_s16_sse2, abs_u16_s16() {
356 return &_oil_function_impl_abs_u16_s16_sse2, abs_u16_s16;
364 OilFunctionImpl* __oil_function_impl_abs_u16_s16_i386asm3() {
365 return &_oil_function_impl_abs_u16_s16_i386asm3;