2 @ ARMv4L optimized DSP utils
3 @ Copyright (c) 2004 AGAWA Koji <i (AT) atty (DOT) jp>
5 @ This file is part of FFmpeg.
7 @ FFmpeg 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.
12 @ FFmpeg 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.
17 @ You should have received a copy of the GNU Lesser General Public
18 @ License along with FFmpeg; if not, write to the Free Software
19 @ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 .macro ADJ_ALIGN_QUADWORD_D shift, Rd0, Rd1, Rd2, Rd3, Rn0, Rn1, Rn2, Rn3, Rn4
30 mov \Rd0, \Rn0, lsr #(\shift * 8)
31 mov \Rd1, \Rn1, lsr #(\shift * 8)
32 mov \Rd2, \Rn2, lsr #(\shift * 8)
33 mov \Rd3, \Rn3, lsr #(\shift * 8)
34 orr \Rd0, \Rd0, \Rn1, lsl #(32 - \shift * 8)
35 orr \Rd1, \Rd1, \Rn2, lsl #(32 - \shift * 8)
36 orr \Rd2, \Rd2, \Rn3, lsl #(32 - \shift * 8)
37 orr \Rd3, \Rd3, \Rn4, lsl #(32 - \shift * 8)
39 .macro ADJ_ALIGN_DOUBLEWORD shift, R0, R1, R2
40 mov \R0, \R0, lsr #(\shift * 8)
41 orr \R0, \R0, \R1, lsl #(32 - \shift * 8)
42 mov \R1, \R1, lsr #(\shift * 8)
43 orr \R1, \R1, \R2, lsl #(32 - \shift * 8)
45 .macro ADJ_ALIGN_DOUBLEWORD_D shift, Rdst0, Rdst1, Rsrc0, Rsrc1, Rsrc2
46 mov \Rdst0, \Rsrc0, lsr #(\shift * 8)
47 mov \Rdst1, \Rsrc1, lsr #(\shift * 8)
48 orr \Rdst0, \Rdst0, \Rsrc1, lsl #(32 - (\shift * 8))
49 orr \Rdst1, \Rdst1, \Rsrc2, lsl #(32 - (\shift * 8))
52 .macro RND_AVG32 Rd0, Rd1, Rn0, Rn1, Rm0, Rm1, Rmask
53 @ Rd = (Rn | Rm) - (((Rn ^ Rm) & ~0x01010101) >> 1)
60 and \Rd0, \Rd0, \Rmask
61 and \Rd1, \Rd1, \Rmask
62 sub \Rd0, \Rn0, \Rd0, lsr #1
63 sub \Rd1, \Rn1, \Rd1, lsr #1
66 .macro NO_RND_AVG32 Rd0, Rd1, Rn0, Rn1, Rm0, Rm1, Rmask
67 @ Rd = (Rn & Rm) - (((Rn ^ Rm) & ~0x01010101) >> 1)
74 and \Rd0, \Rd0, \Rmask
75 and \Rd1, \Rd1, \Rmask
76 add \Rd0, \Rn0, \Rd0, lsr #1
77 add \Rd1, \Rn1, \Rd1, lsr #1
80 @ ----------------------------------------------------------------
82 .global put_pixels16_arm
84 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
85 @ block = word aligned, pixles = unaligned
87 stmfd sp!, {r4-r11, lr} @ R14 is also called LR
91 add r5, r5, r4, lsl #2
101 ldmfd sp!, {r4-r11, pc}
106 ADJ_ALIGN_QUADWORD_D 1, r9, r10, r11, r12, r4, r5, r6, r7, r8
112 ldmfd sp!, {r4-r11, pc}
117 ADJ_ALIGN_QUADWORD_D 2, r9, r10, r11, r12, r4, r5, r6, r7, r8
123 ldmfd sp!, {r4-r11, pc}
128 ADJ_ALIGN_QUADWORD_D 3, r9, r10, r11, r12, r4, r5, r6, r7, r8
134 ldmfd sp!, {r4-r11,pc}
142 @ ----------------------------------------------------------------
144 .global put_pixels8_arm
146 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
147 @ block = word aligned, pixles = unaligned
149 stmfd sp!, {r4-r5,lr} @ R14 is also called LR
153 add r5, r5, r4, lsl #2
163 ldmfd sp!, {r4-r5,pc}
166 ldmia r1, {r4-r5, r12}
168 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r12
174 ldmfd sp!, {r4-r5,pc}
177 ldmia r1, {r4-r5, r12}
179 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r12
185 ldmfd sp!, {r4-r5,pc}
188 ldmia r1, {r4-r5, r12}
190 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r12
196 ldmfd sp!, {r4-r5,pc}
204 @ ----------------------------------------------------------------
206 .global put_pixels8_x2_arm
208 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
209 @ block = word aligned, pixles = unaligned
211 stmfd sp!, {r4-r10,lr} @ R14 is also called LR
215 add r5, r5, r4, lsl #2
219 ldmia r1, {r4-r5, r10}
221 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
223 RND_AVG32 r8, r9, r4, r5, r6, r7, r12
228 ldmfd sp!, {r4-r10,pc}
231 ldmia r1, {r4-r5, r10}
233 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
234 ADJ_ALIGN_DOUBLEWORD_D 2, r8, r9, r4, r5, r10
236 RND_AVG32 r4, r5, r6, r7, r8, r9, r12
241 ldmfd sp!, {r4-r10,pc}
244 ldmia r1, {r4-r5, r10}
246 ADJ_ALIGN_DOUBLEWORD_D 2, r6, r7, r4, r5, r10
247 ADJ_ALIGN_DOUBLEWORD_D 3, r8, r9, r4, r5, r10
249 RND_AVG32 r4, r5, r6, r7, r8, r9, r12
254 ldmfd sp!, {r4-r10,pc}
257 ldmia r1, {r4-r5, r10}
259 ADJ_ALIGN_DOUBLEWORD_D 3, r6, r7, r4, r5, r10
261 RND_AVG32 r8, r9, r6, r7, r5, r10, r12
266 ldmfd sp!, {r4-r10,pc} @@ update PC with LR content.
275 .global put_no_rnd_pixels8_x2_arm
276 put_no_rnd_pixels8_x2_arm:
277 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
278 @ block = word aligned, pixles = unaligned
280 stmfd sp!, {r4-r10,lr} @ R14 is also called LR
284 add r5, r5, r4, lsl #2
288 ldmia r1, {r4-r5, r10}
290 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
292 NO_RND_AVG32 r8, r9, r4, r5, r6, r7, r12
297 ldmfd sp!, {r4-r10,pc}
300 ldmia r1, {r4-r5, r10}
302 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
303 ADJ_ALIGN_DOUBLEWORD_D 2, r8, r9, r4, r5, r10
305 NO_RND_AVG32 r4, r5, r6, r7, r8, r9, r12
310 ldmfd sp!, {r4-r10,pc}
313 ldmia r1, {r4-r5, r10}
315 ADJ_ALIGN_DOUBLEWORD_D 2, r6, r7, r4, r5, r10
316 ADJ_ALIGN_DOUBLEWORD_D 3, r8, r9, r4, r5, r10
318 NO_RND_AVG32 r4, r5, r6, r7, r8, r9, r12
323 ldmfd sp!, {r4-r10,pc}
326 ldmia r1, {r4-r5, r10}
328 ADJ_ALIGN_DOUBLEWORD_D 3, r6, r7, r4, r5, r10
330 NO_RND_AVG32 r8, r9, r6, r7, r5, r10, r12
335 ldmfd sp!, {r4-r10,pc} @@ update PC with LR content.
344 @ ----------------------------------------------------------------
346 .global put_pixels8_y2_arm
348 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
349 @ block = word aligned, pixles = unaligned
351 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
356 add r5, r5, r4, lsl #2
365 RND_AVG32 r8, r9, r4, r5, r6, r7, r12
371 RND_AVG32 r8, r9, r6, r7, r4, r5, r12
376 ldmfd sp!, {r4-r11,pc}
382 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
386 ADJ_ALIGN_DOUBLEWORD 1, r7, r8, r9
387 RND_AVG32 r10, r11, r4, r5, r7, r8, r12
393 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
395 RND_AVG32 r10, r11, r7, r8, r4, r5, r12
399 ldmfd sp!, {r4-r11,pc}
405 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
409 ADJ_ALIGN_DOUBLEWORD 2, r7, r8, r9
410 RND_AVG32 r10, r11, r4, r5, r7, r8, r12
416 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
418 RND_AVG32 r10, r11, r7, r8, r4, r5, r12
422 ldmfd sp!, {r4-r11,pc}
428 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
432 ADJ_ALIGN_DOUBLEWORD 3, r7, r8, r9
433 RND_AVG32 r10, r11, r4, r5, r7, r8, r12
439 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
441 RND_AVG32 r10, r11, r7, r8, r4, r5, r12
445 ldmfd sp!, {r4-r11,pc}
455 .global put_no_rnd_pixels8_y2_arm
456 put_no_rnd_pixels8_y2_arm:
457 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
458 @ block = word aligned, pixles = unaligned
460 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
465 add r5, r5, r4, lsl #2
474 NO_RND_AVG32 r8, r9, r4, r5, r6, r7, r12
480 NO_RND_AVG32 r8, r9, r6, r7, r4, r5, r12
485 ldmfd sp!, {r4-r11,pc}
491 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
495 ADJ_ALIGN_DOUBLEWORD 1, r7, r8, r9
496 NO_RND_AVG32 r10, r11, r4, r5, r7, r8, r12
502 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
504 NO_RND_AVG32 r10, r11, r7, r8, r4, r5, r12
508 ldmfd sp!, {r4-r11,pc}
514 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
518 ADJ_ALIGN_DOUBLEWORD 2, r7, r8, r9
519 NO_RND_AVG32 r10, r11, r4, r5, r7, r8, r12
525 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
527 NO_RND_AVG32 r10, r11, r7, r8, r4, r5, r12
531 ldmfd sp!, {r4-r11,pc}
537 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
541 ADJ_ALIGN_DOUBLEWORD 3, r7, r8, r9
542 NO_RND_AVG32 r10, r11, r4, r5, r7, r8, r12
548 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
550 NO_RND_AVG32 r10, r11, r7, r8, r4, r5, r12
554 ldmfd sp!, {r4-r11,pc}
562 @ ----------------------------------------------------------------
563 .macro RND_XY2_IT align
564 @ l1= (a & 0x03030303) + (b & 0x03030303) ?(+ 0x02020202)
565 @ h1= ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2)
576 ADJ_ALIGN_DOUBLEWORD_D 1, r4, r5, r6, r7, r8
578 ADJ_ALIGN_DOUBLEWORD_D 1, r4, r5, r8, r9, r10
579 ADJ_ALIGN_DOUBLEWORD_D 2, r6, r7, r8, r9, r10
581 ADJ_ALIGN_DOUBLEWORD_D 2, r4, r5, r8, r9, r10
582 ADJ_ALIGN_DOUBLEWORD_D 3, r6, r7, r8, r9, r10
584 ADJ_ALIGN_DOUBLEWORD_D 3, r4, r5, r5, r6, r7
586 ldr r14, [r12, #0] @ 0x03030303
592 ldreq r14, [r12, #16] @ 0x02020202/0x01010101
597 ldr r14, [r12, #20] @ 0xFCFCFCFC >> 2
598 and r4, r14, r4, lsr #2
599 and r5, r14, r5, lsr #2
600 and r6, r14, r6, lsr #2
601 and r7, r14, r7, lsr #2
607 .macro RND_XY2_EXPAND align
609 6: stmfd sp!, {r8-r11}
616 ldr r14, [r12, #24] @ 0x0F0F0F0F
617 and r4, r14, r4, lsr #2
618 and r5, r14, r5, lsr #2
624 ldmfd sp!, {r4-r11,pc}
628 .global put_pixels8_xy2_arm
630 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
631 @ block = word aligned, pixles = unaligned
633 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
636 add r5, r12, r4, lsl #2
660 .word 0xFCFCFCFC >> 2
664 .global put_no_rnd_pixels8_xy2_arm
665 put_no_rnd_pixels8_xy2_arm:
666 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
667 @ block = word aligned, pixles = unaligned
669 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
672 add r5, r12, r4, lsl #2
696 .word 0xFCFCFCFC >> 2