blob: f301c5ca131bc76a4414b7a2c6549b5a90755de3 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Urvang Joshi1ac47a72017-12-07 12:12:50 -080012#include "./aom_dsp_rtcd.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070013#include "./av1_rtcd.h"
Sarah Parker31c66502017-05-19 16:51:07 -070014#include "aom_dsp/inv_txfm.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070015#include "av1/common/enums.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "av1/common/av1_txfm.h"
17#include "av1/common/av1_inv_txfm1d.h"
Sarah Parkereec47e62017-05-15 20:49:22 -070018#include "av1/common/av1_inv_txfm1d_cfg.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019
Debargha Mukherjee1158bff2018-01-01 18:23:59 -080020#define NO_INV_TRANSPOSE 1
21
Yaowu Xuc27fc142016-08-22 16:08:15 -070022static INLINE TxfmFunc inv_txfm_type_to_func(TXFM_TYPE txfm_type) {
23 switch (txfm_type) {
Yaowu Xuf883b422016-08-30 14:01:10 -070024 case TXFM_TYPE_DCT4: return av1_idct4_new;
25 case TXFM_TYPE_DCT8: return av1_idct8_new;
26 case TXFM_TYPE_DCT16: return av1_idct16_new;
27 case TXFM_TYPE_DCT32: return av1_idct32_new;
Urvang Joshi900643b2017-08-08 13:09:51 -070028 case TXFM_TYPE_DCT64: return av1_idct64_new;
Yaowu Xuf883b422016-08-30 14:01:10 -070029 case TXFM_TYPE_ADST4: return av1_iadst4_new;
30 case TXFM_TYPE_ADST8: return av1_iadst8_new;
31 case TXFM_TYPE_ADST16: return av1_iadst16_new;
32 case TXFM_TYPE_ADST32: return av1_iadst32_new;
Sarah Parker3eed4172017-05-15 20:49:22 -070033 case TXFM_TYPE_IDENTITY4: return av1_iidentity4_c;
34 case TXFM_TYPE_IDENTITY8: return av1_iidentity8_c;
35 case TXFM_TYPE_IDENTITY16: return av1_iidentity16_c;
36 case TXFM_TYPE_IDENTITY32: return av1_iidentity32_c;
Debargha Mukherjee570423c2017-10-01 00:35:20 -070037 case TXFM_TYPE_IDENTITY64: return av1_iidentity64_c;
Yaowu Xuc27fc142016-08-22 16:08:15 -070038 default: assert(0); return NULL;
39 }
40}
41
Angie Chiang4a75b5a2018-01-10 17:19:06 -080042static const int8_t inv_shift_4x4[2] = { 0, -4 };
Angie Chiang06250272018-01-16 17:03:35 -080043static const int8_t inv_shift_8x8[2] = { -1, -4 };
44static const int8_t inv_shift_16x16[2] = { -2, -4 };
45static const int8_t inv_shift_32x32[2] = { -2, -4 };
Angie Chiang06250272018-01-16 17:03:35 -080046static const int8_t inv_shift_64x64[2] = { -2, -4 };
Angie Chiang5d7c1fc2018-01-30 15:54:44 -080047static const int8_t inv_shift_4x8[2] = { 0, -4 };
48static const int8_t inv_shift_8x4[2] = { 0, -4 };
Angie Chiang2fc20eb2018-01-12 12:19:00 -080049static const int8_t inv_shift_8x16[2] = { -1, -4 };
50static const int8_t inv_shift_16x8[2] = { -1, -4 };
51static const int8_t inv_shift_16x32[2] = { -1, -4 };
52static const int8_t inv_shift_32x16[2] = { -1, -4 };
Angie Chiang2fc20eb2018-01-12 12:19:00 -080053static const int8_t inv_shift_32x64[2] = { -1, -4 };
54static const int8_t inv_shift_64x32[2] = { -1, -4 };
Angie Chiang2fc20eb2018-01-12 12:19:00 -080055static const int8_t inv_shift_4x16[2] = { -1, -4 };
56static const int8_t inv_shift_16x4[2] = { -1, -4 };
Angie Chiang06250272018-01-16 17:03:35 -080057static const int8_t inv_shift_8x32[2] = { -2, -4 };
58static const int8_t inv_shift_32x8[2] = { -2, -4 };
Angie Chiang06250272018-01-16 17:03:35 -080059static const int8_t inv_shift_16x64[2] = { -2, -4 };
60static const int8_t inv_shift_64x16[2] = { -2, -4 };
Angie Chiang4a75b5a2018-01-10 17:19:06 -080061
62const int8_t *inv_txfm_shift_ls[TX_SIZES_ALL] = {
63 inv_shift_4x4, inv_shift_8x8, inv_shift_16x16, inv_shift_32x32,
Yaowu Xud3d41592018-02-14 13:26:52 -080064 inv_shift_64x64, inv_shift_4x8, inv_shift_8x4, inv_shift_8x16,
65 inv_shift_16x8, inv_shift_16x32, inv_shift_32x16, inv_shift_32x64,
66 inv_shift_64x32, inv_shift_4x16, inv_shift_16x4, inv_shift_8x32,
67 inv_shift_32x8, inv_shift_16x64, inv_shift_64x16,
Angie Chiang4a75b5a2018-01-10 17:19:06 -080068};
69
Peng Bin28744b52018-02-12 11:49:11 +080070/* clang-format off */
71const int8_t inv_cos_bit_col[MAX_TXWH_IDX] // txw_idx
72 [MAX_TXWH_IDX] = { // txh_idx
73 { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, 0, 0 },
74 { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, 0 },
75 { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
76 { 0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
77 { 0, 0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT }
78 };
Angie Chiangd4327bc2018-01-22 20:54:04 -080079
Peng Bin28744b52018-02-12 11:49:11 +080080const int8_t inv_cos_bit_row[MAX_TXWH_IDX] // txw_idx
81 [MAX_TXWH_IDX] = { // txh_idx
82 { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, 0, 0 },
83 { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, 0 },
84 { INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
85 { 0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT },
86 { 0, 0, INV_COS_BIT, INV_COS_BIT, INV_COS_BIT }
87 };
88/* clang-format on */
Angie Chiangd4327bc2018-01-22 20:54:04 -080089
Angie Chiang5d7c1fc2018-01-30 15:54:44 -080090const int8_t iadst4_range[7] = { 0, 1, 0, 0, 0, 0, 0 };
91
Urvang Joshic5022162017-11-21 15:57:42 -080092void av1_get_inv_txfm_cfg(TX_TYPE tx_type, TX_SIZE tx_size,
93 TXFM_2D_FLIP_CFG *cfg) {
94 assert(cfg != NULL);
Angie Chiang0c7b8d82018-01-23 19:20:44 -080095 cfg->tx_size = tx_size;
Urvang Joshic5022162017-11-21 15:57:42 -080096 set_flip_cfg(tx_type, cfg);
Angie Chiang0c7b8d82018-01-23 19:20:44 -080097 av1_zero(cfg->stage_range_col);
98 av1_zero(cfg->stage_range_row);
99 set_flip_cfg(tx_type, cfg);
100 const TX_TYPE_1D tx_type_1d_col = vtx_tab[tx_type];
101 const TX_TYPE_1D tx_type_1d_row = htx_tab[tx_type];
Angie Chiang4a75b5a2018-01-10 17:19:06 -0800102 cfg->shift = inv_txfm_shift_ls[tx_size];
Angie Chiang29d2f212018-01-24 19:42:57 -0800103 const int txw_idx = get_txw_idx(tx_size);
104 const int txh_idx = get_txh_idx(tx_size);
Angie Chiangd4327bc2018-01-22 20:54:04 -0800105 cfg->cos_bit_col = inv_cos_bit_col[txw_idx][txh_idx];
106 cfg->cos_bit_row = inv_cos_bit_row[txw_idx][txh_idx];
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800107 cfg->txfm_type_col = av1_txfm_type_ls[txh_idx][tx_type_1d_col];
Angie Chiang5d7c1fc2018-01-30 15:54:44 -0800108 if (cfg->txfm_type_col == TXFM_TYPE_ADST4) {
109 memcpy(cfg->stage_range_col, iadst4_range, sizeof(iadst4_range));
110 }
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800111 cfg->txfm_type_row = av1_txfm_type_ls[txw_idx][tx_type_1d_row];
Angie Chiang5d7c1fc2018-01-30 15:54:44 -0800112 if (cfg->txfm_type_row == TXFM_TYPE_ADST4) {
113 memcpy(cfg->stage_range_row, iadst4_range, sizeof(iadst4_range));
114 }
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800115 cfg->stage_num_col = av1_txfm_stage_num_list[cfg->txfm_type_col];
116 cfg->stage_num_row = av1_txfm_stage_num_list[cfg->txfm_type_row];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700117}
118
Angie Chiangce3ad282017-08-08 09:51:54 -0700119void av1_gen_inv_stage_range(int8_t *stage_range_col, int8_t *stage_range_row,
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800120 const TXFM_2D_FLIP_CFG *cfg, TX_SIZE tx_size,
Angie Chiangce3ad282017-08-08 09:51:54 -0700121 int bd) {
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800122 const int fwd_shift = inv_start_range[tx_size];
Angie Chiang4a75b5a2018-01-10 17:19:06 -0800123 const int8_t *shift = cfg->shift;
Angie Chiangede07922018-02-28 18:10:56 -0800124 int8_t opt_range_row, opt_range_col;
125 if (bd == 8) {
126 opt_range_row = 16;
127 opt_range_col = 16;
128 } else if (bd == 10) {
129 opt_range_row = 18;
130 opt_range_col = 16;
131 } else {
132 assert(bd == 12);
133 opt_range_row = 20;
134 opt_range_col = 18;
135 }
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800136 // i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800137 for (int i = 0; i < cfg->stage_num_row && i < MAX_TXFM_STAGE_NUM; ++i) {
Angie Chiangede07922018-02-28 18:10:56 -0800138 int real_range_row = cfg->stage_range_row[i] + fwd_shift + bd + 1;
139 (void)real_range_row;
140 // assert(opt_range_row >= real_range_row);
141 stage_range_row[i] = opt_range_row;
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800142 }
143 // i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800144 for (int i = 0; i < cfg->stage_num_col && i < MAX_TXFM_STAGE_NUM; ++i) {
Angie Chiangede07922018-02-28 18:10:56 -0800145 int real_range_col =
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800146 cfg->stage_range_col[i] + fwd_shift + shift[0] + bd + 1;
Angie Chiangede07922018-02-28 18:10:56 -0800147 (void)real_range_col;
148 // assert(opt_range_col >= real_range_col);
149 stage_range_col[i] = opt_range_col;
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800150 }
151}
152
153static INLINE void inv_txfm2d_add_c(const int32_t *input, uint16_t *output,
154 int stride, TXFM_2D_FLIP_CFG *cfg,
155 int32_t *txfm_buf, TX_SIZE tx_size,
156 int bd) {
157 // Note when assigning txfm_size_col, we use the txfm_size from the
158 // row configuration and vice versa. This is intentionally done to
159 // accurately perform rectangular transforms. When the transform is
160 // rectangular, the number of columns will be the same as the
161 // txfm_size stored in the row cfg struct. It will make no difference
162 // for square transforms.
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800163 const int txfm_size_col = tx_size_wide[cfg->tx_size];
164 const int txfm_size_row = tx_size_high[cfg->tx_size];
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800165 // Take the shift from the larger dimension in the rectangular case.
Angie Chiang4a75b5a2018-01-10 17:19:06 -0800166 const int8_t *shift = cfg->shift;
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800167 const int rect_type = get_rect_tx_log_ratio(txfm_size_col, txfm_size_row);
Angie Chiangce3ad282017-08-08 09:51:54 -0700168 int8_t stage_range_row[MAX_TXFM_STAGE_NUM];
169 int8_t stage_range_col[MAX_TXFM_STAGE_NUM];
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800170 assert(cfg->stage_num_row <= MAX_TXFM_STAGE_NUM);
171 assert(cfg->stage_num_col <= MAX_TXFM_STAGE_NUM);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800172 av1_gen_inv_stage_range(stage_range_col, stage_range_row, cfg, tx_size, bd);
Angie Chiangce3ad282017-08-08 09:51:54 -0700173
Angie Chiangd4327bc2018-01-22 20:54:04 -0800174 const int8_t cos_bit_col = cfg->cos_bit_col;
175 const int8_t cos_bit_row = cfg->cos_bit_row;
Angie Chiang0c7b8d82018-01-23 19:20:44 -0800176 const TxfmFunc txfm_func_col = inv_txfm_type_to_func(cfg->txfm_type_col);
177 const TxfmFunc txfm_func_row = inv_txfm_type_to_func(cfg->txfm_type_row);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700178
Angie Chiang4b29ea82018-01-12 14:52:36 -0800179 // txfm_buf's length is txfm_size_row * txfm_size_col + 2 *
180 // AOMMAX(txfm_size_row, txfm_size_col)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700181 // it is used for intermediate data buffering
Angie Chiang08225572018-01-23 13:50:16 -0800182 const int buf_offset = AOMMAX(txfm_size_row, txfm_size_col);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700183 int32_t *temp_in = txfm_buf;
Angie Chiang08225572018-01-23 13:50:16 -0800184 int32_t *temp_out = temp_in + buf_offset;
185 int32_t *buf = temp_out + buf_offset;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700186 int32_t *buf_ptr = buf;
187 int c, r;
188
189 // Rows
Sarah Parker31c66502017-05-19 16:51:07 -0700190 for (r = 0; r < txfm_size_row; ++r) {
Angie Chiang4b29ea82018-01-12 14:52:36 -0800191 if (abs(rect_type) == 1) {
192 for (c = 0; c < txfm_size_col; ++c) {
Angie Chiangc8d6c082018-02-06 14:26:55 -0800193 temp_in[c] = round_shift(input[c] * NewInvSqrt2, NewSqrt2Bits);
Angie Chiang4b29ea82018-01-12 14:52:36 -0800194 }
195 txfm_func_row(temp_in, buf_ptr, cos_bit_row, stage_range_row);
196 } else {
197 txfm_func_row(input, buf_ptr, cos_bit_row, stage_range_row);
198 }
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800199 av1_round_shift_array(buf_ptr, txfm_size_col, -shift[0]);
Debargha Mukherjeea5657c22018-02-05 10:57:37 -0800200 clamp_buf(buf_ptr, txfm_size_col, AOMMAX(bd + 6, 16));
Sarah Parker31c66502017-05-19 16:51:07 -0700201 input += txfm_size_col;
202 buf_ptr += txfm_size_col;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700203 }
204
205 // Columns
Sarah Parker31c66502017-05-19 16:51:07 -0700206 for (c = 0; c < txfm_size_col; ++c) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700207 if (cfg->lr_flip == 0) {
Sarah Parker31c66502017-05-19 16:51:07 -0700208 for (r = 0; r < txfm_size_row; ++r)
209 temp_in[r] = buf[r * txfm_size_col + c];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700210 } else {
211 // flip left right
Sarah Parker31c66502017-05-19 16:51:07 -0700212 for (r = 0; r < txfm_size_row; ++r)
213 temp_in[r] = buf[r * txfm_size_col + (txfm_size_col - c - 1)];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700214 }
215 txfm_func_col(temp_in, temp_out, cos_bit_col, stage_range_col);
Angie Chiang2fc20eb2018-01-12 12:19:00 -0800216 av1_round_shift_array(temp_out, txfm_size_row, -shift[1]);
Sebastien Alaiwana3457cc2017-06-16 10:11:58 +0200217 clamp_buf(temp_out, txfm_size_row, bd + 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700218 if (cfg->ud_flip == 0) {
Jonathan Matthews284f9d02017-06-08 15:49:08 +0100219 for (r = 0; r < txfm_size_row; ++r) {
220 output[r * stride + c] =
221 highbd_clip_pixel_add(output[r * stride + c], temp_out[r], bd);
222 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700223 } else {
224 // flip upside down
Jonathan Matthews284f9d02017-06-08 15:49:08 +0100225 for (r = 0; r < txfm_size_row; ++r) {
226 output[r * stride + c] = highbd_clip_pixel_add(
227 output[r * stride + c], temp_out[txfm_size_row - r - 1], bd);
228 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700229 }
230 }
231}
232
Frederic Barbierc53753f2017-04-25 11:05:01 +0200233static INLINE void inv_txfm2d_add_facade(const int32_t *input, uint16_t *output,
234 int stride, int32_t *txfm_buf,
Urvang Joshi9752a2e2017-10-02 17:32:27 -0700235 TX_TYPE tx_type, TX_SIZE tx_size,
236 int bd) {
Urvang Joshic5022162017-11-21 15:57:42 -0800237 TXFM_2D_FLIP_CFG cfg;
238 av1_get_inv_txfm_cfg(tx_type, tx_size, &cfg);
Urvang Joshia989d832017-12-11 16:41:26 -0800239 // Forward shift sum uses larger square size, to be consistent with what
240 // av1_gen_inv_stage_range() does for inverse shifts.
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800241 inv_txfm2d_add_c(input, output, stride, &cfg, txfm_buf, tx_size, bd);
Sarah Parker31c66502017-05-19 16:51:07 -0700242}
243
244void av1_inv_txfm2d_add_4x8_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700245 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800246 DECLARE_ALIGNED(32, int, txfm_buf[4 * 8 + 8 + 8]);
Sarah Parker31c66502017-05-19 16:51:07 -0700247 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X8, bd);
248}
249
250void av1_inv_txfm2d_add_8x4_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700251 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800252 DECLARE_ALIGNED(32, int, txfm_buf[8 * 4 + 8 + 8]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800253#if NO_INV_TRANSPOSE
254 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X4, bd);
255#else
Angie Chiang155bf9a2017-08-06 19:52:57 -0700256 int32_t rinput[8 * 4];
257 uint16_t routput[8 * 4];
Urvang Joshi9752a2e2017-10-02 17:32:27 -0700258 TX_SIZE tx_size = TX_8X4;
259 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
Urvang Joshi2283d372017-10-02 17:16:45 -0700260 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
Angie Chiang155bf9a2017-08-06 19:52:57 -0700261 int w = tx_size_wide[tx_size];
262 int h = tx_size_high[tx_size];
263 int rw = h;
264 int rh = w;
265 transpose_int32(rinput, rw, input, w, w, h);
266 transpose_uint16(routput, rw, output, stride, w, h);
267 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
268 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800269#endif // NO_INV_TRANSPOSE
Sarah Parker31c66502017-05-19 16:51:07 -0700270}
271
272void av1_inv_txfm2d_add_8x16_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700273 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800274 DECLARE_ALIGNED(32, int, txfm_buf[8 * 16 + 16 + 16]);
Sarah Parker31c66502017-05-19 16:51:07 -0700275 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X16, bd);
276}
277
278void av1_inv_txfm2d_add_16x8_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700279 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800280 DECLARE_ALIGNED(32, int, txfm_buf[16 * 8 + 16 + 16]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800281#if NO_INV_TRANSPOSE
282 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X8, bd);
283#else
Angie Chiang155bf9a2017-08-06 19:52:57 -0700284 int32_t rinput[16 * 8];
285 uint16_t routput[16 * 8];
Urvang Joshi9752a2e2017-10-02 17:32:27 -0700286 TX_SIZE tx_size = TX_16X8;
287 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
Urvang Joshi2283d372017-10-02 17:16:45 -0700288 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
Angie Chiang155bf9a2017-08-06 19:52:57 -0700289 int w = tx_size_wide[tx_size];
290 int h = tx_size_high[tx_size];
291 int rw = h;
292 int rh = w;
293 transpose_int32(rinput, rw, input, w, w, h);
294 transpose_uint16(routput, rw, output, stride, w, h);
295 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
296 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800297#endif // NO_INV_TRANSPOSE
Sarah Parker31c66502017-05-19 16:51:07 -0700298}
299
300void av1_inv_txfm2d_add_16x32_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700301 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800302 DECLARE_ALIGNED(32, int, txfm_buf[16 * 32 + 32 + 32]);
Sarah Parker31c66502017-05-19 16:51:07 -0700303 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X32, bd);
304}
305
306void av1_inv_txfm2d_add_32x16_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700307 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800308 DECLARE_ALIGNED(32, int, txfm_buf[32 * 16 + 32 + 32]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800309#if NO_INV_TRANSPOSE
310 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X16, bd);
311#else
Angie Chiang155bf9a2017-08-06 19:52:57 -0700312 int32_t rinput[32 * 16];
313 uint16_t routput[32 * 16];
Urvang Joshi9752a2e2017-10-02 17:32:27 -0700314 TX_SIZE tx_size = TX_32X16;
315 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
Urvang Joshi2283d372017-10-02 17:16:45 -0700316 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
Angie Chiang155bf9a2017-08-06 19:52:57 -0700317 int w = tx_size_wide[tx_size];
318 int h = tx_size_high[tx_size];
319 int rw = h;
320 int rh = w;
321 transpose_int32(rinput, rw, input, w, w, h);
322 transpose_uint16(routput, rw, output, stride, w, h);
323 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
324 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800325#endif // NO_INV_TRANSPOSE
Frederic Barbierc53753f2017-04-25 11:05:01 +0200326}
327
328void av1_inv_txfm2d_add_4x4_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700329 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800330 DECLARE_ALIGNED(32, int, txfm_buf[4 * 4 + 4 + 4]);
Frederic Barbierc53753f2017-04-25 11:05:01 +0200331 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X4, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700332}
333
Yaowu Xuf883b422016-08-30 14:01:10 -0700334void av1_inv_txfm2d_add_8x8_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700335 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800336 DECLARE_ALIGNED(32, int, txfm_buf[8 * 8 + 8 + 8]);
Frederic Barbierc53753f2017-04-25 11:05:01 +0200337 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X8, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700338}
339
Yaowu Xuf883b422016-08-30 14:01:10 -0700340void av1_inv_txfm2d_add_16x16_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700341 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800342 DECLARE_ALIGNED(32, int, txfm_buf[16 * 16 + 16 + 16]);
Frederic Barbierc53753f2017-04-25 11:05:01 +0200343 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X16, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700344}
345
Yaowu Xuf883b422016-08-30 14:01:10 -0700346void av1_inv_txfm2d_add_32x32_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700347 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800348 DECLARE_ALIGNED(32, int, txfm_buf[32 * 32 + 32 + 32]);
Frederic Barbierc53753f2017-04-25 11:05:01 +0200349 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X32, bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700350}
351
Yaowu Xuf883b422016-08-30 14:01:10 -0700352void av1_inv_txfm2d_add_64x64_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700353 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi80893152017-10-27 11:51:14 -0700354 // TODO(urvang): Can the same array be reused, instead of using a new array?
355 // Remap 32x32 input into a modified 64x64 by:
356 // - Copying over these values in top-left 32x32 locations.
357 // - Setting the rest of the locations to 0.
358 int32_t mod_input[64 * 64];
359 for (int row = 0; row < 32; ++row) {
360 memcpy(mod_input + row * 64, input + row * 32, 32 * sizeof(*mod_input));
361 memset(mod_input + row * 64 + 32, 0, 32 * sizeof(*mod_input));
362 }
363 memset(mod_input + 32 * 64, 0, 32 * 64 * sizeof(*mod_input));
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800364 DECLARE_ALIGNED(32, int, txfm_buf[64 * 64 + 64 + 64]);
Urvang Joshi80893152017-10-27 11:51:14 -0700365 inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_64X64,
366 bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700367}
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700368
369void av1_inv_txfm2d_add_64x32_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700370 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi80893152017-10-27 11:51:14 -0700371 // Remap 32x32 input into a modified 64x32 by:
372 // - Copying over these values in top-left 32x32 locations.
373 // - Setting the rest of the locations to 0.
374 int32_t mod_input[64 * 32];
375 for (int row = 0; row < 32; ++row) {
376 memcpy(mod_input + row * 64, input + row * 32, 32 * sizeof(*mod_input));
377 memset(mod_input + row * 64 + 32, 0, 32 * sizeof(*mod_input));
378 }
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800379 DECLARE_ALIGNED(32, int, txfm_buf[64 * 32 + 64 + 64]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800380#if NO_INV_TRANSPOSE
381 inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_64X32,
382 bd);
383#else
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700384 int32_t rinput[64 * 32];
385 uint16_t routput[64 * 32];
Urvang Joshi9752a2e2017-10-02 17:32:27 -0700386 TX_SIZE tx_size = TX_64X32;
387 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
Urvang Joshi2283d372017-10-02 17:16:45 -0700388 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700389 int w = tx_size_wide[tx_size];
390 int h = tx_size_high[tx_size];
391 int rw = h;
392 int rh = w;
Urvang Joshi80893152017-10-27 11:51:14 -0700393 transpose_int32(rinput, rw, mod_input, w, w, h);
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700394 transpose_uint16(routput, rw, output, stride, w, h);
395 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
396 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800397#endif // NO_INV_TRANSPOSE
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700398}
399
400void av1_inv_txfm2d_add_32x64_c(const int32_t *input, uint16_t *output,
Urvang Joshi2283d372017-10-02 17:16:45 -0700401 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi80893152017-10-27 11:51:14 -0700402 // Remap 32x32 input into a modified 32x64 input by:
403 // - Copying over these values in top-left 32x32 locations.
404 // - Setting the rest of the locations to 0.
405 int32_t mod_input[32 * 64];
406 memcpy(mod_input, input, 32 * 32 * sizeof(*mod_input));
407 memset(mod_input + 32 * 32, 0, 32 * 32 * sizeof(*mod_input));
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800408 DECLARE_ALIGNED(32, int, txfm_buf[64 * 32 + 64 + 64]);
Urvang Joshi80893152017-10-27 11:51:14 -0700409 inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_32X64,
410 bd);
Debargha Mukherjee2b435012017-09-28 08:30:35 -0700411}
Debargha Mukherjee0254fee2017-12-02 09:08:52 -0800412
413void av1_inv_txfm2d_add_16x64_c(const int32_t *input, uint16_t *output,
414 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi030cea92017-12-05 15:27:09 -0800415 // Remap 16x32 input into a modified 16x64 input by:
416 // - Copying over these values in top-left 16x32 locations.
417 // - Setting the rest of the locations to 0.
418 int32_t mod_input[16 * 64];
419 memcpy(mod_input, input, 16 * 32 * sizeof(*mod_input));
420 memset(mod_input + 16 * 32, 0, 16 * 32 * sizeof(*mod_input));
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800421 DECLARE_ALIGNED(32, int, txfm_buf[16 * 64 + 64 + 64]);
Urvang Joshi030cea92017-12-05 15:27:09 -0800422 inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_16X64,
423 bd);
Debargha Mukherjee0254fee2017-12-02 09:08:52 -0800424}
425
426void av1_inv_txfm2d_add_64x16_c(const int32_t *input, uint16_t *output,
427 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi030cea92017-12-05 15:27:09 -0800428 // Remap 32x16 input into a modified 64x16 by:
429 // - Copying over these values in top-left 32x16 locations.
430 // - Setting the rest of the locations to 0.
431 int32_t mod_input[64 * 16];
432 for (int row = 0; row < 16; ++row) {
433 memcpy(mod_input + row * 64, input + row * 32, 32 * sizeof(*mod_input));
434 memset(mod_input + row * 64 + 32, 0, 32 * sizeof(*mod_input));
435 }
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800436 DECLARE_ALIGNED(32, int, txfm_buf[16 * 64 + 64 + 64]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800437#if NO_INV_TRANSPOSE
438 inv_txfm2d_add_facade(mod_input, output, stride, txfm_buf, tx_type, TX_64X16,
439 bd);
440#else
Debargha Mukherjee0254fee2017-12-02 09:08:52 -0800441 int32_t rinput[16 * 64];
442 uint16_t routput[16 * 64];
443 TX_SIZE tx_size = TX_64X16;
444 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
445 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
446 int w = tx_size_wide[tx_size];
447 int h = tx_size_high[tx_size];
448 int rw = h;
449 int rh = w;
Urvang Joshi030cea92017-12-05 15:27:09 -0800450 transpose_int32(rinput, rw, mod_input, w, w, h);
Debargha Mukherjee0254fee2017-12-02 09:08:52 -0800451 transpose_uint16(routput, rw, output, stride, w, h);
452 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
453 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800454#endif // NO_INV_TRANSPOSE
Debargha Mukherjee0254fee2017-12-02 09:08:52 -0800455}
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800456
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800457void av1_inv_txfm2d_add_4x16_c(const int32_t *input, uint16_t *output,
458 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800459 DECLARE_ALIGNED(32, int, txfm_buf[4 * 16 + 16 + 16]);
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800460 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X16, bd);
461}
462
463void av1_inv_txfm2d_add_16x4_c(const int32_t *input, uint16_t *output,
464 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800465 DECLARE_ALIGNED(32, int, txfm_buf[4 * 16 + 16 + 16]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800466#if NO_INV_TRANSPOSE
467 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X4, bd);
468#else
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800469 int32_t rinput[4 * 16];
470 uint16_t routput[4 * 16];
471 TX_SIZE tx_size = TX_16X4;
472 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
473 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
474 int w = tx_size_wide[tx_size];
475 int h = tx_size_high[tx_size];
476 int rw = h;
477 int rh = w;
478 transpose_int32(rinput, rw, input, w, w, h);
479 transpose_uint16(routput, rw, output, stride, w, h);
480 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
481 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800482#endif // NO_INV_TRANSPOSE
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800483}
484
485void av1_inv_txfm2d_add_8x32_c(const int32_t *input, uint16_t *output,
486 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800487 DECLARE_ALIGNED(32, int, txfm_buf[8 * 32 + 32 + 32]);
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800488 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X32, bd);
489}
490
491void av1_inv_txfm2d_add_32x8_c(const int32_t *input, uint16_t *output,
492 int stride, TX_TYPE tx_type, int bd) {
Urvang Joshi1ac47a72017-12-07 12:12:50 -0800493 DECLARE_ALIGNED(32, int, txfm_buf[8 * 32 + 32 + 32]);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800494#if NO_INV_TRANSPOSE
495 inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X8, bd);
496#else
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800497 int32_t rinput[8 * 32];
498 uint16_t routput[8 * 32];
499 TX_SIZE tx_size = TX_32X8;
500 TX_SIZE rtx_size = av1_rotate_tx_size(tx_size);
501 TX_TYPE rtx_type = av1_rotate_tx_type(tx_type);
502 int w = tx_size_wide[tx_size];
503 int h = tx_size_high[tx_size];
504 int rw = h;
505 int rh = w;
506 transpose_int32(rinput, rw, input, w, w, h);
507 transpose_uint16(routput, rw, output, stride, w, h);
508 inv_txfm2d_add_facade(rinput, routput, rw, txfm_buf, rtx_type, rtx_size, bd);
509 transpose_uint16(output, stride, routput, rw, rw, rh);
Debargha Mukherjee1158bff2018-01-01 18:23:59 -0800510#endif // NO_INV_TRANSPOSE
Debargha Mukherjee845057f2017-11-13 07:03:36 -0800511}