Mercurial > libavcodec.hg
annotate armv4l/mpegvideo_armv5te.c @ 5134:879b809b00cb libavcodec
kill one vector constant value load by the right combination of vec_splatX/vec_sl
patch by Sigbjorn Skjaeret %sskjer-1 A broadpark P no%
author | gpoirier |
---|---|
date | Tue, 12 Jun 2007 21:24:25 +0000 |
parents | daff9ebd2e0b |
children | a312a28104e9 |
rev | line source |
---|---|
4341 | 1 /* |
2 * Optimization of some functions from mpegvideo.c for armv5te | |
3 * Copyright (c) 2007 Siarhei Siamashka <ssvb@users.sourceforge.net> | |
4 * | |
5 * This file is part of FFmpeg. | |
6 * | |
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. | |
11 * | |
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. | |
16 * | |
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 | |
20 */ | |
21 | |
22 /* | |
23 * Some useful links for those who may be interested in optimizing code for ARM. | |
24 * ARM Architecture Reference Manual: http://www.arm.com/community/academy/resources.html | |
25 * Instructions timings and optimization guide for ARM9E: http://www.arm.com/pdfs/DDI0222B_9EJS_r1p2.pdf | |
26 */ | |
27 | |
5010
d5ba514e3f4a
Add libavcodec to compiler include flags in order to simplify header
diego
parents:
4435
diff
changeset
|
28 #include "dsputil.h" |
d5ba514e3f4a
Add libavcodec to compiler include flags in order to simplify header
diego
parents:
4435
diff
changeset
|
29 #include "mpegvideo.h" |
d5ba514e3f4a
Add libavcodec to compiler include flags in order to simplify header
diego
parents:
4435
diff
changeset
|
30 #include "avcodec.h" |
4341 | 31 |
32 | |
33 #ifdef ENABLE_ARM_TESTS | |
34 /** | |
35 * h263 dequantizer supplementary function, it is performance critical and needs to | |
36 * have optimized implementations for each architecture. Is also used as a reference | |
37 * implementation in regression tests | |
38 */ | |
39 static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qadd, int count) | |
40 { | |
41 int i, level; | |
42 for (i = 0; i < count; i++) { | |
43 level = block[i]; | |
44 if (level) { | |
45 if (level < 0) { | |
46 level = level * qmul - qadd; | |
47 } else { | |
48 level = level * qmul + qadd; | |
49 } | |
50 block[i] = level; | |
51 } | |
52 } | |
53 } | |
54 #endif | |
55 | |
56 /* GCC 3.1 or higher is required to support symbolic names in assembly code */ | |
57 #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) | |
58 | |
59 /** | |
60 * Special optimized version of dct_unquantize_h263_helper_c, it requires the block | |
61 * to be at least 8 bytes aligned, and may process more elements than requested. | |
62 * But it is guaranteed to never process more than 64 elements provided that | |
63 * xxcount argument is <= 64, so it is safe. This macro is optimized for a common | |
64 * distribution of values for nCoeffs (they are mostly multiple of 8 plus one or | |
65 * two extra elements). So this macro processes data as 8 elements per loop iteration | |
66 * and contains optional 2 elements processing in the end. | |
67 * | |
68 * Inner loop should take 6 cycles per element on arm926ej-s (Nokia 770) | |
69 */ | |
70 #define dct_unquantize_h263_special_helper_armv5te(xxblock, xxqmul, xxqadd, xxcount) \ | |
71 ({ DCTELEM *xblock = xxblock; \ | |
72 int xqmul = xxqmul, xqadd = xxqadd, xcount = xxcount, xtmp; \ | |
73 int xdata1, xdata2; \ | |
74 __asm__ __volatile__( \ | |
4435
04b5141fa890
typo fix by Dmitry Antipov dmantipov =a= yandex =d= ru
mru
parents:
4341
diff
changeset
|
75 "subs %[count], %[count], #2 \n\t" \ |
4341 | 76 "ble 2f \n\t" \ |
77 "ldrd r4, [%[block], #0] \n\t" \ | |
78 "1: \n\t" \ | |
79 "ldrd r6, [%[block], #8] \n\t" \ | |
80 \ | |
81 "rsbs %[data1], %[zero], r4, asr #16 \n\t" \ | |
82 "addgt %[data1], %[qadd], #0 \n\t" \ | |
83 "rsblt %[data1], %[qadd], #0 \n\t" \ | |
84 "smlatbne %[data1], r4, %[qmul], %[data1] \n\t" \ | |
85 \ | |
86 "rsbs %[data2], %[zero], r5, asr #16 \n\t" \ | |
87 "addgt %[data2], %[qadd], #0 \n\t" \ | |
88 "rsblt %[data2], %[qadd], #0 \n\t" \ | |
89 "smlatbne %[data2], r5, %[qmul], %[data2] \n\t" \ | |
90 \ | |
91 "rsbs %[tmp], %[zero], r4, asl #16 \n\t" \ | |
92 "addgt %[tmp], %[qadd], #0 \n\t" \ | |
93 "rsblt %[tmp], %[qadd], #0 \n\t" \ | |
94 "smlabbne r4, r4, %[qmul], %[tmp] \n\t" \ | |
95 \ | |
96 "rsbs %[tmp], %[zero], r5, asl #16 \n\t" \ | |
97 "addgt %[tmp], %[qadd], #0 \n\t" \ | |
98 "rsblt %[tmp], %[qadd], #0 \n\t" \ | |
99 "smlabbne r5, r5, %[qmul], %[tmp] \n\t" \ | |
100 \ | |
101 "strh r4, [%[block]], #2 \n\t" \ | |
102 "strh %[data1], [%[block]], #2 \n\t" \ | |
103 "strh r5, [%[block]], #2 \n\t" \ | |
104 "strh %[data2], [%[block]], #2 \n\t" \ | |
105 \ | |
106 "rsbs %[data1], %[zero], r6, asr #16 \n\t" \ | |
107 "addgt %[data1], %[qadd], #0 \n\t" \ | |
108 "rsblt %[data1], %[qadd], #0 \n\t" \ | |
109 "smlatbne %[data1], r6, %[qmul], %[data1] \n\t" \ | |
110 \ | |
111 "rsbs %[data2], %[zero], r7, asr #16 \n\t" \ | |
112 "addgt %[data2], %[qadd], #0 \n\t" \ | |
113 "rsblt %[data2], %[qadd], #0 \n\t" \ | |
114 "smlatbne %[data2], r7, %[qmul], %[data2] \n\t" \ | |
115 \ | |
116 "rsbs %[tmp], %[zero], r6, asl #16 \n\t" \ | |
117 "addgt %[tmp], %[qadd], #0 \n\t" \ | |
118 "rsblt %[tmp], %[qadd], #0 \n\t" \ | |
119 "smlabbne r6, r6, %[qmul], %[tmp] \n\t" \ | |
120 \ | |
121 "rsbs %[tmp], %[zero], r7, asl #16 \n\t" \ | |
122 "addgt %[tmp], %[qadd], #0 \n\t" \ | |
123 "rsblt %[tmp], %[qadd], #0 \n\t" \ | |
124 "smlabbne r7, r7, %[qmul], %[tmp] \n\t" \ | |
125 \ | |
126 "strh r6, [%[block]], #2 \n\t" \ | |
127 "strh %[data1], [%[block]], #2 \n\t" \ | |
128 "strh r7, [%[block]], #2 \n\t" \ | |
129 "strh %[data2], [%[block]], #2 \n\t" \ | |
130 \ | |
4435
04b5141fa890
typo fix by Dmitry Antipov dmantipov =a= yandex =d= ru
mru
parents:
4341
diff
changeset
|
131 "subs %[count], %[count], #8 \n\t" \ |
4341 | 132 "ldrgtd r4, [%[block], #0] \n\t" /* load data early to avoid load/use pipeline stall */ \ |
133 "bgt 1b \n\t" \ | |
134 \ | |
4435
04b5141fa890
typo fix by Dmitry Antipov dmantipov =a= yandex =d= ru
mru
parents:
4341
diff
changeset
|
135 "adds %[count], %[count], #2 \n\t" \ |
4341 | 136 "ble 3f \n\t" \ |
137 "2: \n\t" \ | |
138 "ldrsh %[data1], [%[block], #0] \n\t" \ | |
139 "ldrsh %[data2], [%[block], #2] \n\t" \ | |
140 "mov %[tmp], %[qadd] \n\t" \ | |
141 "cmp %[data1], #0 \n\t" \ | |
142 "rsblt %[tmp], %[qadd], #0 \n\t" \ | |
143 "smlabbne %[data1], %[data1], %[qmul], %[tmp] \n\t" \ | |
144 "mov %[tmp], %[qadd] \n\t" \ | |
145 "cmp %[data2], #0 \n\t" \ | |
146 "rsblt %[tmp], %[qadd], #0 \n\t" \ | |
147 "smlabbne %[data2], %[data2], %[qmul], %[tmp] \n\t" \ | |
148 "strh %[data1], [%[block]], #2 \n\t" \ | |
149 "strh %[data2], [%[block]], #2 \n\t" \ | |
150 "3: \n\t" \ | |
151 : [block] "+&r" (xblock), [count] "+&r" (xcount), [tmp] "=&r" (xtmp), \ | |
152 [data1] "=&r" (xdata1), [data2] "=&r" (xdata2) \ | |
153 : [qmul] "r" (xqmul), [qadd] "r" (xqadd), [zero] "r" (0) \ | |
154 : "r4", "r5", "r6", "r7", "cc", "memory" \ | |
155 ); \ | |
156 }) | |
157 | |
158 static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s, | |
159 DCTELEM *block, int n, int qscale) | |
160 { | |
5100 | 161 int level, qmul, qadd; |
4341 | 162 int nCoeffs; |
163 | |
164 assert(s->block_last_index[n]>=0); | |
165 | |
166 qmul = qscale << 1; | |
167 | |
168 if (!s->h263_aic) { | |
169 if (n < 4) | |
170 level = block[0] * s->y_dc_scale; | |
171 else | |
172 level = block[0] * s->c_dc_scale; | |
173 qadd = (qscale - 1) | 1; | |
174 }else{ | |
175 qadd = 0; | |
176 level = block[0]; | |
177 } | |
178 if(s->ac_pred) | |
179 nCoeffs=63; | |
180 else | |
181 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; | |
182 | |
183 dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1); | |
184 block[0] = level; | |
185 } | |
186 | |
187 static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s, | |
188 DCTELEM *block, int n, int qscale) | |
189 { | |
5100 | 190 int qmul, qadd; |
4341 | 191 int nCoeffs; |
192 | |
193 assert(s->block_last_index[n]>=0); | |
194 | |
195 qadd = (qscale - 1) | 1; | |
196 qmul = qscale << 1; | |
197 | |
198 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; | |
199 | |
200 dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1); | |
201 } | |
202 | |
203 #define HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED | |
204 | |
205 #endif | |
206 | |
207 void MPV_common_init_armv5te(MpegEncContext *s) | |
208 { | |
209 #ifdef HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED | |
210 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_armv5te; | |
211 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_armv5te; | |
212 #endif | |
213 } |