av1_inv_txfm2d.c 20.7 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 "./aom_dsp_rtcd.h"
13
#include "./av1_rtcd.h"
14
#include "aom_dsp/inv_txfm.h"
15
#include "av1/common/enums.h"
16 17
#include "av1/common/av1_txfm.h"
#include "av1/common/av1_inv_txfm1d.h"
18
#include "av1/common/av1_inv_txfm1d_cfg.h"
Angie Chiang's avatar
Angie Chiang committed
19

20 21
#define NO_INV_TRANSPOSE 1

Yaowu Xu's avatar
Yaowu Xu committed
22
static INLINE TxfmFunc inv_txfm_type_to_func(TXFM_TYPE txfm_type) {
23
  switch (txfm_type) {
24 25 26 27
    case TXFM_TYPE_DCT4: return av1_idct4_new;
    case TXFM_TYPE_DCT8: return av1_idct8_new;
    case TXFM_TYPE_DCT16: return av1_idct16_new;
    case TXFM_TYPE_DCT32: return av1_idct32_new;
28
    case TXFM_TYPE_DCT64: return av1_idct64_new;
29 30 31 32
    case TXFM_TYPE_ADST4: return av1_iadst4_new;
    case TXFM_TYPE_ADST8: return av1_iadst8_new;
    case TXFM_TYPE_ADST16: return av1_iadst16_new;
    case TXFM_TYPE_ADST32: return av1_iadst32_new;
33 34 35 36
    case TXFM_TYPE_IDENTITY4: return av1_iidentity4_c;
    case TXFM_TYPE_IDENTITY8: return av1_iidentity8_c;
    case TXFM_TYPE_IDENTITY16: return av1_iidentity16_c;
    case TXFM_TYPE_IDENTITY32: return av1_iidentity32_c;
37
    case TXFM_TYPE_IDENTITY64: return av1_iidentity64_c;
38
    default: assert(0); return NULL;
39 40 41
  }
}

42
static const int8_t inv_shift_4x4[2] = { 0, -4 };
Angie Chiang's avatar
Angie Chiang committed
43 44 45 46
static const int8_t inv_shift_8x8[2] = { -1, -4 };
static const int8_t inv_shift_16x16[2] = { -2, -4 };
static const int8_t inv_shift_32x32[2] = { -2, -4 };
static const int8_t inv_shift_64x64[2] = { -2, -4 };
Angie Chiang's avatar
Angie Chiang committed
47 48
static const int8_t inv_shift_4x8[2] = { 0, -4 };
static const int8_t inv_shift_8x4[2] = { 0, -4 };
49 50 51 52 53 54 55 56
static const int8_t inv_shift_8x16[2] = { -1, -4 };
static const int8_t inv_shift_16x8[2] = { -1, -4 };
static const int8_t inv_shift_16x32[2] = { -1, -4 };
static const int8_t inv_shift_32x16[2] = { -1, -4 };
static const int8_t inv_shift_32x64[2] = { -1, -4 };
static const int8_t inv_shift_64x32[2] = { -1, -4 };
static const int8_t inv_shift_4x16[2] = { -1, -4 };
static const int8_t inv_shift_16x4[2] = { -1, -4 };
Angie Chiang's avatar
Angie Chiang committed
57 58 59 60
static const int8_t inv_shift_8x32[2] = { -2, -4 };
static const int8_t inv_shift_32x8[2] = { -2, -4 };
static const int8_t inv_shift_16x64[2] = { -2, -4 };
static const int8_t inv_shift_64x16[2] = { -2, -4 };
61 62 63

const int8_t *inv_txfm_shift_ls[TX_SIZES_ALL] = {
  inv_shift_4x4,   inv_shift_8x8,   inv_shift_16x16, inv_shift_32x32,
Yaowu Xu's avatar
Yaowu Xu committed
64 65 66 67
  inv_shift_64x64, inv_shift_4x8,   inv_shift_8x4,   inv_shift_8x16,
  inv_shift_16x8,  inv_shift_16x32, inv_shift_32x16, inv_shift_32x64,
  inv_shift_64x32, inv_shift_4x16,  inv_shift_16x4,  inv_shift_8x32,
  inv_shift_32x8,  inv_shift_16x64, inv_shift_64x16,
68 69
};

Peng Bin's avatar
Peng Bin committed
70 71 72 73 74 75 76 77 78
/* clang-format off */
const int8_t inv_cos_bit_col[MAX_TXWH_IDX]      // txw_idx
                            [MAX_TXWH_IDX] = {  // txh_idx
    { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT,           0,           0 },
    { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT,           0 },
    { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
    {           0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
    {           0,           0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT }
  };
79

Peng Bin's avatar
Peng Bin committed
80 81 82 83 84 85 86 87 88
const int8_t inv_cos_bit_row[MAX_TXWH_IDX]      // txw_idx
                            [MAX_TXWH_IDX] = {  // txh_idx
    { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT,           0,           0 },
    { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT,           0 },
    { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
    {           0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
    {           0,           0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT }
  };
/* clang-format on */
89

Angie Chiang's avatar
Angie Chiang committed
90 91
const int8_t iadst4_range[7] = { 0, 1, 0, 0, 0, 0, 0 };

92 93 94
void av1_get_inv_txfm_cfg(TX_TYPE tx_type, TX_SIZE tx_size,
                          TXFM_2D_FLIP_CFG *cfg) {
  assert(cfg != NULL);
Angie Chiang's avatar
Angie Chiang committed
95 96 97 98
  cfg->tx_size = tx_size;
  set_flip_cfg(tx_type, cfg);
  av1_zero(cfg->stage_range_col);
  av1_zero(cfg->stage_range_row);
99
  set_flip_cfg(tx_type, cfg);
Angie Chiang's avatar
Angie Chiang committed
100 101
  const TX_TYPE_1D tx_type_1d_col = vtx_tab[tx_type];
  const TX_TYPE_1D tx_type_1d_row = htx_tab[tx_type];
102
  cfg->shift = inv_txfm_shift_ls[tx_size];
Angie Chiang's avatar
Angie Chiang committed
103 104
  const int txw_idx = get_txw_idx(tx_size);
  const int txh_idx = get_txh_idx(tx_size);
105 106
  cfg->cos_bit_col = inv_cos_bit_col[txw_idx][txh_idx];
  cfg->cos_bit_row = inv_cos_bit_row[txw_idx][txh_idx];
Angie Chiang's avatar
Angie Chiang committed
107
  cfg->txfm_type_col = av1_txfm_type_ls[txh_idx][tx_type_1d_col];
Angie Chiang's avatar
Angie Chiang committed
108 109 110
  if (cfg->txfm_type_col == TXFM_TYPE_ADST4) {
    memcpy(cfg->stage_range_col, iadst4_range, sizeof(iadst4_range));
  }
Angie Chiang's avatar
Angie Chiang committed
111
  cfg->txfm_type_row = av1_txfm_type_ls[txw_idx][tx_type_1d_row];
Angie Chiang's avatar
Angie Chiang committed
112 113 114
  if (cfg->txfm_type_row == TXFM_TYPE_ADST4) {
    memcpy(cfg->stage_range_row, iadst4_range, sizeof(iadst4_range));
  }
Angie Chiang's avatar
Angie Chiang committed
115 116
  cfg->stage_num_col = av1_txfm_stage_num_list[cfg->txfm_type_col];
  cfg->stage_num_row = av1_txfm_stage_num_list[cfg->txfm_type_row];
117 118
}

119
void av1_gen_inv_stage_range(int8_t *stage_range_col, int8_t *stage_range_row,
120
                             const TXFM_2D_FLIP_CFG *cfg, TX_SIZE tx_size,
121
                             int bd) {
122
  const int fwd_shift = inv_start_range[tx_size];
123
  const int8_t *shift = cfg->shift;
124
  // i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
Angie Chiang's avatar
Angie Chiang committed
125 126
  for (int i = 0; i < cfg->stage_num_row && i < MAX_TXFM_STAGE_NUM; ++i) {
    stage_range_row[i] = cfg->stage_range_row[i] + fwd_shift + bd + 1;
127 128
  }
  // i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
Angie Chiang's avatar
Angie Chiang committed
129
  for (int i = 0; i < cfg->stage_num_col && i < MAX_TXFM_STAGE_NUM; ++i) {
130
    stage_range_col[i] =
Angie Chiang's avatar
Angie Chiang committed
131
        cfg->stage_range_col[i] + fwd_shift + shift[0] + bd + 1;
132 133 134
  }
}

135
static INLINE void inv_txfm2d_add_c(const int32_t *input, uint16_t *output,
136
                                    int stride, TXFM_2D_FLIP_CFG *cfg,
137
                                    int32_t *txfm_buf, TX_SIZE tx_size,
138
                                    int bd) {
139 140 141 142 143 144
  // Note when assigning txfm_size_col, we use the txfm_size from the
  // row configuration and vice versa. This is intentionally done to
  // accurately perform rectangular transforms. When the transform is
  // rectangular, the number of columns will be the same as the
  // txfm_size stored in the row cfg struct. It will make no difference
  // for square transforms.
Angie Chiang's avatar
Angie Chiang committed
145 146
  const int txfm_size_col = tx_size_wide[cfg->tx_size];
  const int txfm_size_row = tx_size_high[cfg->tx_size];
147
  // Take the shift from the larger dimension in the rectangular case.
148
  const int8_t *shift = cfg->shift;
149
  const int rect_type = get_rect_tx_log_ratio(txfm_size_col, txfm_size_row);
150 151
  int8_t stage_range_row[MAX_TXFM_STAGE_NUM];
  int8_t stage_range_col[MAX_TXFM_STAGE_NUM];
Angie Chiang's avatar
Angie Chiang committed
152 153
  assert(cfg->stage_num_row <= MAX_TXFM_STAGE_NUM);
  assert(cfg->stage_num_col <= MAX_TXFM_STAGE_NUM);
154
  av1_gen_inv_stage_range(stage_range_col, stage_range_row, cfg, tx_size, bd);
155

156 157
  const int8_t cos_bit_col = cfg->cos_bit_col;
  const int8_t cos_bit_row = cfg->cos_bit_row;
Angie Chiang's avatar
Angie Chiang committed
158 159
  const TxfmFunc txfm_func_col = inv_txfm_type_to_func(cfg->txfm_type_col);
  const TxfmFunc txfm_func_row = inv_txfm_type_to_func(cfg->txfm_type_row);
Angie Chiang's avatar
Angie Chiang committed
160

161 162
  // txfm_buf's length is  txfm_size_row * txfm_size_col + 2 *
  // AOMMAX(txfm_size_row, txfm_size_col)
Angie Chiang's avatar
Angie Chiang committed
163
  // it is used for intermediate data buffering
164
  const int buf_offset = AOMMAX(txfm_size_row, txfm_size_col);
Angie Chiang's avatar
Angie Chiang committed
165
  int32_t *temp_in = txfm_buf;
166 167
  int32_t *temp_out = temp_in + buf_offset;
  int32_t *buf = temp_out + buf_offset;
Angie Chiang's avatar
Angie Chiang committed
168
  int32_t *buf_ptr = buf;
169
  int c, r;
Angie Chiang's avatar
Angie Chiang committed
170 171

  // Rows
172
  for (r = 0; r < txfm_size_row; ++r) {
173 174
    if (abs(rect_type) == 1) {
      for (c = 0; c < txfm_size_col; ++c) {
175
        temp_in[c] = round_shift(input[c] * NewInvSqrt2, NewSqrt2Bits);
176 177 178 179 180
      }
      txfm_func_row(temp_in, buf_ptr, cos_bit_row, stage_range_row);
    } else {
      txfm_func_row(input, buf_ptr, cos_bit_row, stage_range_row);
    }
181
    av1_round_shift_array(buf_ptr, txfm_size_col, -shift[0]);
182
    clamp_buf(buf_ptr, txfm_size_col, AOMMAX(bd + 6, 16));
183 184
    input += txfm_size_col;
    buf_ptr += txfm_size_col;
Angie Chiang's avatar
Angie Chiang committed
185 186 187
  }

  // Columns
188
  for (c = 0; c < txfm_size_col; ++c) {
189
    if (cfg->lr_flip == 0) {
190 191
      for (r = 0; r < txfm_size_row; ++r)
        temp_in[r] = buf[r * txfm_size_col + c];
192 193
    } else {
      // flip left right
194 195
      for (r = 0; r < txfm_size_row; ++r)
        temp_in[r] = buf[r * txfm_size_col + (txfm_size_col - c - 1)];
196
    }
Angie Chiang's avatar
Angie Chiang committed
197
    txfm_func_col(temp_in, temp_out, cos_bit_col, stage_range_col);
198
    av1_round_shift_array(temp_out, txfm_size_row, -shift[1]);
199
    clamp_buf(temp_out, txfm_size_row, bd + 1);
200
    if (cfg->ud_flip == 0) {
201 202 203 204
      for (r = 0; r < txfm_size_row; ++r) {
        output[r * stride + c] =
            highbd_clip_pixel_add(output[r * stride + c], temp_out[r], bd);
      }
205 206
    } else {
      // flip upside down
207 208 209 210
      for (r = 0; r < txfm_size_row; ++r) {
        output[r * stride + c] = highbd_clip_pixel_add(
            output[r * stride + c], temp_out[txfm_size_row - r - 1], bd);
      }
211
    }
Angie Chiang's avatar
Angie Chiang committed
212 213 214
  }
}

215 216
static INLINE void inv_txfm2d_add_facade(const int32_t *input, uint16_t *output,
                                         int stride, int32_t *txfm_buf,
217 218
                                         TX_TYPE tx_type, TX_SIZE tx_size,
                                         int bd) {
219 220
  TXFM_2D_FLIP_CFG cfg;
  av1_get_inv_txfm_cfg(tx_type, tx_size, &cfg);
221 222
  // Forward shift sum uses larger square size, to be consistent with what
  // av1_gen_inv_stage_range() does for inverse shifts.
223
  inv_txfm2d_add_c(input, output, stride, &cfg, txfm_buf, tx_size, bd);
224 225 226
}

void av1_inv_txfm2d_add_4x8_c(const int32_t *input, uint16_t *output,
227
                              int stride, TX_TYPE tx_type, int bd) {
228
  DECLARE_ALIGNED(32, int, txfm_buf[4 * 8 + 8 + 8]);
229 230 231 232
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X8, bd);
}

void av1_inv_txfm2d_add_8x4_c(const int32_t *input, uint16_t *output,
233
                              int stride, TX_TYPE tx_type, int bd) {
234
  DECLARE_ALIGNED(32, int, txfm_buf[8 * 4 + 8 + 8]);
235 236 237
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X4, bd);
#else
238 239
  int32_t rinput[8 * 4];
  uint16_t routput[8 * 4];
240 241
  TX_SIZE tx_size = TX_8X4;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
242
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
243 244 245 246 247 248 249 250
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
  transpose_int32(rinput, rw, input, w, w, h);
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
251
#endif  // NO_INV_TRANSPOSE
252 253 254
}

void av1_inv_txfm2d_add_8x16_c(const int32_t *input, uint16_t *output,
255
                               int stride, TX_TYPE tx_type, int bd) {
256
  DECLARE_ALIGNED(32, int, txfm_buf[8 * 16 + 16 + 16]);
257 258 259 260
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X16, bd);
}

void av1_inv_txfm2d_add_16x8_c(const int32_t *input, uint16_t *output,
261
                               int stride, TX_TYPE tx_type, int bd) {
262
  DECLARE_ALIGNED(32, int, txfm_buf[16 * 8 + 16 + 16]);
263 264 265
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X8, bd);
#else
266 267
  int32_t rinput[16 * 8];
  uint16_t routput[16 * 8];
268 269
  TX_SIZE tx_size = TX_16X8;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
270
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
271 272 273 274 275 276 277 278
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
  transpose_int32(rinput, rw, input, w, w, h);
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
279
#endif  // NO_INV_TRANSPOSE
280 281 282
}

void av1_inv_txfm2d_add_16x32_c(const int32_t *input, uint16_t *output,
283
                                int stride, TX_TYPE tx_type, int bd) {
284
  DECLARE_ALIGNED(32, int, txfm_buf[16 * 32 + 32 + 32]);
285 286 287 288
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X32, bd);
}

void av1_inv_txfm2d_add_32x16_c(const int32_t *input, uint16_t *output,
289
                                int stride, TX_TYPE tx_type, int bd) {
290
  DECLARE_ALIGNED(32, int, txfm_buf[32 * 16 + 32 + 32]);
291 292 293
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X16, bd);
#else
294 295
  int32_t rinput[32 * 16];
  uint16_t routput[32 * 16];
296 297
  TX_SIZE tx_size = TX_32X16;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
298
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
299 300 301 302 303 304 305 306
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
  transpose_int32(rinput, rw, input, w, w, h);
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
307
#endif  // NO_INV_TRANSPOSE
308 309 310
}

void av1_inv_txfm2d_add_4x4_c(const int32_t *input, uint16_t *output,
311
                              int stride, TX_TYPE tx_type, int bd) {
312
  DECLARE_ALIGNED(32, int, txfm_buf[4 * 4 + 4 + 4]);
313
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X4, bd);
Angie Chiang's avatar
Angie Chiang committed
314 315
}

316
void av1_inv_txfm2d_add_8x8_c(const int32_t *input, uint16_t *output,
317
                              int stride, TX_TYPE tx_type, int bd) {
318
  DECLARE_ALIGNED(32, int, txfm_buf[8 * 8 + 8 + 8]);
319
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X8, bd);
Angie Chiang's avatar
Angie Chiang committed
320 321
}

322
void av1_inv_txfm2d_add_16x16_c(const int32_t *input, uint16_t *output,
323
                                int stride, TX_TYPE tx_type, int bd) {
324
  DECLARE_ALIGNED(32, int, txfm_buf[16 * 16 + 16 + 16]);
325
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X16, bd);
Angie Chiang's avatar
Angie Chiang committed
326 327
}

328
void av1_inv_txfm2d_add_32x32_c(const int32_t *input, uint16_t *output,
329
                                int stride, TX_TYPE tx_type, int bd) {
330
  DECLARE_ALIGNED(32, int, txfm_buf[32 * 32 + 32 + 32]);
331
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X32, bd);
Angie Chiang's avatar
Angie Chiang committed
332
}
Angie Chiang's avatar
Angie Chiang committed
333

334
void av1_inv_txfm2d_add_64x64_c(const int32_t *input, uint16_t *output,
335
                                int stride, TX_TYPE tx_type, int bd) {
336 337 338 339 340 341 342 343 344 345
  // TODO(urvang): Can the same array be reused, instead of using a new array?
  // Remap 32x32 input into a modified 64x64 by:
  // - Copying over these values in top-left 32x32 locations.
  // - Setting the rest of the locations to 0.
  int32_t mod_input[64 * 64];
  for (int row = 0; row < 32; ++row) {
    memcpy(mod_input + row * 64, input + row * 32, 32 * sizeof(*mod_input));
    memset(mod_input + row * 64 + 32, 0, 32 * sizeof(*mod_input));
  }
  memset(mod_input + 32 * 64, 0, 32 * 64 * sizeof(*mod_input));
346
  DECLARE_ALIGNED(32, int, txfm_buf[64 * 64 + 64 + 64]);
347 348
  inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_64X64,
                        bd);
Angie Chiang's avatar
Angie Chiang committed
349
}
350 351

void av1_inv_txfm2d_add_64x32_c(const int32_t *input, uint16_t *output,
352
                                int stride, TX_TYPE tx_type, int bd) {
353 354 355 356 357 358 359 360
  // Remap 32x32 input into a modified 64x32 by:
  // - Copying over these values in top-left 32x32 locations.
  // - Setting the rest of the locations to 0.
  int32_t mod_input[64 * 32];
  for (int row = 0; row < 32; ++row) {
    memcpy(mod_input + row * 64, input + row * 32, 32 * sizeof(*mod_input));
    memset(mod_input + row * 64 + 32, 0, 32 * sizeof(*mod_input));
  }
361
  DECLARE_ALIGNED(32, int, txfm_buf[64 * 32 + 64 + 64]);
362 363 364 365
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_64X32,
                        bd);
#else
366 367
  int32_t rinput[64 * 32];
  uint16_t routput[64 * 32];
368 369
  TX_SIZE tx_size = TX_64X32;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
370
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
371 372 373 374
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
375
  transpose_int32(rinput, rw, mod_input, w, w, h);
376 377 378
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
379
#endif  // NO_INV_TRANSPOSE
380 381 382
}

void av1_inv_txfm2d_add_32x64_c(const int32_t *input, uint16_t *output,
383
                                int stride, TX_TYPE tx_type, int bd) {
384 385 386 387 388 389
  // Remap 32x32 input into a modified 32x64 input by:
  // - Copying over these values in top-left 32x32 locations.
  // - Setting the rest of the locations to 0.
  int32_t mod_input[32 * 64];
  memcpy(mod_input, input, 32 * 32 * sizeof(*mod_input));
  memset(mod_input + 32 * 32, 0, 32 * 32 * sizeof(*mod_input));
390
  DECLARE_ALIGNED(32, int, txfm_buf[64 * 32 + 64 + 64]);
391 392
  inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_32X64,
                        bd);
393
}
394 395 396

void av1_inv_txfm2d_add_16x64_c(const int32_t *input, uint16_t *output,
                                int stride, TX_TYPE tx_type, int bd) {
397 398 399 400 401 402
  // Remap 16x32 input into a modified 16x64 input by:
  // - Copying over these values in top-left 16x32 locations.
  // - Setting the rest of the locations to 0.
  int32_t mod_input[16 * 64];
  memcpy(mod_input, input, 16 * 32 * sizeof(*mod_input));
  memset(mod_input + 16 * 32, 0, 16 * 32 * sizeof(*mod_input));
403
  DECLARE_ALIGNED(32, int, txfm_buf[16 * 64 + 64 + 64]);
404 405
  inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_16X64,
                        bd);
406 407 408 409
}

void av1_inv_txfm2d_add_64x16_c(const int32_t *input, uint16_t *output,
                                int stride, TX_TYPE tx_type, int bd) {
410 411 412 413 414 415 416 417
  // Remap 32x16 input into a modified 64x16 by:
  // - Copying over these values in top-left 32x16 locations.
  // - Setting the rest of the locations to 0.
  int32_t mod_input[64 * 16];
  for (int row = 0; row < 16; ++row) {
    memcpy(mod_input + row * 64, input + row * 32, 32 * sizeof(*mod_input));
    memset(mod_input + row * 64 + 32, 0, 32 * sizeof(*mod_input));
  }
418
  DECLARE_ALIGNED(32, int, txfm_buf[16 * 64 + 64 + 64]);
419 420 421 422
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_64X16,
                        bd);
#else
423 424 425 426 427 428 429 430 431
  int32_t rinput[16 * 64];
  uint16_t routput[16 * 64];
  TX_SIZE tx_size = TX_64X16;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
432
  transpose_int32(rinput, rw, mod_input, w, w, h);
433 434 435
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
436
#endif  // NO_INV_TRANSPOSE
437
}
438 439 440

void av1_inv_txfm2d_add_4x16_c(const int32_t *input, uint16_t *output,
                               int stride, TX_TYPE tx_type, int bd) {
441
  DECLARE_ALIGNED(32, int, txfm_buf[4 * 16 + 16 + 16]);
442 443 444 445 446
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X16, bd);
}

void av1_inv_txfm2d_add_16x4_c(const int32_t *input, uint16_t *output,
                               int stride, TX_TYPE tx_type, int bd) {
447
  DECLARE_ALIGNED(32, int, txfm_buf[4 * 16 + 16 + 16]);
448 449 450
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X4, bd);
#else
451 452 453 454 455 456 457 458 459 460 461 462 463
  int32_t rinput[4 * 16];
  uint16_t routput[4 * 16];
  TX_SIZE tx_size = TX_16X4;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
  transpose_int32(rinput, rw, input, w, w, h);
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
464
#endif  // NO_INV_TRANSPOSE
465 466 467 468
}

void av1_inv_txfm2d_add_8x32_c(const int32_t *input, uint16_t *output,
                               int stride, TX_TYPE tx_type, int bd) {
469
  DECLARE_ALIGNED(32, int, txfm_buf[8 * 32 + 32 + 32]);
470 471 472 473 474
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X32, bd);
}

void av1_inv_txfm2d_add_32x8_c(const int32_t *input, uint16_t *output,
                               int stride, TX_TYPE tx_type, int bd) {
475
  DECLARE_ALIGNED(32, int, txfm_buf[8 * 32 + 32 + 32]);
476 477 478
#if NO_INV_TRANSPOSE
  inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X8, bd);
#else
479 480 481 482 483 484 485 486 487 488 489 490 491
  int32_t rinput[8 * 32];
  uint16_t routput[8 * 32];
  TX_SIZE tx_size = TX_32X8;
  TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
  TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
  int w = tx_size_wide[tx_size];
  int h = tx_size_high[tx_size];
  int rw = h;
  int rh = w;
  transpose_int32(rinput, rw, input, w, w, h);
  transpose_uint16(routput, rw, output, stride, w, h);
  inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
  transpose_uint16(output, stride, routput, rw, rw, rh);
492
#endif  // NO_INV_TRANSPOSE
493
}