arm: hpeldsp: Move half-pel assembly from dsputil to hpeldsp
[ffmpeg.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 #include "config_bfin.h"
22
23 DEFUN(put_pixels_clamped,mL1,
24         (int16_t *block, uint8_t *dest, int line_size)):
25     [--SP] = (R7:4);
26     R4 = 0;
27     R5.l = 0x00ff;
28     R5.h = 0x00ff;
29     I0 = R0;         // block
30     I1 = R1;         // dest
31     R2 += -4;        // line_size
32     M1 = R2;
33     P0 = 8;
34     R0 = [I0++];
35     R1 = [I0++];
36     R2 = MAX(R0, R4) (V);
37     LSETUP (ppc$0,ppc$1) LC0=P0;
38 ppc$0: R2 = MIN(R2, R5) (V);
39        R3 = MAX(R1, R4) (V);
40        R3 = MIN(R3, R5) (V)      || R0 = [I0++];
41        R6 = BYTEPACK (R2,R3)     || R1 = [I0++];
42        R2 = MAX(R0, R4) (V)      || [I1++] = R6;
43        R2 = MIN(R2, R5) (V);
44        R3 = MAX(R1, R4) (V);
45        R3 = MIN(R3, R5) (V)      || R0 = [I0++];
46        R6 = BYTEPACK (R2,R3)     || R1 = [I0++];
47 ppc$1: R2 = Max(R0, R4) (V)      || [I1++M1] = R6;
48
49     (R7:4) = [SP++];
50     RTS;
51 DEFUN_END(put_pixels_clamped)
52
53 DEFUN(add_pixels_clamped,mL1,
54         (int16_t *block, uint8_t *dest, int line_size)):
55     [-- SP] = (R7:4);
56     R4 = 0;
57     I0 = 0;
58     R2 += -4;        // line_size
59     M0 = R2;
60     I1 = R1;         // dest
61     I3 = R0;         // block
62     I2 = R1;         // dest
63     P0 = 8;
64     M3 = 2;
65     R0 = [I3++]  || R2 = [I1];
66     R2 = R2 << 8                      || R0.H = W[I3--]  || R3 = [I1++];
67     R3 = R3 >> 8                      || R1.L = W[I3]    || I3 += 4;
68     R6 = BYTEOP3P(R1:0, R3:2) (LO)    || R1.H = W[I3++]  || R2 = [I1];
69
70     LSETUP(apc$2,apc$3) LC1 = P0;
71 apc$2: R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++]     || R3 = [I1++M0];
72        R2 = R2 << 8                      || R0.H = W[I3--];
73        R3 = R3 >> 8                      || R1.L = W[I3]    || I3 += 4;
74        R6 = R6 + R7 (S)                  || R1.H = W[I3];
75        R6 = BYTEOP3P(R1:0, R3:2) (LO)    || I3+=M3          || [I2++]=R6;
76        R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++]     || R2 = [I1];
77        R2 = R2 << 8                      || R0.H = W[I3--]  || R3 = [I1++];
78        R3 = R3 >> 8                      || R1.L = W[I3]    || I3 += 4;
79        R6 = R6 + R7 (S)                  || R1.H = W[I3++];
80 apc$3: R6 = BYTEOP3P(R1:0, R3:2) (LO)    || [I2++M0] = R6   || R2 = [I1];
81
82     (R7:4) = [SP++];
83     RTS;
84 DEFUN_END(add_pixels_clamped)
85
86
87 /*
88   motion compensation
89   primitives
90
91      * Halfpel motion compensation with rounding (a+b+1)>>1.
92      * This is an array[4][4] of motion compensation funcions for 4
93      * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
94      * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
95      * @param block destination where the result is stored
96      * @param pixels source
97      * @param line_size number of bytes in a horizontal line of block
98      * @param h height
99
100 */
101
102 DEFUN(put_pixels8uc,mL1,
103         (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
104                  int dest_size, int line_size, int h)):
105         i3=r0;        // dest
106         i0=r1;        // src0
107         i1=r2;        // src1
108         r0=[sp+12];   // dest_size
109         r2=[sp+16];   // line_size
110         p0=[sp+20];   // h
111         [--sp] = (r7:6);
112         r0+=-4;
113         m3=r0;
114         r2+=-8;
115         m0=r2;
116         LSETUP(pp8$0,pp8$1) LC0=P0;
117         DISALGNEXCPT                || R0 = [I0++]  || R2  =[I1++];
118
119 pp8$0:  DISALGNEXCPT                || R1 = [I0++]  || R3  =[I1++];
120         R6 = BYTEOP1P(R1:0,R3:2)    || R0 = [I0++M0]|| R2  =[I1++M0];
121         R7 = BYTEOP1P(R1:0,R3:2)(R) || R0 = [I0++]  || [I3++] = R6 ;
122 pp8$1:  DISALGNEXCPT                || R2 = [I1++]  || [I3++M3] = R7;
123
124         (r7:6) = [sp++];
125         RTS;
126 DEFUN_END(put_pixels8uc)
127
128 DEFUN(put_pixels16uc,mL1,
129         (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
130                  int dest_size, int line_size, int h)):
131         link 0;
132         [--sp] = (r7:6);
133         i3=r0;        // dest
134         i0=r1;        // src0
135         i1=r2;        // src1
136         r0=[fp+20];   // dest_size
137         r2=[fp+24];   // line_size
138         p0=[fp+28];   // h
139
140
141         r0+=-12;
142         m3=r0;        // line_size
143         r2+=-16;
144         m0=r2;
145
146         LSETUP(pp16$0,pp16$1) LC0=P0;
147          DISALGNEXCPT                || R0 = [I0++]   || R2  =[I1++];
148
149 pp16$0:  DISALGNEXCPT                || R1 = [I0++]   || R3  =[I1++];
150          R6 = BYTEOP1P(R1:0,R3:2)    || R0 = [I0++]   || R2  =[I1++];
151          R7 = BYTEOP1P(R1:0,R3:2)(R) || R1 = [I0++]   || R3  =[I1++];
152          [I3++] = R6;
153          R6 = BYTEOP1P(R1:0,R3:2)    || R0 = [I0++M0] || R2  =[I1++M0];
154          R7 = BYTEOP1P(R1:0,R3:2)(R) || R0 = [I0++]   || [I3++] = R7 ;
155          [I3++] = R6;
156 pp16$1:  DISALGNEXCPT                || R2 = [I1++]   || [I3++M3] = R7;
157
158         (r7:6) = [sp++];
159         unlink;
160         RTS;
161 DEFUN_END(put_pixels16uc)
162
163
164
165
166
167
168 DEFUN(put_pixels8uc_nornd,mL1,
169         (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
170                  int line_size, int h)):
171         i3=r0;        // dest
172         i0=r1;        // src0
173         i1=r2;        // src1
174         r2=[sp+12];   // line_size
175         p0=[sp+16];   // h
176         [--sp] = (r7:6);
177         r2+=-4;
178         m3=r2;
179         r2+=-4;
180         m0=r2;
181         LSETUP(pp8$2,pp8$3) LC0=P0;
182         DISALGNEXCPT                || R0 = [I0++]  || R2  =[I1++];
183
184 pp8$2:  DISALGNEXCPT                || R1 = [I0++]  || R3  =[I1++];
185         R6 = BYTEOP1P(R1:0,R3:2)(T)  || R0 = [I0++M0]|| R2  =[I1++M0];
186         R7 = BYTEOP1P(R1:0,R3:2)(T,R) || R0 = [I0++]  || [I3++] = R6 ;
187 pp8$3:  DISALGNEXCPT                || R2 = [I1++]  || [I3++M3] = R7;
188
189         (r7:6) = [sp++];
190         RTS;
191 DEFUN_END(put_pixels8uc_nornd)
192
193 DEFUN(put_pixels16uc_nornd,mL1,
194         (uint8_t *block, const uint8_t *s0, const uint8_t *s1,
195                  int line_size, int h)):
196         i3=r0;        // dest
197         i0=r1;        // src0
198         i1=r2;        // src1
199         r2=[sp+12];   // line_size
200         p0=[sp+16];   // h
201
202         [--sp] = (r7:6);
203         r2+=-12;
204         m3=r2;        // line_size
205         r2+=-4;
206         m0=r2;
207
208         LSETUP(pp16$2,pp16$3) LC0=P0;
209         DISALGNEXCPT                || R0 = [I0++]   || R2  =[I1++];
210
211 pp16$2:
212         DISALGNEXCPT                || R1 = [I0++]   || R3  =[I1++];
213         R6 = BYTEOP1P(R1:0,R3:2)(T)    || R0 = [I0++]   || R2  =[I1++];
214         R7 = BYTEOP1P(R1:0,R3:2)(T,R) || R1 = [I0++]   || R3  =[I1++];
215         [I3++] = R6;
216
217         R6 = BYTEOP1P(R1:0,R3:2)(T)    || R0 = [I0++M0] || R2  =[I1++M0];
218         R7 = BYTEOP1P(R1:0,R3:2)(T,R) || R0 = [I0++]   || [I3++] = R7 ;
219         [I3++] = R6;
220 pp16$3: DISALGNEXCPT                || R2 = [I1++]   || [I3++M3] = R7;
221
222         (r7:6) = [sp++];
223
224         RTS;
225 DEFUN_END(put_pixels16uc_nornd)
226
227 DEFUN(z_put_pixels16_xy2,mL1,
228         (uint8_t *block, const uint8_t *s0,
229                  int dest_size, int line_size, int h)):
230         link 0;
231         [--sp] = (r7:4);
232         i3=r0;        // dest
233         i0=r1;        // src0--> pixels
234         i1=r1;        // src1--> pixels + line_size
235         r2+=-12;
236         m2=r2;        // m2=dest_width-4
237         r2=[fp+20];
238         m3=r2;        // line_size
239         p0=[fp+24];   // h
240         r2+=-16;
241         i1+=m3;       /* src1 + line_size */
242         m0=r2;        /* line-size - 20 */
243
244         B0 = I0;
245         B1 = I1;
246         B3 = I3;
247
248         DISALGNEXCPT                       || R0 = [I0++] || R2  =[I1++];
249
250         LSETUP(LS$16E,LE$16E) LC0=P0;
251 LS$16E: DISALGNEXCPT                       || R1 = [I0++] || R3  =[I1++];
252         R4 = BYTEOP2P (R3:2,R1:0) (RNDL)   || R0 = [I0++] || R2  =[I1++];
253         R5 = BYTEOP2P (R3:2,R1:0) (RNDL,R) || R1 = [I0++] || [I3++] = R4 ;
254         DISALGNEXCPT                       || R3 = [I1++] || [I3++] = R5;
255         R4 = BYTEOP2P (R3:2,R1:0) (RNDL)   || R0 = [I0++M0]|| R2  = [I1++M0];
256         R5 = BYTEOP2P (R3:2,R1:0) (RNDL,R) || R0 = [I0++] || [I3++] = R4 ;
257 LE$16E: DISALGNEXCPT                       || R2 = [I1++] || [I3++M2] = R5;
258
259         M1 = 1;
260         I3 = B3;
261         I1 = B1;
262         I0 = B0;
263
264         I0 += M1;
265         I1 += M1;
266
267         DISALGNEXCPT                       || R0 = [I0++] || R2  =[I1++];
268         LSETUP(LS$16O,LE$16O) LC0=P0;
269 LS$16O: DISALGNEXCPT                       || R1 = [I0++] || R3  =[I1++];
270         R4 = BYTEOP2P (R3:2,R1:0) (RNDH)   || R0 = [I0++] || R2  =[I1++];
271         R5 = BYTEOP2P (R3:2,R1:0) (RNDH,R) || R1 = [I0++] || R6  =[I3++];
272         R4 = R4 +|+ R6                       || R7 = [I3--];
273         R5 = R5 +|+ R7                       || [I3++] = R4;
274         DISALGNEXCPT                       || R3  =[I1++] || [I3++] = R5;
275         R4 = BYTEOP2P (R3:2,R1:0) (RNDH)   || R0 = [I0++M0]|| R2  = [I1++M0];
276         R5 = BYTEOP2P (R3:2,R1:0) (RNDH,R) || R0 = [I0++] || R6 = [I3++];
277         R4 = R4 +|+ R6                       || R7 = [I3--];
278         R5 = R5 +|+ R7                       || [I3++] = R4;
279 LE$16O: DISALGNEXCPT                       || R2 = [I1++] || [I3++M2] = R5;
280
281         (r7:4) = [sp++];
282         unlink;
283         rts;
284 DEFUN_END(z_put_pixels16_xy2)
285
286 DEFUN(put_pixels16_xy2_nornd,mL1,
287         (uint8_t *block, const uint8_t *s0,
288                  int line_size, int h)):
289         link 0;
290         [--sp] = (r7:4);
291         i3=r0;        // dest
292         i0=r1;        // src0--> pixels
293         i1=r1;        // src1--> pixels + line_size
294         m3=r2;
295         r2+=-12;
296         m2=r2;
297         r2+=-4;
298         i1+=m3;       /* src1 + line_size */
299         m0=r2;        /* line-size - 20 */
300         p0=[fp+20];   // h
301
302         B0=I0;
303         B1=I1;
304         B3=I3;
305
306         DISALGNEXCPT                       || R0 = [I0++] || R2  =[I1++];
307
308         LSETUP(LS$16ET,LE$16ET) LC0=P0;
309 LS$16ET:DISALGNEXCPT                       || R1 = [I0++] || R3  =[I1++];
310         R4 = BYTEOP2P (R3:2,R1:0) (TL)     || R0 = [I0++] || R2  =[I1++];
311         R5 = BYTEOP2P (R3:2,R1:0) (TL,R)   || R1 = [I0++] || [I3++] = R4 ;
312         DISALGNEXCPT                       || R3 = [I1++] || [I3++] = R5;
313         R4 = BYTEOP2P (R3:2,R1:0) (TL)     || R0 = [I0++M0]|| R2  = [I1++M0];
314         R5 = BYTEOP2P (R3:2,R1:0) (TL,R)   || R0 = [I0++] || [I3++] = R4 ;
315 LE$16ET:DISALGNEXCPT                       || R2 = [I1++] || [I3++M2] = R5;
316
317         M1 = 1;
318         I3=B3;
319         I1=B1;
320         I0=B0;
321
322         I0 += M1;
323         I1 += M1;
324
325         DISALGNEXCPT                       || R0 = [I0++] || R2  =[I1++];
326         LSETUP(LS$16OT,LE$16OT) LC0=P0;
327 LS$16OT:DISALGNEXCPT                       || R1 = [I0++] || R3  =[I1++];
328         R4 = BYTEOP2P (R3:2,R1:0) (TH)     || R0 = [I0++] || R2  =[I1++];
329         R5 = BYTEOP2P (R3:2,R1:0) (TH,R)   || R1 = [I0++] || R6  =[I3++];
330         R4 = R4 +|+ R6                                    || R7 = [I3--];
331         R5 = R5 +|+ R7                                    || [I3++] = R4;
332         DISALGNEXCPT                       || R3  =[I1++] || [I3++] = R5;
333         R4 = BYTEOP2P (R3:2,R1:0) (TH)     || R0 = [I0++M0]|| R2  = [I1++M0];
334         R5 = BYTEOP2P (R3:2,R1:0) (TH,R)   || R0 = [I0++] || R6 = [I3++];
335         R4 = R4 +|+ R6                                    || R7 = [I3--];
336         R5 = R5 +|+ R7                                    || [I3++] = R4;
337 LE$16OT:DISALGNEXCPT                       || R2 = [I1++] || [I3++M2] = R5;
338
339         (r7:4) = [sp++];
340         unlink;
341         rts;
342 DEFUN_END(put_pixels16_xy2_nornd)
343
344 DEFUN(z_put_pixels8_xy2,mL1,
345         (uint8_t *block, const uint8_t *s0,
346                  int dest_size, int line_size, int h)):
347         link 0;
348         [--sp] = (r7:4);
349         i3=r0;        // dest
350         i0=r1;        // src0--> pixels
351         i1=r1;        // src1--> pixels + line_size
352         r2+=-4;
353         m2=r2;        // m2=dest_width-4
354         r2=[fp+20];
355         m3=r2;        // line_size
356         p0=[fp+24];   // h
357         r2+=-8;
358         i1+=m3;       /* src1 + line_size */
359         m0=r2;        /* line-size - 20 */
360
361         b0 = I0;
362         b1 = I1;
363         b3 = I3;
364
365         LSETUP(LS$8E,LE$8E) LC0=P0;
366         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
367 LS$8E:  DISALGNEXCPT                       || R1 = [I0++]   || R3  =[I1++];
368         R4 = BYTEOP2P (R3:2,R1:0) (RNDL)   || R0 = [I0++M0] || R2  =[I1++M0];
369         R5 = BYTEOP2P (R3:2,R1:0) (RNDL,R) || R0 = [I0++]   || [I3++] = R4 ;
370 LE$8E:  DISALGNEXCPT                       || R2 = [I1++]   || [I3++M2] = R5;
371
372         M1 = 1;
373         I3 = b3;
374         I1 = b1;
375         I0 = b0;
376
377         I0 += M1;
378         I1 += M1;
379
380         LSETUP(LS$8O,LE$8O) LC0=P0;
381         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
382 LS$8O:  DISALGNEXCPT                       || R1 = [I0++]   || R3  =[I1++];
383         R4 = BYTEOP2P (R3:2,R1:0) (RNDH)   || R0 = [I0++M0] || R2  =[I1++M0];
384         R5 = BYTEOP2P (R3:2,R1:0) (RNDH,R) || R0 = [I0++]   || R6  =[I3++];
385         R4 = R4 +|+ R6                                      || R7 = [I3--];
386         R5 = R5 +|+ R7                                      || [I3++] = R4;
387 LE$8O:  DISALGNEXCPT                       || R2  =[I1++]   || [I3++M2] = R5;
388
389         (r7:4) = [sp++];
390         unlink;
391         rts;
392 DEFUN_END(z_put_pixels8_xy2)
393
394 DEFUN(put_pixels8_xy2_nornd,mL1,
395         (uint8_t *block, const uint8_t *s0, int line_size, int h)):
396         link 0;
397         [--sp] = (r7:4);
398         i3=r0;        // dest
399         i0=r1;        // src0--> pixels
400         i1=r1;        // src1--> pixels + line_size
401         m3=r2;
402         r2+=-4;
403         m2=r2;
404         r2+=-4;
405         i1+=m3;       /* src1 + line_size */
406         m0=r2;        /* line-size - 20 */
407         p0=[fp+20];   // h
408
409
410         b0 = I0;
411         b1 = I1;
412         b3 = I3;
413
414         LSETUP(LS$8ET,LE$8ET) LC0=P0;
415         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
416
417 LS$8ET: DISALGNEXCPT                       || R1 = [I0++]   || R3 = [I1++];
418         R4 = BYTEOP2P (R3:2,R1:0) (TL)     || R0 = [I0++M0] || R2 = [I1++M0];
419         R5 = BYTEOP2P (R3:2,R1:0) (TL,R)   || R0 = [I0++]   || [I3++] = R4 ;
420 LE$8ET: DISALGNEXCPT                       || R2 = [I1++]   || [I3++M2] = R5;
421
422         M1 = 1;
423         I3 = b3;
424         I1 = b1;
425         I0 = b0;
426
427         I0 += M1;
428         I1 += M1;
429
430         LSETUP(LS$8OT,LE$8OT) LC0=P0;
431         DISALGNEXCPT                       || R0 = [I0++]   || R2 = [I1++];
432
433 LS$8OT: DISALGNEXCPT                       || R1 = [I0++]   || R3 = [I1++];
434         R4 = BYTEOP2P (R3:2,R1:0) (TH)     || R0 = [I0++M0] || R2 = [I1++M0];
435         R5 = BYTEOP2P (R3:2,R1:0) (TH,R)   || R0 = [I0++]   || R6 = [I3++];
436         R4 = R4 +|+ R6                                      || R7 = [I3--];
437         R5 = R5 +|+ R7                                      || [I3++] = R4;
438 LE$8OT: DISALGNEXCPT                       || R2  =[I1++]   || [I3++M2] = R5;
439
440         (r7:4) = [sp++];
441         unlink;
442         rts;
443 DEFUN_END(put_pixels8_xy2_nornd)
444
445 DEFUN(diff_pixels,mL1,
446        (int16_t *block, uint8_t *s1, uint8_t *s2, int stride)):
447         link 0;
448         [--sp] = (r7:4);
449         p0=8;
450         i3=r0;        // block
451         i0=r1;        // s1
452         i1=r2;        // s2
453         r2=[fp+20];   // stride
454         r2+=-8;
455         m0=r2;
456
457
458         LSETUP(.LS0,.LE0) LC0=P0;
459         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
460
461 .LS0:   DISALGNEXCPT                       || R1 = [I0++]   || R3 = [I1++];
462         (R5,R4) = BYTEOP16M (R1:0,R3:2)    || R0 = [I0++M0] || R2 = [I1++M0];
463         (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++]   || [I3++] = R4;
464         DISALGNEXCPT                       || R2 = [I1++]   || [I3++] = R5;
465         [i3++]=r6;
466 .LE0:  [i3++]=r7;
467
468         (r7:4) = [sp++];
469         unlink;
470         rts;
471 DEFUN_END(diff_pixels)
472
473 /*
474     for (i = 0; i < 16; i++) {
475         for (j = 0; j < 16; j++) {
476           sum += pix[j];
477         }
478         pix += line_size;
479     }
480 */
481 DEFUN(pix_sum,mL1,
482         (uint8_t *p, int stride)):
483         link 0;
484         [--sp] = (r7:4);
485         p0=8;
486         i0=r0;        // s1
487         i1=r0;
488         m1=r1;
489         r1=r1+r1;
490         r1+=-16;       // stride
491         m0=r1;
492         i1+=m1;
493
494         r6=0;
495
496         LSETUP(LS$PS,LE$PS) LC0=P0;
497         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
498
499 LS$PS:  DISALGNEXCPT                       || R1 = [I0++]   || R3 = [I1++];
500         (R5,R4) = BYTEOP16P (R3:2,R1:0)    || R0 = [I0++]   || R2 = [I1++];
501         r6=r6+|+r5;
502         r6=r6+|+r4;
503         (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R1 = [I0++]   || R3 = [I1++];
504         r6=r6+|+r5;
505         r6=r6+|+r4;
506         (R5,R4) = BYTEOP16P (R3:2,R1:0)    || R0 = [I0++m0] || R2 = [I1++m0];
507         r6=r6+|+r5;
508         r6=r6+|+r4;
509         (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R0 = [I0++]   || R2 = [I1++];
510         r6=r6+|+r5;
511 LE$PS:  r6=r6+|+r4;
512         r0.l=r6.l+r6.h;
513         r0.h=0;
514
515         (r7:4) = [sp++];
516         unlink;
517         rts;
518 DEFUN_END(pix_sum)
519
520
521 DEFUN(get_pixels,mL1,
522         (int16_t *restrict block, const uint8_t *pixels, int line_size)):
523         [--sp] = (r7:4);
524         i3=r0;        // dest
525         i0=r1;        // src0
526         p0=8;
527         r2+=-8;
528         m0=r2;
529         LSETUP(gp8$0,gp8$1) LC0=P0;
530
531         DISALGNEXCPT                   || R0 = [I0++];
532         DISALGNEXCPT                   || R1 = [I0++];
533
534 gp8$0:  (R7,R6) = byteunpack R1:0      || R0 = [I0++M0];
535         (R5,R4) = byteunpack R1:0 (R)  || R0 = [I0++]    || [I3++]=R6;
536         DISALGNEXCPT                   || R1 = [I0++]    || [I3++]=R7;
537         [I3++]=R4;
538 gp8$1:  [I3++]=R5
539
540
541         (r7:4) = [sp++];
542         RTS;
543 DEFUN_END(get_pixels)
544
545
546 /* sad = sad16x16 (ubyte *mb, ubyte *refwin, srcwidth, refwinwidth, h) */
547 /* 91 cycles */
548 DEFUN(z_sad16x16,mL1,
549         (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
550         link 0;
551         I0 = R0;
552         I1 = R1;
553
554         A1 = A0 = 0;
555         R0 = [sp+20]; // rwidth
556         P2 = [sp+24]; // height
557         R3 = 16;
558         R0 = R0 - R3;
559         R3 = R2 - R3;
560         M1 = R0;
561         M0 = R3;
562
563         DISALGNEXCPT         || R0 = [I0++]    || R2 = [I1++];
564         LSETUP (s$16, e$16) LC0=P2;
565 s$16:   DISALGNEXCPT         || R1 = [I0++]    || R3 = [I1++];
566         SAA (R1:0,R3:2)      || R0 = [I0++]    || R2 = [I1++];
567         SAA (R1:0,R3:2) (R)  || R1 = [I0++]    || R3 = [I1++];
568         SAA (R1:0,R3:2)      || R0 = [I0++M0]  || R2 = [I1++M1];
569 e$16:   SAA (R1:0,R3:2) (R)  || R0 = [I0++]    || R2 = [I1++];
570
571         R3=A1.L+A1.H,  R2=A0.L+A0.H ;
572         R0 = R2 + R3 ;
573         unlink;
574         RTS;
575 DEFUN_END(z_sad16x16)
576
577 /* sad = sad8x8 (ubyte *mb, ubyte *refwin, int srcwidth, int refwinwidth, int h) */
578 /* 36 cycles */
579 DEFUN(z_sad8x8,mL1,
580         (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
581         I0 = R0;
582         I1 = R1;
583
584         A1 = A0 = 0;
585         r0 = [sp+12]; // rwidth
586         P2 = [sp+16]; //height
587         R3 = 8;
588         R0 = R0 - R3;
589         R3 = R2 - R3;
590         M0 = R3;
591         M1 = R0;
592
593         LSETUP (s$8, e$8) LC0=P2;
594         DISALGNEXCPT         || R0 = [I0++]   || R2 = [I1++];
595         DISALGNEXCPT         || R1 = [I0++]   || R3 = [I1++];
596 s$8:    SAA (R1:0,R3:2)      || R0 = [I0++M0] || R2 = [I1++M1];
597         SAA (R1:0,R3:2) (R)  || R0 = [I0++]   || R2 = [I1++];
598 e$8:    DISALGNEXCPT         || R1 = [I0++]   || R3 = [I1++];
599
600         R3=A1.L+A1.H,  R2=A0.L+A0.H ;
601         R0 = R2 + R3 ;
602         RTS;
603 DEFUN_END(z_sad8x8)
604
605 DEFUN(pix_norm1,mL1,
606         (uint8_t * pix, int line_size)):
607         [--SP]=(R7:4,P5:3);
608
609         // Fetch the input arguments.
610         P1 = R0;  // pix
611         P0 = R1;  // line_size
612         P5 = 16;  // loop ctr.
613         P0 -= P5;
614         M0 = P0;  // M0 = line_size-16;
615         // Now for the real work.
616         A1 = A0 = 0;
617         lsetup(_pix_norm1_blkfn_loopStart, _pix_norm1_blkfn_loopEnd) LC1 = P5;
618         I0 = P1;
619         DISALGNEXCPT || r0 = [i0++];
620
621 _pix_norm1_blkfn_loopStart:
622         // following unpacks pix1[0..15] pix1+line_size[0..15]
623         DISALGNEXCPT || r1 = [i0++];
624
625         (r5, r4) = byteunpack r1:0 || r0 = [i0++];
626         a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
627         a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
628         (r5, r4) = byteunpack r1:0(r) || r1 = [i0++];
629         a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
630         a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
631         (r5, r4) = byteunpack r1:0 || r0 = [i0++M0];
632         a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
633         a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
634         (r5, r4) = byteunpack r1:0(r) || r0 = [i0++];
635         a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
636 _pix_norm1_blkfn_loopEnd:
637         a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
638
639
640 // Clean up at the end:
641         R2 = A0, R3 = A1;
642         R0 = R2 + R3 (S);
643
644         (R7:4,P5:3)=[SP++];
645
646         RTS;
647 DEFUN_END(pix_norm1)
648
649 DEFUN(sse4,mL1,
650         (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
651         link 0;
652         [--sp] = (r7:6);
653         p0=[fp+24];   // h
654         i0=r1;        // pix1
655         i1=r2;        // pix2
656         r2=[fp+20];   // line_size
657         r2+=-4;
658         m0=r2;
659
660         a0=a1=0;
661         LSETUP(.S40,.E40) LC0=P0;
662         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
663
664 .S40:   DISALGNEXCPT                       || R1 = [I0++M0] || R3 = [I1++M0];
665         (R7,R6) = BYTEOP16M (R1:0,R3:2);
666         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
667 .E40:   a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
668         a0 += a1;
669         r0 = a0;
670
671         (r7:6) = [sp++];
672         unlink;
673         rts;
674 DEFUN_END(sse4)
675
676 DEFUN(sse8,mL1,
677         (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
678         link 0;
679         [--sp] = (r7:6);
680         p0=[fp+24];   // h
681         i0=r1;        // pix1
682         i1=r2;        // pix2
683         r2=[fp+20];   // line_size
684         r2+=-8;
685         m0=r2;
686
687         a0=a1=0;
688         LSETUP(.S80,.E80) LC0=P0;
689         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
690
691 .S80:   DISALGNEXCPT                       || R1 = [I0++]   || R3 = [I1++];
692         (R7,R6) = BYTEOP16M (R1:0,R3:2)    || R0 = [I0++M0] || R2 = [I1++M0];
693         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
694         a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
695         (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++]   || R2 = [I1++];
696         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
697 .E80:   a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
698         a0 += a1;
699         r0 = a0;
700
701         (r7:6) = [sp++];
702         unlink;
703         rts;
704 DEFUN_END(sse8)
705
706 DEFUN(sse16,mL1,
707         (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
708         link 0;
709         [--sp] = (r7:6);
710         p0=[fp+24];   // h
711         i0=r1;        // pix1
712         i1=r2;        // pix2
713         r2=[fp+20];   // line_size
714         r2+=-16;
715         m0=r2;
716
717         a0=a1=0;
718         DISALGNEXCPT                       || R0 = [I0++]   || R2  =[I1++];
719         LSETUP(.S160,.E160) LC0=P0;
720
721 .S160:  DISALGNEXCPT                       || R1 = [I0++]   || R3 = [I1++];
722         (R7,R6) = BYTEOP16M (R1:0,R3:2)    || R0 = [I0++]   || R2 = [I1++];
723         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
724         a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
725         (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R1 = [I0++]   || R3 = [I1++];
726         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
727         a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
728         (R7,R6) = BYTEOP16M (R1:0,R3:2)    || R0 = [I0++M0] || R2 = [I1++M0];
729         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
730         a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
731         (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++]   || R2 = [I1++];
732         a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
733 .E160:  a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
734         a0 += a1;
735         r0 = a0;
736
737         (r7:6) = [sp++];
738         unlink;
739         rts;
740 DEFUN_END(sse16)