av1_inv_txfm1d.c 77.2 KB
Newer Older
Angie Chiang's avatar
Angie Chiang committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Angie Chiang's avatar
Angie Chiang committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Angie Chiang's avatar
Angie Chiang committed
10 11
 */

12
#include <stdlib.h>
13
#include "aom_dsp/inv_txfm.h"
Yaowu Xu's avatar
Yaowu Xu committed
14
#include "av1/common/av1_inv_txfm1d.h"
Angie Chiang's avatar
Angie Chiang committed
15
#if CONFIG_COEFFICIENT_RANGE_CHECKING
16 17 18

void range_check_func(int32_t stage, const int32_t *input, const int32_t *buf,
                      int32_t size, int8_t bit) {
19 20
  const int64_t maxValue = (1LL << (bit - 1)) - 1;
  const int64_t minValue = -(1LL << (bit - 1));
21

22 23
  int in_range = 1;

24 25
  for (int i = 0; i < size; ++i) {
    if (buf[i] < minValue || buf[i] > maxValue) {
26 27 28 29 30 31
      in_range = 0;
    }
  }

  if (!in_range) {
    fprintf(stderr, "Error: coeffs contain out-of-range values\n");
32
    fprintf(stderr, "size: %d\n", size);
33 34 35 36 37
    fprintf(stderr, "stage: %d\n", stage);
    fprintf(stderr, "allowed range: [%" PRId64 ";%" PRId64 "]\n", minValue,
            maxValue);

    fprintf(stderr, "coeffs: ");
38

39 40 41 42
    fprintf(stderr, "[");
    for (int j = 0; j < size; j++) {
      if (j > 0) fprintf(stderr, ", ");
      fprintf(stderr, "%d", input[j]);
43
    }
44 45 46 47 48 49 50 51 52 53
    fprintf(stderr, "]\n");

    fprintf(stderr, "   buf: ");

    fprintf(stderr, "[");
    for (int j = 0; j < size; j++) {
      if (j > 0) fprintf(stderr, ", ");
      fprintf(stderr, "%d", buf[j]);
    }
    fprintf(stderr, "]\n\n");
Angie Chiang's avatar
Angie Chiang committed
54
  }
55 56

  assert(in_range);
57 58
}

59
#define apply_range(stage, input, buf, size, bit) \
60
  range_check_func(stage, input, buf, size, bit)
Angie Chiang's avatar
Angie Chiang committed
61
#else
62 63 64 65 66 67 68 69 70
#define apply_range(stage, input, buf, size, bit) \
  clamp_buf((int32_t *)buf, size, bit)

void clamp_buf(int32_t *buf, int32_t size, int8_t bit) {
  if (bit <= 16) {
    const int32_t maxValue = (1 << 15) - 1;
    const int32_t minValue = -(1 << 15);

    for (int i = 0; i < size; ++i) buf[i] = clamp(buf[i], minValue, maxValue);
71
  }
72
}
Angie Chiang's avatar
Angie Chiang committed
73 74
#endif

75
// TODO(angiebird): Make 1-d txfm functions static
76
void av1_idct4_new(const int32_t *input, int32_t *output, int8_t cos_bit,
Yaowu Xu's avatar
Yaowu Xu committed
77
                   const int8_t *stage_range) {
Angie Chiang's avatar
Angie Chiang committed
78 79 80 81 82 83 84 85
  const int32_t size = 4;
  const int32_t *cospi;

  int32_t stage = 0;
  int32_t *bf0, *bf1;
  int32_t step[4];

  // stage 0;
86
  apply_range(stage, input, input, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
87 88 89

  // stage 1;
  stage++;
90
  assert(output != input);
Angie Chiang's avatar
Angie Chiang committed
91 92 93 94 95
  bf1 = output;
  bf1[0] = input[0];
  bf1[1] = input[2];
  bf1[2] = input[1];
  bf1[3] = input[3];
96
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
97 98 99

  // stage 2
  stage++;
100
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
101 102
  bf0 = output;
  bf1 = step;
103 104 105 106
  bf1[0] = half_btf(cospi[32], bf0[0], cospi[32], bf0[1], cos_bit);
  bf1[1] = half_btf(cospi[32], bf0[0], -cospi[32], bf0[1], cos_bit);
  bf1[2] = half_btf(cospi[48], bf0[2], -cospi[16], bf0[3], cos_bit);
  bf1[3] = half_btf(cospi[16], bf0[2], cospi[48], bf0[3], cos_bit);
107
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
108 109 110 111 112 113 114 115 116

  // stage 3
  stage++;
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0] + bf0[3];
  bf1[1] = bf0[1] + bf0[2];
  bf1[2] = bf0[1] - bf0[2];
  bf1[3] = bf0[0] - bf0[3];
117
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
118
}
Angie Chiang's avatar
Angie Chiang committed
119

120
void av1_idct8_new(const int32_t *input, int32_t *output, int8_t cos_bit,
Yaowu Xu's avatar
Yaowu Xu committed
121
                   const int8_t *stage_range) {
Angie Chiang's avatar
Angie Chiang committed
122 123 124 125 126 127 128 129
  const int32_t size = 8;
  const int32_t *cospi;

  int32_t stage = 0;
  int32_t *bf0, *bf1;
  int32_t step[8];

  // stage 0;
130
  apply_range(stage, input, input, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
131 132 133

  // stage 1;
  stage++;
134
  assert(output != input);
Angie Chiang's avatar
Angie Chiang committed
135 136 137 138 139 140 141 142 143
  bf1 = output;
  bf1[0] = input[0];
  bf1[1] = input[4];
  bf1[2] = input[2];
  bf1[3] = input[6];
  bf1[4] = input[1];
  bf1[5] = input[5];
  bf1[6] = input[3];
  bf1[7] = input[7];
144
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
145 146 147

  // stage 2
  stage++;
148
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
149 150 151 152 153 154
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
155 156 157 158
  bf1[4] = half_btf(cospi[56], bf0[4], -cospi[8], bf0[7], cos_bit);
  bf1[5] = half_btf(cospi[24], bf0[5], -cospi[40], bf0[6], cos_bit);
  bf1[6] = half_btf(cospi[40], bf0[5], cospi[24], bf0[6], cos_bit);
  bf1[7] = half_btf(cospi[8], bf0[4], cospi[56], bf0[7], cos_bit);
159
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
160 161 162

  // stage 3
  stage++;
163
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
164 165
  bf0 = step;
  bf1 = output;
166 167 168 169
  bf1[0] = half_btf(cospi[32], bf0[0], cospi[32], bf0[1], cos_bit);
  bf1[1] = half_btf(cospi[32], bf0[0], -cospi[32], bf0[1], cos_bit);
  bf1[2] = half_btf(cospi[48], bf0[2], -cospi[16], bf0[3], cos_bit);
  bf1[3] = half_btf(cospi[16], bf0[2], cospi[48], bf0[3], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
170 171 172 173
  bf1[4] = bf0[4] + bf0[5];
  bf1[5] = bf0[4] - bf0[5];
  bf1[6] = -bf0[6] + bf0[7];
  bf1[7] = bf0[6] + bf0[7];
174
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
175 176 177

  // stage 4
  stage++;
178
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
179 180 181 182 183 184 185
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0] + bf0[3];
  bf1[1] = bf0[1] + bf0[2];
  bf1[2] = bf0[1] - bf0[2];
  bf1[3] = bf0[0] - bf0[3];
  bf1[4] = bf0[4];
186 187
  bf1[5] = half_btf(-cospi[32], bf0[5], cospi[32], bf0[6], cos_bit);
  bf1[6] = half_btf(cospi[32], bf0[5], cospi[32], bf0[6], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
188
  bf1[7] = bf0[7];
189
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
190 191 192 193 194 195 196 197 198 199 200 201 202

  // stage 5
  stage++;
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0] + bf0[7];
  bf1[1] = bf0[1] + bf0[6];
  bf1[2] = bf0[2] + bf0[5];
  bf1[3] = bf0[3] + bf0[4];
  bf1[4] = bf0[3] - bf0[4];
  bf1[5] = bf0[2] - bf0[5];
  bf1[6] = bf0[1] - bf0[6];
  bf1[7] = bf0[0] - bf0[7];
203
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
204
}
Angie Chiang's avatar
Angie Chiang committed
205

206 207
void av1_idct16_new(const int32_t *input, int32_t *output, int8_t cos_bit,
                    const int8_t *stage_range) {
Angie Chiang's avatar
Angie Chiang committed
208 209 210 211 212 213 214 215
  const int32_t size = 16;
  const int32_t *cospi;

  int32_t stage = 0;
  int32_t *bf0, *bf1;
  int32_t step[16];

  // stage 0;
216
  apply_range(stage, input, input, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
217 218 219

  // stage 1;
  stage++;
220
  assert(output != input);
Angie Chiang's avatar
Angie Chiang committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
  bf1 = output;
  bf1[0] = input[0];
  bf1[1] = input[8];
  bf1[2] = input[4];
  bf1[3] = input[12];
  bf1[4] = input[2];
  bf1[5] = input[10];
  bf1[6] = input[6];
  bf1[7] = input[14];
  bf1[8] = input[1];
  bf1[9] = input[9];
  bf1[10] = input[5];
  bf1[11] = input[13];
  bf1[12] = input[3];
  bf1[13] = input[11];
  bf1[14] = input[7];
  bf1[15] = input[15];
238
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
239 240 241

  // stage 2
  stage++;
242
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
243 244 245 246 247 248 249 250 251 252
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
  bf1[4] = bf0[4];
  bf1[5] = bf0[5];
  bf1[6] = bf0[6];
  bf1[7] = bf0[7];
253 254 255 256 257 258 259 260
  bf1[8] = half_btf(cospi[60], bf0[8], -cospi[4], bf0[15], cos_bit);
  bf1[9] = half_btf(cospi[28], bf0[9], -cospi[36], bf0[14], cos_bit);
  bf1[10] = half_btf(cospi[44], bf0[10], -cospi[20], bf0[13], cos_bit);
  bf1[11] = half_btf(cospi[12], bf0[11], -cospi[52], bf0[12], cos_bit);
  bf1[12] = half_btf(cospi[52], bf0[11], cospi[12], bf0[12], cos_bit);
  bf1[13] = half_btf(cospi[20], bf0[10], cospi[44], bf0[13], cos_bit);
  bf1[14] = half_btf(cospi[36], bf0[9], cospi[28], bf0[14], cos_bit);
  bf1[15] = half_btf(cospi[4], bf0[8], cospi[60], bf0[15], cos_bit);
261
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
262 263 264

  // stage 3
  stage++;
265
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
266 267 268 269 270 271
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
272 273 274 275
  bf1[4] = half_btf(cospi[56], bf0[4], -cospi[8], bf0[7], cos_bit);
  bf1[5] = half_btf(cospi[24], bf0[5], -cospi[40], bf0[6], cos_bit);
  bf1[6] = half_btf(cospi[40], bf0[5], cospi[24], bf0[6], cos_bit);
  bf1[7] = half_btf(cospi[8], bf0[4], cospi[56], bf0[7], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
276 277 278 279 280 281 282 283
  bf1[8] = bf0[8] + bf0[9];
  bf1[9] = bf0[8] - bf0[9];
  bf1[10] = -bf0[10] + bf0[11];
  bf1[11] = bf0[10] + bf0[11];
  bf1[12] = bf0[12] + bf0[13];
  bf1[13] = bf0[12] - bf0[13];
  bf1[14] = -bf0[14] + bf0[15];
  bf1[15] = bf0[14] + bf0[15];
284
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
285 286 287

  // stage 4
  stage++;
288
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
289 290
  bf0 = output;
  bf1 = step;
291 292 293 294
  bf1[0] = half_btf(cospi[32], bf0[0], cospi[32], bf0[1], cos_bit);
  bf1[1] = half_btf(cospi[32], bf0[0], -cospi[32], bf0[1], cos_bit);
  bf1[2] = half_btf(cospi[48], bf0[2], -cospi[16], bf0[3], cos_bit);
  bf1[3] = half_btf(cospi[16], bf0[2], cospi[48], bf0[3], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
295 296 297 298 299
  bf1[4] = bf0[4] + bf0[5];
  bf1[5] = bf0[4] - bf0[5];
  bf1[6] = -bf0[6] + bf0[7];
  bf1[7] = bf0[6] + bf0[7];
  bf1[8] = bf0[8];
300 301
  bf1[9] = half_btf(-cospi[16], bf0[9], cospi[48], bf0[14], cos_bit);
  bf1[10] = half_btf(-cospi[48], bf0[10], -cospi[16], bf0[13], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
302 303
  bf1[11] = bf0[11];
  bf1[12] = bf0[12];
304 305
  bf1[13] = half_btf(-cospi[16], bf0[10], cospi[48], bf0[13], cos_bit);
  bf1[14] = half_btf(cospi[48], bf0[9], cospi[16], bf0[14], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
306
  bf1[15] = bf0[15];
307
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
308 309 310

  // stage 5
  stage++;
311
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
312 313 314 315 316 317 318
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0] + bf0[3];
  bf1[1] = bf0[1] + bf0[2];
  bf1[2] = bf0[1] - bf0[2];
  bf1[3] = bf0[0] - bf0[3];
  bf1[4] = bf0[4];
319 320
  bf1[5] = half_btf(-cospi[32], bf0[5], cospi[32], bf0[6], cos_bit);
  bf1[6] = half_btf(cospi[32], bf0[5], cospi[32], bf0[6], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
321 322 323 324 325 326 327 328 329
  bf1[7] = bf0[7];
  bf1[8] = bf0[8] + bf0[11];
  bf1[9] = bf0[9] + bf0[10];
  bf1[10] = bf0[9] - bf0[10];
  bf1[11] = bf0[8] - bf0[11];
  bf1[12] = -bf0[12] + bf0[15];
  bf1[13] = -bf0[13] + bf0[14];
  bf1[14] = bf0[13] + bf0[14];
  bf1[15] = bf0[12] + bf0[15];
330
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
331 332 333

  // stage 6
  stage++;
334
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
335 336 337 338 339 340 341 342 343 344 345 346
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0] + bf0[7];
  bf1[1] = bf0[1] + bf0[6];
  bf1[2] = bf0[2] + bf0[5];
  bf1[3] = bf0[3] + bf0[4];
  bf1[4] = bf0[3] - bf0[4];
  bf1[5] = bf0[2] - bf0[5];
  bf1[6] = bf0[1] - bf0[6];
  bf1[7] = bf0[0] - bf0[7];
  bf1[8] = bf0[8];
  bf1[9] = bf0[9];
347 348 349 350
  bf1[10] = half_btf(-cospi[32], bf0[10], cospi[32], bf0[13], cos_bit);
  bf1[11] = half_btf(-cospi[32], bf0[11], cospi[32], bf0[12], cos_bit);
  bf1[12] = half_btf(cospi[32], bf0[11], cospi[32], bf0[12], cos_bit);
  bf1[13] = half_btf(cospi[32], bf0[10], cospi[32], bf0[13], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
351 352
  bf1[14] = bf0[14];
  bf1[15] = bf0[15];
353
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374

  // stage 7
  stage++;
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0] + bf0[15];
  bf1[1] = bf0[1] + bf0[14];
  bf1[2] = bf0[2] + bf0[13];
  bf1[3] = bf0[3] + bf0[12];
  bf1[4] = bf0[4] + bf0[11];
  bf1[5] = bf0[5] + bf0[10];
  bf1[6] = bf0[6] + bf0[9];
  bf1[7] = bf0[7] + bf0[8];
  bf1[8] = bf0[7] - bf0[8];
  bf1[9] = bf0[6] - bf0[9];
  bf1[10] = bf0[5] - bf0[10];
  bf1[11] = bf0[4] - bf0[11];
  bf1[12] = bf0[3] - bf0[12];
  bf1[13] = bf0[2] - bf0[13];
  bf1[14] = bf0[1] - bf0[14];
  bf1[15] = bf0[0] - bf0[15];
375
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
376
}
Angie Chiang's avatar
Angie Chiang committed
377

378 379
void av1_idct32_new(const int32_t *input, int32_t *output, int8_t cos_bit,
                    const int8_t *stage_range) {
Angie Chiang's avatar
Angie Chiang committed
380 381 382 383 384 385 386 387
  const int32_t size = 32;
  const int32_t *cospi;

  int32_t stage = 0;
  int32_t *bf0, *bf1;
  int32_t step[32];

  // stage 0;
388
  apply_range(stage, input, input, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
389 390 391

  // stage 1;
  stage++;
392
  assert(output != input);
Angie Chiang's avatar
Angie Chiang committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
  bf1 = output;
  bf1[0] = input[0];
  bf1[1] = input[16];
  bf1[2] = input[8];
  bf1[3] = input[24];
  bf1[4] = input[4];
  bf1[5] = input[20];
  bf1[6] = input[12];
  bf1[7] = input[28];
  bf1[8] = input[2];
  bf1[9] = input[18];
  bf1[10] = input[10];
  bf1[11] = input[26];
  bf1[12] = input[6];
  bf1[13] = input[22];
  bf1[14] = input[14];
  bf1[15] = input[30];
  bf1[16] = input[1];
  bf1[17] = input[17];
  bf1[18] = input[9];
  bf1[19] = input[25];
  bf1[20] = input[5];
  bf1[21] = input[21];
  bf1[22] = input[13];
  bf1[23] = input[29];
  bf1[24] = input[3];
  bf1[25] = input[19];
  bf1[26] = input[11];
  bf1[27] = input[27];
  bf1[28] = input[7];
  bf1[29] = input[23];
  bf1[30] = input[15];
  bf1[31] = input[31];
426
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
427 428 429

  // stage 2
  stage++;
430
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
  bf1[4] = bf0[4];
  bf1[5] = bf0[5];
  bf1[6] = bf0[6];
  bf1[7] = bf0[7];
  bf1[8] = bf0[8];
  bf1[9] = bf0[9];
  bf1[10] = bf0[10];
  bf1[11] = bf0[11];
  bf1[12] = bf0[12];
  bf1[13] = bf0[13];
  bf1[14] = bf0[14];
  bf1[15] = bf0[15];
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
  bf1[16] = half_btf(cospi[62], bf0[16], -cospi[2], bf0[31], cos_bit);
  bf1[17] = half_btf(cospi[30], bf0[17], -cospi[34], bf0[30], cos_bit);
  bf1[18] = half_btf(cospi[46], bf0[18], -cospi[18], bf0[29], cos_bit);
  bf1[19] = half_btf(cospi[14], bf0[19], -cospi[50], bf0[28], cos_bit);
  bf1[20] = half_btf(cospi[54], bf0[20], -cospi[10], bf0[27], cos_bit);
  bf1[21] = half_btf(cospi[22], bf0[21], -cospi[42], bf0[26], cos_bit);
  bf1[22] = half_btf(cospi[38], bf0[22], -cospi[26], bf0[25], cos_bit);
  bf1[23] = half_btf(cospi[6], bf0[23], -cospi[58], bf0[24], cos_bit);
  bf1[24] = half_btf(cospi[58], bf0[23], cospi[6], bf0[24], cos_bit);
  bf1[25] = half_btf(cospi[26], bf0[22], cospi[38], bf0[25], cos_bit);
  bf1[26] = half_btf(cospi[42], bf0[21], cospi[22], bf0[26], cos_bit);
  bf1[27] = half_btf(cospi[10], bf0[20], cospi[54], bf0[27], cos_bit);
  bf1[28] = half_btf(cospi[50], bf0[19], cospi[14], bf0[28], cos_bit);
  bf1[29] = half_btf(cospi[18], bf0[18], cospi[46], bf0[29], cos_bit);
  bf1[30] = half_btf(cospi[34], bf0[17], cospi[30], bf0[30], cos_bit);
  bf1[31] = half_btf(cospi[2], bf0[16], cospi[62], bf0[31], cos_bit);
465
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
466 467 468

  // stage 3
  stage++;
469
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
470 471 472 473 474 475 476 477 478 479
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
  bf1[4] = bf0[4];
  bf1[5] = bf0[5];
  bf1[6] = bf0[6];
  bf1[7] = bf0[7];
480 481 482 483 484 485 486 487
  bf1[8] = half_btf(cospi[60], bf0[8], -cospi[4], bf0[15], cos_bit);
  bf1[9] = half_btf(cospi[28], bf0[9], -cospi[36], bf0[14], cos_bit);
  bf1[10] = half_btf(cospi[44], bf0[10], -cospi[20], bf0[13], cos_bit);
  bf1[11] = half_btf(cospi[12], bf0[11], -cospi[52], bf0[12], cos_bit);
  bf1[12] = half_btf(cospi[52], bf0[11], cospi[12], bf0[12], cos_bit);
  bf1[13] = half_btf(cospi[20], bf0[10], cospi[44], bf0[13], cos_bit);
  bf1[14] = half_btf(cospi[36], bf0[9], cospi[28], bf0[14], cos_bit);
  bf1[15] = half_btf(cospi[4], bf0[8], cospi[60], bf0[15], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
  bf1[16] = bf0[16] + bf0[17];
  bf1[17] = bf0[16] - bf0[17];
  bf1[18] = -bf0[18] + bf0[19];
  bf1[19] = bf0[18] + bf0[19];
  bf1[20] = bf0[20] + bf0[21];
  bf1[21] = bf0[20] - bf0[21];
  bf1[22] = -bf0[22] + bf0[23];
  bf1[23] = bf0[22] + bf0[23];
  bf1[24] = bf0[24] + bf0[25];
  bf1[25] = bf0[24] - bf0[25];
  bf1[26] = -bf0[26] + bf0[27];
  bf1[27] = bf0[26] + bf0[27];
  bf1[28] = bf0[28] + bf0[29];
  bf1[29] = bf0[28] - bf0[29];
  bf1[30] = -bf0[30] + bf0[31];
  bf1[31] = bf0[30] + bf0[31];
504
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
505 506 507

  // stage 4
  stage++;
508
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
509 510 511 512 513 514
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
515 516 517 518
  bf1[4] = half_btf(cospi[56], bf0[4], -cospi[8], bf0[7], cos_bit);
  bf1[5] = half_btf(cospi[24], bf0[5], -cospi[40], bf0[6], cos_bit);
  bf1[6] = half_btf(cospi[40], bf0[5], cospi[24], bf0[6], cos_bit);
  bf1[7] = half_btf(cospi[8], bf0[4], cospi[56], bf0[7], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
519 520 521 522 523 524 525 526 527
  bf1[8] = bf0[8] + bf0[9];
  bf1[9] = bf0[8] - bf0[9];
  bf1[10] = -bf0[10] + bf0[11];
  bf1[11] = bf0[10] + bf0[11];
  bf1[12] = bf0[12] + bf0[13];
  bf1[13] = bf0[12] - bf0[13];
  bf1[14] = -bf0[14] + bf0[15];
  bf1[15] = bf0[14] + bf0[15];
  bf1[16] = bf0[16];
528 529
  bf1[17] = half_btf(-cospi[8], bf0[17], cospi[56], bf0[30], cos_bit);
  bf1[18] = half_btf(-cospi[56], bf0[18], -cospi[8], bf0[29], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
530 531
  bf1[19] = bf0[19];
  bf1[20] = bf0[20];
532 533
  bf1[21] = half_btf(-cospi[40], bf0[21], cospi[24], bf0[26], cos_bit);
  bf1[22] = half_btf(-cospi[24], bf0[22], -cospi[40], bf0[25], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
534 535
  bf1[23] = bf0[23];
  bf1[24] = bf0[24];
536 537
  bf1[25] = half_btf(-cospi[40], bf0[22], cospi[24], bf0[25], cos_bit);
  bf1[26] = half_btf(cospi[24], bf0[21], cospi[40], bf0[26], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
538 539
  bf1[27] = bf0[27];
  bf1[28] = bf0[28];
540 541
  bf1[29] = half_btf(-cospi[8], bf0[18], cospi[56], bf0[29], cos_bit);
  bf1[30] = half_btf(cospi[56], bf0[17], cospi[8], bf0[30], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
542
  bf1[31] = bf0[31];
543
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
544 545 546

  // stage 5
  stage++;
547
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
548 549
  bf0 = step;
  bf1 = output;
550 551 552 553
  bf1[0] = half_btf(cospi[32], bf0[0], cospi[32], bf0[1], cos_bit);
  bf1[1] = half_btf(cospi[32], bf0[0], -cospi[32], bf0[1], cos_bit);
  bf1[2] = half_btf(cospi[48], bf0[2], -cospi[16], bf0[3], cos_bit);
  bf1[3] = half_btf(cospi[16], bf0[2], cospi[48], bf0[3], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
554 555 556 557 558
  bf1[4] = bf0[4] + bf0[5];
  bf1[5] = bf0[4] - bf0[5];
  bf1[6] = -bf0[6] + bf0[7];
  bf1[7] = bf0[6] + bf0[7];
  bf1[8] = bf0[8];
559 560
  bf1[9] = half_btf(-cospi[16], bf0[9], cospi[48], bf0[14], cos_bit);
  bf1[10] = half_btf(-cospi[48], bf0[10], -cospi[16], bf0[13], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
561 562
  bf1[11] = bf0[11];
  bf1[12] = bf0[12];
563 564
  bf1[13] = half_btf(-cospi[16], bf0[10], cospi[48], bf0[13], cos_bit);
  bf1[14] = half_btf(cospi[48], bf0[9], cospi[16], bf0[14], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
  bf1[15] = bf0[15];
  bf1[16] = bf0[16] + bf0[19];
  bf1[17] = bf0[17] + bf0[18];
  bf1[18] = bf0[17] - bf0[18];
  bf1[19] = bf0[16] - bf0[19];
  bf1[20] = -bf0[20] + bf0[23];
  bf1[21] = -bf0[21] + bf0[22];
  bf1[22] = bf0[21] + bf0[22];
  bf1[23] = bf0[20] + bf0[23];
  bf1[24] = bf0[24] + bf0[27];
  bf1[25] = bf0[25] + bf0[26];
  bf1[26] = bf0[25] - bf0[26];
  bf1[27] = bf0[24] - bf0[27];
  bf1[28] = -bf0[28] + bf0[31];
  bf1[29] = -bf0[29] + bf0[30];
  bf1[30] = bf0[29] + bf0[30];
  bf1[31] = bf0[28] + bf0[31];
582
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
583 584 585

  // stage 6
  stage++;
586
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
587 588 589 590 591 592 593
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0] + bf0[3];
  bf1[1] = bf0[1] + bf0[2];
  bf1[2] = bf0[1] - bf0[2];
  bf1[3] = bf0[0] - bf0[3];
  bf1[4] = bf0[4];
594 595
  bf1[5] = half_btf(-cospi[32], bf0[5], cospi[32], bf0[6], cos_bit);
  bf1[6] = half_btf(cospi[32], bf0[5], cospi[32], bf0[6], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
596 597 598 599 600 601 602 603 604 605 606
  bf1[7] = bf0[7];
  bf1[8] = bf0[8] + bf0[11];
  bf1[9] = bf0[9] + bf0[10];
  bf1[10] = bf0[9] - bf0[10];
  bf1[11] = bf0[8] - bf0[11];
  bf1[12] = -bf0[12] + bf0[15];
  bf1[13] = -bf0[13] + bf0[14];
  bf1[14] = bf0[13] + bf0[14];
  bf1[15] = bf0[12] + bf0[15];
  bf1[16] = bf0[16];
  bf1[17] = bf0[17];
607 608 609 610
  bf1[18] = half_btf(-cospi[16], bf0[18], cospi[48], bf0[29], cos_bit);
  bf1[19] = half_btf(-cospi[16], bf0[19], cospi[48], bf0[28], cos_bit);
  bf1[20] = half_btf(-cospi[48], bf0[20], -cospi[16], bf0[27], cos_bit);
  bf1[21] = half_btf(-cospi[48], bf0[21], -cospi[16], bf0[26], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
611 612 613 614
  bf1[22] = bf0[22];
  bf1[23] = bf0[23];
  bf1[24] = bf0[24];
  bf1[25] = bf0[25];
615 616 617 618
  bf1[26] = half_btf(-cospi[16], bf0[21], cospi[48], bf0[26], cos_bit);
  bf1[27] = half_btf(-cospi[16], bf0[20], cospi[48], bf0[27], cos_bit);
  bf1[28] = half_btf(cospi[48], bf0[19], cospi[16], bf0[28], cos_bit);
  bf1[29] = half_btf(cospi[48], bf0[18], cospi[16], bf0[29], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
619 620
  bf1[30] = bf0[30];
  bf1[31] = bf0[31];
621
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
622 623 624

  // stage 7
  stage++;
625
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
626 627 628 629 630 631 632 633 634 635 636 637
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0] + bf0[7];
  bf1[1] = bf0[1] + bf0[6];
  bf1[2] = bf0[2] + bf0[5];
  bf1[3] = bf0[3] + bf0[4];
  bf1[4] = bf0[3] - bf0[4];
  bf1[5] = bf0[2] - bf0[5];
  bf1[6] = bf0[1] - bf0[6];
  bf1[7] = bf0[0] - bf0[7];
  bf1[8] = bf0[8];
  bf1[9] = bf0[9];
638 639 640 641
  bf1[10] = half_btf(-cospi[32], bf0[10], cospi[32], bf0[13], cos_bit);
  bf1[11] = half_btf(-cospi[32], bf0[11], cospi[32], bf0[12], cos_bit);
  bf1[12] = half_btf(cospi[32], bf0[11], cospi[32], bf0[12], cos_bit);
  bf1[13] = half_btf(cospi[32], bf0[10], cospi[32], bf0[13], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
  bf1[14] = bf0[14];
  bf1[15] = bf0[15];
  bf1[16] = bf0[16] + bf0[23];
  bf1[17] = bf0[17] + bf0[22];
  bf1[18] = bf0[18] + bf0[21];
  bf1[19] = bf0[19] + bf0[20];
  bf1[20] = bf0[19] - bf0[20];
  bf1[21] = bf0[18] - bf0[21];
  bf1[22] = bf0[17] - bf0[22];
  bf1[23] = bf0[16] - bf0[23];
  bf1[24] = -bf0[24] + bf0[31];
  bf1[25] = -bf0[25] + bf0[30];
  bf1[26] = -bf0[26] + bf0[29];
  bf1[27] = -bf0[27] + bf0[28];
  bf1[28] = bf0[27] + bf0[28];
  bf1[29] = bf0[26] + bf0[29];
  bf1[30] = bf0[25] + bf0[30];
  bf1[31] = bf0[24] + bf0[31];
660
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
661 662 663

  // stage 8
  stage++;
664
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0] + bf0[15];
  bf1[1] = bf0[1] + bf0[14];
  bf1[2] = bf0[2] + bf0[13];
  bf1[3] = bf0[3] + bf0[12];
  bf1[4] = bf0[4] + bf0[11];
  bf1[5] = bf0[5] + bf0[10];
  bf1[6] = bf0[6] + bf0[9];
  bf1[7] = bf0[7] + bf0[8];
  bf1[8] = bf0[7] - bf0[8];
  bf1[9] = bf0[6] - bf0[9];
  bf1[10] = bf0[5] - bf0[10];
  bf1[11] = bf0[4] - bf0[11];
  bf1[12] = bf0[3] - bf0[12];
  bf1[13] = bf0[2] - bf0[13];
  bf1[14] = bf0[1] - bf0[14];
  bf1[15] = bf0[0] - bf0[15];
  bf1[16] = bf0[16];
  bf1[17] = bf0[17];
  bf1[18] = bf0[18];
  bf1[19] = bf0[19];
687 688 689 690 691 692 693 694
  bf1[20] = half_btf(-cospi[32], bf0[20], cospi[32], bf0[27], cos_bit);
  bf1[21] = half_btf(-cospi[32], bf0[21], cospi[32], bf0[26], cos_bit);
  bf1[22] = half_btf(-cospi[32], bf0[22], cospi[32], bf0[25], cos_bit);
  bf1[23] = half_btf(-cospi[32], bf0[23], cospi[32], bf0[24], cos_bit);
  bf1[24] = half_btf(cospi[32], bf0[23], cospi[32], bf0[24], cos_bit);
  bf1[25] = half_btf(cospi[32], bf0[22], cospi[32], bf0[25], cos_bit);
  bf1[26] = half_btf(cospi[32], bf0[21], cospi[32], bf0[26], cos_bit);
  bf1[27] = half_btf(cospi[32], bf0[20], cospi[32], bf0[27], cos_bit);
Angie Chiang's avatar
Angie Chiang committed
695 696 697 698
  bf1[28] = bf0[28];
  bf1[29] = bf0[29];
  bf1[30] = bf0[30];
  bf1[31] = bf0[31];
699
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736

  // stage 9
  stage++;
  bf0 = step;
  bf1 = output;
  bf1[0] = bf0[0] + bf0[31];
  bf1[1] = bf0[1] + bf0[30];
  bf1[2] = bf0[2] + bf0[29];
  bf1[3] = bf0[3] + bf0[28];
  bf1[4] = bf0[4] + bf0[27];
  bf1[5] = bf0[5] + bf0[26];
  bf1[6] = bf0[6] + bf0[25];
  bf1[7] = bf0[7] + bf0[24];
  bf1[8] = bf0[8] + bf0[23];
  bf1[9] = bf0[9] + bf0[22];
  bf1[10] = bf0[10] + bf0[21];
  bf1[11] = bf0[11] + bf0[20];
  bf1[12] = bf0[12] + bf0[19];
  bf1[13] = bf0[13] + bf0[18];
  bf1[14] = bf0[14] + bf0[17];
  bf1[15] = bf0[15] + bf0[16];
  bf1[16] = bf0[15] - bf0[16];
  bf1[17] = bf0[14] - bf0[17];
  bf1[18] = bf0[13] - bf0[18];
  bf1[19] = bf0[12] - bf0[19];
  bf1[20] = bf0[11] - bf0[20];
  bf1[21] = bf0[10] - bf0[21];
  bf1[22] = bf0[9] - bf0[22];
  bf1[23] = bf0[8] - bf0[23];
  bf1[24] = bf0[7] - bf0[24];
  bf1[25] = bf0[6] - bf0[25];
  bf1[26] = bf0[5] - bf0[26];
  bf1[27] = bf0[4] - bf0[27];
  bf1[28] = bf0[3] - bf0[28];
  bf1[29] = bf0[2] - bf0[29];
  bf1[30] = bf0[1] - bf0[30];
  bf1[31] = bf0[0] - bf0[31];
737
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
738
}
Angie Chiang's avatar
Angie Chiang committed
739

740 741
void av1_iadst4_new(const int32_t *input, int32_t *output, int8_t cos_bit,
                    const int8_t *stage_range) {
Yaowu Xu's avatar
Yaowu Xu committed
742 743
  const int32_t size = 4;
  int32_t stage = 0;
744
  int bit = cos_bit;
745 746
  const int32_t *sinpi = sinpi_arr(bit);
  int32_t s0, s1, s2, s3, s4, s5, s6, s7;
Yaowu Xu's avatar
Yaowu Xu committed
747
  // stage 0;
748
  apply_range(stage, input, input, size, stage_range[stage]);
749 750 751 752 753 754 755 756 757 758

  int32_t x0 = input[0];
  int32_t x1 = input[1];
  int32_t x2 = input[2];
  int32_t x3 = input[3];

  if (!(x0 | x1 | x2 | x3)) {
    output[0] = output[1] = output[2] = output[3] = 0;
    return;
  }
Angie Chiang's avatar
Angie Chiang committed
759

760 761 762 763 764 765 766
  s0 = sinpi[1] * x0;
  s1 = sinpi[2] * x0;
  s2 = sinpi[3] * x1;
  s3 = sinpi[4] * x2;
  s4 = sinpi[1] * x2;
  s5 = sinpi[2] * x3;
  s6 = sinpi[4] * x3;
Yaowu Xu's avatar
Yaowu Xu committed
767
  s7 = x0 - x2 + x3;
768 769 770 771

  s0 = s0 + s3 + s5;
  s1 = s1 - s4 - s6;
  s3 = s2;
772
  s2 = sinpi[3] * s7;
773 774 775 776 777

  // 1-D transform scaling factor is sqrt(2).
  // The overall dynamic range is 14b (input) + 14b (multiplication scaling)
  // + 1b (addition) = 29b.
  // Hence the output bit depth is 15b.
Yaowu Xu's avatar
Yaowu Xu committed
778
  stage = 3;
779 780 781 782
  output[0] = round_shift(s0 + s3, bit);
  output[1] = round_shift(s1 + s3, bit);
  output[2] = round_shift(s2, bit);
  output[3] = round_shift(s0 + s1 - s3, bit);
783
  apply_range(stage, input, output, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
784
}
Angie Chiang's avatar
Angie Chiang committed
785

786 787
void av1_iadst8_new(const int32_t *input, int32_t *output, int8_t cos_bit,
                    const int8_t *stage_range) {
Angie Chiang's avatar
Angie Chiang committed
788 789 790 791 792 793 794 795
  const int32_t size = 8;
  const int32_t *cospi;

  int32_t stage = 0;
  int32_t *bf0, *bf1;
  int32_t step[8];

  // stage 0;
796
  apply_range(stage, input, input, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
797 798 799 800

  // stage 1;
  stage++;
  bf1 = output;
801 802 803 804 805 806 807 808
  bf1[0] = input[7];
  bf1[1] = input[0];
  bf1[2] = input[5];
  bf1[3] = input[2];
  bf1[4] = input[3];
  bf1[5] = input[4];
  bf1[6] = input[1];
  bf1[7] = input[6];
809
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
810 811 812

  // stage 2
  stage++;
813
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
814 815
  bf0 = output;
  bf1 = step;
816 817 818 819 820 821 822 823
  bf1[0] = half_btf(cospi[4], bf0[0], cospi[60], bf0[1], cos_bit);
  bf1[1] = half_btf(-cospi[4], bf0[1], cospi[60], bf0[0], cos_bit);
  bf1[2] = half_btf(cospi[20], bf0[2], cospi[44], bf0[3], cos_bit);
  bf1[3] = half_btf(-cospi[20], bf0[3], cospi[44], bf0[2], cos_bit);
  bf1[4] = half_btf(cospi[36], bf0[4], cospi[28], bf0[5], cos_bit);
  bf1[5] = half_btf(-cospi[36], bf0[5], cospi[28], bf0[4], cos_bit);
  bf1[6] = half_btf(cospi[52], bf0[6], cospi[12], bf0[7], cos_bit);
  bf1[7] = half_btf(-cospi[52], bf0[7], cospi[12], bf0[6], cos_bit);
824
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
825 826 827 828 829

  // stage 3
  stage++;
  bf0 = step;
  bf1 = output;
830 831 832 833 834 835 836 837
  bf1[0] = bf0[0] + bf0[4];
  bf1[1] = bf0[1] + bf0[5];
  bf1[2] = bf0[2] + bf0[6];
  bf1[3] = bf0[3] + bf0[7];
  bf1[4] = -bf0[4] + bf0[0];
  bf1[5] = -bf0[5] + bf0[1];
  bf1[6] = -bf0[6] + bf0[2];
  bf1[7] = -bf0[7] + bf0[3];
838
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
839 840 841

  // stage 4
  stage++;
842
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
843 844 845 846 847 848
  bf0 = output;
  bf1 = step;
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
  bf1[2] = bf0[2];
  bf1[3] = bf0[3];
849 850 851 852
  bf1[4] = half_btf(cospi[16], bf0[4], cospi[48], bf0[5], cos_bit);
  bf1[5] = half_btf(-cospi[16], bf0[5], cospi[48], bf0[4], cos_bit);
  bf1[6] = half_btf(-cospi[48], bf0[6], cospi[16], bf0[7], cos_bit);
  bf1[7] = half_btf(cospi[48], bf0[7], cospi[16], bf0[6], cos_bit);
853
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
854 855 856 857 858

  // stage 5
  stage++;
  bf0 = step;
  bf1 = output;
859 860 861 862 863 864 865 866
  bf1[0] = bf0[0] + bf0[2];
  bf1[1] = bf0[1] + bf0[3];
  bf1[2] = -bf0[2] + bf0[0];
  bf1[3] = -bf0[3] + bf0[1];
  bf1[4] = bf0[4] + bf0[6];
  bf1[5] = bf0[5] + bf0[7];
  bf1[6] = -bf0[6] + bf0[4];
  bf1[7] = -bf0[7] + bf0[5];
867
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
868 869 870

  // stage 6
  stage++;
871
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
872 873
  bf0 = output;
  bf1 = step;
874 875
  bf1[0] = bf0[0];
  bf1[1] = bf0[1];
876 877
  bf1[2] = half_btf(cospi[32], bf0[2], cospi[32], bf0[3], cos_bit);
  bf1[3] = half_btf(-cospi[32], bf0[3], cospi[32], bf0[2], cos_bit);
878 879
  bf1[4] = bf0[4];
  bf1[5] = bf0[5];
880 881
  bf1[6] = half_btf(cospi[32], bf0[6], cospi[32], bf0[7], cos_bit);
  bf1[7] = half_btf(-cospi[32], bf0[7], cospi[32], bf0[6], cos_bit);
882
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
883 884 885 886 887

  // stage 7
  stage++;
  bf0 = step;
  bf1 = output;
888 889 890 891 892 893 894 895
  bf1[0] = bf0[0];
  bf1[1] = -bf0[4];
  bf1[2] = bf0[6];
  bf1[3] = -bf0[2];
  bf1[4] = bf0[3];
  bf1[5] = -bf0[7];
  bf1[6] = bf0[5];
  bf1[7] = -bf0[1];
896
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
897
}
Angie Chiang's avatar
Angie Chiang committed
898

899 900
void av1_iadst16_new(const int32_t *input, int32_t *output, int8_t cos_bit,
                     const int8_t *stage_range) {
Angie Chiang's avatar
Angie Chiang committed
901 902 903 904 905 906 907 908
  const int32_t size = 16;
  const int32_t *cospi;

  int32_t stage = 0;
  int32_t *bf0, *bf1;
  int32_t step[16];

  // stage 0;
909
  apply_range(stage, input, input, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
910 911 912 913

  // stage 1;
  stage++;
  bf1 = output;
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
  bf1[0] = input[15];
  bf1[1] = input[0];
  bf1[2] = input[13];
  bf1[3] = input[2];
  bf1[4] = input[11];
  bf1[5] = input[4];
  bf1[6] = input[9];
  bf1[7] = input[6];
  bf1[8] = input[7];
  bf1[9] = input[8];
  bf1[10] = input[5];
  bf1[11] = input[10];
  bf1[12] = input[3];
  bf1[13] = input[12];
  bf1[14] = input[1];
  bf1[15] = input[14];
930
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
931 932 933

  // stage 2
  stage++;
934
  cospi = cospi_arr(cos_bit);
Angie Chiang's avatar
Angie Chiang committed
935 936
  bf0 = output;
  bf1 = step;
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
  bf1[0] = half_btf(cospi[2], bf0[0], cospi[62], bf0[1], cos_bit);
  bf1[1] = half_btf(-cospi[2], bf0[1], cospi[62], bf0[0], cos_bit);
  bf1[2] = half_btf(cospi[10], bf0[2], cospi[54], bf0[3], cos_bit);
  bf1[3] = half_btf(-cospi[10], bf0[3], cospi[54], bf0[2], cos_bit);
  bf1[4] = half_btf(cospi[18], bf0[4], cospi[46], bf0[5], cos_bit);
  bf1[5] = half_btf(-cospi[18], bf0[5], cospi[46], bf0[4], cos_bit);
  bf1[6] = half_btf(cospi[26], bf0[6], cospi[38], bf0[7], cos_bit);
  bf1[7] = half_btf(-cospi[26], bf0[7], cospi[38], bf0[6], cos_bit);
  bf1[8] = half_btf(cospi[34], bf0[8], cospi[30], bf0[9], cos_bit);
  bf1[9] = half_btf(-cospi[34], bf0[9], cospi[30], bf0[8], cos_bit);
  bf1[10] = half_btf(cospi[42], bf0[10], cospi[22], bf0[11], cos_bit);
  bf1[11] = half_btf(-cospi[42], bf0[11], cospi[22], bf0[10], cos_bit);
  bf1[12] = half_btf(cospi[50], bf0[12], cospi[14], bf0[13], cos_bit);
  bf1[13] = half_btf(-cospi[50], bf0[13], cospi[14], bf0[12], cos_bit);
  bf1[14] = half_btf(cospi[58], bf0[14], cospi[6], bf0[15], cos_bit);
  bf1[15] = half_btf(-cospi[58], bf0[15], cospi[6], bf0[14], cos_bit);
953
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
954 955 956 957 958

  // stage 3
  stage++;
  bf0 = step;
  bf1 = output;
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
  bf1[0] = bf0[0] + bf0[8];
  bf1[1] = bf0[1] + bf0[9];
  bf1[2] = bf0[2] + bf0[10];
  bf1[3] = bf0[3] + bf0[11];
  bf1[4] = bf0[4] + bf0[12];
  bf1[5] = bf0[5] + bf0[13];
  bf1[6] = bf0[6] + bf0[14];
  bf1[7] = bf0[7] + bf0[15];
  bf1[8] = -bf0[8] + bf0[0];
  bf1[9] = -bf0[9] + bf0[1];
  bf1[10] = -bf0[10] + bf0[2];
  bf1[11] = -bf0[11] + bf0[3];
  bf1[12] = -bf0[12] + bf0[4];
  bf1[13] = -bf0[13] + bf0[5];
  bf1[14] = -bf0[14] + bf0[6];
  bf1[15] = -bf0[15] + bf0[7];
975
  apply_range(stage, input, bf1, size, stage_range[stage]);
Angie Chiang's avatar
Angie Chiang committed
976 977 978

  // stage 4
  stage++;
979
  cospi = cospi_arr(cos_bit);