idct.c 72.7 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
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.
Jingning Han's avatar
Jingning Han committed
10 11 12 13
 */

#include <math.h>

Yaowu Xu's avatar
Yaowu Xu committed
14
#include "./aom_dsp_rtcd.h"
Geza Lore's avatar
Geza Lore committed
15 16 17 18
#include "./av1_rtcd.h"
#include "aom_dsp/inv_txfm.h"
#include "aom_ports/mem.h"
#include "av1/common/av1_inv_txfm2d_cfg.h"
19 20 21
#include "av1/common/blockd.h"
#include "av1/common/enums.h"
#include "av1/common/idct.h"
Jingning Han's avatar
Jingning Han committed
22

23 24
int get_tx_scale(const MACROBLOCKD *const xd, const TX_TYPE tx_type,
                 const TX_SIZE tx_size) {
clang-format's avatar
clang-format committed
25
  (void)tx_type;
Yaowu Xu's avatar
Yaowu Xu committed
26
#if CONFIG_AOM_HIGHBITDEPTH
27
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
28
    return txsize_sqr_up_map[tx_size] == TX_32X32;
29 30 31 32
  }
#else
  (void)xd;
#endif
33
  return txsize_sqr_up_map[tx_size] == TX_32X32;
34 35
}

36 37 38
// NOTE: The implementation of all inverses need to be aware of the fact
// that input and output could be the same buffer.

39
#if CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
40 41 42 43 44 45 46 47
static void iidtx4_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  for (i = 0; i < 4; ++i)
    output[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
}

static void iidtx8_c(const tran_low_t *input, tran_low_t *output) {
  int i;
clang-format's avatar
clang-format committed
48
  for (i = 0; i < 8; ++i) output[i] = input[i] * 2;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
49 50 51 52 53 54 55 56 57 58
}

static void iidtx16_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  for (i = 0; i < 16; ++i)
    output[i] = (tran_low_t)dct_const_round_shift(input[i] * 2 * Sqrt2);
}

static void iidtx32_c(const tran_low_t *input, tran_low_t *output) {
  int i;
clang-format's avatar
clang-format committed
59
  for (i = 0; i < 32; ++i) output[i] = input[i] * 4;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
60
}
61
#endif  // CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
62

63
// For use in lieu of ADST
64 65 66 67 68 69 70
static void ihalfright32_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  tran_low_t inputhalf[16];
  // Multiply input by sqrt(2)
  for (i = 0; i < 16; ++i) {
    inputhalf[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
  }
71 72 73
  for (i = 0; i < 16; ++i) {
    output[i] = input[16 + i] * 4;
  }
Luca Barbato's avatar
Luca Barbato committed
74
  aom_idct16_c(inputhalf, output + 16);
75 76 77
  // Note overall scaling factor is 4 times orthogonal
}

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#if CONFIG_TX64X64
static void idct64_col_c(const tran_low_t *input, tran_low_t *output) {
  int32_t in[64], out[64];
  int i;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
  av1_idct64_new(in, out, inv_cos_bit_col_dct_dct_64,
                 inv_stage_range_col_dct_dct_64);
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}

static void idct64_row_c(const tran_low_t *input, tran_low_t *output) {
  int32_t in[64], out[64];
  int i;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
  av1_idct64_new(in, out, inv_cos_bit_row_dct_dct_64,
                 inv_stage_range_row_dct_dct_64);
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}

static void iidtx64_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  for (i = 0; i < 64; ++i)
    output[i] = (tran_low_t)dct_const_round_shift(input[i] * 4 * Sqrt2);
}

// For use in lieu of ADST
static void ihalfright64_c(const tran_low_t *input, tran_low_t *output) {
  int i;
  tran_low_t inputhalf[32];
  // Multiply input by sqrt(2)
  for (i = 0; i < 32; ++i) {
    inputhalf[i] = (tran_low_t)dct_const_round_shift(input[i] * Sqrt2);
  }
  for (i = 0; i < 32; ++i) {
    output[i] = (tran_low_t)dct_const_round_shift(input[32 + i] * 4 * Sqrt2);
  }
  aom_idct32_c(inputhalf, output + 32);
  // Note overall scaling factor is 4 * sqrt(2)  times orthogonal
}
#endif  // CONFIG_TX64X64

Yaowu Xu's avatar
Yaowu Xu committed
119
#if CONFIG_AOM_HIGHBITDEPTH
120
#if CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
121 122 123 124
static void highbd_iidtx4_c(const tran_low_t *input, tran_low_t *output,
                            int bd) {
  int i;
  for (i = 0; i < 4; ++i)
clang-format's avatar
clang-format committed
125 126
    output[i] =
        HIGHBD_WRAPLOW(highbd_dct_const_round_shift(input[i] * Sqrt2), bd);
Debargha Mukherjee's avatar
Debargha Mukherjee committed
127 128 129 130 131
}

static void highbd_iidtx8_c(const tran_low_t *input, tran_low_t *output,
                            int bd) {
  int i;
clang-format's avatar
clang-format committed
132 133
  (void)bd;
  for (i = 0; i < 8; ++i) output[i] = input[i] * 2;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
134 135 136
}

static void highbd_iidtx16_c(const tran_low_t *input, tran_low_t *output,
clang-format's avatar
clang-format committed
137
                             int bd) {
Debargha Mukherjee's avatar
Debargha Mukherjee committed
138 139
  int i;
  for (i = 0; i < 16; ++i)
clang-format's avatar
clang-format committed
140 141
    output[i] =
        HIGHBD_WRAPLOW(highbd_dct_const_round_shift(input[i] * 2 * Sqrt2), bd);
Debargha Mukherjee's avatar
Debargha Mukherjee committed
142 143 144 145 146
}

static void highbd_iidtx32_c(const tran_low_t *input, tran_low_t *output,
                             int bd) {
  int i;
clang-format's avatar
clang-format committed
147 148
  (void)bd;
  for (i = 0; i < 32; ++i) output[i] = input[i] * 4;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
149
}
150
#endif  // CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
151

152 153 154 155 156 157
static void highbd_ihalfright32_c(const tran_low_t *input, tran_low_t *output,
                                  int bd) {
  int i;
  tran_low_t inputhalf[16];
  // Multiply input by sqrt(2)
  for (i = 0; i < 16; ++i) {
clang-format's avatar
clang-format committed
158 159
    inputhalf[i] =
        HIGHBD_WRAPLOW(highbd_dct_const_round_shift(input[i] * Sqrt2), bd);
160
  }
161 162 163
  for (i = 0; i < 16; ++i) {
    output[i] = input[16 + i] * 4;
  }
Yaowu Xu's avatar
Yaowu Xu committed
164
  aom_highbd_idct16_c(inputhalf, output + 16, bd);
165 166
  // Note overall scaling factor is 4 times orthogonal
}
167

168
#if CONFIG_EXT_TX
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
#if CONFIG_TX64X64
static void highbd_iidtx64_c(const tran_low_t *input, tran_low_t *output,
                             int bd) {
  int i;
  for (i = 0; i < 64; ++i)
    output[i] =
        HIGHBD_WRAPLOW(highbd_dct_const_round_shift(input[i] * 4 * Sqrt2), bd);
}

// For use in lieu of ADST
static void highbd_ihalfright64_c(const tran_low_t *input, tran_low_t *output,
                                  int bd) {
  int i;
  tran_low_t inputhalf[32];
  // Multiply input by sqrt(2)
  for (i = 0; i < 32; ++i) {
    inputhalf[i] =
        HIGHBD_WRAPLOW(highbd_dct_const_round_shift(input[i] * Sqrt2), bd);
  }
  for (i = 0; i < 32; ++i) {
    output[i] = HIGHBD_WRAPLOW(
        highbd_dct_const_round_shift(input[32 + i] * 4 * Sqrt2), bd);
  }
  aom_highbd_idct32_c(inputhalf, output + 32, bd);
  // Note overall scaling factor is 4 * sqrt(2)  times orthogonal
}

static void highbd_idct64_col_c(const tran_low_t *input, tran_low_t *output,
                                int bd) {
  int32_t in[64], out[64];
  int i;
  (void)bd;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
  av1_idct64_new(in, out, inv_cos_bit_col_dct_dct_64,
                 inv_stage_range_col_dct_dct_64);
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}

static void highbd_idct64_row_c(const tran_low_t *input, tran_low_t *output,
                                int bd) {
  int32_t in[64], out[64];
  int i;
  (void)bd;
  for (i = 0; i < 64; ++i) in[i] = (int32_t)input[i];
  av1_idct64_new(in, out, inv_cos_bit_row_dct_dct_64,
                 inv_stage_range_row_dct_dct_64);
  for (i = 0; i < 64; ++i) output[i] = (tran_low_t)out[i];
}
#endif  // CONFIG_TX64X64
218
#endif  // CONFIG_EXT_TX
Yaowu Xu's avatar
Yaowu Xu committed
219
#endif  // CONFIG_AOM_HIGHBITDEPTH
220

Jingning Han's avatar
Jingning Han committed
221
// Inverse identity transform and add.
222
#if CONFIG_EXT_TX
223
static void inv_idtx_add_c(const tran_low_t *input, uint8_t *dest, int stride,
Jingning Han's avatar
Jingning Han committed
224
                           int bs, int tx_type) {
225 226
  int r, c;
  const int shift = bs < 32 ? 3 : 2;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
227
  if (tx_type == IDTX) {
Jingning Han's avatar
Jingning Han committed
228 229
    for (r = 0; r < bs; ++r) {
      for (c = 0; c < bs; ++c)
Debargha Mukherjee's avatar
Debargha Mukherjee committed
230 231 232
        dest[c] = clip_pixel_add(dest[c], input[c] >> shift);
      dest += stride;
      input += bs;
Jingning Han's avatar
Jingning Han committed
233
    }
234 235
  }
}
236
#endif  // CONFIG_EXT_TX
237

clang-format's avatar
clang-format committed
238 239 240 241 242
#define FLIPUD_PTR(dest, stride, size)       \
  do {                                       \
    (dest) = (dest) + ((size)-1) * (stride); \
    (stride) = -(stride);                    \
  } while (0)
243

244
#if CONFIG_EXT_TX
clang-format's avatar
clang-format committed
245 246 247
static void maybe_flip_strides(uint8_t **dst, int *dstride, tran_low_t **src,
                               int *sstride, int tx_type, int sizey,
                               int sizex) {
248 249 250 251 252 253 254 255
  // Note that the transpose of src will be added to dst. In order to LR
  // flip the addends (in dst coordinates), we UD flip the src. To UD flip
  // the addends, we UD flip the dst.
  switch (tx_type) {
    case DCT_DCT:
    case ADST_DCT:
    case DCT_ADST:
    case ADST_ADST:
Debargha Mukherjee's avatar
Debargha Mukherjee committed
256
    case IDTX:
Jingning Han's avatar
Jingning Han committed
257 258
    case V_DCT:
    case H_DCT:
259
    case V_ADST:
clang-format's avatar
clang-format committed
260
    case H_ADST: break;
261 262
    case FLIPADST_DCT:
    case FLIPADST_ADST:
263
    case V_FLIPADST:
264
      // flip UD
265
      FLIPUD_PTR(*dst, *dstride, sizey);
266 267 268
      break;
    case DCT_FLIPADST:
    case ADST_FLIPADST:
269
    case H_FLIPADST:
270
      // flip LR
271
      FLIPUD_PTR(*src, *sstride, sizex);
272 273 274
      break;
    case FLIPADST_FLIPADST:
      // flip UD
275
      FLIPUD_PTR(*dst, *dstride, sizey);
276
      // flip LR
277
      FLIPUD_PTR(*src, *sstride, sizex);
278
      break;
clang-format's avatar
clang-format committed
279
    default: assert(0); break;
280 281
  }
}
282
#endif  // CONFIG_EXT_TX
283

Yaowu Xu's avatar
Yaowu Xu committed
284
#if CONFIG_AOM_HIGHBITDEPTH
285
#if CONFIG_EXT_TX
286
static void highbd_inv_idtx_add_c(const tran_low_t *input, uint8_t *dest8,
287
                                  int stride, int bs, int tx_type, int bd) {
288 289 290
  int r, c;
  const int shift = bs < 32 ? 3 : 2;
  uint16_t *dest = CONVERT_TO_SHORTPTR(dest8);
291

Debargha Mukherjee's avatar
Debargha Mukherjee committed
292
  if (tx_type == IDTX) {
293 294
    for (r = 0; r < bs; ++r) {
      for (c = 0; c < bs; ++c)
Debargha Mukherjee's avatar
Debargha Mukherjee committed
295 296 297
        dest[c] = highbd_clip_pixel_add(dest[c], input[c] >> shift, bd);
      dest += stride;
      input += bs;
298
    }
299 300
  }
}
301

clang-format's avatar
clang-format committed
302 303 304
static void maybe_flip_strides16(uint16_t **dst, int *dstride, tran_low_t **src,
                                 int *sstride, int tx_type, int sizey,
                                 int sizex) {
305 306 307 308 309 310 311 312
  // Note that the transpose of src will be added to dst. In order to LR
  // flip the addends (in dst coordinates), we UD flip the src. To UD flip
  // the addends, we UD flip the dst.
  switch (tx_type) {
    case DCT_DCT:
    case ADST_DCT:
    case DCT_ADST:
    case ADST_ADST:
Debargha Mukherjee's avatar
Debargha Mukherjee committed
313 314 315
    case IDTX:
    case V_DCT:
    case H_DCT:
316
    case V_ADST:
clang-format's avatar
clang-format committed
317
    case H_ADST: break;
318 319
    case FLIPADST_DCT:
    case FLIPADST_ADST:
320
    case V_FLIPADST:
321
      // flip UD
322
      FLIPUD_PTR(*dst, *dstride, sizey);
323 324 325
      break;
    case DCT_FLIPADST:
    case ADST_FLIPADST:
326
    case H_FLIPADST:
327
      // flip LR
328
      FLIPUD_PTR(*src, *sstride, sizex);
329 330 331
      break;
    case FLIPADST_FLIPADST:
      // flip UD
332
      FLIPUD_PTR(*dst, *dstride, sizey);
333
      // flip LR
334
      FLIPUD_PTR(*src, *sstride, sizex);
335
      break;
clang-format's avatar
clang-format committed
336
    default: assert(0); break;
337 338
  }
}
339
#endif  // CONFIG_EXT_TX
340
#endif  // CONFIG_AOM_HIGHBITDEPTH
341

Yaowu Xu's avatar
Yaowu Xu committed
342 343
void av1_iht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
344
  static const transform_2d IHT_4[] = {
Luca Barbato's avatar
Luca Barbato committed
345 346 347 348
    { aom_idct4_c, aom_idct4_c },    // DCT_DCT  = 0
    { aom_iadst4_c, aom_idct4_c },   // ADST_DCT = 1
    { aom_idct4_c, aom_iadst4_c },   // DCT_ADST = 2
    { aom_iadst4_c, aom_iadst4_c },  // ADST_ADST = 3
349
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
350 351 352 353 354 355 356 357 358 359 360 361 362
    { aom_iadst4_c, aom_idct4_c },   // FLIPADST_DCT
    { aom_idct4_c, aom_iadst4_c },   // DCT_FLIPADST
    { aom_iadst4_c, aom_iadst4_c },  // FLIPADST_FLIPADST
    { aom_iadst4_c, aom_iadst4_c },  // ADST_FLIPADST
    { aom_iadst4_c, aom_iadst4_c },  // FLIPADST_ADST
    { iidtx4_c, iidtx4_c },          // IDTX
    { aom_idct4_c, iidtx4_c },       // V_DCT
    { iidtx4_c, aom_idct4_c },       // H_DCT
    { aom_iadst4_c, iidtx4_c },      // V_ADST
    { iidtx4_c, aom_iadst4_c },      // H_ADST
    { aom_iadst4_c, iidtx4_c },      // V_FLIPADST
    { iidtx4_c, aom_iadst4_c },      // H_FLIPADST
#endif                               // CONFIG_EXT_TX
363 364 365
  };

  int i, j;
366 367 368 369
  tran_low_t tmp;
  tran_low_t out[4][4];
  tran_low_t *outp = &out[0][0];
  int outstride = 4;
370 371 372

  // inverse transform row vectors
  for (i = 0; i < 4; ++i) {
373
    IHT_4[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
374
    input += 4;
375 376 377
  }

  // transpose
clang-format's avatar
clang-format committed
378
  for (i = 1; i < 4; i++) {
379
    for (j = 0; j < i; j++) {
clang-format's avatar
clang-format committed
380
      tmp = out[i][j];
381 382 383
      out[i][j] = out[j][i];
      out[j][i] = tmp;
    }
384 385 386 387
  }

  // inverse transform column vectors
  for (i = 0; i < 4; ++i) {
388 389 390 391
    IHT_4[tx_type].cols(out[i], out[i]);
  }

#if CONFIG_EXT_TX
392
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 4, 4);
393 394 395 396
#endif

  // Sum with the destination
  for (i = 0; i < 4; ++i) {
397
    for (j = 0; j < 4; ++j) {
398 399 400
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 4));
401 402 403 404
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
405 406
void av1_iht4x8_32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
407
  static const transform_2d IHT_4x8[] = {
Luca Barbato's avatar
Luca Barbato committed
408 409 410 411
    { aom_idct8_c, aom_idct4_c },    // DCT_DCT
    { aom_iadst8_c, aom_idct4_c },   // ADST_DCT
    { aom_idct8_c, aom_iadst4_c },   // DCT_ADST
    { aom_iadst8_c, aom_iadst4_c },  // ADST_ADST
412
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
413 414 415 416 417 418 419 420 421 422 423 424
    { aom_iadst8_c, aom_idct4_c },   // FLIPADST_DCT
    { aom_idct8_c, aom_iadst4_c },   // DCT_FLIPADST
    { aom_iadst8_c, aom_iadst4_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, aom_iadst4_c },  // ADST_FLIPADST
    { aom_iadst8_c, aom_iadst4_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx4_c },          // IDTX
    { aom_idct8_c, iidtx4_c },       // V_DCT
    { iidtx8_c, aom_idct4_c },       // H_DCT
    { aom_iadst8_c, iidtx4_c },      // V_ADST
    { iidtx8_c, aom_iadst4_c },      // H_ADST
    { aom_iadst8_c, iidtx4_c },      // V_FLIPADST
    { iidtx8_c, aom_iadst4_c },      // H_FLIPADST
425
#endif
426 427
  };

428 429
  const int n = 4;
  const int n2 = 8;
430 431 432
  int i, j;
  tran_low_t out[4][8], outtmp[4];
  tran_low_t *outp = &out[0][0];
433
  int outstride = n2;
434 435

  // inverse transform row vectors and transpose
436
  for (i = 0; i < n2; ++i) {
437
    IHT_4x8[tx_type].rows(input, outtmp);
438
    for (j = 0; j < n; ++j)
439
      out[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
440
    input += n;
441 442 443
  }

  // inverse transform column vectors
444
  for (i = 0; i < n; ++i) {
445 446 447
    IHT_4x8[tx_type].cols(out[i], out[i]);
  }

448
#if CONFIG_EXT_TX
449
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
450
#endif
451 452

  // Sum with the destination
453 454
  for (i = 0; i < n2; ++i) {
    for (j = 0; j < n; ++j) {
455 456 457 458 459 460 461
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
462 463
void av1_iht8x4_32_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
464
  static const transform_2d IHT_8x4[] = {
Luca Barbato's avatar
Luca Barbato committed
465 466 467 468
    { aom_idct4_c, aom_idct8_c },    // DCT_DCT
    { aom_iadst4_c, aom_idct8_c },   // ADST_DCT
    { aom_idct4_c, aom_iadst8_c },   // DCT_ADST
    { aom_iadst4_c, aom_iadst8_c },  // ADST_ADST
469
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
470 471 472 473 474 475 476 477 478 479 480 481
    { aom_iadst4_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct4_c, aom_iadst8_c },   // DCT_FLIPADST
    { aom_iadst4_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { aom_iadst4_c, aom_iadst8_c },  // ADST_FLIPADST
    { aom_iadst4_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx4_c, iidtx8_c },          // IDTX
    { aom_idct4_c, iidtx8_c },       // V_DCT
    { iidtx4_c, aom_idct8_c },       // H_DCT
    { aom_iadst4_c, iidtx8_c },      // V_ADST
    { iidtx4_c, aom_iadst8_c },      // H_ADST
    { aom_iadst4_c, iidtx8_c },      // V_FLIPADST
    { iidtx4_c, aom_iadst8_c },      // H_FLIPADST
482
#endif
483
  };
484 485
  const int n = 4;
  const int n2 = 8;
486 487 488 489

  int i, j;
  tran_low_t out[8][4], outtmp[8];
  tran_low_t *outp = &out[0][0];
490
  int outstride = n;
491 492

  // inverse transform row vectors and transpose
493
  for (i = 0; i < n; ++i) {
494
    IHT_8x4[tx_type].rows(input, outtmp);
495
    for (j = 0; j < n2; ++j)
496
      out[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
497
    input += n2;
498 499 500
  }

  // inverse transform column vectors
501
  for (i = 0; i < n2; ++i) {
502 503 504
    IHT_8x4[tx_type].cols(out[i], out[i]);
  }

505
#if CONFIG_EXT_TX
506
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
507
#endif
508 509

  // Sum with the destination
510 511
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n2; ++j) {
512 513 514 515 516 517 518
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
519 520
void av1_iht8x16_128_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                           int tx_type) {
521
  static const transform_2d IHT_8x16[] = {
Luca Barbato's avatar
Luca Barbato committed
522 523 524 525
    { aom_idct16_c, aom_idct8_c },    // DCT_DCT
    { aom_iadst16_c, aom_idct8_c },   // ADST_DCT
    { aom_idct16_c, aom_iadst8_c },   // DCT_ADST
    { aom_iadst16_c, aom_iadst8_c },  // ADST_ADST
526
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
527 528 529 530 531 532 533 534 535 536 537 538
    { aom_iadst16_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct16_c, aom_iadst8_c },   // DCT_FLIPADST
    { aom_iadst16_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, aom_iadst8_c },  // ADST_FLIPADST
    { aom_iadst16_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx8_c },          // IDTX
    { aom_idct16_c, iidtx8_c },       // V_DCT
    { iidtx16_c, aom_idct8_c },       // H_DCT
    { aom_iadst16_c, iidtx8_c },      // V_ADST
    { iidtx16_c, aom_iadst8_c },      // H_ADST
    { aom_iadst16_c, iidtx8_c },      // V_FLIPADST
    { iidtx16_c, aom_iadst8_c },      // H_FLIPADST
539
#endif
540 541 542 543 544 545 546 547 548 549 550 551 552 553
  };

  const int n = 8;
  const int n2 = 16;
  int i, j;
  tran_low_t out[8][16], outtmp[8];
  tran_low_t *outp = &out[0][0];
  int outstride = n2;

  // inverse transform row vectors and transpose
  for (i = 0; i < n2; ++i) {
    IHT_8x16[tx_type].rows(input, outtmp);
    for (j = 0; j < n; ++j)
      out[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
554
    input += n;
555 556 557 558 559 560 561
  }

  // inverse transform column vectors
  for (i = 0; i < n; ++i) {
    IHT_8x16[tx_type].cols(out[i], out[i]);
  }

562
#if CONFIG_EXT_TX
563
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
564
#endif
565 566 567 568 569 570 571 572 573 574 575

  // Sum with the destination
  for (i = 0; i < n2; ++i) {
    for (j = 0; j < n; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
576 577
void av1_iht16x8_128_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                           int tx_type) {
578
  static const transform_2d IHT_16x8[] = {
Luca Barbato's avatar
Luca Barbato committed
579 580 581 582
    { aom_idct8_c, aom_idct16_c },    // DCT_DCT
    { aom_iadst8_c, aom_idct16_c },   // ADST_DCT
    { aom_idct8_c, aom_iadst16_c },   // DCT_ADST
    { aom_iadst8_c, aom_iadst16_c },  // ADST_ADST
583
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
584 585 586 587 588 589 590 591 592 593 594 595
    { aom_iadst8_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct8_c, aom_iadst16_c },   // DCT_FLIPADST
    { aom_iadst8_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, aom_iadst16_c },  // ADST_FLIPADST
    { aom_iadst8_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx16_c },          // IDTX
    { aom_idct8_c, iidtx16_c },       // V_DCT
    { iidtx8_c, aom_idct16_c },       // H_DCT
    { aom_iadst8_c, iidtx16_c },      // V_ADST
    { iidtx8_c, aom_iadst16_c },      // H_ADST
    { aom_iadst8_c, iidtx16_c },      // V_FLIPADST
    { iidtx8_c, aom_iadst16_c },      // H_FLIPADST
596
#endif
597 598 599 600 601 602 603 604 605 606 607 608 609 610
  };
  const int n = 8;
  const int n2 = 16;

  int i, j;
  tran_low_t out[16][8], outtmp[16];
  tran_low_t *outp = &out[0][0];
  int outstride = n;

  // inverse transform row vectors and transpose
  for (i = 0; i < n; ++i) {
    IHT_16x8[tx_type].rows(input, outtmp);
    for (j = 0; j < n2; ++j)
      out[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
611
    input += n2;
612 613 614 615 616 617 618
  }

  // inverse transform column vectors
  for (i = 0; i < n2; ++i) {
    IHT_16x8[tx_type].cols(out[i], out[i]);
  }

619
#if CONFIG_EXT_TX
620
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
621
#endif
622 623 624 625 626 627 628 629 630 631 632

  // Sum with the destination
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n2; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
633 634
void av1_iht16x32_512_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                            int tx_type) {
635
  static const transform_2d IHT_16x32[] = {
Luca Barbato's avatar
Luca Barbato committed
636 637 638 639
    { aom_idct32_c, aom_idct16_c },     // DCT_DCT
    { ihalfright32_c, aom_idct16_c },   // ADST_DCT
    { aom_idct32_c, aom_iadst16_c },    // DCT_ADST
    { ihalfright32_c, aom_iadst16_c },  // ADST_ADST
640
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
641 642 643 644 645 646 647 648 649 650 651 652
    { ihalfright32_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct32_c, aom_iadst16_c },    // DCT_FLIPADST
    { ihalfright32_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { ihalfright32_c, aom_iadst16_c },  // ADST_FLIPADST
    { ihalfright32_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx32_c, iidtx16_c },           // IDTX
    { aom_idct32_c, iidtx16_c },        // V_DCT
    { iidtx32_c, aom_idct16_c },        // H_DCT
    { ihalfright32_c, iidtx16_c },      // V_ADST
    { iidtx32_c, aom_iadst16_c },       // H_ADST
    { ihalfright32_c, iidtx16_c },      // V_FLIPADST
    { iidtx32_c, aom_iadst16_c },       // H_FLIPADST
653
#endif
654 655 656 657 658 659 660 661 662 663 664 665 666 667
  };

  const int n = 16;
  const int n2 = 32;
  int i, j;
  tran_low_t out[16][32], outtmp[16];
  tran_low_t *outp = &out[0][0];
  int outstride = n2;

  // inverse transform row vectors and transpose
  for (i = 0; i < n2; ++i) {
    IHT_16x32[tx_type].rows(input, outtmp);
    for (j = 0; j < n; ++j)
      out[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
668
    input += n;
669 670 671 672 673 674 675
  }

  // inverse transform column vectors
  for (i = 0; i < n; ++i) {
    IHT_16x32[tx_type].cols(out[i], out[i]);
  }

676
#if CONFIG_EXT_TX
677
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n2, n);
678
#endif
679 680 681 682 683 684 685 686 687 688 689

  // Sum with the destination
  for (i = 0; i < n2; ++i) {
    for (j = 0; j < n; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
690 691
void av1_iht32x16_512_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                            int tx_type) {
692
  static const transform_2d IHT_32x16[] = {
Luca Barbato's avatar
Luca Barbato committed
693 694 695 696
    { aom_idct16_c, aom_idct32_c },     // DCT_DCT
    { aom_iadst16_c, aom_idct32_c },    // ADST_DCT
    { aom_idct16_c, ihalfright32_c },   // DCT_ADST
    { aom_iadst16_c, ihalfright32_c },  // ADST_ADST
697
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
698 699 700 701 702 703 704 705 706 707 708 709
    { aom_iadst16_c, aom_idct32_c },    // FLIPADST_DCT
    { aom_idct16_c, ihalfright32_c },   // DCT_FLIPADST
    { aom_iadst16_c, ihalfright32_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, ihalfright32_c },  // ADST_FLIPADST
    { aom_iadst16_c, ihalfright32_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx32_c },           // IDTX
    { aom_idct16_c, iidtx32_c },        // V_DCT
    { iidtx16_c, aom_idct32_c },        // H_DCT
    { aom_iadst16_c, iidtx32_c },       // V_ADST
    { iidtx16_c, ihalfright32_c },      // H_ADST
    { aom_iadst16_c, iidtx32_c },       // V_FLIPADST
    { iidtx16_c, ihalfright32_c },      // H_FLIPADST
710
#endif
711 712 713 714 715 716 717 718 719 720 721 722 723 724
  };
  const int n = 16;
  const int n2 = 32;

  int i, j;
  tran_low_t out[32][16], outtmp[32];
  tran_low_t *outp = &out[0][0];
  int outstride = n;

  // inverse transform row vectors and transpose
  for (i = 0; i < n; ++i) {
    IHT_32x16[tx_type].rows(input, outtmp);
    for (j = 0; j < n2; ++j)
      out[j][i] = (tran_low_t)dct_const_round_shift(outtmp[j] * Sqrt2);
clang-format's avatar
clang-format committed
725
    input += n2;
726 727 728 729 730 731 732
  }

  // inverse transform column vectors
  for (i = 0; i < n2; ++i) {
    IHT_32x16[tx_type].cols(out[i], out[i]);
  }

733
#if CONFIG_EXT_TX
734
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, n, n2);
735
#endif
736 737 738 739 740 741 742 743 744 745 746

  // Sum with the destination
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n2; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
747 748
void av1_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                         int tx_type) {
749
  static const transform_2d IHT_8[] = {
Luca Barbato's avatar
Luca Barbato committed
750 751 752 753
    { aom_idct8_c, aom_idct8_c },    // DCT_DCT  = 0
    { aom_iadst8_c, aom_idct8_c },   // ADST_DCT = 1
    { aom_idct8_c, aom_iadst8_c },   // DCT_ADST = 2
    { aom_iadst8_c, aom_iadst8_c },  // ADST_ADST = 3
754
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
755 756 757 758 759 760 761 762 763 764 765 766 767
    { aom_iadst8_c, aom_idct8_c },   // FLIPADST_DCT
    { aom_idct8_c, aom_iadst8_c },   // DCT_FLIPADST
    { aom_iadst8_c, aom_iadst8_c },  // FLIPADST_FLIPADST
    { aom_iadst8_c, aom_iadst8_c },  // ADST_FLIPADST
    { aom_iadst8_c, aom_iadst8_c },  // FLIPADST_ADST
    { iidtx8_c, iidtx8_c },          // IDTX
    { aom_idct8_c, iidtx8_c },       // V_DCT
    { iidtx8_c, aom_idct8_c },       // H_DCT
    { aom_iadst8_c, iidtx8_c },      // V_ADST
    { iidtx8_c, aom_iadst8_c },      // H_ADST
    { aom_iadst8_c, iidtx8_c },      // V_FLIPADST
    { iidtx8_c, aom_iadst8_c },      // H_FLIPADST
#endif                               // CONFIG_EXT_TX
768 769
  };

Jingning Han's avatar
Jingning Han committed
770
  int i, j;
771 772 773 774
  tran_low_t tmp;
  tran_low_t out[8][8];
  tran_low_t *outp = &out[0][0];
  int outstride = 8;
Jingning Han's avatar
Jingning Han committed
775 776 777

  // inverse transform row vectors
  for (i = 0; i < 8; ++i) {
778
    IHT_8[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
779
    input += 8;
780 781 782
  }

  // transpose
clang-format's avatar
clang-format committed
783
  for (i = 1; i < 8; i++) {
784
    for (j = 0; j < i; j++) {
clang-format's avatar
clang-format committed
785
      tmp = out[i][j];
786 787 788
      out[i][j] = out[j][i];
      out[j][i] = tmp;
    }
Jingning Han's avatar
Jingning Han committed
789 790 791 792
  }

  // inverse transform column vectors
  for (i = 0; i < 8; ++i) {
793 794 795 796
    IHT_8[tx_type].cols(out[i], out[i]);
  }

#if CONFIG_EXT_TX
797
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 8, 8);
798 799 800 801
#endif

  // Sum with the destination
  for (i = 0; i < 8; ++i) {
Jingning Han's avatar
Jingning Han committed
802
    for (j = 0; j < 8; ++j) {
803 804 805
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
Jingning Han's avatar
Jingning Han committed
806 807 808 809
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
810 811
void av1_iht16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                            int tx_type) {
812
  static const transform_2d IHT_16[] = {
Luca Barbato's avatar
Luca Barbato committed
813 814 815 816
    { aom_idct16_c, aom_idct16_c },    // DCT_DCT  = 0
    { aom_iadst16_c, aom_idct16_c },   // ADST_DCT = 1
    { aom_idct16_c, aom_iadst16_c },   // DCT_ADST = 2
    { aom_iadst16_c, aom_iadst16_c },  // ADST_ADST = 3
817
#if CONFIG_EXT_TX
Luca Barbato's avatar
Luca Barbato committed
818 819 820 821 822 823 824 825 826 827 828 829 830
    { aom_iadst16_c, aom_idct16_c },   // FLIPADST_DCT
    { aom_idct16_c, aom_iadst16_c },   // DCT_FLIPADST
    { aom_iadst16_c, aom_iadst16_c },  // FLIPADST_FLIPADST
    { aom_iadst16_c, aom_iadst16_c },  // ADST_FLIPADST
    { aom_iadst16_c, aom_iadst16_c },  // FLIPADST_ADST
    { iidtx16_c, iidtx16_c },          // IDTX
    { aom_idct16_c, iidtx16_c },       // V_DCT
    { iidtx16_c, aom_idct16_c },       // H_DCT
    { aom_iadst16_c, iidtx16_c },      // V_ADST
    { iidtx16_c, aom_iadst16_c },      // H_ADST
    { aom_iadst16_c, iidtx16_c },      // V_FLIPADST
    { iidtx16_c, aom_iadst16_c },      // H_FLIPADST
#endif                                 // CONFIG_EXT_TX
831
  };
832

Jingning Han's avatar
Jingning Han committed
833
  int i, j;
834 835 836 837 838 839 840 841
  tran_low_t tmp;
  tran_low_t out[16][16];
  tran_low_t *outp = &out[0][0];
  int outstride = 16;

  // inverse transform row vectors
  for (i = 0; i < 16; ++i) {
    IHT_16[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
842
    input += 16;
843 844 845
  }

  // transpose
clang-format's avatar
clang-format committed
846
  for (i = 1; i < 16; i++) {
847
    for (j = 0; j < i; j++) {
clang-format's avatar
clang-format committed
848
      tmp = out[i][j];
849 850 851 852
      out[i][j] = out[j][i];
      out[j][i] = tmp;
    }
  }
Jingning Han's avatar
Jingning Han committed
853

854
  // inverse transform column vectors
Jingning Han's avatar
Jingning Han committed
855
  for (i = 0; i < 16; ++i) {
856
    IHT_16[tx_type].cols(out[i], out[i]);
Jingning Han's avatar
Jingning Han committed
857 858
  }

859
#if CONFIG_EXT_TX
860
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 16, 16);
861 862 863
#endif

  // Sum with the destination
Jingning Han's avatar
Jingning Han committed
864 865
  for (i = 0; i < 16; ++i) {
    for (j = 0; j < 16; ++j) {
866 867 868
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
Jingning Han's avatar
Jingning Han committed
869 870 871 872
    }
  }
}

873
#if CONFIG_EXT_TX
Yaowu Xu's avatar
Yaowu Xu committed
874 875
void av1_iht32x32_1024_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                             int tx_type) {
876
  static const transform_2d IHT_32[] = {
Luca Barbato's avatar
Luca Barbato committed
877 878 879
    { aom_idct32_c, aom_idct32_c },      // DCT_DCT
    { ihalfright32_c, aom_idct32_c },    // ADST_DCT
    { aom_idct32_c, ihalfright32_c },    // DCT_ADST
clang-format's avatar
clang-format committed
880
    { ihalfright32_c, ihalfright32_c },  // ADST_ADST
Luca Barbato's avatar
Luca Barbato committed
881 882
    { ihalfright32_c, aom_idct32_c },    // FLIPADST_DCT
    { aom_idct32_c, ihalfright32_c },    // DCT_FLIPADST
clang-format's avatar
clang-format committed
883 884 885 886
    { ihalfright32_c, ihalfright32_c },  // FLIPADST_FLIPADST
    { ihalfright32_c, ihalfright32_c },  // ADST_FLIPADST
    { ihalfright32_c, ihalfright32_c },  // FLIPADST_ADST
    { iidtx32_c, iidtx32_c },            // IDTX
Luca Barbato's avatar
Luca Barbato committed
887 888
    { aom_idct32_c, iidtx32_c },         // V_DCT
    { iidtx32_c, aom_idct32_c },         // H_DCT
889 890 891 892
    { ihalfright32_c, iidtx32_c },       // V_ADST
    { iidtx32_c, ihalfright32_c },       // H_ADST
    { ihalfright32_c, iidtx32_c },       // V_FLIPADST
    { iidtx32_c, ihalfright32_c },       // H_FLIPADST
893 894 895 896 897 898 899 900 901 902 903
  };

  int i, j;
  tran_low_t tmp;
  tran_low_t out[32][32];
  tran_low_t *outp = &out[0][0];
  int outstride = 32;

  // inverse transform row vectors
  for (i = 0; i < 32; ++i) {
    IHT_32[tx_type].rows(input, out[i]);
clang-format's avatar
clang-format committed
904
    input += 32;
905 906 907
  }

  // transpose
clang-format's avatar
clang-format committed
908
  for (i = 1; i < 32; i++) {
909
    for (j = 0; j < i; j++) {
clang-format's avatar
clang-format committed
910
      tmp = out[i][j];
911 912 913 914 915 916 917 918 919 920
      out[i][j] = out[j][i];
      out[j][i] = tmp;
    }
  }

  // inverse transform column vectors
  for (i = 0; i < 32; ++i) {
    IHT_32[tx_type].cols(out[i], out[i]);
  }

921
  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 32, 32);
922 923 924 925 926 927 928 929 930 931

  // Sum with the destination
  for (i = 0; i < 32; ++i) {
    for (j = 0; j < 32; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 6));
    }
  }
}
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993

#if CONFIG_TX64X64
void av1_iht64x64_4096_add_c(const tran_low_t *input, uint8_t *dest, int stride,
                             int tx_type) {
  static const transform_2d IHT_64[] = {
    { idct64_col_c, idct64_row_c },      // DCT_DCT
    { ihalfright64_c, idct64_row_c },    // ADST_DCT
    { idct64_col_c, ihalfright64_c },    // DCT_ADST
    { ihalfright64_c, ihalfright64_c },  // ADST_ADST
    { ihalfright64_c, idct64_row_c },    // FLIPADST_DCT
    { idct64_col_c, ihalfright64_c },    // DCT_FLIPADST
    { ihalfright64_c, ihalfright64_c },  // FLIPADST_FLIPADST
    { ihalfright64_c, ihalfright64_c },  // ADST_FLIPADST
    { ihalfright64_c, ihalfright64_c },  // FLIPADST_ADST
    { iidtx64_c, iidtx64_c },            // IDTX
    { idct64_col_c, iidtx64_c },         // V_DCT
    { iidtx64_c, idct64_row_c },         // H_DCT
    { ihalfright64_c, iidtx64_c },       // V_ADST
    { iidtx64_c, ihalfright64_c },       // H_ADST
    { ihalfright64_c, iidtx64_c },       // V_FLIPADST
    { iidtx64_c, ihalfright64_c },       // H_FLIPADST
  };

  int i, j;
  tran_low_t tmp;
  tran_low_t out[64][64];
  tran_low_t *outp = &out[0][0];
  int outstride = 64;

  // inverse transform row vectors
  for (i = 0; i < 64; ++i) {
    IHT_64[tx_type].rows(input, out[i]);
    for (j = 0; j < 64; ++j) out[i][j] = ROUND_POWER_OF_TWO(out[i][j], 1);
    input += 64;
  }

  // transpose
  for (i = 1; i < 64; i++) {
    for (j = 0; j < i; j++) {
      tmp = out[i][j];
      out[i][j] = out[j][i];
      out[j][i] = tmp;
    }
  }

  // inverse transform column vectors
  for (i = 0; i < 64; ++i) {
    IHT_64[tx_type].cols(out[i], out[i]);
  }

  maybe_flip_strides(&dest, &stride, &outp, &outstride, tx_type, 64, 64);

  // Sum with the destination
  for (i = 0; i < 64; ++i) {
    for (j = 0; j < 64; ++j) {
      int d = i * stride + j;
      int s = j * outstride + i;
      dest[d] = clip_pixel_add(dest[d], ROUND_POWER_OF_TWO(outp[s], 5));
    }
  }
}
#endif  // CONFIG_TX64X64
994 995
#endif  // CONFIG_EXT_TX