bfin: Refactor duplicated assembly-related macros
[libav.git] / libavcodec / bfin / pixels_bfin.S
1 /*
2 * Blackfin Pixel Operations
3 * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
4 *
5 * This file is part of Libav.
6 *
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/bfin/asm.h"
23
24 DEFUN(put_pixels_clamped,mL1,
25 (int16_t *block, uint8_t *dest, int line_size)):
26 [--SP] = (R7:4);
27 R4 = 0;
28 R5.l = 0x00ff;
29 R5.h = 0x00ff;
30 I0 = R0; // block
31 I1 = R1; // dest
32 R2 += -4; // line_size
33 M1 = R2;
34 P0 = 8;
35 R0 = [I0++];
36 R1 = [I0++];
37 R2 = MAX(R0, R4) (V);
38 LSETUP (ppc$0,ppc$1) LC0=P0;
39 ppc$0: R2 = MIN(R2, R5) (V);
40 R3 = MAX(R1, R4) (V);
41 R3 = MIN(R3, R5) (V) || R0 = [I0++];
42 R6 = BYTEPACK (R2,R3) || R1 = [I0++];
43 R2 = MAX(R0, R4) (V) || [I1++] = R6;
44 R2 = MIN(R2, R5) (V);
45 R3 = MAX(R1, R4) (V);
46 R3 = MIN(R3, R5) (V) || R0 = [I0++];
47 R6 = BYTEPACK (R2,R3) || R1 = [I0++];
48 ppc$1: R2 = Max(R0, R4) (V) || [I1++M1] = R6;
49
50 (R7:4) = [SP++];
51 RTS;
52 DEFUN_END(put_pixels_clamped)
53
54 DEFUN(add_pixels_clamped,mL1,
55 (int16_t *block, uint8_t *dest, int line_size)):
56 [-- SP] = (R7:4);
57 R4 = 0;
58 I0 = 0;
59 R2 += -4; // line_size
60 M0 = R2;
61 I1 = R1; // dest
62 I3 = R0; // block
63 I2 = R1; // dest
64 P0 = 8;
65 M3 = 2;
66 R0 = [I3++] || R2 = [I1];
67 R2 = R2 << 8 || R0.H = W[I3--] || R3 = [I1++];
68 R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
69 R6 = BYTEOP3P(R1:0, R3:2) (LO) || R1.H = W[I3++] || R2 = [I1];
70
71 LSETUP(apc$2,apc$3) LC1 = P0;
72 apc$2: R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++] || R3 = [I1++M0];
73 R2 = R2 << 8 || R0.H = W[I3--];
74 R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
75 R6 = R6 + R7 (S) || R1.H = W[I3];
76 R6 = BYTEOP3P(R1:0, R3:2) (LO) || I3+=M3 || [I2++]=R6;
77 R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++] || R2 = [I1];
78 R2 = R2 << 8 || R0.H = W[I3--] || R3 = [I1++];
79 R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
80 R6 = R6 + R7 (S) || R1.H = W[I3++];
81 apc$3: R6 = BYTEOP3P(R1:0, R3:2) (LO) || [I2++M0] = R6 || R2 = [I1];
82
83 (R7:4) = [SP++];
84 RTS;
85 DEFUN_END(add_pixels_clamped)
86
87 DEFUN(diff_pixels,mL1,
88 (int16_t *block, uint8_t *s1, uint8_t *s2, int stride)):
89 link 0;
90 [--sp] = (r7:4);
91 p0=8;
92 i3=r0; // block
93 i0=r1; // s1
94 i1=r2; // s2
95 r2=[fp+20]; // stride
96 r2+=-8;
97 m0=r2;
98
99
100 LSETUP(.LS0,.LE0) LC0=P0;
101 DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
102
103 .LS0: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
104 (R5,R4) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
105 (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || [I3++] = R4;
106 DISALGNEXCPT || R2 = [I1++] || [I3++] = R5;
107 [i3++]=r6;
108 .LE0: [i3++]=r7;
109
110 (r7:4) = [sp++];
111 unlink;
112 rts;
113 DEFUN_END(diff_pixels)
114
115 /*
116 for (i = 0; i < 16; i++) {
117 for (j = 0; j < 16; j++) {
118 sum += pix[j];
119 }
120 pix += line_size;
121 }
122 */
123 DEFUN(pix_sum,mL1,
124 (uint8_t *p, int stride)):
125 link 0;
126 [--sp] = (r7:4);
127 p0=8;
128 i0=r0; // s1
129 i1=r0;
130 m1=r1;
131 r1=r1+r1;
132 r1+=-16; // stride
133 m0=r1;
134 i1+=m1;
135
136 r6=0;
137
138 LSETUP(LS$PS,LE$PS) LC0=P0;
139 DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
140
141 LS$PS: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
142 (R5,R4) = BYTEOP16P (R3:2,R1:0) || R0 = [I0++] || R2 = [I1++];
143 r6=r6+|+r5;
144 r6=r6+|+r4;
145 (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R1 = [I0++] || R3 = [I1++];
146 r6=r6+|+r5;
147 r6=r6+|+r4;
148 (R5,R4) = BYTEOP16P (R3:2,R1:0) || R0 = [I0++m0] || R2 = [I1++m0];
149 r6=r6+|+r5;
150 r6=r6+|+r4;
151 (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R0 = [I0++] || R2 = [I1++];
152 r6=r6+|+r5;
153 LE$PS: r6=r6+|+r4;
154 r0.l=r6.l+r6.h;
155 r0.h=0;
156
157 (r7:4) = [sp++];
158 unlink;
159 rts;
160 DEFUN_END(pix_sum)
161
162
163 DEFUN(get_pixels,mL1,
164 (int16_t *restrict block, const uint8_t *pixels, int line_size)):
165 [--sp] = (r7:4);
166 i3=r0; // dest
167 i0=r1; // src0
168 p0=8;
169 r2+=-8;
170 m0=r2;
171 LSETUP(gp8$0,gp8$1) LC0=P0;
172
173 DISALGNEXCPT || R0 = [I0++];
174 DISALGNEXCPT || R1 = [I0++];
175
176 gp8$0: (R7,R6) = byteunpack R1:0 || R0 = [I0++M0];
177 (R5,R4) = byteunpack R1:0 (R) || R0 = [I0++] || [I3++]=R6;
178 DISALGNEXCPT || R1 = [I0++] || [I3++]=R7;
179 [I3++]=R4;
180 gp8$1: [I3++]=R5
181
182
183 (r7:4) = [sp++];
184 RTS;
185 DEFUN_END(get_pixels)
186
187
188 /* sad = sad16x16 (ubyte *mb, ubyte *refwin, srcwidth, refwinwidth, h) */
189 /* 91 cycles */
190 DEFUN(z_sad16x16,mL1,
191 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
192 link 0;
193 I0 = R0;
194 I1 = R1;
195
196 A1 = A0 = 0;
197 R0 = [sp+20]; // rwidth
198 P2 = [sp+24]; // height
199 R3 = 16;
200 R0 = R0 - R3;
201 R3 = R2 - R3;
202 M1 = R0;
203 M0 = R3;
204
205 DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
206 LSETUP (s$16, e$16) LC0=P2;
207 s$16: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
208 SAA (R1:0,R3:2) || R0 = [I0++] || R2 = [I1++];
209 SAA (R1:0,R3:2) (R) || R1 = [I0++] || R3 = [I1++];
210 SAA (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M1];
211 e$16: SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++];
212
213 R3=A1.L+A1.H, R2=A0.L+A0.H ;
214 R0 = R2 + R3 ;
215 unlink;
216 RTS;
217 DEFUN_END(z_sad16x16)
218
219 /* sad = sad8x8 (ubyte *mb, ubyte *refwin, int srcwidth, int refwinwidth, int h) */
220 /* 36 cycles */
221 DEFUN(z_sad8x8,mL1,
222 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
223 I0 = R0;
224 I1 = R1;
225
226 A1 = A0 = 0;
227 r0 = [sp+12]; // rwidth
228 P2 = [sp+16]; //height
229 R3 = 8;
230 R0 = R0 - R3;
231 R3 = R2 - R3;
232 M0 = R3;
233 M1 = R0;
234
235 LSETUP (s$8, e$8) LC0=P2;
236 DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
237 DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
238 s$8: SAA (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M1];
239 SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++];
240 e$8: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
241
242 R3=A1.L+A1.H, R2=A0.L+A0.H ;
243 R0 = R2 + R3 ;
244 RTS;
245 DEFUN_END(z_sad8x8)
246
247 DEFUN(pix_norm1,mL1,
248 (uint8_t * pix, int line_size)):
249 [--SP]=(R7:4,P5:3);
250
251 // Fetch the input arguments.
252 P1 = R0; // pix
253 P0 = R1; // line_size
254 P5 = 16; // loop ctr.
255 P0 -= P5;
256 M0 = P0; // M0 = line_size-16;
257 // Now for the real work.
258 A1 = A0 = 0;
259 lsetup(_pix_norm1_blkfn_loopStart, _pix_norm1_blkfn_loopEnd) LC1 = P5;
260 I0 = P1;
261 DISALGNEXCPT || r0 = [i0++];
262
263 _pix_norm1_blkfn_loopStart:
264 // following unpacks pix1[0..15] pix1+line_size[0..15]
265 DISALGNEXCPT || r1 = [i0++];
266
267 (r5, r4) = byteunpack r1:0 || r0 = [i0++];
268 a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
269 a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
270 (r5, r4) = byteunpack r1:0(r) || r1 = [i0++];
271 a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
272 a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
273 (r5, r4) = byteunpack r1:0 || r0 = [i0++M0];
274 a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
275 a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
276 (r5, r4) = byteunpack r1:0(r) || r0 = [i0++];
277 a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
278 _pix_norm1_blkfn_loopEnd:
279 a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
280
281
282 // Clean up at the end:
283 R2 = A0, R3 = A1;
284 R0 = R2 + R3 (S);
285
286 (R7:4,P5:3)=[SP++];
287
288 RTS;
289 DEFUN_END(pix_norm1)
290
291 DEFUN(sse4,mL1,
292 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
293 link 0;
294 [--sp] = (r7:6);
295 p0=[fp+24]; // h
296 i0=r1; // pix1
297 i1=r2; // pix2
298 r2=[fp+20]; // line_size
299 r2+=-4;
300 m0=r2;
301
302 a0=a1=0;
303 LSETUP(.S40,.E40) LC0=P0;
304 DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
305
306 .S40: DISALGNEXCPT || R1 = [I0++M0] || R3 = [I1++M0];
307 (R7,R6) = BYTEOP16M (R1:0,R3:2);
308 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
309 .E40: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
310 a0 += a1;
311 r0 = a0;
312
313 (r7:6) = [sp++];
314 unlink;
315 rts;
316 DEFUN_END(sse4)
317
318 DEFUN(sse8,mL1,
319 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
320 link 0;
321 [--sp] = (r7:6);
322 p0=[fp+24]; // h
323 i0=r1; // pix1
324 i1=r2; // pix2
325 r2=[fp+20]; // line_size
326 r2+=-8;
327 m0=r2;
328
329 a0=a1=0;
330 LSETUP(.S80,.E80) LC0=P0;
331 DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
332
333 .S80: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
334 (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
335 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
336 a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
337 (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || R2 = [I1++];
338 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
339 .E80: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
340 a0 += a1;
341 r0 = a0;
342
343 (r7:6) = [sp++];
344 unlink;
345 rts;
346 DEFUN_END(sse8)
347
348 DEFUN(sse16,mL1,
349 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
350 link 0;
351 [--sp] = (r7:6);
352 p0=[fp+24]; // h
353 i0=r1; // pix1
354 i1=r2; // pix2
355 r2=[fp+20]; // line_size
356 r2+=-16;
357 m0=r2;
358
359 a0=a1=0;
360 DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
361 LSETUP(.S160,.E160) LC0=P0;
362
363 .S160: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
364 (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++] || R2 = [I1++];
365 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
366 a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
367 (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R1 = [I0++] || R3 = [I1++];
368 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
369 a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
370 (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
371 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
372 a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
373 (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || R2 = [I1++];
374 a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
375 .E160: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
376 a0 += a1;
377 r0 = a0;
378
379 (r7:6) = [sp++];
380 unlink;
381 rts;
382 DEFUN_END(sse16)