ARMv5TE optimized IDCT
[libav.git] / libavcodec / armv4l / dsputil_arm.c
1 /*
2 * ARMv4L optimized DSP utils
3 * Copyright (c) 2001 Lionel Ulmer.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "../dsputil.h"
21 #ifdef HAVE_IPP
22 #include "ipp.h"
23 #endif
24
25 extern void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx);
26
27 extern void j_rev_dct_ARM(DCTELEM *data);
28 extern void simple_idct_ARM(DCTELEM *data);
29
30 extern void simple_idct_armv5te(DCTELEM *data);
31 extern void simple_idct_put_armv5te(uint8_t *dest, int line_size,
32 DCTELEM *data);
33 extern void simple_idct_add_armv5te(uint8_t *dest, int line_size,
34 DCTELEM *data);
35
36 /* XXX: local hack */
37 static void (*ff_put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
38 static void (*ff_add_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
39
40 void put_pixels8_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
41 void put_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
42 void put_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
43 void put_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
44
45 void put_no_rnd_pixels8_x2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
46 void put_no_rnd_pixels8_y2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
47 void put_no_rnd_pixels8_xy2_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
48
49 void put_pixels16_arm(uint8_t *block, const uint8_t *pixels, int line_size, int h);
50
51 CALL_2X_PIXELS(put_pixels16_x2_arm , put_pixels8_x2_arm , 8)
52 CALL_2X_PIXELS(put_pixels16_y2_arm , put_pixels8_y2_arm , 8)
53 CALL_2X_PIXELS(put_pixels16_xy2_arm, put_pixels8_xy2_arm, 8)
54 CALL_2X_PIXELS(put_no_rnd_pixels16_x2_arm , put_no_rnd_pixels8_x2_arm , 8)
55 CALL_2X_PIXELS(put_no_rnd_pixels16_y2_arm , put_no_rnd_pixels8_y2_arm , 8)
56 CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_arm, put_no_rnd_pixels8_xy2_arm, 8)
57
58 static void add_pixels_clamped_ARM(short *block, unsigned char *dest, int line_size)
59 {
60 asm volatile (
61 "mov r10, #8 \n\t"
62
63 "1: \n\t"
64
65 /* load dest */
66 "ldr r4, [%1] \n\t"
67 /* block[0] and block[1]*/
68 "ldrsh r5, [%0] \n\t"
69 "ldrsh r7, [%0, #2] \n\t"
70 "and r6, r4, #0xFF \n\t"
71 "and r8, r4, #0xFF00 \n\t"
72 "add r6, r5, r6 \n\t"
73 "add r8, r7, r8, lsr #8 \n\t"
74 "mvn r5, r5 \n\t"
75 "mvn r7, r7 \n\t"
76 "tst r6, #0x100 \n\t"
77 "movne r6, r5, lsr #24 \n\t"
78 "tst r8, #0x100 \n\t"
79 "movne r8, r7, lsr #24 \n\t"
80 "mov r9, r6 \n\t"
81 "ldrsh r5, [%0, #4] \n\t" /* moved form [A] */
82 "orr r9, r9, r8, lsl #8 \n\t"
83 /* block[2] and block[3] */
84 /* [A] */
85 "ldrsh r7, [%0, #6] \n\t"
86 "and r6, r4, #0xFF0000 \n\t"
87 "and r8, r4, #0xFF000000 \n\t"
88 "add r6, r5, r6, lsr #16 \n\t"
89 "add r8, r7, r8, lsr #24 \n\t"
90 "mvn r5, r5 \n\t"
91 "mvn r7, r7 \n\t"
92 "tst r6, #0x100 \n\t"
93 "movne r6, r5, lsr #24 \n\t"
94 "tst r8, #0x100 \n\t"
95 "movne r8, r7, lsr #24 \n\t"
96 "orr r9, r9, r6, lsl #16 \n\t"
97 "ldr r4, [%1, #4] \n\t" /* moved form [B] */
98 "orr r9, r9, r8, lsl #24 \n\t"
99 /* store dest */
100 "ldrsh r5, [%0, #8] \n\t" /* moved form [C] */
101 "str r9, [%1] \n\t"
102
103 /* load dest */
104 /* [B] */
105 /* block[4] and block[5] */
106 /* [C] */
107 "ldrsh r7, [%0, #10] \n\t"
108 "and r6, r4, #0xFF \n\t"
109 "and r8, r4, #0xFF00 \n\t"
110 "add r6, r5, r6 \n\t"
111 "add r8, r7, r8, lsr #8 \n\t"
112 "mvn r5, r5 \n\t"
113 "mvn r7, r7 \n\t"
114 "tst r6, #0x100 \n\t"
115 "movne r6, r5, lsr #24 \n\t"
116 "tst r8, #0x100 \n\t"
117 "movne r8, r7, lsr #24 \n\t"
118 "mov r9, r6 \n\t"
119 "ldrsh r5, [%0, #12] \n\t" /* moved from [D] */
120 "orr r9, r9, r8, lsl #8 \n\t"
121 /* block[6] and block[7] */
122 /* [D] */
123 "ldrsh r7, [%0, #14] \n\t"
124 "and r6, r4, #0xFF0000 \n\t"
125 "and r8, r4, #0xFF000000 \n\t"
126 "add r6, r5, r6, lsr #16 \n\t"
127 "add r8, r7, r8, lsr #24 \n\t"
128 "mvn r5, r5 \n\t"
129 "mvn r7, r7 \n\t"
130 "tst r6, #0x100 \n\t"
131 "movne r6, r5, lsr #24 \n\t"
132 "tst r8, #0x100 \n\t"
133 "movne r8, r7, lsr #24 \n\t"
134 "orr r9, r9, r6, lsl #16 \n\t"
135 "add %0, %0, #16 \n\t" /* moved from [E] */
136 "orr r9, r9, r8, lsl #24 \n\t"
137 "subs r10, r10, #1 \n\t" /* moved from [F] */
138 /* store dest */
139 "str r9, [%1, #4] \n\t"
140
141 /* [E] */
142 /* [F] */
143 "add %1, %1, %2 \n\t"
144 "bne 1b \n\t"
145 : "+r"(block),
146 "+r"(dest)
147 : "r"(line_size)
148 : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "cc", "memory" );
149 }
150
151 /* XXX: those functions should be suppressed ASAP when all IDCTs are
152 converted */
153 static void j_rev_dct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
154 {
155 j_rev_dct_ARM (block);
156 ff_put_pixels_clamped(block, dest, line_size);
157 }
158 static void j_rev_dct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
159 {
160 j_rev_dct_ARM (block);
161 ff_add_pixels_clamped(block, dest, line_size);
162 }
163 static void simple_idct_ARM_put(uint8_t *dest, int line_size, DCTELEM *block)
164 {
165 simple_idct_ARM (block);
166 ff_put_pixels_clamped(block, dest, line_size);
167 }
168 static void simple_idct_ARM_add(uint8_t *dest, int line_size, DCTELEM *block)
169 {
170 simple_idct_ARM (block);
171 ff_add_pixels_clamped(block, dest, line_size);
172 }
173
174 #ifdef HAVE_IPP
175 static void simple_idct_ipp(DCTELEM *block)
176 {
177 ippiDCT8x8Inv_Video_16s_C1I(block);
178 }
179 static void simple_idct_ipp_put(uint8_t *dest, int line_size, DCTELEM *block)
180 {
181 ippiDCT8x8Inv_Video_16s8u_C1R(block, dest, line_size);
182 }
183
184 void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size);
185
186 static void simple_idct_ipp_add(uint8_t *dest, int line_size, DCTELEM *block)
187 {
188 ippiDCT8x8Inv_Video_16s_C1I(block);
189 #ifdef HAVE_IWMMXT
190 add_pixels_clamped_iwmmxt(block, dest, line_size);
191 #else
192 add_pixels_clamped_ARM(block, dest, line_size);
193 #endif
194 }
195 #endif
196
197 void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx)
198 {
199 int idct_algo= avctx->idct_algo;
200
201 ff_put_pixels_clamped = c->put_pixels_clamped;
202 ff_add_pixels_clamped = c->add_pixels_clamped;
203
204 if(idct_algo == FF_IDCT_AUTO){
205 #if defined(HAVE_IPP)
206 idct_algo = FF_IDCT_IPP;
207 #elif defined(HAVE_ARMV5TE)
208 idct_algo = FF_IDCT_SIMPLEARMV5TE;
209 #else
210 idct_algo = FF_IDCT_ARM;
211 #endif
212 }
213
214 if(idct_algo==FF_IDCT_ARM){
215 c->idct_put= j_rev_dct_ARM_put;
216 c->idct_add= j_rev_dct_ARM_add;
217 c->idct = j_rev_dct_ARM;
218 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;/* FF_NO_IDCT_PERM */
219 } else if (idct_algo==FF_IDCT_SIMPLEARM){
220 c->idct_put= simple_idct_ARM_put;
221 c->idct_add= simple_idct_ARM_add;
222 c->idct = simple_idct_ARM;
223 c->idct_permutation_type= FF_NO_IDCT_PERM;
224 #ifdef HAVE_ARMV5TE
225 } else if (idct_algo==FF_IDCT_SIMPLEARMV5TE){
226 c->idct_put= simple_idct_put_armv5te;
227 c->idct_add= simple_idct_add_armv5te;
228 c->idct = simple_idct_armv5te;
229 c->idct_permutation_type = FF_NO_IDCT_PERM;
230 #endif
231 #ifdef HAVE_IPP
232 } else if (idct_algo==FF_IDCT_IPP){
233 c->idct_put= simple_idct_ipp_put;
234 c->idct_add= simple_idct_ipp_add;
235 c->idct = simple_idct_ipp;
236 c->idct_permutation_type= FF_NO_IDCT_PERM;
237 #endif
238 }
239
240 /* c->put_pixels_tab[0][0] = put_pixels16_arm; */ // NG!
241 c->put_pixels_tab[0][1] = put_pixels16_x2_arm; //OK!
242 c->put_pixels_tab[0][2] = put_pixels16_y2_arm; //OK!
243 /* c->put_pixels_tab[0][3] = put_pixels16_xy2_arm; /\* NG *\/ */
244 /* c->put_no_rnd_pixels_tab[0][0] = put_pixels16_arm; */
245 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_arm; // OK
246 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_arm; //OK
247 /* c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_arm; //NG */
248 c->put_pixels_tab[1][0] = put_pixels8_arm; //OK
249 c->put_pixels_tab[1][1] = put_pixels8_x2_arm; //OK
250 /* c->put_pixels_tab[1][2] = put_pixels8_y2_arm; //NG */
251 /* c->put_pixels_tab[1][3] = put_pixels8_xy2_arm; //NG */
252 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_arm;//OK
253 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_arm; //OK
254 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_arm; //OK
255 /* c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm;//NG */
256
257 #ifdef HAVE_IWMMXT
258 dsputil_init_iwmmxt(c, avctx);
259 #endif
260 }