blob: 418c9261de3ce1dff37e1afe9558ca67bd7e35de [file] [log] [blame]
Daniel Kangfed8a182012-08-02 17:03:14 -07001/*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <math.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "third_party/googletest/src/include/gtest/gtest.h"
Jingning Han8f92a7e2013-09-05 12:44:03 -070016#include "test/acm_random.h"
17#include "test/clear_system_state.h"
18#include "test/register_state_check.h"
19#include "test/util.h"
Daniel Kangfed8a182012-08-02 17:03:14 -070020
Yaowu Xuafffa3d2013-09-05 08:45:56 -070021#include "./vp9_rtcd.h"
James Zern002ad402014-01-18 13:03:31 -080022#include "vp9/common/vp9_entropy.h"
Deb Mukherjee10783d42014-09-02 16:34:09 -070023#include "vpx/vpx_codec.h"
James Zern002ad402014-01-18 13:03:31 -080024#include "vpx/vpx_integer.h"
25
Daniel Kangfed8a182012-08-02 17:03:14 -070026using libvpx_test::ACMRandom;
27
28namespace {
29
Yaowu Xu77f889b2013-02-04 15:22:55 -080030#ifdef _MSC_VER
31static int round(double x) {
32 if (x < 0)
Yaowu Xuafffa3d2013-09-05 08:45:56 -070033 return static_cast<int>(ceil(x - 0.5));
Yaowu Xu77f889b2013-02-04 15:22:55 -080034 else
Yaowu Xuafffa3d2013-09-05 08:45:56 -070035 return static_cast<int>(floor(x + 0.5));
Yaowu Xu77f889b2013-02-04 15:22:55 -080036}
37#endif
38
Jingning Han8f92a7e2013-09-05 12:44:03 -070039const int kNumCoeffs = 256;
Daniel Kangfed8a182012-08-02 17:03:14 -070040const double PI = 3.1415926535898;
41void reference2_16x16_idct_2d(double *input, double *output) {
42 double x;
43 for (int l = 0; l < 16; ++l) {
44 for (int k = 0; k < 16; ++k) {
45 double s = 0;
46 for (int i = 0; i < 16; ++i) {
47 for (int j = 0; j < 16; ++j) {
Yaowu Xuafffa3d2013-09-05 08:45:56 -070048 x = cos(PI * j * (l + 0.5) / 16.0) *
49 cos(PI * i * (k + 0.5) / 16.0) *
50 input[i * 16 + j] / 256;
Daniel Kangfed8a182012-08-02 17:03:14 -070051 if (i != 0)
52 x *= sqrt(2.0);
53 if (j != 0)
54 x *= sqrt(2.0);
55 s += x;
56 }
57 }
58 output[k*16+l] = s;
59 }
60 }
61}
62
Yaowu Xu0b17ea62012-08-07 13:55:49 -070063
Jingning Han8f92a7e2013-09-05 12:44:03 -070064const double C1 = 0.995184726672197;
65const double C2 = 0.98078528040323;
66const double C3 = 0.956940335732209;
67const double C4 = 0.923879532511287;
68const double C5 = 0.881921264348355;
69const double C6 = 0.831469612302545;
70const double C7 = 0.773010453362737;
71const double C8 = 0.707106781186548;
72const double C9 = 0.634393284163646;
73const double C10 = 0.555570233019602;
74const double C11 = 0.471396736825998;
75const double C12 = 0.38268343236509;
76const double C13 = 0.290284677254462;
77const double C14 = 0.195090322016128;
78const double C15 = 0.098017140329561;
Yaowu Xu0b17ea62012-08-07 13:55:49 -070079
Jingning Hanec4b2742013-08-27 17:03:46 -070080void butterfly_16x16_dct_1d(double input[16], double output[16]) {
Daniel Kangfed8a182012-08-02 17:03:14 -070081 double step[16];
82 double intermediate[16];
83 double temp1, temp2;
84
Daniel Kangfed8a182012-08-02 17:03:14 -070085 // step 1
86 step[ 0] = input[0] + input[15];
87 step[ 1] = input[1] + input[14];
88 step[ 2] = input[2] + input[13];
89 step[ 3] = input[3] + input[12];
90 step[ 4] = input[4] + input[11];
91 step[ 5] = input[5] + input[10];
92 step[ 6] = input[6] + input[ 9];
93 step[ 7] = input[7] + input[ 8];
94 step[ 8] = input[7] - input[ 8];
95 step[ 9] = input[6] - input[ 9];
96 step[10] = input[5] - input[10];
97 step[11] = input[4] - input[11];
98 step[12] = input[3] - input[12];
99 step[13] = input[2] - input[13];
100 step[14] = input[1] - input[14];
101 step[15] = input[0] - input[15];
102
103 // step 2
104 output[0] = step[0] + step[7];
105 output[1] = step[1] + step[6];
106 output[2] = step[2] + step[5];
107 output[3] = step[3] + step[4];
108 output[4] = step[3] - step[4];
109 output[5] = step[2] - step[5];
110 output[6] = step[1] - step[6];
111 output[7] = step[0] - step[7];
112
Jingning Han8f92a7e2013-09-05 12:44:03 -0700113 temp1 = step[ 8] * C7;
114 temp2 = step[15] * C9;
Daniel Kangfed8a182012-08-02 17:03:14 -0700115 output[ 8] = temp1 + temp2;
116
Jingning Han8f92a7e2013-09-05 12:44:03 -0700117 temp1 = step[ 9] * C11;
118 temp2 = step[14] * C5;
Daniel Kangfed8a182012-08-02 17:03:14 -0700119 output[ 9] = temp1 - temp2;
120
Jingning Han8f92a7e2013-09-05 12:44:03 -0700121 temp1 = step[10] * C3;
122 temp2 = step[13] * C13;
Daniel Kangfed8a182012-08-02 17:03:14 -0700123 output[10] = temp1 + temp2;
124
Jingning Han8f92a7e2013-09-05 12:44:03 -0700125 temp1 = step[11] * C15;
126 temp2 = step[12] * C1;
Daniel Kangfed8a182012-08-02 17:03:14 -0700127 output[11] = temp1 - temp2;
128
Jingning Han8f92a7e2013-09-05 12:44:03 -0700129 temp1 = step[11] * C1;
130 temp2 = step[12] * C15;
Daniel Kangfed8a182012-08-02 17:03:14 -0700131 output[12] = temp2 + temp1;
132
Jingning Han8f92a7e2013-09-05 12:44:03 -0700133 temp1 = step[10] * C13;
134 temp2 = step[13] * C3;
Daniel Kangfed8a182012-08-02 17:03:14 -0700135 output[13] = temp2 - temp1;
136
Jingning Han8f92a7e2013-09-05 12:44:03 -0700137 temp1 = step[ 9] * C5;
138 temp2 = step[14] * C11;
Daniel Kangfed8a182012-08-02 17:03:14 -0700139 output[14] = temp2 + temp1;
140
Jingning Han8f92a7e2013-09-05 12:44:03 -0700141 temp1 = step[ 8] * C9;
142 temp2 = step[15] * C7;
Daniel Kangfed8a182012-08-02 17:03:14 -0700143 output[15] = temp2 - temp1;
144
145 // step 3
146 step[ 0] = output[0] + output[3];
147 step[ 1] = output[1] + output[2];
148 step[ 2] = output[1] - output[2];
149 step[ 3] = output[0] - output[3];
150
Jingning Han8f92a7e2013-09-05 12:44:03 -0700151 temp1 = output[4] * C14;
152 temp2 = output[7] * C2;
Daniel Kangfed8a182012-08-02 17:03:14 -0700153 step[ 4] = temp1 + temp2;
154
Jingning Han8f92a7e2013-09-05 12:44:03 -0700155 temp1 = output[5] * C10;
156 temp2 = output[6] * C6;
Daniel Kangfed8a182012-08-02 17:03:14 -0700157 step[ 5] = temp1 + temp2;
158
Jingning Han8f92a7e2013-09-05 12:44:03 -0700159 temp1 = output[5] * C6;
160 temp2 = output[6] * C10;
Daniel Kangfed8a182012-08-02 17:03:14 -0700161 step[ 6] = temp2 - temp1;
162
Jingning Han8f92a7e2013-09-05 12:44:03 -0700163 temp1 = output[4] * C2;
164 temp2 = output[7] * C14;
Daniel Kangfed8a182012-08-02 17:03:14 -0700165 step[ 7] = temp2 - temp1;
166
167 step[ 8] = output[ 8] + output[11];
168 step[ 9] = output[ 9] + output[10];
169 step[10] = output[ 9] - output[10];
170 step[11] = output[ 8] - output[11];
171
172 step[12] = output[12] + output[15];
173 step[13] = output[13] + output[14];
174 step[14] = output[13] - output[14];
175 step[15] = output[12] - output[15];
176
177 // step 4
178 output[ 0] = (step[ 0] + step[ 1]);
179 output[ 8] = (step[ 0] - step[ 1]);
180
Jingning Han8f92a7e2013-09-05 12:44:03 -0700181 temp1 = step[2] * C12;
182 temp2 = step[3] * C4;
Daniel Kangfed8a182012-08-02 17:03:14 -0700183 temp1 = temp1 + temp2;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700184 output[ 4] = 2*(temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700185
Jingning Han8f92a7e2013-09-05 12:44:03 -0700186 temp1 = step[2] * C4;
187 temp2 = step[3] * C12;
Daniel Kangfed8a182012-08-02 17:03:14 -0700188 temp1 = temp2 - temp1;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700189 output[12] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700190
Jingning Han8f92a7e2013-09-05 12:44:03 -0700191 output[ 2] = 2 * ((step[4] + step[ 5]) * C8);
192 output[14] = 2 * ((step[7] - step[ 6]) * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700193
194 temp1 = step[4] - step[5];
195 temp2 = step[6] + step[7];
196 output[ 6] = (temp1 + temp2);
197 output[10] = (temp1 - temp2);
198
199 intermediate[8] = step[8] + step[14];
200 intermediate[9] = step[9] + step[15];
201
Jingning Han8f92a7e2013-09-05 12:44:03 -0700202 temp1 = intermediate[8] * C12;
203 temp2 = intermediate[9] * C4;
Daniel Kangfed8a182012-08-02 17:03:14 -0700204 temp1 = temp1 - temp2;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700205 output[3] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700206
Jingning Han8f92a7e2013-09-05 12:44:03 -0700207 temp1 = intermediate[8] * C4;
208 temp2 = intermediate[9] * C12;
Daniel Kangfed8a182012-08-02 17:03:14 -0700209 temp1 = temp2 + temp1;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700210 output[13] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700211
Jingning Han8f92a7e2013-09-05 12:44:03 -0700212 output[ 9] = 2 * ((step[10] + step[11]) * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700213
214 intermediate[11] = step[10] - step[11];
215 intermediate[12] = step[12] + step[13];
216 intermediate[13] = step[12] - step[13];
217 intermediate[14] = step[ 8] - step[14];
218 intermediate[15] = step[ 9] - step[15];
219
220 output[15] = (intermediate[11] + intermediate[12]);
221 output[ 1] = -(intermediate[11] - intermediate[12]);
222
Jingning Han8f92a7e2013-09-05 12:44:03 -0700223 output[ 7] = 2 * (intermediate[13] * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700224
Jingning Han8f92a7e2013-09-05 12:44:03 -0700225 temp1 = intermediate[14] * C12;
226 temp2 = intermediate[15] * C4;
Daniel Kangfed8a182012-08-02 17:03:14 -0700227 temp1 = temp1 - temp2;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700228 output[11] = -2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700229
Jingning Han8f92a7e2013-09-05 12:44:03 -0700230 temp1 = intermediate[14] * C4;
231 temp2 = intermediate[15] * C12;
Daniel Kangfed8a182012-08-02 17:03:14 -0700232 temp1 = temp2 + temp1;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700233 output[ 5] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700234}
235
Jingning Han8f92a7e2013-09-05 12:44:03 -0700236void reference_16x16_dct_2d(int16_t input[256], double output[256]) {
Daniel Kangfed8a182012-08-02 17:03:14 -0700237 // First transform columns
238 for (int i = 0; i < 16; ++i) {
239 double temp_in[16], temp_out[16];
240 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700241 temp_in[j] = input[j * 16 + i];
Daniel Kangfed8a182012-08-02 17:03:14 -0700242 butterfly_16x16_dct_1d(temp_in, temp_out);
243 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700244 output[j * 16 + i] = temp_out[j];
Daniel Kangfed8a182012-08-02 17:03:14 -0700245 }
246 // Then transform rows
247 for (int i = 0; i < 16; ++i) {
248 double temp_in[16], temp_out[16];
249 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700250 temp_in[j] = output[j + i * 16];
Daniel Kangfed8a182012-08-02 17:03:14 -0700251 butterfly_16x16_dct_1d(temp_in, temp_out);
252 // Scale by some magic number
253 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700254 output[j + i * 16] = temp_out[j]/2;
Daniel Kangfed8a182012-08-02 17:03:14 -0700255 }
256}
257
Deb Mukherjee10783d42014-09-02 16:34:09 -0700258typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride);
259typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride);
260typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride,
James Zern44f84842014-07-16 18:53:33 -0700261 int tx_type);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700262typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
James Zern44f84842014-07-16 18:53:33 -0700263 int tx_type);
Jingning Hancf768b22013-07-09 16:16:49 -0700264
Deb Mukherjee10783d42014-09-02 16:34:09 -0700265typedef std::tr1::tuple<FdctFunc, IdctFunc, int, vpx_bit_depth_t> Dct16x16Param;
266typedef std::tr1::tuple<FhtFunc, IhtFunc, int, vpx_bit_depth_t> Ht16x16Param;
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100267typedef std::tr1::tuple<IdctFunc, IdctFunc, int, vpx_bit_depth_t>
268 Idct16x16Param;
Joshua Litt51490e52013-11-18 17:07:55 -0800269
Deb Mukherjee10783d42014-09-02 16:34:09 -0700270void fdct16x16_ref(const int16_t *in, tran_low_t *out, int stride,
James Zern632e4192014-08-22 12:11:42 -0700271 int /*tx_type*/) {
Dmitry Kovalev02feb632013-10-23 10:57:12 -0700272 vp9_fdct16x16_c(in, out, stride);
Jingning Han37705a32013-09-09 17:07:55 -0700273}
274
Deb Mukherjee10783d42014-09-02 16:34:09 -0700275void idct16x16_ref(const tran_low_t *in, uint8_t *dest, int stride,
James Zern632e4192014-08-22 12:11:42 -0700276 int /*tx_type*/) {
Jingning Han49b4a272014-05-29 12:50:54 -0700277 vp9_idct16x16_256_add_c(in, dest, stride);
278}
279
Deb Mukherjee10783d42014-09-02 16:34:09 -0700280void fht16x16_ref(const int16_t *in, tran_low_t *out, int stride,
281 int tx_type) {
Dmitry Kovalev005fc692014-02-06 11:54:15 -0800282 vp9_fht16x16_c(in, out, stride, tx_type);
Jingning Han37705a32013-09-09 17:07:55 -0700283}
284
Deb Mukherjee10783d42014-09-02 16:34:09 -0700285void iht16x16_ref(const tran_low_t *in, uint8_t *dest, int stride,
286 int tx_type) {
Jingning Han49b4a272014-05-29 12:50:54 -0700287 vp9_iht16x16_256_add_c(in, dest, stride, tx_type);
288}
289
Deb Mukherjee10783d42014-09-02 16:34:09 -0700290#if CONFIG_VP9_HIGHBITDEPTH
291void idct16x16_10(const tran_low_t *in, uint8_t *out, int stride) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700292 vp9_highbd_idct16x16_256_add_c(in, out, stride, 10);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700293}
294
295void idct16x16_12(const tran_low_t *in, uint8_t *out, int stride) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700296 vp9_highbd_idct16x16_256_add_c(in, out, stride, 12);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700297}
298
299void idct16x16_10_ref(const tran_low_t *in, uint8_t *out, int stride,
300 int tx_type) {
301 idct16x16_10(in, out, stride);
302}
303
304void idct16x16_12_ref(const tran_low_t *in, uint8_t *out, int stride,
305 int tx_type) {
306 idct16x16_12(in, out, stride);
307}
308
309void iht16x16_10(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700310 vp9_highbd_iht16x16_256_add_c(in, out, stride, tx_type, 10);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700311}
312
313void iht16x16_12(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700314 vp9_highbd_iht16x16_256_add_c(in, out, stride, tx_type, 12);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700315}
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100316
317void idct16x16_10_add_10_c(const tran_low_t *in, uint8_t *out, int stride) {
318 vp9_highbd_idct16x16_10_add_c(in, out, stride, 10);
319}
320
321void idct16x16_10_add_12_c(const tran_low_t *in, uint8_t *out, int stride) {
322 vp9_highbd_idct16x16_10_add_c(in, out, stride, 12);
323}
324
325#if HAVE_SSE2
326void idct16x16_256_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
327 vp9_highbd_idct16x16_256_add_sse2(in, out, stride, 10);
328}
329
330void idct16x16_256_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
331 vp9_highbd_idct16x16_256_add_sse2(in, out, stride, 12);
332}
333
334void idct16x16_10_add_10_sse2(const tran_low_t *in, uint8_t *out, int stride) {
335 vp9_highbd_idct16x16_10_add_sse2(in, out, stride, 10);
336}
337
338void idct16x16_10_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) {
339 vp9_highbd_idct16x16_10_add_sse2(in, out, stride, 12);
340}
341#endif // HAVE_SSE2
342#endif // CONFIG_VP9_HIGHBITDEPTH
Deb Mukherjee10783d42014-09-02 16:34:09 -0700343
Jingning Han8f92a7e2013-09-05 12:44:03 -0700344class Trans16x16TestBase {
Jingning Hancf768b22013-07-09 16:16:49 -0700345 public:
Jingning Han8f92a7e2013-09-05 12:44:03 -0700346 virtual ~Trans16x16TestBase() {}
Jingning Hancf768b22013-07-09 16:16:49 -0700347
Jingning Han8f92a7e2013-09-05 12:44:03 -0700348 protected:
Deb Mukherjee10783d42014-09-02 16:34:09 -0700349 virtual void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) = 0;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700350
Deb Mukherjee10783d42014-09-02 16:34:09 -0700351 virtual void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) = 0;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700352
353 void RunAccuracyCheck() {
354 ACMRandom rnd(ACMRandom::DeterministicSeed());
Jingning Han37705a32013-09-09 17:07:55 -0700355 uint32_t max_error = 0;
356 int64_t total_error = 0;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700357 const int count_test_block = 10000;
358 for (int i = 0; i < count_test_block; ++i) {
359 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700360 DECLARE_ALIGNED_ARRAY(16, tran_low_t, test_temp_block, kNumCoeffs);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700361 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
362 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700363#if CONFIG_VP9_HIGHBITDEPTH
364 DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
365 DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
366#endif
Jingning Han8f92a7e2013-09-05 12:44:03 -0700367
Deb Mukherjee10783d42014-09-02 16:34:09 -0700368 // Initialize a test block with input range [-mask_, mask_].
Jingning Han8f92a7e2013-09-05 12:44:03 -0700369 for (int j = 0; j < kNumCoeffs; ++j) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700370 if (bit_depth_ == VPX_BITS_8) {
371 src[j] = rnd.Rand8();
372 dst[j] = rnd.Rand8();
373 test_input_block[j] = src[j] - dst[j];
374#if CONFIG_VP9_HIGHBITDEPTH
375 } else {
376 src16[j] = rnd.Rand16() & mask_;
377 dst16[j] = rnd.Rand16() & mask_;
378 test_input_block[j] = src16[j] - dst16[j];
379#endif
380 }
Jingning Han8f92a7e2013-09-05 12:44:03 -0700381 }
382
James Zern29e1b1a2014-07-09 21:02:02 -0700383 ASM_REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
384 test_temp_block, pitch_));
Deb Mukherjee10783d42014-09-02 16:34:09 -0700385 if (bit_depth_ == VPX_BITS_8) {
386 ASM_REGISTER_STATE_CHECK(
387 RunInvTxfm(test_temp_block, dst, pitch_));
388#if CONFIG_VP9_HIGHBITDEPTH
389 } else {
390 ASM_REGISTER_STATE_CHECK(
391 RunInvTxfm(test_temp_block, CONVERT_TO_BYTEPTR(dst16), pitch_));
392#endif
393 }
Jingning Han8f92a7e2013-09-05 12:44:03 -0700394
395 for (int j = 0; j < kNumCoeffs; ++j) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700396#if CONFIG_VP9_HIGHBITDEPTH
397 const uint32_t diff =
398 bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
399#else
Jingning Han37705a32013-09-09 17:07:55 -0700400 const uint32_t diff = dst[j] - src[j];
Deb Mukherjee10783d42014-09-02 16:34:09 -0700401#endif
Jingning Han37705a32013-09-09 17:07:55 -0700402 const uint32_t error = diff * diff;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700403 if (max_error < error)
404 max_error = error;
405 total_error += error;
406 }
407 }
408
Deb Mukherjee10783d42014-09-02 16:34:09 -0700409 EXPECT_GE(1u << 2 * (bit_depth_ - 8), max_error)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700410 << "Error: 16x16 FHT/IHT has an individual round trip error > 1";
411
Deb Mukherjee10783d42014-09-02 16:34:09 -0700412 EXPECT_GE(count_test_block << 2 * (bit_depth_ - 8), total_error)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700413 << "Error: 16x16 FHT/IHT has average round trip error > 1 per block";
414 }
415
Jingning Han37705a32013-09-09 17:07:55 -0700416 void RunCoeffCheck() {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700417 ACMRandom rnd(ACMRandom::DeterministicSeed());
418 const int count_test_block = 1000;
Jingning Han37705a32013-09-09 17:07:55 -0700419 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700420 DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
421 DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700422
Jingning Han37705a32013-09-09 17:07:55 -0700423 for (int i = 0; i < count_test_block; ++i) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700424 // Initialize a test block with input range [-mask_, mask_].
Jingning Han37705a32013-09-09 17:07:55 -0700425 for (int j = 0; j < kNumCoeffs; ++j)
Deb Mukherjee10783d42014-09-02 16:34:09 -0700426 input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
Jingning Han37705a32013-09-09 17:07:55 -0700427
428 fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
James Zern29e1b1a2014-07-09 21:02:02 -0700429 ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
Jingning Han37705a32013-09-09 17:07:55 -0700430
431 // The minimum quant value is 4.
432 for (int j = 0; j < kNumCoeffs; ++j)
433 EXPECT_EQ(output_block[j], output_ref_block[j]);
434 }
435 }
436
437 void RunMemCheck() {
438 ACMRandom rnd(ACMRandom::DeterministicSeed());
439 const int count_test_block = 1000;
440 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
441 DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700442 DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
443 DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_block, kNumCoeffs);
Jingning Han37705a32013-09-09 17:07:55 -0700444
445 for (int i = 0; i < count_test_block; ++i) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700446 // Initialize a test block with input range [-mask_, mask_].
Jingning Han8f92a7e2013-09-05 12:44:03 -0700447 for (int j = 0; j < kNumCoeffs; ++j) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700448 input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
449 input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700450 }
Jingning Han5c2696c2014-06-02 16:40:01 -0700451 if (i == 0) {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700452 for (int j = 0; j < kNumCoeffs; ++j)
Deb Mukherjee10783d42014-09-02 16:34:09 -0700453 input_extreme_block[j] = mask_;
Jingning Han5c2696c2014-06-02 16:40:01 -0700454 } else if (i == 1) {
Jingning Han37705a32013-09-09 17:07:55 -0700455 for (int j = 0; j < kNumCoeffs; ++j)
Deb Mukherjee10783d42014-09-02 16:34:09 -0700456 input_extreme_block[j] = -mask_;
Jingning Han5c2696c2014-06-02 16:40:01 -0700457 }
Jingning Han8f92a7e2013-09-05 12:44:03 -0700458
Jingning Han37705a32013-09-09 17:07:55 -0700459 fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
James Zern29e1b1a2014-07-09 21:02:02 -0700460 ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
461 output_block, pitch_));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700462
463 // The minimum quant value is 4.
464 for (int j = 0; j < kNumCoeffs; ++j) {
Jingning Han37705a32013-09-09 17:07:55 -0700465 EXPECT_EQ(output_block[j], output_ref_block[j]);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700466 EXPECT_GE(4 * DCT_MAX_VALUE << (bit_depth_ - 8), abs(output_block[j]))
Jingning Han8f92a7e2013-09-05 12:44:03 -0700467 << "Error: 16x16 FDCT has coefficient larger than 4*DCT_MAX_VALUE";
Jingning Han8f92a7e2013-09-05 12:44:03 -0700468 }
Jingning Hancf768b22013-07-09 16:16:49 -0700469 }
470 }
471
Jingning Han49b4a272014-05-29 12:50:54 -0700472 void RunQuantCheck(int dc_thred, int ac_thred) {
473 ACMRandom rnd(ACMRandom::DeterministicSeed());
Jingning Han12344f22014-10-06 10:18:17 -0700474 const int count_test_block = 100000;
Jingning Han49b4a272014-05-29 12:50:54 -0700475 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
476 DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700477 DECLARE_ALIGNED_ARRAY(16, tran_low_t, output_ref_block, kNumCoeffs);
Jingning Han49b4a272014-05-29 12:50:54 -0700478
479 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
480 DECLARE_ALIGNED_ARRAY(16, uint8_t, ref, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700481#if CONFIG_VP9_HIGHBITDEPTH
482 DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
483 DECLARE_ALIGNED_ARRAY(16, uint16_t, ref16, kNumCoeffs);
484#endif
Jingning Han49b4a272014-05-29 12:50:54 -0700485
486 for (int i = 0; i < count_test_block; ++i) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700487 // Initialize a test block with input range [-mask_, mask_].
Jingning Han49b4a272014-05-29 12:50:54 -0700488 for (int j = 0; j < kNumCoeffs; ++j) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700489 if (bit_depth_ == VPX_BITS_8)
490 input_block[j] = rnd.Rand8() - rnd.Rand8();
491 else
492 input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
493 input_extreme_block[j] = rnd.Rand8() % 2 ? mask_ : -mask_;
Jingning Han49b4a272014-05-29 12:50:54 -0700494 }
495 if (i == 0)
496 for (int j = 0; j < kNumCoeffs; ++j)
Deb Mukherjee10783d42014-09-02 16:34:09 -0700497 input_extreme_block[j] = mask_;
Jingning Han49b4a272014-05-29 12:50:54 -0700498 if (i == 1)
499 for (int j = 0; j < kNumCoeffs; ++j)
Deb Mukherjee10783d42014-09-02 16:34:09 -0700500 input_extreme_block[j] = -mask_;
Jingning Han49b4a272014-05-29 12:50:54 -0700501
502 fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
503
504 // clear reconstructed pixel buffers
505 vpx_memset(dst, 0, kNumCoeffs * sizeof(uint8_t));
506 vpx_memset(ref, 0, kNumCoeffs * sizeof(uint8_t));
Deb Mukherjee10783d42014-09-02 16:34:09 -0700507#if CONFIG_VP9_HIGHBITDEPTH
508 vpx_memset(dst16, 0, kNumCoeffs * sizeof(uint16_t));
509 vpx_memset(ref16, 0, kNumCoeffs * sizeof(uint16_t));
510#endif
Jingning Han49b4a272014-05-29 12:50:54 -0700511
512 // quantization with maximum allowed step sizes
513 output_ref_block[0] = (output_ref_block[0] / dc_thred) * dc_thred;
514 for (int j = 1; j < kNumCoeffs; ++j)
515 output_ref_block[j] = (output_ref_block[j] / ac_thred) * ac_thred;
Deb Mukherjee10783d42014-09-02 16:34:09 -0700516 if (bit_depth_ == VPX_BITS_8) {
517 inv_txfm_ref(output_ref_block, ref, pitch_, tx_type_);
518 ASM_REGISTER_STATE_CHECK(RunInvTxfm(output_ref_block, dst, pitch_));
519#if CONFIG_VP9_HIGHBITDEPTH
520 } else {
521 inv_txfm_ref(output_ref_block, CONVERT_TO_BYTEPTR(ref16), pitch_,
522 tx_type_);
523 ASM_REGISTER_STATE_CHECK(RunInvTxfm(output_ref_block,
524 CONVERT_TO_BYTEPTR(dst16), pitch_));
525#endif
526 }
527 if (bit_depth_ == VPX_BITS_8) {
528 for (int j = 0; j < kNumCoeffs; ++j)
529 EXPECT_EQ(ref[j], dst[j]);
530#if CONFIG_VP9_HIGHBITDEPTH
531 } else {
532 for (int j = 0; j < kNumCoeffs; ++j)
533 EXPECT_EQ(ref16[j], dst16[j]);
534#endif
535 }
Jingning Han49b4a272014-05-29 12:50:54 -0700536 }
537 }
538
Jingning Han8f92a7e2013-09-05 12:44:03 -0700539 void RunInvAccuracyCheck() {
540 ACMRandom rnd(ACMRandom::DeterministicSeed());
541 const int count_test_block = 1000;
Jingning Han37705a32013-09-09 17:07:55 -0700542 DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700543 DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
Jingning Han37705a32013-09-09 17:07:55 -0700544 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
545 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700546#if CONFIG_VP9_HIGHBITDEPTH
547 DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
548 DECLARE_ALIGNED_ARRAY(16, uint16_t, src16, kNumCoeffs);
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100549#endif // CONFIG_VP9_HIGHBITDEPTH
Jingning Han8f92a7e2013-09-05 12:44:03 -0700550
551 for (int i = 0; i < count_test_block; ++i) {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700552 double out_r[kNumCoeffs];
553
554 // Initialize a test block with input range [-255, 255].
555 for (int j = 0; j < kNumCoeffs; ++j) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700556 if (bit_depth_ == VPX_BITS_8) {
557 src[j] = rnd.Rand8();
558 dst[j] = rnd.Rand8();
559 in[j] = src[j] - dst[j];
560#if CONFIG_VP9_HIGHBITDEPTH
561 } else {
562 src16[j] = rnd.Rand16() & mask_;
563 dst16[j] = rnd.Rand16() & mask_;
564 in[j] = src16[j] - dst16[j];
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100565#endif // CONFIG_VP9_HIGHBITDEPTH
Deb Mukherjee10783d42014-09-02 16:34:09 -0700566 }
Jingning Han8f92a7e2013-09-05 12:44:03 -0700567 }
568
569 reference_16x16_dct_2d(in, out_r);
570 for (int j = 0; j < kNumCoeffs; ++j)
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100571 coeff[j] = static_cast<tran_low_t>(round(out_r[j]));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700572
Deb Mukherjee10783d42014-09-02 16:34:09 -0700573 if (bit_depth_ == VPX_BITS_8) {
574 ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, 16));
575#if CONFIG_VP9_HIGHBITDEPTH
576 } else {
577 ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
578 16));
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100579#endif // CONFIG_VP9_HIGHBITDEPTH
Deb Mukherjee10783d42014-09-02 16:34:09 -0700580 }
Jingning Han8f92a7e2013-09-05 12:44:03 -0700581
582 for (int j = 0; j < kNumCoeffs; ++j) {
Deb Mukherjee10783d42014-09-02 16:34:09 -0700583#if CONFIG_VP9_HIGHBITDEPTH
584 const uint32_t diff =
585 bit_depth_ == VPX_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j];
586#else
Jingning Han37705a32013-09-09 17:07:55 -0700587 const uint32_t diff = dst[j] - src[j];
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100588#endif // CONFIG_VP9_HIGHBITDEPTH
Jingning Han37705a32013-09-09 17:07:55 -0700589 const uint32_t error = diff * diff;
590 EXPECT_GE(1u, error)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700591 << "Error: 16x16 IDCT has error " << error
592 << " at index " << j;
593 }
594 }
Jingning Hancf768b22013-07-09 16:16:49 -0700595 }
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100596
597 void CompareInvReference(IdctFunc ref_txfm, int thresh) {
598 ACMRandom rnd(ACMRandom::DeterministicSeed());
599 const int count_test_block = 10000;
600 const int eob = 10;
601 const int16_t *scan = vp9_default_scan_orders[TX_16X16].scan;
602 DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, kNumCoeffs);
603 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
604 DECLARE_ALIGNED_ARRAY(16, uint8_t, ref, kNumCoeffs);
605#if CONFIG_VP9_HIGHBITDEPTH
606 DECLARE_ALIGNED_ARRAY(16, uint16_t, dst16, kNumCoeffs);
607 DECLARE_ALIGNED_ARRAY(16, uint16_t, ref16, kNumCoeffs);
608#endif // CONFIG_VP9_HIGHBITDEPTH
609
610 for (int i = 0; i < count_test_block; ++i) {
611 for (int j = 0; j < kNumCoeffs; ++j) {
612 if (j < eob) {
613 // Random values less than the threshold, either positive or negative
614 coeff[scan[j]] = rnd(thresh) * (1 - 2 * (i % 2));
615 } else {
616 coeff[scan[j]] = 0;
617 }
618 if (bit_depth_ == VPX_BITS_8) {
619 dst[j] = 0;
620 ref[j] = 0;
621#if CONFIG_VP9_HIGHBITDEPTH
622 } else {
623 dst16[j] = 0;
624 ref16[j] = 0;
625#endif // CONFIG_VP9_HIGHBITDEPTH
626 }
627 }
628 if (bit_depth_ == VPX_BITS_8) {
629 ref_txfm(coeff, ref, pitch_);
630 ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
631 } else {
632#if CONFIG_VP9_HIGHBITDEPTH
633 ref_txfm(coeff, CONVERT_TO_BYTEPTR(ref16), pitch_);
634 ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, CONVERT_TO_BYTEPTR(dst16),
635 pitch_));
636#endif // CONFIG_VP9_HIGHBITDEPTH
637 }
638
639 for (int j = 0; j < kNumCoeffs; ++j) {
640#if CONFIG_VP9_HIGHBITDEPTH
641 const uint32_t diff =
642 bit_depth_ == VPX_BITS_8 ? dst[j] - ref[j] : dst16[j] - ref16[j];
643#else
644 const uint32_t diff = dst[j] - ref[j];
645#endif // CONFIG_VP9_HIGHBITDEPTH
646 const uint32_t error = diff * diff;
647 EXPECT_EQ(0u, error)
648 << "Error: 16x16 IDCT Comparison has error " << error
649 << " at index " << j;
650 }
651 }
652 }
653
Jingning Han37705a32013-09-09 17:07:55 -0700654 int pitch_;
655 int tx_type_;
Deb Mukherjee10783d42014-09-02 16:34:09 -0700656 vpx_bit_depth_t bit_depth_;
657 int mask_;
James Zern44f84842014-07-16 18:53:33 -0700658 FhtFunc fwd_txfm_ref;
659 IhtFunc inv_txfm_ref;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700660};
661
Joshua Litt51490e52013-11-18 17:07:55 -0800662class Trans16x16DCT
663 : public Trans16x16TestBase,
James Zern44f84842014-07-16 18:53:33 -0700664 public ::testing::TestWithParam<Dct16x16Param> {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700665 public:
666 virtual ~Trans16x16DCT() {}
667
668 virtual void SetUp() {
669 fwd_txfm_ = GET_PARAM(0);
670 inv_txfm_ = GET_PARAM(1);
671 tx_type_ = GET_PARAM(2);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700672 bit_depth_ = GET_PARAM(3);
Dmitry Kovalev1aa7fd52013-10-18 11:49:33 -0700673 pitch_ = 16;
Jingning Han37705a32013-09-09 17:07:55 -0700674 fwd_txfm_ref = fdct16x16_ref;
Jingning Han49b4a272014-05-29 12:50:54 -0700675 inv_txfm_ref = idct16x16_ref;
Deb Mukherjee10783d42014-09-02 16:34:09 -0700676 mask_ = (1 << bit_depth_) - 1;
677#if CONFIG_VP9_HIGHBITDEPTH
678 switch (bit_depth_) {
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100679 case VPX_BITS_10:
Deb Mukherjee10783d42014-09-02 16:34:09 -0700680 inv_txfm_ref = idct16x16_10_ref;
681 break;
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100682 case VPX_BITS_12:
Deb Mukherjee10783d42014-09-02 16:34:09 -0700683 inv_txfm_ref = idct16x16_12_ref;
684 break;
685 default:
686 inv_txfm_ref = idct16x16_ref;
687 break;
688 }
689#else
690 inv_txfm_ref = idct16x16_ref;
691#endif
Jingning Han8f92a7e2013-09-05 12:44:03 -0700692 }
693 virtual void TearDown() { libvpx_test::ClearSystemState(); }
694
695 protected:
Deb Mukherjee10783d42014-09-02 16:34:09 -0700696 void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700697 fwd_txfm_(in, out, stride);
698 }
Deb Mukherjee10783d42014-09-02 16:34:09 -0700699 void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) {
Dmitry Kovalev1aa7fd52013-10-18 11:49:33 -0700700 inv_txfm_(out, dst, stride);
Jingning Hancf768b22013-07-09 16:16:49 -0700701 }
702
James Zern44f84842014-07-16 18:53:33 -0700703 FdctFunc fwd_txfm_;
704 IdctFunc inv_txfm_;
Jingning Hancf768b22013-07-09 16:16:49 -0700705};
706
Jingning Han8f92a7e2013-09-05 12:44:03 -0700707TEST_P(Trans16x16DCT, AccuracyCheck) {
708 RunAccuracyCheck();
Jingning Hancf768b22013-07-09 16:16:49 -0700709}
710
Jingning Han37705a32013-09-09 17:07:55 -0700711TEST_P(Trans16x16DCT, CoeffCheck) {
712 RunCoeffCheck();
713}
714
715TEST_P(Trans16x16DCT, MemCheck) {
716 RunMemCheck();
Jingning Hancf768b22013-07-09 16:16:49 -0700717}
718
Jingning Han49b4a272014-05-29 12:50:54 -0700719TEST_P(Trans16x16DCT, QuantCheck) {
720 // Use maximally allowed quantization step sizes for DC and AC
721 // coefficients respectively.
722 RunQuantCheck(1336, 1828);
723}
724
Jingning Han8f92a7e2013-09-05 12:44:03 -0700725TEST_P(Trans16x16DCT, InvAccuracyCheck) {
726 RunInvAccuracyCheck();
Daniel Kangfed8a182012-08-02 17:03:14 -0700727}
Scott LaVarnwaya272ff22013-05-15 13:16:02 -0400728
Joshua Litt51490e52013-11-18 17:07:55 -0800729class Trans16x16HT
730 : public Trans16x16TestBase,
James Zern44f84842014-07-16 18:53:33 -0700731 public ::testing::TestWithParam<Ht16x16Param> {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700732 public:
733 virtual ~Trans16x16HT() {}
734
735 virtual void SetUp() {
736 fwd_txfm_ = GET_PARAM(0);
737 inv_txfm_ = GET_PARAM(1);
738 tx_type_ = GET_PARAM(2);
Deb Mukherjee10783d42014-09-02 16:34:09 -0700739 bit_depth_ = GET_PARAM(3);
Jingning Han37705a32013-09-09 17:07:55 -0700740 pitch_ = 16;
741 fwd_txfm_ref = fht16x16_ref;
Jingning Han49b4a272014-05-29 12:50:54 -0700742 inv_txfm_ref = iht16x16_ref;
Deb Mukherjee10783d42014-09-02 16:34:09 -0700743 mask_ = (1 << bit_depth_) - 1;
744#if CONFIG_VP9_HIGHBITDEPTH
745 switch (bit_depth_) {
746 case VPX_BITS_10:
747 inv_txfm_ref = iht16x16_10;
748 break;
749 case VPX_BITS_12:
750 inv_txfm_ref = iht16x16_12;
751 break;
752 default:
753 inv_txfm_ref = iht16x16_ref;
754 break;
755 }
756#else
757 inv_txfm_ref = iht16x16_ref;
758#endif
Jingning Han8f92a7e2013-09-05 12:44:03 -0700759 }
760 virtual void TearDown() { libvpx_test::ClearSystemState(); }
761
762 protected:
Deb Mukherjee10783d42014-09-02 16:34:09 -0700763 void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) {
Jingning Han37705a32013-09-09 17:07:55 -0700764 fwd_txfm_(in, out, stride, tx_type_);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700765 }
Deb Mukherjee10783d42014-09-02 16:34:09 -0700766 void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) {
Jingning Han37705a32013-09-09 17:07:55 -0700767 inv_txfm_(out, dst, stride, tx_type_);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700768 }
769
James Zern44f84842014-07-16 18:53:33 -0700770 FhtFunc fwd_txfm_;
771 IhtFunc inv_txfm_;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700772};
773
774TEST_P(Trans16x16HT, AccuracyCheck) {
775 RunAccuracyCheck();
776}
777
Jingning Han37705a32013-09-09 17:07:55 -0700778TEST_P(Trans16x16HT, CoeffCheck) {
779 RunCoeffCheck();
780}
781
782TEST_P(Trans16x16HT, MemCheck) {
783 RunMemCheck();
Jingning Han8f92a7e2013-09-05 12:44:03 -0700784}
785
Jingning Han49b4a272014-05-29 12:50:54 -0700786TEST_P(Trans16x16HT, QuantCheck) {
787 // The encoder skips any non-DC intra prediction modes,
788 // when the quantization step size goes beyond 988.
Jingning Han12344f22014-10-06 10:18:17 -0700789 RunQuantCheck(429, 729);
Jingning Han49b4a272014-05-29 12:50:54 -0700790}
791
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100792class InvTrans16x16DCT
793 : public Trans16x16TestBase,
794 public ::testing::TestWithParam<Idct16x16Param> {
795 public:
796 virtual ~InvTrans16x16DCT() {}
797
798 virtual void SetUp() {
799 ref_txfm_ = GET_PARAM(0);
800 inv_txfm_ = GET_PARAM(1);
801 thresh_ = GET_PARAM(2);
802 bit_depth_ = GET_PARAM(3);
803 pitch_ = 16;
804 mask_ = (1 << bit_depth_) - 1;
805}
806 virtual void TearDown() { libvpx_test::ClearSystemState(); }
807
808 protected:
809 void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) {}
810 void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) {
811 inv_txfm_(out, dst, stride);
812 }
813
814 IdctFunc ref_txfm_;
815 IdctFunc inv_txfm_;
816 int thresh_;
817};
818
819TEST_P(InvTrans16x16DCT, CompareReference) {
820 CompareInvReference(ref_txfm_, thresh_);
821}
822
Jingning Han8f92a7e2013-09-05 12:44:03 -0700823using std::tr1::make_tuple;
824
Deb Mukherjee10783d42014-09-02 16:34:09 -0700825#if CONFIG_VP9_HIGHBITDEPTH
Jingning Han8f92a7e2013-09-05 12:44:03 -0700826INSTANTIATE_TEST_CASE_P(
827 C, Trans16x16DCT,
828 ::testing::Values(
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700829 make_tuple(&vp9_highbd_fdct16x16_c, &idct16x16_10, 0, VPX_BITS_10),
830 make_tuple(&vp9_highbd_fdct16x16_c, &idct16x16_12, 0, VPX_BITS_12),
Deb Mukherjee10783d42014-09-02 16:34:09 -0700831 make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_c, 0, VPX_BITS_8)));
832#else
833INSTANTIATE_TEST_CASE_P(
834 C, Trans16x16DCT,
835 ::testing::Values(
836 make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_c, 0, VPX_BITS_8)));
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100837#endif // CONFIG_VP9_HIGHBITDEPTH
Deb Mukherjee10783d42014-09-02 16:34:09 -0700838
839#if CONFIG_VP9_HIGHBITDEPTH
Jingning Han8f92a7e2013-09-05 12:44:03 -0700840INSTANTIATE_TEST_CASE_P(
841 C, Trans16x16HT,
842 ::testing::Values(
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700843 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_10, 0, VPX_BITS_10),
844 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_10, 1, VPX_BITS_10),
845 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_10, 2, VPX_BITS_10),
846 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_10, 3, VPX_BITS_10),
847 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_12, 0, VPX_BITS_12),
848 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_12, 1, VPX_BITS_12),
849 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_12, 2, VPX_BITS_12),
850 make_tuple(&vp9_highbd_fht16x16_c, &iht16x16_12, 3, VPX_BITS_12),
Deb Mukherjee10783d42014-09-02 16:34:09 -0700851 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 0, VPX_BITS_8),
852 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8),
853 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8),
854 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 3, VPX_BITS_8)));
855#else
856INSTANTIATE_TEST_CASE_P(
857 C, Trans16x16HT,
858 ::testing::Values(
859 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 0, VPX_BITS_8),
860 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8),
861 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8),
862 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 3, VPX_BITS_8)));
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100863#endif // CONFIG_VP9_HIGHBITDEPTH
Jingning Han8f92a7e2013-09-05 12:44:03 -0700864
Deb Mukherjeed50716f2014-10-02 15:43:27 -0700865#if HAVE_NEON_ASM && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
James Zernadbb8812014-02-25 23:11:49 -0800866INSTANTIATE_TEST_CASE_P(
867 NEON, Trans16x16DCT,
868 ::testing::Values(
869 make_tuple(&vp9_fdct16x16_c,
Deb Mukherjee10783d42014-09-02 16:34:09 -0700870 &vp9_idct16x16_256_add_neon, 0, VPX_BITS_8)));
James Zernadbb8812014-02-25 23:11:49 -0800871#endif
872
Deb Mukherjeed50716f2014-10-02 15:43:27 -0700873#if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
Jingning Han8f92a7e2013-09-05 12:44:03 -0700874INSTANTIATE_TEST_CASE_P(
875 SSE2, Trans16x16DCT,
876 ::testing::Values(
Dmitry Kovalev02feb632013-10-23 10:57:12 -0700877 make_tuple(&vp9_fdct16x16_sse2,
Deb Mukherjee10783d42014-09-02 16:34:09 -0700878 &vp9_idct16x16_256_add_sse2, 0, VPX_BITS_8)));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700879INSTANTIATE_TEST_CASE_P(
880 SSE2, Trans16x16HT,
881 ::testing::Values(
Deb Mukherjee10783d42014-09-02 16:34:09 -0700882 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 0,
883 VPX_BITS_8),
884 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 1,
885 VPX_BITS_8),
886 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 2,
887 VPX_BITS_8),
888 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 3,
889 VPX_BITS_8)));
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100890#endif // HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
891
892#if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
893INSTANTIATE_TEST_CASE_P(
894 SSE2, Trans16x16DCT,
895 ::testing::Values(
896 make_tuple(&vp9_highbd_fdct16x16_sse2,
897 &idct16x16_10, 0, VPX_BITS_10),
898 make_tuple(&vp9_highbd_fdct16x16_c,
899 &idct16x16_256_add_10_sse2, 0, VPX_BITS_10),
900 make_tuple(&vp9_highbd_fdct16x16_sse2,
901 &idct16x16_12, 0, VPX_BITS_12),
902 make_tuple(&vp9_highbd_fdct16x16_c,
903 &idct16x16_256_add_12_sse2, 0, VPX_BITS_12),
904 make_tuple(&vp9_fdct16x16_sse2,
905 &vp9_idct16x16_256_add_c, 0, VPX_BITS_8)));
906INSTANTIATE_TEST_CASE_P(
907 SSE2, Trans16x16HT,
908 ::testing::Values(
909 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 0, VPX_BITS_10),
910 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 1, VPX_BITS_10),
911 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 2, VPX_BITS_10),
912 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_10, 3, VPX_BITS_10),
913 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 0, VPX_BITS_12),
914 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 1, VPX_BITS_12),
915 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 2, VPX_BITS_12),
916 make_tuple(&vp9_highbd_fht16x16_sse2, &iht16x16_12, 3, VPX_BITS_12),
917 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 0, VPX_BITS_8),
918 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8),
919 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8),
920 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_c, 3,
921 VPX_BITS_8)));
922// Optimizations take effect at a threshold of 3155, so we use a value close to
923// that to test both branches.
924INSTANTIATE_TEST_CASE_P(
925 SSE2, InvTrans16x16DCT,
926 ::testing::Values(
927 make_tuple(&idct16x16_10_add_10_c,
928 &idct16x16_10_add_10_sse2, 3167, VPX_BITS_10),
929 make_tuple(&idct16x16_10,
930 &idct16x16_256_add_10_sse2, 3167, VPX_BITS_10),
931 make_tuple(&idct16x16_10_add_12_c,
932 &idct16x16_10_add_12_sse2, 3167, VPX_BITS_12),
933 make_tuple(&idct16x16_12,
934 &idct16x16_256_add_12_sse2, 3167, VPX_BITS_12)));
935#endif // HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
Jingning Hane4a758b2014-05-22 11:31:43 -0700936
Deb Mukherjeed50716f2014-10-02 15:43:27 -0700937#if HAVE_SSSE3 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
Jingning Hane4a758b2014-05-22 11:31:43 -0700938INSTANTIATE_TEST_CASE_P(
939 SSSE3, Trans16x16DCT,
940 ::testing::Values(
Deb Mukherjee10783d42014-09-02 16:34:09 -0700941 make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_ssse3, 0,
942 VPX_BITS_8)));
Peter de Rivaz7e40a552014-10-24 08:48:02 +0100943#endif // HAVE_SSSE3 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
Daniel Kangfed8a182012-08-02 17:03:14 -0700944} // namespace