04be0cef061287edfb5a33d2e515783331e7b1ff
2 * Simple IDCT (Alpha optimized)
4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
6 * based upon some outcommented C code from mpeg2dec (idct_mmx.c
7 * written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
9 * Alpha optimizations by Måns Rullgård <mans@mansr.com>
10 * and Falk Hueffner <falk@debian.org>
12 * This file is part of FFmpeg.
14 * FFmpeg is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * FFmpeg is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with FFmpeg; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "idctdsp_alpha.h"
32 // cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
33 // W4 is actually exactly 16384, but using 16383 works around
34 // accumulating rounding errors for some encoders
45 /* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
46 static inline int idct_row(int16_t *row
)
48 int a0
, a1
, a2
, a3
, b0
, b1
, b2
, b3
, t
;
56 a0
= W4
* sextw(l
) + (1 << (ROW_SHIFT
- 1));
58 if (((l
& ~0xffffUL
) | r
) == 0) {
73 t
= extwl(l
, 4); /* row[2] */
82 t
= extwl(r
, 0); /* row[4] */
91 t
= extwl(r
, 4); /* row[6] */
100 t
= extwl(l
, 2); /* row[1] */
114 t
= extwl(l
, 6); /* row[3] */
124 t
= extwl(r
, 2); /* row[5] */
133 t
= extwl(r
, 6); /* row[7] */
142 row
[0] = (a0
+ b0
) >> ROW_SHIFT
;
143 row
[1] = (a1
+ b1
) >> ROW_SHIFT
;
144 row
[2] = (a2
+ b2
) >> ROW_SHIFT
;
145 row
[3] = (a3
+ b3
) >> ROW_SHIFT
;
146 row
[4] = (a3
- b3
) >> ROW_SHIFT
;
147 row
[5] = (a2
- b2
) >> ROW_SHIFT
;
148 row
[6] = (a1
- b1
) >> ROW_SHIFT
;
149 row
[7] = (a0
- b0
) >> ROW_SHIFT
;
154 static inline void idct_col(int16_t *col
)
156 int a0
, a1
, a2
, a3
, b0
, b1
, b2
, b3
;
158 col
[0] += (1 << (COL_SHIFT
- 1)) / W4
;
160 a0
= W4
* col
[8 * 0];
161 a1
= W4
* col
[8 * 0];
162 a2
= W4
* col
[8 * 0];
163 a3
= W4
* col
[8 * 0];
166 a0
+= W2
* col
[8 * 2];
167 a1
+= W6
* col
[8 * 2];
168 a2
-= W6
* col
[8 * 2];
169 a3
-= W2
* col
[8 * 2];
173 a0
+= W4
* col
[8 * 4];
174 a1
-= W4
* col
[8 * 4];
175 a2
-= W4
* col
[8 * 4];
176 a3
+= W4
* col
[8 * 4];
180 a0
+= W6
* col
[8 * 6];
181 a1
-= W2
* col
[8 * 6];
182 a2
+= W2
* col
[8 * 6];
183 a3
-= W6
* col
[8 * 6];
187 b0
= W1
* col
[8 * 1];
188 b1
= W3
* col
[8 * 1];
189 b2
= W5
* col
[8 * 1];
190 b3
= W7
* col
[8 * 1];
199 b0
+= W3
* col
[8 * 3];
200 b1
-= W7
* col
[8 * 3];
201 b2
-= W1
* col
[8 * 3];
202 b3
-= W5
* col
[8 * 3];
206 b0
+= W5
* col
[8 * 5];
207 b1
-= W1
* col
[8 * 5];
208 b2
+= W7
* col
[8 * 5];
209 b3
+= W3
* col
[8 * 5];
213 b0
+= W7
* col
[8 * 7];
214 b1
-= W5
* col
[8 * 7];
215 b2
+= W3
* col
[8 * 7];
216 b3
-= W1
* col
[8 * 7];
219 col
[8 * 0] = (a0
+ b0
) >> COL_SHIFT
;
220 col
[8 * 7] = (a0
- b0
) >> COL_SHIFT
;
221 col
[8 * 1] = (a1
+ b1
) >> COL_SHIFT
;
222 col
[8 * 6] = (a1
- b1
) >> COL_SHIFT
;
223 col
[8 * 2] = (a2
+ b2
) >> COL_SHIFT
;
224 col
[8 * 5] = (a2
- b2
) >> COL_SHIFT
;
225 col
[8 * 3] = (a3
+ b3
) >> COL_SHIFT
;
226 col
[8 * 4] = (a3
- b3
) >> COL_SHIFT
;
229 /* If all rows but the first one are zero after row transformation,
230 all rows will be identical after column transformation. */
231 static inline void idct_col2(int16_t *col
)
236 for (i
= 0; i
< 8; ++i
) {
237 int a0
= col
[i
] + (1 << (COL_SHIFT
- 1)) / W4
;
240 col
[i
] = a0
>> COL_SHIFT
;
243 l
= ldq(col
+ 0 * 4); r
= ldq(col
+ 1 * 4);
244 stq(l
, col
+ 2 * 4); stq(r
, col
+ 3 * 4);
245 stq(l
, col
+ 4 * 4); stq(r
, col
+ 5 * 4);
246 stq(l
, col
+ 6 * 4); stq(r
, col
+ 7 * 4);
247 stq(l
, col
+ 8 * 4); stq(r
, col
+ 9 * 4);
248 stq(l
, col
+ 10 * 4); stq(r
, col
+ 11 * 4);
249 stq(l
, col
+ 12 * 4); stq(r
, col
+ 13 * 4);
250 stq(l
, col
+ 14 * 4); stq(r
, col
+ 15 * 4);
253 void ff_simple_idct_axp(int16_t *block
)
257 int rowsZero
= 1; /* all rows except row 0 zero */
258 int rowsConstant
= 1; /* all rows consist of a constant value */
260 for (i
= 0; i
< 8; i
++) {
261 int sparseness
= idct_row(block
+ 8 * i
);
263 if (i
> 0 && sparseness
> 0)
271 } else if (rowsConstant
) {
273 for (i
= 0; i
< 8; i
+= 2) {
274 uint64_t v
= (uint16_t) block
[0];
275 uint64_t w
= (uint16_t) block
[8];
281 stq(v
, block
+ 0 * 4);
282 stq(v
, block
+ 1 * 4);
283 stq(w
, block
+ 2 * 4);
284 stq(w
, block
+ 3 * 4);
288 for (i
= 0; i
< 8; i
++)
293 void ff_simple_idct_put_axp(uint8_t *dest
, int line_size
, int16_t *block
)
295 ff_simple_idct_axp(block
);
296 put_pixels_clamped_axp_p(block
, dest
, line_size
);
299 void ff_simple_idct_add_axp(uint8_t *dest
, int line_size
, int16_t *block
)
301 ff_simple_idct_axp(block
);
302 add_pixels_clamped_axp_p(block
, dest
, line_size
);