dsputil_rnd_template.c
Go to the documentation of this file.
1 /*
2  * DSP utils mmx functions are compiled twice for rnd/no_rnd
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2003-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
7  * mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
8  * and improved by Zdenek Kabelac <kabi@users.sf.net>
9  *
10  * This file is part of FFmpeg.
11  *
12  * FFmpeg is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * FFmpeg is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with FFmpeg; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 // put_pixels
28 static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
29 {
30  MOVQ_ZERO(mm7);
31  SET_RND(mm6); // =2 for rnd and =1 for no_rnd version
32  __asm__ volatile(
33  "movq (%1), %%mm0 \n\t"
34  "movq 1(%1), %%mm4 \n\t"
35  "movq %%mm0, %%mm1 \n\t"
36  "movq %%mm4, %%mm5 \n\t"
37  "punpcklbw %%mm7, %%mm0 \n\t"
38  "punpcklbw %%mm7, %%mm4 \n\t"
39  "punpckhbw %%mm7, %%mm1 \n\t"
40  "punpckhbw %%mm7, %%mm5 \n\t"
41  "paddusw %%mm0, %%mm4 \n\t"
42  "paddusw %%mm1, %%mm5 \n\t"
43  "xor %%"REG_a", %%"REG_a" \n\t"
44  "add %3, %1 \n\t"
45  ".p2align 3 \n\t"
46  "1: \n\t"
47  "movq (%1, %%"REG_a"), %%mm0 \n\t"
48  "movq 1(%1, %%"REG_a"), %%mm2 \n\t"
49  "movq %%mm0, %%mm1 \n\t"
50  "movq %%mm2, %%mm3 \n\t"
51  "punpcklbw %%mm7, %%mm0 \n\t"
52  "punpcklbw %%mm7, %%mm2 \n\t"
53  "punpckhbw %%mm7, %%mm1 \n\t"
54  "punpckhbw %%mm7, %%mm3 \n\t"
55  "paddusw %%mm2, %%mm0 \n\t"
56  "paddusw %%mm3, %%mm1 \n\t"
57  "paddusw %%mm6, %%mm4 \n\t"
58  "paddusw %%mm6, %%mm5 \n\t"
59  "paddusw %%mm0, %%mm4 \n\t"
60  "paddusw %%mm1, %%mm5 \n\t"
61  "psrlw $2, %%mm4 \n\t"
62  "psrlw $2, %%mm5 \n\t"
63  "packuswb %%mm5, %%mm4 \n\t"
64  "movq %%mm4, (%2, %%"REG_a") \n\t"
65  "add %3, %%"REG_a" \n\t"
66 
67  "movq (%1, %%"REG_a"), %%mm2 \n\t" // 0 <-> 2 1 <-> 3
68  "movq 1(%1, %%"REG_a"), %%mm4 \n\t"
69  "movq %%mm2, %%mm3 \n\t"
70  "movq %%mm4, %%mm5 \n\t"
71  "punpcklbw %%mm7, %%mm2 \n\t"
72  "punpcklbw %%mm7, %%mm4 \n\t"
73  "punpckhbw %%mm7, %%mm3 \n\t"
74  "punpckhbw %%mm7, %%mm5 \n\t"
75  "paddusw %%mm2, %%mm4 \n\t"
76  "paddusw %%mm3, %%mm5 \n\t"
77  "paddusw %%mm6, %%mm0 \n\t"
78  "paddusw %%mm6, %%mm1 \n\t"
79  "paddusw %%mm4, %%mm0 \n\t"
80  "paddusw %%mm5, %%mm1 \n\t"
81  "psrlw $2, %%mm0 \n\t"
82  "psrlw $2, %%mm1 \n\t"
83  "packuswb %%mm1, %%mm0 \n\t"
84  "movq %%mm0, (%2, %%"REG_a") \n\t"
85  "add %3, %%"REG_a" \n\t"
86 
87  "subl $2, %0 \n\t"
88  "jnz 1b \n\t"
89  :"+g"(h), "+S"(pixels)
90  :"D"(block), "r"((x86_reg)line_size)
91  :REG_a, "memory");
92 }
93 
94 // in case more speed is needed - unroling would certainly help
95 static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
96 {
97  MOVQ_BFE(mm6);
98  JUMPALIGN();
99  do {
100  __asm__ volatile(
101  "movq %0, %%mm0 \n\t"
102  "movq %1, %%mm1 \n\t"
103  OP_AVG(%%mm0, %%mm1, %%mm2, %%mm6)
104  "movq %%mm2, %0 \n\t"
105  :"+m"(*block)
106  :"m"(*pixels)
107  :"memory");
108  pixels += line_size;
109  block += line_size;
110  }
111  while (--h);
112 }
113 
114 static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
115 {
116  MOVQ_BFE(mm6);
117  JUMPALIGN();
118  do {
119  __asm__ volatile(
120  "movq %0, %%mm0 \n\t"
121  "movq %1, %%mm1 \n\t"
122  OP_AVG(%%mm0, %%mm1, %%mm2, %%mm6)
123  "movq %%mm2, %0 \n\t"
124  "movq 8%0, %%mm0 \n\t"
125  "movq 8%1, %%mm1 \n\t"
126  OP_AVG(%%mm0, %%mm1, %%mm2, %%mm6)
127  "movq %%mm2, 8%0 \n\t"
128  :"+m"(*block)
129  :"m"(*pixels)
130  :"memory");
131  pixels += line_size;
132  block += line_size;
133  }
134  while (--h);
135 }
136 
137 // this routine is 'slightly' suboptimal but mostly unused
138 static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
139 {
140  MOVQ_ZERO(mm7);
141  SET_RND(mm6); // =2 for rnd and =1 for no_rnd version
142  __asm__ volatile(
143  "movq (%1), %%mm0 \n\t"
144  "movq 1(%1), %%mm4 \n\t"
145  "movq %%mm0, %%mm1 \n\t"
146  "movq %%mm4, %%mm5 \n\t"
147  "punpcklbw %%mm7, %%mm0 \n\t"
148  "punpcklbw %%mm7, %%mm4 \n\t"
149  "punpckhbw %%mm7, %%mm1 \n\t"
150  "punpckhbw %%mm7, %%mm5 \n\t"
151  "paddusw %%mm0, %%mm4 \n\t"
152  "paddusw %%mm1, %%mm5 \n\t"
153  "xor %%"REG_a", %%"REG_a" \n\t"
154  "add %3, %1 \n\t"
155  ".p2align 3 \n\t"
156  "1: \n\t"
157  "movq (%1, %%"REG_a"), %%mm0 \n\t"
158  "movq 1(%1, %%"REG_a"), %%mm2 \n\t"
159  "movq %%mm0, %%mm1 \n\t"
160  "movq %%mm2, %%mm3 \n\t"
161  "punpcklbw %%mm7, %%mm0 \n\t"
162  "punpcklbw %%mm7, %%mm2 \n\t"
163  "punpckhbw %%mm7, %%mm1 \n\t"
164  "punpckhbw %%mm7, %%mm3 \n\t"
165  "paddusw %%mm2, %%mm0 \n\t"
166  "paddusw %%mm3, %%mm1 \n\t"
167  "paddusw %%mm6, %%mm4 \n\t"
168  "paddusw %%mm6, %%mm5 \n\t"
169  "paddusw %%mm0, %%mm4 \n\t"
170  "paddusw %%mm1, %%mm5 \n\t"
171  "psrlw $2, %%mm4 \n\t"
172  "psrlw $2, %%mm5 \n\t"
173  "movq (%2, %%"REG_a"), %%mm3 \n\t"
174  "packuswb %%mm5, %%mm4 \n\t"
175  "pcmpeqd %%mm2, %%mm2 \n\t"
176  "paddb %%mm2, %%mm2 \n\t"
177  OP_AVG(%%mm3, %%mm4, %%mm5, %%mm2)
178  "movq %%mm5, (%2, %%"REG_a") \n\t"
179  "add %3, %%"REG_a" \n\t"
180 
181  "movq (%1, %%"REG_a"), %%mm2 \n\t" // 0 <-> 2 1 <-> 3
182  "movq 1(%1, %%"REG_a"), %%mm4 \n\t"
183  "movq %%mm2, %%mm3 \n\t"
184  "movq %%mm4, %%mm5 \n\t"
185  "punpcklbw %%mm7, %%mm2 \n\t"
186  "punpcklbw %%mm7, %%mm4 \n\t"
187  "punpckhbw %%mm7, %%mm3 \n\t"
188  "punpckhbw %%mm7, %%mm5 \n\t"
189  "paddusw %%mm2, %%mm4 \n\t"
190  "paddusw %%mm3, %%mm5 \n\t"
191  "paddusw %%mm6, %%mm0 \n\t"
192  "paddusw %%mm6, %%mm1 \n\t"
193  "paddusw %%mm4, %%mm0 \n\t"
194  "paddusw %%mm5, %%mm1 \n\t"
195  "psrlw $2, %%mm0 \n\t"
196  "psrlw $2, %%mm1 \n\t"
197  "movq (%2, %%"REG_a"), %%mm3 \n\t"
198  "packuswb %%mm1, %%mm0 \n\t"
199  "pcmpeqd %%mm2, %%mm2 \n\t"
200  "paddb %%mm2, %%mm2 \n\t"
201  OP_AVG(%%mm3, %%mm0, %%mm1, %%mm2)
202  "movq %%mm1, (%2, %%"REG_a") \n\t"
203  "add %3, %%"REG_a" \n\t"
204 
205  "subl $2, %0 \n\t"
206  "jnz 1b \n\t"
207  :"+g"(h), "+S"(pixels)
208  :"D"(block), "r"((x86_reg)line_size)
209  :REG_a, "memory");
210 }
211 
212 //FIXME optimize
213 static void DEF(put, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){
214  DEF(put, pixels8_xy2)(block , pixels , line_size, h);
215  DEF(put, pixels8_xy2)(block+8, pixels+8, line_size, h);
216 }
217 
218 static void DEF(avg, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h){
219  DEF(avg, pixels8_xy2)(block , pixels , line_size, h);
220  DEF(avg, pixels8_xy2)(block+8, pixels+8, line_size, h);
221 }
uint8_t
#define put(d, s)
Definition: dsputil_align.c:51
#define OP_AVG(dst, val)
Definition: diracdsp.c:77
static void DEF(put, pixels8_xy2)
int x86_reg
#define avg(d, s)
Definition: dsputil_align.c:52