ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
[libav.git] / libavcodec / ps2 / dsputil_mmi.c
1 /*
2 * MMI optimized DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
4 *
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.
9 *
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.
14 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * MMI optimization by Leon van Stuivenberg <leonvs@iae.nl>
20 */
21
22 #include "../dsputil.h"
23 #include "mmi.h"
24
25 /* the provided 'as' in binutils 2.9EE doesn't support
26 the EE's mips3 instructions properly */
27 #define AS_BUGGY
28
29
30 static void clear_blocks_mmi(DCTELEM * blocks)
31 {
32 int i;
33 for (i = 0; i < 6; i++) {
34 asm volatile(
35 "sq $0, 0(%0) \n\t"
36 "sq $0, 16(%0) \n\t"
37 "sq $0, 32(%0) \n\t"
38 "sq $0, 48(%0) \n\t"
39 "sq $0, 64(%0) \n\t"
40 "sq $0, 80(%0) \n\t"
41 "sq $0, 96(%0) \n\t"
42 "sq $0, 112(%0) \n\t" :: "r" (blocks) : "memory" );
43 blocks += 64;
44 }
45 }
46
47
48 static void get_pixels_mmi(DCTELEM *block, const UINT8 *pixels, int line_size)
49 {
50 int i;
51 for(i=0;i<8;i++) {
52 #ifdef AS_BUGGY
53 ld3(5, 0, 8);
54 asm volatile(
55 "add %1, %1, %2 \n\t"
56 "pextlb $8, $0, $8 \n\t"
57 "sq $8, 0(%0) \n\t" :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "memory" );
58 #else
59 asm volatile(
60 "ld $8, 0(%1) \n\t"
61 "add %1, %1, %2 \n\t"
62 "pextlb $8, $0, $8 \n\t"
63 "sq $8, 0(%0) \n\t" :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "memory" );
64 #endif
65 block += 8;
66 }
67 }
68
69
70 static void put_pixels8_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
71 {
72 int i;
73 for(i=0; i<h; i++) {
74 #ifdef AS_BUGGY
75 ldr3(5, 0, 8);
76 ldl3(5, 7, 8);
77 asm volatile ( "add $5, $5, $6 \n\t" );
78 sd3(8, 0, 4);
79 asm volatile ( "add $4, $4, $6 \n\t" );
80 #else
81 asm volatile(
82 "ldr $8, 0(%1) \n\t"
83 "ldl $8, 7(%1) \n\t"
84 "add %1, %1, %2 \n\t"
85 "sd $8, 0(%0) \n\t"
86 "add %0, %0, %2 \n\t" :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "memory" );
87 #endif
88 }
89 }
90
91
92 static void put_pixels16_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
93 {
94 int i;
95 for(i=0; i<h; i++) {
96 #ifdef AS_BUGGY
97 ldr3(5, 0, 8);
98 ldl3(5, 7, 8);
99 ldr3(5, 8, 9);
100 ldl3(5, 15, 9);
101 asm volatile ( "add $5, $5, $6 \n\t" );
102 pcpyld($9, $8, $8);
103 sq($8, 0, $4);
104 asm volatile ( "add $4, $4, $6 \n\t" );
105 #else
106 asm volatile (
107 "ldr $8, 0(%1) \n\t"
108 "ldl $8, 7(%1) \n\t"
109 "ldr $9, 8(%1) \n\t"
110 "ldl $9, 15(%1) \n\t"
111 "add %1, %1, %2 \n\t"
112 "pcpyld $8, $9, $8 \n\t"
113 "sq $8, 0(%0) \n\t"
114 "add %0, %0, %2 \n\t" :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "$9", "memory" );
115 #endif
116 }
117 }
118
119
120 void dsputil_init_mmi(void)
121 {
122 clear_blocks = clear_blocks_mmi;
123
124 put_pixels_tab[1][0] = put_pixels8_mmi;
125 put_no_rnd_pixels_tab[1][0] = put_pixels8_mmi;
126
127 put_pixels_tab[0][0] = put_pixels16_mmi;
128 put_no_rnd_pixels_tab[0][0] = put_pixels16_mmi;
129
130 get_pixels = get_pixels_mmi;
131 }
132