2 @ ARMv4L optimized DSP utils
3 @ Copyright (c) 2004 AGAWA Koji <i (AT) atty (DOT) jp>
5 @ This library is free software; you can redistribute it and/or
6 @ modify it under the terms of the GNU Lesser General Public
7 @ License as published by the Free Software Foundation; either
8 @ version 2 of the License, or (at your option) any later version.
10 @ This library is distributed in the hope that it will be useful,
11 @ but WITHOUT ANY WARRANTY; without even the implied warranty of
12 @ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 @ Lesser General Public License for more details.
15 @ You should have received a copy of the GNU Lesser General Public
16 @ License along with this library; if not, write to the Free Software
17 @ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 .macro ADJ_ALIGN_QUADWORD_D shift, Rd0, Rd1, Rd2, Rd3, Rn0, Rn1, Rn2, Rn3, Rn4
21 mov \Rd0, \Rn0, lsr #(\shift * 8)
22 mov \Rd1, \Rn1, lsr #(\shift * 8)
23 mov \Rd2, \Rn2, lsr #(\shift * 8)
24 mov \Rd3, \Rn3, lsr #(\shift * 8)
25 orr \Rd0, \Rd0, \Rn1, lsl #(32 - \shift * 8)
26 orr \Rd1, \Rd1, \Rn2, lsl #(32 - \shift * 8)
27 orr \Rd2, \Rd2, \Rn3, lsl #(32 - \shift * 8)
28 orr \Rd3, \Rd3, \Rn4, lsl #(32 - \shift * 8)
30 .macro ADJ_ALIGN_DOUBLEWORD shift, R0, R1, R2
31 mov \R0, \R0, lsr #(\shift * 8)
32 orr \R0, \R0, \R1, lsl #(32 - \shift * 8)
33 mov \R1, \R1, lsr #(\shift * 8)
34 orr \R1, \R1, \R2, lsl #(32 - \shift * 8)
36 .macro ADJ_ALIGN_DOUBLEWORD_D shift, Rdst0, Rdst1, Rsrc0, Rsrc1, Rsrc2
37 mov \Rdst0, \Rsrc0, lsr #(\shift * 8)
38 mov \Rdst1, \Rsrc1, lsr #(\shift * 8)
39 orr \Rdst0, \Rdst0, \Rsrc1, lsl #(32 - (\shift * 8))
40 orr \Rdst1, \Rdst1, \Rsrc2, lsl #(32 - (\shift * 8))
43 .macro RND_AVG32 Rd0, Rd1, Rn0, Rn1, Rm0, Rm1, Rmask
44 @ Rd = (Rn | Rm) - (((Rn ^ Rm) & ~0x01010101) >> 1)
51 and \Rd0, \Rd0, \Rmask
52 and \Rd1, \Rd1, \Rmask
53 sub \Rd0, \Rn0, \Rd0, lsr #1
54 sub \Rd1, \Rn1, \Rd1, lsr #1
57 .macro NO_RND_AVG32 Rd0, Rd1, Rn0, Rn1, Rm0, Rm1, Rmask
58 @ Rd = (Rn & Rm) - (((Rn ^ Rm) & ~0x01010101) >> 1)
65 and \Rd0, \Rd0, \Rmask
66 and \Rd1, \Rd1, \Rmask
67 add \Rd0, \Rn0, \Rd0, lsr #1
68 add \Rd1, \Rn1, \Rd1, lsr #1
71 @ ----------------------------------------------------------------
73 .global put_pixels16_arm
75 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
76 @ block = word aligned, pixles = unaligned
78 stmfd sp!, {r4-r11, lr} @ R14 is also called LR
82 add r5, r5, r4, lsl #2
92 ldmfd sp!, {r4-r11, pc}
97 ADJ_ALIGN_QUADWORD_D 1, r9, r10, r11, r12, r4, r5, r6, r7, r8
103 ldmfd sp!, {r4-r11, pc}
108 ADJ_ALIGN_QUADWORD_D 2, r9, r10, r11, r12, r4, r5, r6, r7, r8
114 ldmfd sp!, {r4-r11, pc}
119 ADJ_ALIGN_QUADWORD_D 3, r9, r10, r11, r12, r4, r5, r6, r7, r8
125 ldmfd sp!, {r4-r11,pc}
133 @ ----------------------------------------------------------------
135 .global put_pixels8_arm
137 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
138 @ block = word aligned, pixles = unaligned
140 stmfd sp!, {r4-r5,lr} @ R14 is also called LR
144 add r5, r5, r4, lsl #2
154 ldmfd sp!, {r4-r5,pc}
157 ldmia r1, {r4-r5, r12}
159 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r12
165 ldmfd sp!, {r4-r5,pc}
168 ldmia r1, {r4-r5, r12}
170 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r12
176 ldmfd sp!, {r4-r5,pc}
179 ldmia r1, {r4-r5, r12}
181 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r12
187 ldmfd sp!, {r4-r5,pc}
195 @ ----------------------------------------------------------------
197 .global put_pixels8_x2_arm
199 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
200 @ block = word aligned, pixles = unaligned
202 stmfd sp!, {r4-r10,lr} @ R14 is also called LR
206 add r5, r5, r4, lsl #2
210 ldmia r1, {r4-r5, r10}
212 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
214 RND_AVG32 r8, r9, r4, r5, r6, r7, r12
219 ldmfd sp!, {r4-r10,pc}
222 ldmia r1, {r4-r5, r10}
224 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
225 ADJ_ALIGN_DOUBLEWORD_D 2, r8, r9, r4, r5, r10
227 RND_AVG32 r4, r5, r6, r7, r8, r9, r12
232 ldmfd sp!, {r4-r10,pc}
235 ldmia r1, {r4-r5, r10}
237 ADJ_ALIGN_DOUBLEWORD_D 2, r6, r7, r4, r5, r10
238 ADJ_ALIGN_DOUBLEWORD_D 3, r8, r9, r4, r5, r10
240 RND_AVG32 r4, r5, r6, r7, r8, r9, r12
245 ldmfd sp!, {r4-r10,pc}
248 ldmia r1, {r4-r5, r10}
250 ADJ_ALIGN_DOUBLEWORD_D 3, r6, r7, r4, r5, r10
252 RND_AVG32 r8, r9, r6, r7, r5, r10, r12
257 ldmfd sp!, {r4-r10,pc} @@ update PC with LR content.
266 .global put_no_rnd_pixels8_x2_arm
267 put_no_rnd_pixels8_x2_arm:
268 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
269 @ block = word aligned, pixles = unaligned
271 stmfd sp!, {r4-r10,lr} @ R14 is also called LR
275 add r5, r5, r4, lsl #2
279 ldmia r1, {r4-r5, r10}
281 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
283 NO_RND_AVG32 r8, r9, r4, r5, r6, r7, r12
288 ldmfd sp!, {r4-r10,pc}
291 ldmia r1, {r4-r5, r10}
293 ADJ_ALIGN_DOUBLEWORD_D 1, r6, r7, r4, r5, r10
294 ADJ_ALIGN_DOUBLEWORD_D 2, r8, r9, r4, r5, r10
296 NO_RND_AVG32 r4, r5, r6, r7, r8, r9, r12
301 ldmfd sp!, {r4-r10,pc}
304 ldmia r1, {r4-r5, r10}
306 ADJ_ALIGN_DOUBLEWORD_D 2, r6, r7, r4, r5, r10
307 ADJ_ALIGN_DOUBLEWORD_D 3, r8, r9, r4, r5, r10
309 NO_RND_AVG32 r4, r5, r6, r7, r8, r9, r12
314 ldmfd sp!, {r4-r10,pc}
317 ldmia r1, {r4-r5, r10}
319 ADJ_ALIGN_DOUBLEWORD_D 3, r6, r7, r4, r5, r10
321 NO_RND_AVG32 r8, r9, r6, r7, r5, r10, r12
326 ldmfd sp!, {r4-r10,pc} @@ update PC with LR content.
335 @ ----------------------------------------------------------------
337 .global put_pixels8_y2_arm
339 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
340 @ block = word aligned, pixles = unaligned
342 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
347 add r5, r5, r4, lsl #2
356 RND_AVG32 r8, r9, r4, r5, r6, r7, r12
362 RND_AVG32 r8, r9, r6, r7, r4, r5, r12
367 ldmfd sp!, {r4-r11,pc}
373 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
377 ADJ_ALIGN_DOUBLEWORD 1, r7, r8, r9
378 RND_AVG32 r10, r11, r4, r5, r7, r8, r12
384 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
386 RND_AVG32 r10, r11, r7, r8, r4, r5, r12
390 ldmfd sp!, {r4-r11,pc}
396 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
400 ADJ_ALIGN_DOUBLEWORD 2, r7, r8, r9
401 RND_AVG32 r10, r11, r4, r5, r7, r8, r12
407 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
409 RND_AVG32 r10, r11, r7, r8, r4, r5, r12
413 ldmfd sp!, {r4-r11,pc}
419 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
423 ADJ_ALIGN_DOUBLEWORD 3, r7, r8, r9
424 RND_AVG32 r10, r11, r4, r5, r7, r8, r12
430 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
432 RND_AVG32 r10, r11, r7, r8, r4, r5, r12
436 ldmfd sp!, {r4-r11,pc}
446 .global put_no_rnd_pixels8_y2_arm
447 put_no_rnd_pixels8_y2_arm:
448 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
449 @ block = word aligned, pixles = unaligned
451 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
456 add r5, r5, r4, lsl #2
465 NO_RND_AVG32 r8, r9, r4, r5, r6, r7, r12
471 NO_RND_AVG32 r8, r9, r6, r7, r4, r5, r12
476 ldmfd sp!, {r4-r11,pc}
482 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
486 ADJ_ALIGN_DOUBLEWORD 1, r7, r8, r9
487 NO_RND_AVG32 r10, r11, r4, r5, r7, r8, r12
493 ADJ_ALIGN_DOUBLEWORD 1, r4, r5, r6
495 NO_RND_AVG32 r10, r11, r7, r8, r4, r5, r12
499 ldmfd sp!, {r4-r11,pc}
505 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
509 ADJ_ALIGN_DOUBLEWORD 2, r7, r8, r9
510 NO_RND_AVG32 r10, r11, r4, r5, r7, r8, r12
516 ADJ_ALIGN_DOUBLEWORD 2, r4, r5, r6
518 NO_RND_AVG32 r10, r11, r7, r8, r4, r5, r12
522 ldmfd sp!, {r4-r11,pc}
528 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
532 ADJ_ALIGN_DOUBLEWORD 3, r7, r8, r9
533 NO_RND_AVG32 r10, r11, r4, r5, r7, r8, r12
539 ADJ_ALIGN_DOUBLEWORD 3, r4, r5, r6
541 NO_RND_AVG32 r10, r11, r7, r8, r4, r5, r12
545 ldmfd sp!, {r4-r11,pc}
553 @ ----------------------------------------------------------------
554 .macro RND_XY2_IT align, rnd
555 @ l1= (a & 0x03030303) + (b & 0x03030303) ?(+ 0x02020202)
556 @ h1= ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2)
567 ADJ_ALIGN_DOUBLEWORD_D 1, r4, r5, r6, r7, r8
569 ADJ_ALIGN_DOUBLEWORD_D 1, r4, r5, r8, r9, r10
570 ADJ_ALIGN_DOUBLEWORD_D 2, r6, r7, r8, r9, r10
572 ADJ_ALIGN_DOUBLEWORD_D 2, r4, r5, r8, r9, r10
573 ADJ_ALIGN_DOUBLEWORD_D 3, r6, r7, r8, r9, r10
575 ADJ_ALIGN_DOUBLEWORD_D 3, r4, r5, r5, r6, r7
577 ldr r14, [r12, #0] @ 0x03030303
584 ldreq r14, [r12, #16] @ 0x02020202
586 ldreq r14, [r12, #28] @ 0x01010101
592 ldr r14, [r12, #20] @ 0xFCFCFCFC >> 2
593 and r4, r14, r4, lsr #2
594 and r5, r14, r5, lsr #2
595 and r6, r14, r6, lsr #2
596 and r7, r14, r7, lsr #2
601 .macro RND_XY2_EXPAND align, rnd
602 RND_XY2_IT \align, \rnd
603 6: stmfd sp!, {r8-r11}
604 RND_XY2_IT \align, \rnd
610 ldr r14, [r12, #24] @ 0x0F0F0F0F
611 and r4, r14, r4, lsr #2
612 and r5, r14, r5, lsr #2
619 ldmfd sp!, {r4-r11,pc}
623 .global put_pixels8_xy2_arm
625 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
626 @ block = word aligned, pixles = unaligned
628 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
631 add r5, r12, r4, lsl #2
655 .word 0xFCFCFCFC >> 2
660 .global put_no_rnd_pixels8_xy2_arm
661 put_no_rnd_pixels8_xy2_arm:
662 @ void func(uint8_t *block, const uint8_t *pixels, int line_size, int h)
663 @ block = word aligned, pixles = unaligned
665 stmfd sp!, {r4-r11,lr} @ R14 is also called LR
668 add r5, r12, r4, lsl #2
692 .word 0xFCFCFCFC >> 2