2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * 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.
13 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
15 #include "config/aom_config.h"
16 #include "config/av1_rtcd.h"
18 #include "test/acm_random.h"
19 #include "test/clear_system_state.h"
20 #include "test/register_state_check.h"
21 #include "av1/common/scan.h"
25 typedef void (*QuantizeFpFunc
)(
26 const tran_low_t
*coeff_ptr
, intptr_t count
, const int16_t *zbin_ptr
,
27 const int16_t *round_ptr
, const int16_t *quant_ptr
,
28 const int16_t *quant_shift_ptr
, tran_low_t
*qcoeff_ptr
,
29 tran_low_t
*dqcoeff_ptr
, const int16_t *dequant_ptr
, uint16_t *eob_ptr
,
30 const int16_t *scan
, const int16_t *iscan
, int log_scale
);
32 struct QuantizeFuncParams
{
33 QuantizeFuncParams(QuantizeFpFunc qF
= NULL
, QuantizeFpFunc qRefF
= NULL
,
35 : qFunc(qF
), qFuncRef(qRefF
), coeffCount(count
) {}
37 QuantizeFpFunc qFuncRef
;
41 using libaom_test::ACMRandom
;
43 const int numTests
= 1000;
44 const int maxSize
= 1024;
45 const int roundFactorRange
= 127;
46 const int dequantRange
= 32768;
47 const int coeffRange
= (1 << 20) - 1;
49 class AV1QuantizeTest
: public ::testing::TestWithParam
<QuantizeFuncParams
> {
51 void RunQuantizeTest() {
52 ACMRandom
rnd(ACMRandom::DeterministicSeed());
53 DECLARE_ALIGNED(16, tran_low_t
, coeff_ptr
[maxSize
]);
54 DECLARE_ALIGNED(16, int16_t, zbin_ptr
[8]);
55 DECLARE_ALIGNED(16, int16_t, round_ptr
[8]);
56 DECLARE_ALIGNED(16, int16_t, quant_ptr
[8]);
57 DECLARE_ALIGNED(16, int16_t, quant_shift_ptr
[8]);
58 DECLARE_ALIGNED(16, tran_low_t
, qcoeff_ptr
[maxSize
]);
59 DECLARE_ALIGNED(16, tran_low_t
, dqcoeff_ptr
[maxSize
]);
60 DECLARE_ALIGNED(16, tran_low_t
, ref_qcoeff_ptr
[maxSize
]);
61 DECLARE_ALIGNED(16, tran_low_t
, ref_dqcoeff_ptr
[maxSize
]);
62 DECLARE_ALIGNED(16, int16_t, dequant_ptr
[8]);
65 int err_count_total
= 0;
66 int first_failure
= -1;
67 int count
= params_
.coeffCount
;
68 const TX_SIZE txSize
= getTxSize(count
);
69 int log_scale
= (txSize
== TX_32X32
);
70 QuantizeFpFunc quanFunc
= params_
.qFunc
;
71 QuantizeFpFunc quanFuncRef
= params_
.qFuncRef
;
73 const SCAN_ORDER scanOrder
= av1_default_scan_orders
[txSize
];
74 for (int i
= 0; i
< numTests
; i
++) {
77 for (int j
= 0; j
< count
; j
++) {
78 coeff_ptr
[j
] = rnd(coeffRange
);
81 for (int j
= 0; j
< 2; j
++) {
82 zbin_ptr
[j
] = rnd
.Rand16();
83 quant_shift_ptr
[j
] = rnd
.Rand16();
85 dequant_ptr
[j
] = abs(rnd(dequantRange
));
86 quant_ptr
[j
] = (1 << 16) / dequant_ptr
[j
];
87 round_ptr
[j
] = (abs(rnd(roundFactorRange
)) * dequant_ptr
[j
]) >> 7;
89 for (int j
= 2; j
< 8; ++j
) {
90 zbin_ptr
[j
] = zbin_ptr
[1];
91 quant_shift_ptr
[j
] = quant_shift_ptr
[1];
92 dequant_ptr
[j
] = dequant_ptr
[1];
93 quant_ptr
[j
] = quant_ptr
[1];
94 round_ptr
[j
] = round_ptr
[1];
96 quanFuncRef(coeff_ptr
, count
, zbin_ptr
, round_ptr
, quant_ptr
,
97 quant_shift_ptr
, ref_qcoeff_ptr
, ref_dqcoeff_ptr
, dequant_ptr
,
98 &ref_eob
, scanOrder
.scan
, scanOrder
.iscan
, log_scale
);
100 ASM_REGISTER_STATE_CHECK(
101 quanFunc(coeff_ptr
, count
, zbin_ptr
, round_ptr
, quant_ptr
,
102 quant_shift_ptr
, qcoeff_ptr
, dqcoeff_ptr
, dequant_ptr
, &eob
,
103 scanOrder
.scan
, scanOrder
.iscan
, log_scale
));
105 for (int j
= 0; j
< count
; ++j
) {
106 err_count
+= (ref_qcoeff_ptr
[j
] != qcoeff_ptr
[j
]) |
107 (ref_dqcoeff_ptr
[j
] != dqcoeff_ptr
[j
]);
108 ASSERT_EQ(ref_qcoeff_ptr
[j
], qcoeff_ptr
[j
])
109 << "qcoeff error: i = " << i
<< " j = " << j
<< "\n";
110 EXPECT_EQ(ref_dqcoeff_ptr
[j
], dqcoeff_ptr
[j
])
111 << "dqcoeff error: i = " << i
<< " j = " << j
<< "\n";
113 EXPECT_EQ(ref_eob
, eob
) << "eob error: "
114 << "i = " << i
<< "\n";
115 err_count
+= (ref_eob
!= eob
);
116 if (err_count
&& !err_count_total
) {
119 err_count_total
+= err_count
;
121 EXPECT_EQ(0, err_count_total
)
122 << "Error: Quantization Test, C output doesn't match SSE2 output. "
123 << "First failed at test case " << first_failure
;
127 ACMRandom
rnd(ACMRandom::DeterministicSeed());
128 DECLARE_ALIGNED(16, tran_low_t
, coeff_ptr
[maxSize
]);
129 DECLARE_ALIGNED(16, int16_t, zbin_ptr
[8]);
130 DECLARE_ALIGNED(16, int16_t, round_ptr
[8]);
131 DECLARE_ALIGNED(16, int16_t, quant_ptr
[8]);
132 DECLARE_ALIGNED(16, int16_t, quant_shift_ptr
[8]);
133 DECLARE_ALIGNED(16, tran_low_t
, qcoeff_ptr
[maxSize
]);
134 DECLARE_ALIGNED(16, tran_low_t
, dqcoeff_ptr
[maxSize
]);
135 DECLARE_ALIGNED(16, tran_low_t
, ref_qcoeff_ptr
[maxSize
]);
136 DECLARE_ALIGNED(16, tran_low_t
, ref_dqcoeff_ptr
[maxSize
]);
137 DECLARE_ALIGNED(16, int16_t, dequant_ptr
[8]);
140 int count
= params_
.coeffCount
;
141 const TX_SIZE txSize
= getTxSize(count
);
142 int log_scale
= (txSize
== TX_32X32
);
143 QuantizeFpFunc quanFunc
= params_
.qFunc
;
144 QuantizeFpFunc quanFuncRef
= params_
.qFuncRef
;
145 const SCAN_ORDER scanOrder
= av1_default_scan_orders
[txSize
];
147 for (int i
= 0; i
< numTests
; i
++) {
149 for (int j
= 0; j
< count
; j
++) {
153 coeff_ptr
[rnd(count
)] = rnd(coeffRange
);
154 coeff_ptr
[rnd(count
)] = rnd(coeffRange
);
155 coeff_ptr
[rnd(count
)] = rnd(coeffRange
);
157 for (int j
= 0; j
< 2; j
++) {
158 zbin_ptr
[j
] = rnd
.Rand16();
159 quant_shift_ptr
[j
] = rnd
.Rand16();
161 dequant_ptr
[j
] = abs(rnd(dequantRange
));
162 quant_ptr
[j
] = (1 << 16) / dequant_ptr
[j
];
163 round_ptr
[j
] = (abs(rnd(roundFactorRange
)) * dequant_ptr
[j
]) >> 7;
165 for (int j
= 2; j
< 8; ++j
) {
166 zbin_ptr
[j
] = zbin_ptr
[1];
167 quant_shift_ptr
[j
] = quant_shift_ptr
[1];
168 dequant_ptr
[j
] = dequant_ptr
[1];
169 quant_ptr
[j
] = quant_ptr
[1];
170 round_ptr
[j
] = round_ptr
[1];
173 quanFuncRef(coeff_ptr
, count
, zbin_ptr
, round_ptr
, quant_ptr
,
174 quant_shift_ptr
, ref_qcoeff_ptr
, ref_dqcoeff_ptr
, dequant_ptr
,
175 &ref_eob
, scanOrder
.scan
, scanOrder
.iscan
, log_scale
);
177 ASM_REGISTER_STATE_CHECK(
178 quanFunc(coeff_ptr
, count
, zbin_ptr
, round_ptr
, quant_ptr
,
179 quant_shift_ptr
, qcoeff_ptr
, dqcoeff_ptr
, dequant_ptr
, &eob
,
180 scanOrder
.scan
, scanOrder
.iscan
, log_scale
));
181 EXPECT_EQ(ref_eob
, eob
) << "eob error: "
182 << "i = " << i
<< "\n";
186 virtual void SetUp() { params_
= GetParam(); }
188 virtual void TearDown() { libaom_test::ClearSystemState(); }
190 virtual ~AV1QuantizeTest() {}
193 TX_SIZE
getTxSize(int count
) {
195 case 16: return TX_4X4
;
196 case 64: return TX_8X8
;
197 case 256: return TX_16X16
;
198 case 1024: return TX_32X32
;
199 default: return TX_4X4
;
203 QuantizeFuncParams params_
;
206 TEST_P(AV1QuantizeTest
, BitExactCheck
) { RunQuantizeTest(); }
207 TEST_P(AV1QuantizeTest
, EobVerify
) { RunEobTest(); }
210 const QuantizeFuncParams qfps
[4] = {
211 QuantizeFuncParams(&av1_highbd_quantize_fp_sse4_1
, &av1_highbd_quantize_fp_c
,
213 QuantizeFuncParams(&av1_highbd_quantize_fp_sse4_1
, &av1_highbd_quantize_fp_c
,
215 QuantizeFuncParams(&av1_highbd_quantize_fp_sse4_1
, &av1_highbd_quantize_fp_c
,
217 QuantizeFuncParams(&av1_highbd_quantize_fp_sse4_1
, &av1_highbd_quantize_fp_c
,
221 INSTANTIATE_TEST_CASE_P(SSE4_1
, AV1QuantizeTest
, ::testing::ValuesIn(qfps
));
222 #endif // HAVE_SSE4_1
225 const QuantizeFuncParams qfps_avx2
[4] = {
226 QuantizeFuncParams(&av1_highbd_quantize_fp_avx2
, &av1_highbd_quantize_fp_c
,
228 QuantizeFuncParams(&av1_highbd_quantize_fp_avx2
, &av1_highbd_quantize_fp_c
,
230 QuantizeFuncParams(&av1_highbd_quantize_fp_avx2
, &av1_highbd_quantize_fp_c
,
232 QuantizeFuncParams(&av1_highbd_quantize_fp_avx2
, &av1_highbd_quantize_fp_c
,
236 INSTANTIATE_TEST_CASE_P(AVX2
, AV1QuantizeTest
, ::testing::ValuesIn(qfps_avx2
));