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 Libav.
14 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "libavcodec/dsputil.h"
30 #include "dsputil_alpha.h"
33 // cos(i * M_PI / 16) * sqrt(2) * (1 << 14)
34 // W4 is actually exactly 16384, but using 16383 works around
35 // accumulating rounding errors for some encoders
46 /* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */
47 static inline int idct_row(DCTELEM *row)
49 int a0, a1, a2, a3, b0, b1, b2, b3, t;
57 a0 = W4 * sextw(l) + (1 << (ROW_SHIFT - 1));
59 if (((l & ~0xffffUL) | r) == 0) {
74 t = extwl(l, 4); /* row[2] */
83 t = extwl(r, 0); /* row[4] */
92 t = extwl(r, 4); /* row[6] */
101 t = extwl(l, 2); /* row[1] */
115 t = extwl(l, 6); /* row[3] */
125 t = extwl(r, 2); /* row[5] */
134 t = extwl(r, 6); /* row[7] */
143 row[0] = (a0 + b0) >> ROW_SHIFT;
144 row[1] = (a1 + b1) >> ROW_SHIFT;
145 row[2] = (a2 + b2) >> ROW_SHIFT;
146 row[3] = (a3 + b3) >> ROW_SHIFT;
147 row[4] = (a3 - b3) >> ROW_SHIFT;
148 row[5] = (a2 - b2) >> ROW_SHIFT;
149 row[6] = (a1 - b1) >> ROW_SHIFT;
150 row[7] = (a0 - b0) >> ROW_SHIFT;
155 static inline void idct_col(DCTELEM *col)
157 int a0, a1, a2, a3, b0, b1, b2, b3;
159 col[0] += (1 << (COL_SHIFT - 1)) / W4;
161 a0 = W4 * col[8 * 0];
162 a1 = W4 * col[8 * 0];
163 a2 = W4 * col[8 * 0];
164 a3 = W4 * col[8 * 0];
167 a0 += W2 * col[8 * 2];
168 a1 += W6 * col[8 * 2];
169 a2 -= W6 * col[8 * 2];
170 a3 -= W2 * col[8 * 2];
174 a0 += W4 * col[8 * 4];
175 a1 -= W4 * col[8 * 4];
176 a2 -= W4 * col[8 * 4];
177 a3 += W4 * col[8 * 4];
181 a0 += W6 * col[8 * 6];
182 a1 -= W2 * col[8 * 6];
183 a2 += W2 * col[8 * 6];
184 a3 -= W6 * col[8 * 6];
188 b0 = W1 * col[8 * 1];
189 b1 = W3 * col[8 * 1];
190 b2 = W5 * col[8 * 1];
191 b3 = W7 * col[8 * 1];
200 b0 += W3 * col[8 * 3];
201 b1 -= W7 * col[8 * 3];
202 b2 -= W1 * col[8 * 3];
203 b3 -= W5 * col[8 * 3];
207 b0 += W5 * col[8 * 5];
208 b1 -= W1 * col[8 * 5];
209 b2 += W7 * col[8 * 5];
210 b3 += W3 * col[8 * 5];
214 b0 += W7 * col[8 * 7];
215 b1 -= W5 * col[8 * 7];
216 b2 += W3 * col[8 * 7];
217 b3 -= W1 * col[8 * 7];
220 col[8 * 0] = (a0 + b0) >> COL_SHIFT;
221 col[8 * 7] = (a0 - b0) >> COL_SHIFT;
222 col[8 * 1] = (a1 + b1) >> COL_SHIFT;
223 col[8 * 6] = (a1 - b1) >> COL_SHIFT;
224 col[8 * 2] = (a2 + b2) >> COL_SHIFT;
225 col[8 * 5] = (a2 - b2) >> COL_SHIFT;
226 col[8 * 3] = (a3 + b3) >> COL_SHIFT;
227 col[8 * 4] = (a3 - b3) >> COL_SHIFT;
230 /* If all rows but the first one are zero after row transformation,
231 all rows will be identical after column transformation. */
232 static inline void idct_col2(DCTELEM *col)
237 for (i = 0; i < 8; ++i) {
238 int a0 = col[i] + (1 << (COL_SHIFT - 1)) / W4;
241 col[i] = a0 >> COL_SHIFT;
244 l = ldq(col + 0 * 4); r = ldq(col + 1 * 4);
245 stq(l, col + 2 * 4); stq(r, col + 3 * 4);
246 stq(l, col + 4 * 4); stq(r, col + 5 * 4);
247 stq(l, col + 6 * 4); stq(r, col + 7 * 4);
248 stq(l, col + 8 * 4); stq(r, col + 9 * 4);
249 stq(l, col + 10 * 4); stq(r, col + 11 * 4);
250 stq(l, col + 12 * 4); stq(r, col + 13 * 4);
251 stq(l, col + 14 * 4); stq(r, col + 15 * 4);
254 void ff_simple_idct_axp(DCTELEM *block)
258 int rowsZero = 1; /* all rows except row 0 zero */
259 int rowsConstant = 1; /* all rows consist of a constant value */
261 for (i = 0; i < 8; i++) {
262 int sparseness = idct_row(block + 8 * i);
264 if (i > 0 && sparseness > 0)
272 } else if (rowsConstant) {
274 for (i = 0; i < 8; i += 2) {
275 uint64_t v = (uint16_t) block[0];
276 uint64_t w = (uint16_t) block[8];
282 stq(v, block + 0 * 4);
283 stq(v, block + 1 * 4);
284 stq(w, block + 2 * 4);
285 stq(w, block + 3 * 4);
289 for (i = 0; i < 8; i++)
294 void ff_simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block)
296 ff_simple_idct_axp(block);
297 put_pixels_clamped_axp_p(block, dest, line_size);
300 void ff_simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block)
302 ff_simple_idct_axp(block);
303 add_pixels_clamped_axp_p(block, dest, line_size);