2 * Simple IDCT (Alpha optimized)
4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * based upon some outcommented c code from mpeg2dec (idct_mmx.c
21 * written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
23 * Alpha optimiziations by Måns Rullgård <mru@users.sourceforge.net>
24 * and Falk Hueffner <falk@debian.org>
28 #include "../dsputil.h"
30 extern void (*put_pixels_clamped_axp_p
)(const DCTELEM
*block
, uint8_t *pixels
,
32 extern void (*add_pixels_clamped_axp_p
)(const DCTELEM
*block
, uint8_t *pixels
,
35 // cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
36 // W4 is actually exactly 16384, but using 16383 works around
37 // accumulating rounding errors for some encoders
38 #define W1 ((int_fast32_t) 22725)
39 #define W2 ((int_fast32_t) 21407)
40 #define W3 ((int_fast32_t) 19266)
41 #define W4 ((int_fast32_t) 16383)
42 #define W5 ((int_fast32_t) 12873)
43 #define W6 ((int_fast32_t) 8867)
44 #define W7 ((int_fast32_t) 4520)
48 /* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
49 static inline int idct_row(DCTELEM
*row
)
51 int_fast32_t a0
, a1
, a2
, a3
, b0
, b1
, b2
, b3
, t
;
59 a0
= W4
* sextw(l
) + (1 << (ROW_SHIFT
- 1));
61 if (((l
& ~0xffffUL
) | r
) == 0) {
76 t
= extwl(l
, 4); /* row[2] */
85 t
= extwl(r
, 0); /* row[4] */
94 t
= extwl(r
, 4); /* row[6] */
103 t
= extwl(l
, 2); /* row[1] */
117 t
= extwl(l
, 6); /* row[3] */
127 t
= extwl(r
, 2); /* row[5] */
136 t
= extwl(r
, 6); /* row[7] */
145 row
[0] = (a0
+ b0
) >> ROW_SHIFT
;
146 row
[1] = (a1
+ b1
) >> ROW_SHIFT
;
147 row
[2] = (a2
+ b2
) >> ROW_SHIFT
;
148 row
[3] = (a3
+ b3
) >> ROW_SHIFT
;
149 row
[4] = (a3
- b3
) >> ROW_SHIFT
;
150 row
[5] = (a2
- b2
) >> ROW_SHIFT
;
151 row
[6] = (a1
- b1
) >> ROW_SHIFT
;
152 row
[7] = (a0
- b0
) >> ROW_SHIFT
;
157 static inline void idct_col(DCTELEM
*col
)
159 int_fast32_t a0
, a1
, a2
, a3
, b0
, b1
, b2
, b3
;
161 col
[0] += (1 << (COL_SHIFT
- 1)) / W4
;
163 a0
= W4
* col
[8 * 0];
164 a1
= W4
* col
[8 * 0];
165 a2
= W4
* col
[8 * 0];
166 a3
= W4
* col
[8 * 0];
169 a0
+= W2
* col
[8 * 2];
170 a1
+= W6
* col
[8 * 2];
171 a2
-= W6
* col
[8 * 2];
172 a3
-= W2
* col
[8 * 2];
176 a0
+= W4
* col
[8 * 4];
177 a1
-= W4
* col
[8 * 4];
178 a2
-= W4
* col
[8 * 4];
179 a3
+= W4
* col
[8 * 4];
183 a0
+= W6
* col
[8 * 6];
184 a1
-= W2
* col
[8 * 6];
185 a2
+= W2
* col
[8 * 6];
186 a3
-= W6
* col
[8 * 6];
190 b0
= W1
* col
[8 * 1];
191 b1
= W3
* col
[8 * 1];
192 b2
= W5
* col
[8 * 1];
193 b3
= W7
* col
[8 * 1];
202 b0
+= W3
* col
[8 * 3];
203 b1
-= W7
* col
[8 * 3];
204 b2
-= W1
* col
[8 * 3];
205 b3
-= W5
* col
[8 * 3];
209 b0
+= W5
* col
[8 * 5];
210 b1
-= W1
* col
[8 * 5];
211 b2
+= W7
* col
[8 * 5];
212 b3
+= W3
* col
[8 * 5];
216 b0
+= W7
* col
[8 * 7];
217 b1
-= W5
* col
[8 * 7];
218 b2
+= W3
* col
[8 * 7];
219 b3
-= W1
* col
[8 * 7];
222 col
[8 * 0] = (a0
+ b0
) >> COL_SHIFT
;
223 col
[8 * 7] = (a0
- b0
) >> COL_SHIFT
;
224 col
[8 * 1] = (a1
+ b1
) >> COL_SHIFT
;
225 col
[8 * 6] = (a1
- b1
) >> COL_SHIFT
;
226 col
[8 * 2] = (a2
+ b2
) >> COL_SHIFT
;
227 col
[8 * 5] = (a2
- b2
) >> COL_SHIFT
;
228 col
[8 * 3] = (a3
+ b3
) >> COL_SHIFT
;
229 col
[8 * 4] = (a3
- b3
) >> COL_SHIFT
;
232 /* If all rows but the first one are zero after row transformation,
233 all rows will be identical after column transformation. */
234 static inline void idct_col2(DCTELEM
*col
)
238 uint64_t *lcol
= (uint64_t *) col
;
240 for (i
= 0; i
< 8; ++i
) {
241 int_fast32_t a0
= col
[0] + (1 << (COL_SHIFT
- 1)) / W4
;
244 col
[0] = a0
>> COL_SHIFT
;
250 lcol
[ 2] = l
; lcol
[ 3] = r
;
251 lcol
[ 4] = l
; lcol
[ 5] = r
;
252 lcol
[ 6] = l
; lcol
[ 7] = r
;
253 lcol
[ 8] = l
; lcol
[ 9] = r
;
254 lcol
[10] = l
; lcol
[11] = r
;
255 lcol
[12] = l
; lcol
[13] = r
;
256 lcol
[14] = l
; lcol
[15] = r
;
259 void simple_idct_axp(DCTELEM
*block
)
263 int rowsZero
= 1; /* all rows except row 0 zero */
264 int rowsConstant
= 1; /* all rows consist of a constant value */
266 for (i
= 0; i
< 8; i
++) {
267 int sparseness
= idct_row(block
+ 8 * i
);
269 if (i
> 0 && sparseness
> 0)
277 } else if (rowsConstant
) {
278 uint64_t *lblock
= (uint64_t *) block
;
281 for (i
= 0; i
< 8; i
+= 2) {
282 uint64_t v
= (uint16_t) block
[i
* 8];
283 uint64_t w
= (uint16_t) block
[i
* 8 + 8];
296 for (i
= 0; i
< 8; i
++)
301 void simple_idct_put_axp(uint8_t *dest
, int line_size
, DCTELEM
*block
)
303 simple_idct_axp(block
);
304 put_pixels_clamped_axp_p(block
, dest
, line_size
);
307 void simple_idct_add_axp(uint8_t *dest
, int line_size
, DCTELEM
*block
)
309 simple_idct_axp(block
);
310 add_pixels_clamped_axp_p(block
, dest
, line_size
);