Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, Alliance for Open Media. All rights reserved |
| 3 | * |
| 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. |
| 10 | */ |
| 11 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 12 | |
| 13 | #include "aom_ports/aom_timer.h" |
| 14 | #include "./av1_rtcd.h" |
| 15 | #include "test/util.h" |
| 16 | #include "test/acm_random.h" |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 17 | #include "av1/common/cfl.h" |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 18 | |
| 19 | using std::tr1::make_tuple; |
| 20 | |
| 21 | using libaom_test::ACMRandom; |
| 22 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 23 | #define NUM_ITERATIONS (100) |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 24 | #define NUM_ITERATIONS_SPEED (INT16_MAX) |
| 25 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 26 | #define ALL_CFL_SIZES(function) \ |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 27 | make_tuple(4, 4, &function), make_tuple(8, 4, &function), \ |
| 28 | make_tuple(4, 8, &function), make_tuple(8, 8, &function), \ |
| 29 | make_tuple(16, 8, &function), make_tuple(8, 16, &function), \ |
| 30 | make_tuple(16, 16, &function), make_tuple(32, 16, &function), \ |
| 31 | make_tuple(16, 32, &function), make_tuple(32, 32, &function) |
| 32 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 33 | #define CHROMA_420_CFL_SIZES(function) \ |
| 34 | make_tuple(4, 4, &function), make_tuple(8, 4, &function), \ |
| 35 | make_tuple(4, 8, &function), make_tuple(8, 8, &function), \ |
| 36 | make_tuple(16, 8, &function), make_tuple(8, 16, &function), \ |
| 37 | make_tuple(16, 16, &function) |
| 38 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 39 | #define ALL_CFL_TX_SIZES(function) \ |
| 40 | make_tuple(TX_4X4, &function), make_tuple(TX_4X8, &function), \ |
| 41 | make_tuple(TX_4X16, &function), make_tuple(TX_8X4, &function), \ |
| 42 | make_tuple(TX_8X8, &function), make_tuple(TX_8X16, &function), \ |
| 43 | make_tuple(TX_8X32, &function), make_tuple(TX_16X4, &function), \ |
| 44 | make_tuple(TX_16X8, &function), make_tuple(TX_16X16, &function), \ |
| 45 | make_tuple(TX_16X32, &function), make_tuple(TX_32X8, &function), \ |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 46 | make_tuple(TX_32X16, &function), make_tuple(TX_32X32, &function) |
| 47 | |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 48 | namespace { |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 49 | typedef cfl_subsample_lbd_fn (*get_subsample_fn)(int width, int height); |
| 50 | |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 51 | typedef cfl_predict_lbd_fn (*get_predict_fn)(TX_SIZE tx_size); |
| 52 | |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 53 | typedef cfl_predict_hbd_fn (*get_predict_fn_hbd)(TX_SIZE tx_size); |
| 54 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 55 | typedef cfl_subtract_average_fn (*sub_avg_fn)(TX_SIZE tx_size); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 56 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 57 | typedef std::tr1::tuple<int, int, get_subsample_fn> subsample_param; |
| 58 | |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 59 | typedef std::tr1::tuple<TX_SIZE, get_predict_fn> predict_param; |
| 60 | |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 61 | typedef std::tr1::tuple<TX_SIZE, get_predict_fn_hbd> predict_param_hbd; |
| 62 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 63 | typedef std::tr1::tuple<TX_SIZE, sub_avg_fn> sub_avg_param; |
| 64 | |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 65 | static void assertFaster(int ref_elapsed_time, int elapsed_time) { |
| 66 | EXPECT_GT(ref_elapsed_time, elapsed_time) |
| 67 | << "Error: CFLSubtractSpeedTest, SIMD slower than C." << std::endl |
| 68 | << "C time: " << ref_elapsed_time << " us" << std::endl |
| 69 | << "SIMD time: " << elapsed_time << " us" << std::endl; |
| 70 | } |
| 71 | |
| 72 | static void printSpeed(int ref_elapsed_time, int elapsed_time, int width, |
| 73 | int height) { |
| 74 | std::cout.precision(2); |
| 75 | std::cout << "[ ] " << width << "x" << height |
| 76 | << ": C time = " << ref_elapsed_time |
| 77 | << " us, SIMD time = " << elapsed_time << " us" |
| 78 | << " (~" << ref_elapsed_time / (double)elapsed_time << "x) " |
| 79 | << std::endl; |
| 80 | } |
| 81 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 82 | class CFLSubAvgTest : public ::testing::TestWithParam<sub_avg_param> { |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 83 | public: |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 84 | virtual ~CFLSubAvgTest() {} |
| 85 | virtual void SetUp() { sub_avg = GET_PARAM(1); } |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 86 | |
| 87 | protected: |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 88 | int Width() const { return tx_size_wide[GET_PARAM(0)]; } |
| 89 | int Height() const { return tx_size_high[GET_PARAM(0)]; } |
| 90 | TX_SIZE Tx_size() const { return GET_PARAM(0); } |
| 91 | sub_avg_fn sub_avg; |
| 92 | int16_t data[CFL_BUF_SQUARE]; |
| 93 | int16_t data_ref[CFL_BUF_SQUARE]; |
| 94 | void init() { |
| 95 | const int width = Width(); |
| 96 | const int height = Height(); |
| 97 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 98 | for (int j = 0; j < height; j++) { |
| 99 | for (int i = 0; i < width; i++) { |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 100 | const int16_t d = rnd.Rand15Signed(); |
| 101 | data[j * CFL_BUF_LINE + i] = d; |
| 102 | data_ref[j * CFL_BUF_LINE + i] = d; |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |
| 106 | }; |
| 107 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 108 | class CFLSubsampleTest : public ::testing::TestWithParam<subsample_param> { |
| 109 | public: |
| 110 | virtual ~CFLSubsampleTest() {} |
| 111 | virtual void SetUp() { subsample = GET_PARAM(2); } |
| 112 | |
| 113 | protected: |
| 114 | int Width() const { return GET_PARAM(0); } |
| 115 | int Height() const { return GET_PARAM(1); } |
| 116 | get_subsample_fn subsample; |
| 117 | uint8_t luma_pels[CFL_BUF_SQUARE]; |
| 118 | uint8_t luma_pels_ref[CFL_BUF_SQUARE]; |
| 119 | int16_t sub_luma_pels[CFL_BUF_SQUARE]; |
| 120 | int16_t sub_luma_pels_ref[CFL_BUF_SQUARE]; |
| 121 | void init(int width, int height) { |
| 122 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 123 | for (int j = 0; j < height * 2; j++) { |
| 124 | for (int i = 0; i < width * 2; i++) { |
| 125 | const int val = rnd.Rand8(); |
| 126 | luma_pels[j * CFL_BUF_LINE + i] = val; |
| 127 | luma_pels_ref[j * CFL_BUF_LINE + i] = val; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | }; |
| 132 | |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 133 | class CFLPredictTest : public ::testing::TestWithParam<predict_param> { |
| 134 | public: |
| 135 | virtual ~CFLPredictTest() {} |
David Michael Barr | c653277 | 2018-01-17 09:28:19 +0900 | [diff] [blame] | 136 | virtual void SetUp() { |
| 137 | predict = GET_PARAM(1); |
| 138 | chroma_pels_ref = reinterpret_cast<uint8_t *>( |
| 139 | aom_memalign(32, sizeof(uint8_t) * CFL_BUF_SQUARE)); |
| 140 | sub_luma_pels_ref = reinterpret_cast<int16_t *>( |
| 141 | aom_memalign(32, sizeof(int16_t) * CFL_BUF_SQUARE)); |
| 142 | chroma_pels = reinterpret_cast<uint8_t *>( |
| 143 | aom_memalign(32, sizeof(uint8_t) * CFL_BUF_SQUARE)); |
| 144 | sub_luma_pels = reinterpret_cast<int16_t *>( |
| 145 | aom_memalign(32, sizeof(int16_t) * CFL_BUF_SQUARE)); |
| 146 | } |
| 147 | |
| 148 | virtual void TearDown() { |
| 149 | aom_free(chroma_pels_ref); |
| 150 | aom_free(sub_luma_pels_ref); |
| 151 | aom_free(chroma_pels); |
| 152 | aom_free(sub_luma_pels); |
| 153 | } |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 154 | |
| 155 | protected: |
| 156 | int Width() const { return tx_size_wide[GET_PARAM(0)]; } |
| 157 | int Height() const { return tx_size_high[GET_PARAM(0)]; } |
| 158 | TX_SIZE Tx_size() const { return GET_PARAM(0); } |
David Michael Barr | c653277 | 2018-01-17 09:28:19 +0900 | [diff] [blame] | 159 | uint8_t *chroma_pels_ref; |
| 160 | int16_t *sub_luma_pels_ref; |
| 161 | uint8_t *chroma_pels; |
| 162 | int16_t *sub_luma_pels; |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 163 | get_predict_fn predict; |
| 164 | int alpha_q3; |
| 165 | uint8_t dc; |
| 166 | void init(int width, int height) { |
| 167 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 168 | alpha_q3 = rnd(33) - 16; |
| 169 | dc = rnd.Rand8(); |
| 170 | for (int j = 0; j < height; j++) { |
| 171 | for (int i = 0; i < width; i++) { |
| 172 | chroma_pels[j * CFL_BUF_LINE + i] = dc; |
| 173 | chroma_pels_ref[j * CFL_BUF_LINE + i] = dc; |
| 174 | sub_luma_pels_ref[j * CFL_BUF_LINE + i] = |
| 175 | sub_luma_pels[j * CFL_BUF_LINE + i] = rnd.Rand8() - 128; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | }; |
| 180 | |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 181 | class CFLPredictHBDTest : public ::testing::TestWithParam<predict_param_hbd> { |
| 182 | public: |
| 183 | virtual ~CFLPredictHBDTest() {} |
David Michael Barr | c653277 | 2018-01-17 09:28:19 +0900 | [diff] [blame] | 184 | virtual void SetUp() { |
| 185 | predict = GET_PARAM(1); |
| 186 | chroma_pels_ref = reinterpret_cast<uint16_t *>( |
| 187 | aom_memalign(32, sizeof(uint16_t) * CFL_BUF_SQUARE)); |
| 188 | sub_luma_pels_ref = reinterpret_cast<int16_t *>( |
| 189 | aom_memalign(32, sizeof(int16_t) * CFL_BUF_SQUARE)); |
| 190 | chroma_pels = reinterpret_cast<uint16_t *>( |
| 191 | aom_memalign(32, sizeof(uint16_t) * CFL_BUF_SQUARE)); |
| 192 | sub_luma_pels = reinterpret_cast<int16_t *>( |
| 193 | aom_memalign(32, sizeof(int16_t) * CFL_BUF_SQUARE)); |
| 194 | } |
| 195 | |
| 196 | virtual void TearDown() { |
| 197 | aom_free(chroma_pels_ref); |
| 198 | aom_free(sub_luma_pels_ref); |
| 199 | aom_free(chroma_pels); |
| 200 | aom_free(sub_luma_pels); |
| 201 | } |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 202 | |
| 203 | protected: |
| 204 | int Width() const { return tx_size_wide[GET_PARAM(0)]; } |
| 205 | int Height() const { return tx_size_high[GET_PARAM(0)]; } |
| 206 | TX_SIZE Tx_size() const { return GET_PARAM(0); } |
David Michael Barr | c653277 | 2018-01-17 09:28:19 +0900 | [diff] [blame] | 207 | uint16_t *chroma_pels_ref; |
| 208 | int16_t *sub_luma_pels_ref; |
| 209 | uint16_t *chroma_pels; |
| 210 | int16_t *sub_luma_pels; |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 211 | get_predict_fn_hbd predict; |
| 212 | int bd; |
| 213 | int alpha_q3; |
| 214 | uint8_t dc; |
| 215 | void init(int width, int height) { |
| 216 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 217 | bd = 12; |
| 218 | alpha_q3 = rnd(33) - 16; |
| 219 | dc = rnd(1 << bd); |
| 220 | for (int j = 0; j < height; j++) { |
| 221 | for (int i = 0; i < width; i++) { |
| 222 | chroma_pels[j * CFL_BUF_LINE + i] = dc; |
| 223 | chroma_pels_ref[j * CFL_BUF_LINE + i] = dc; |
| 224 | sub_luma_pels_ref[j * CFL_BUF_LINE + i] = |
| 225 | sub_luma_pels[j * CFL_BUF_LINE + i] = |
| 226 | rnd(1 << bd) - (1 << (bd - 1)); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | }; |
| 231 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 232 | TEST_P(CFLSubAvgTest, SubAvgTest) { |
| 233 | const TX_SIZE tx_size = Tx_size(); |
| 234 | const int width = tx_size_wide[tx_size]; |
| 235 | const int height = tx_size_high[tx_size]; |
| 236 | const cfl_subtract_average_fn ref_sub = get_subtract_average_fn_c(tx_size); |
| 237 | const cfl_subtract_average_fn sub = sub_avg(tx_size); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 238 | for (int it = 0; it < NUM_ITERATIONS; it++) { |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 239 | init(); |
| 240 | sub(data); |
| 241 | ref_sub(data_ref); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 242 | for (int j = 0; j < height; j++) { |
| 243 | for (int i = 0; i < width; i++) { |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 244 | ASSERT_EQ(data_ref[j * CFL_BUF_LINE + i], data[j * CFL_BUF_LINE + i]); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 250 | TEST_P(CFLSubAvgTest, DISABLED_SubAvgSpeedTest) { |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 251 | const int width = Width(); |
| 252 | const int height = Height(); |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 253 | const TX_SIZE tx_size = Tx_size(); |
| 254 | |
| 255 | const cfl_subtract_average_fn ref_sub = get_subtract_average_fn_c(tx_size); |
| 256 | const cfl_subtract_average_fn sub = sub_avg(tx_size); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 257 | |
| 258 | aom_usec_timer ref_timer; |
| 259 | aom_usec_timer timer; |
| 260 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 261 | init(); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 262 | aom_usec_timer_start(&ref_timer); |
| 263 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 264 | ref_sub(data_ref); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 265 | } |
| 266 | aom_usec_timer_mark(&ref_timer); |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 267 | int ref_elapsed_time = (int)aom_usec_timer_elapsed(&ref_timer); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 268 | |
| 269 | aom_usec_timer_start(&timer); |
| 270 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 271 | sub(data); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 272 | } |
| 273 | aom_usec_timer_mark(&timer); |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 274 | int elapsed_time = (int)aom_usec_timer_elapsed(&timer); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 275 | |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 276 | printSpeed(ref_elapsed_time, elapsed_time, width, height); |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 277 | assertFaster(ref_elapsed_time, elapsed_time); |
| 278 | } |
| 279 | |
| 280 | TEST_P(CFLSubsampleTest, SubsampleTest) { |
| 281 | const int width = Width(); |
| 282 | const int height = Height(); |
| 283 | |
| 284 | for (int it = 0; it < NUM_ITERATIONS; it++) { |
| 285 | init(width, height); |
| 286 | subsample(1, 1)(luma_pels, CFL_BUF_LINE, sub_luma_pels, width, height); |
| 287 | get_subsample_lbd_fn_c(1, 1)(luma_pels_ref, CFL_BUF_LINE, sub_luma_pels_ref, |
| 288 | width, height); |
| 289 | for (int j = 0; j < height; j++) { |
| 290 | for (int i = 0; i < width; i++) { |
| 291 | ASSERT_EQ(sub_luma_pels_ref[j * CFL_BUF_LINE + i], |
| 292 | sub_luma_pels[j * CFL_BUF_LINE + i]); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | TEST_P(CFLSubsampleTest, DISABLED_SubsampleSpeedTest) { |
| 299 | const int width = Width(); |
| 300 | const int height = Height(); |
| 301 | |
| 302 | aom_usec_timer ref_timer; |
| 303 | aom_usec_timer timer; |
| 304 | |
| 305 | init(width, height); |
| 306 | aom_usec_timer_start(&ref_timer); |
| 307 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
| 308 | get_subsample_lbd_fn_c(1, 1)(luma_pels, CFL_BUF_LINE, sub_luma_pels, width, |
| 309 | height); |
| 310 | } |
| 311 | aom_usec_timer_mark(&ref_timer); |
| 312 | int ref_elapsed_time = (int)aom_usec_timer_elapsed(&ref_timer); |
| 313 | |
| 314 | aom_usec_timer_start(&timer); |
| 315 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
| 316 | subsample(1, 1)(luma_pels_ref, CFL_BUF_LINE, sub_luma_pels_ref, width, |
| 317 | height); |
| 318 | } |
| 319 | aom_usec_timer_mark(&timer); |
| 320 | int elapsed_time = (int)aom_usec_timer_elapsed(&timer); |
| 321 | |
| 322 | printSpeed(ref_elapsed_time, elapsed_time, width, height); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 323 | assertFaster(ref_elapsed_time, elapsed_time); |
| 324 | } |
| 325 | |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 326 | TEST_P(CFLPredictTest, PredictTest) { |
| 327 | const int width = Width(); |
| 328 | const int height = Height(); |
| 329 | const TX_SIZE tx_size = Tx_size(); |
| 330 | |
| 331 | for (int it = 0; it < NUM_ITERATIONS; it++) { |
| 332 | init(width, height); |
| 333 | predict(tx_size)(sub_luma_pels, chroma_pels, CFL_BUF_LINE, tx_size, |
| 334 | alpha_q3); |
| 335 | get_predict_lbd_fn_c(tx_size)(sub_luma_pels_ref, chroma_pels_ref, |
| 336 | CFL_BUF_LINE, tx_size, alpha_q3); |
| 337 | for (int j = 0; j < height; j++) { |
| 338 | for (int i = 0; i < width; i++) { |
| 339 | ASSERT_EQ(chroma_pels_ref[j * CFL_BUF_LINE + i], |
| 340 | chroma_pels[j * CFL_BUF_LINE + i]); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | TEST_P(CFLPredictTest, DISABLED_PredictSpeedTest) { |
| 347 | const int width = Width(); |
| 348 | const int height = Height(); |
| 349 | const TX_SIZE tx_size = Tx_size(); |
| 350 | |
| 351 | aom_usec_timer ref_timer; |
| 352 | aom_usec_timer timer; |
| 353 | |
| 354 | init(width, height); |
| 355 | cfl_predict_lbd_fn predict_impl = get_predict_lbd_fn_c(tx_size); |
| 356 | aom_usec_timer_start(&ref_timer); |
| 357 | |
| 358 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
| 359 | predict_impl(sub_luma_pels_ref, chroma_pels_ref, CFL_BUF_LINE, tx_size, |
| 360 | alpha_q3); |
| 361 | } |
| 362 | aom_usec_timer_mark(&ref_timer); |
| 363 | int ref_elapsed_time = (int)aom_usec_timer_elapsed(&ref_timer); |
| 364 | |
| 365 | predict_impl = predict(tx_size); |
| 366 | aom_usec_timer_start(&timer); |
| 367 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
| 368 | predict_impl(sub_luma_pels, chroma_pels, CFL_BUF_LINE, tx_size, alpha_q3); |
| 369 | } |
| 370 | aom_usec_timer_mark(&timer); |
| 371 | int elapsed_time = (int)aom_usec_timer_elapsed(&timer); |
| 372 | |
| 373 | printSpeed(ref_elapsed_time, elapsed_time, width, height); |
| 374 | assertFaster(ref_elapsed_time, elapsed_time); |
| 375 | } |
| 376 | |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 377 | TEST_P(CFLPredictHBDTest, PredictHBDTest) { |
| 378 | const int width = Width(); |
| 379 | const int height = Height(); |
| 380 | const TX_SIZE tx_size = Tx_size(); |
| 381 | |
| 382 | for (int it = 0; it < NUM_ITERATIONS; it++) { |
| 383 | init(width, height); |
| 384 | predict(tx_size)(sub_luma_pels, chroma_pels, CFL_BUF_LINE, tx_size, |
| 385 | alpha_q3, bd); |
| 386 | get_predict_hbd_fn_c(tx_size)(sub_luma_pels_ref, chroma_pels_ref, |
| 387 | CFL_BUF_LINE, tx_size, alpha_q3, bd); |
| 388 | for (int j = 0; j < height; j++) { |
| 389 | for (int i = 0; i < width; i++) { |
| 390 | ASSERT_EQ(chroma_pels_ref[j * CFL_BUF_LINE + i], |
| 391 | chroma_pels[j * CFL_BUF_LINE + i]); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | TEST_P(CFLPredictHBDTest, DISABLED_PredictHBDSpeedTest) { |
| 398 | const int width = Width(); |
| 399 | const int height = Height(); |
| 400 | const TX_SIZE tx_size = Tx_size(); |
| 401 | |
| 402 | aom_usec_timer ref_timer; |
| 403 | aom_usec_timer timer; |
| 404 | |
| 405 | init(width, height); |
| 406 | cfl_predict_hbd_fn predict_impl = get_predict_hbd_fn_c(tx_size); |
| 407 | aom_usec_timer_start(&ref_timer); |
| 408 | |
| 409 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
| 410 | predict_impl(sub_luma_pels_ref, chroma_pels_ref, CFL_BUF_LINE, tx_size, |
| 411 | alpha_q3, bd); |
| 412 | } |
| 413 | aom_usec_timer_mark(&ref_timer); |
| 414 | int ref_elapsed_time = (int)aom_usec_timer_elapsed(&ref_timer); |
| 415 | |
| 416 | predict_impl = predict(tx_size); |
| 417 | aom_usec_timer_start(&timer); |
| 418 | for (int k = 0; k < NUM_ITERATIONS_SPEED; k++) { |
| 419 | predict_impl(sub_luma_pels, chroma_pels, CFL_BUF_LINE, tx_size, alpha_q3, |
| 420 | bd); |
| 421 | } |
| 422 | aom_usec_timer_mark(&timer); |
| 423 | int elapsed_time = (int)aom_usec_timer_elapsed(&timer); |
| 424 | |
| 425 | printSpeed(ref_elapsed_time, elapsed_time, width, height); |
| 426 | assertFaster(ref_elapsed_time, elapsed_time); |
| 427 | } |
| 428 | |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 429 | #if HAVE_SSE2 |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 430 | const sub_avg_param sub_avg_sizes_sse2[] = { ALL_CFL_TX_SIZES( |
| 431 | get_subtract_average_fn_sse2) }; |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 432 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 433 | INSTANTIATE_TEST_CASE_P(SSE2, CFLSubAvgTest, |
| 434 | ::testing::ValuesIn(sub_avg_sizes_sse2)); |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 435 | |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 436 | #endif |
| 437 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 438 | #if HAVE_SSSE3 |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 439 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 440 | const subsample_param subsample_sizes_ssse3[] = { CHROMA_420_CFL_SIZES( |
| 441 | get_subsample_lbd_fn_ssse3) }; |
| 442 | |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 443 | const predict_param predict_sizes_ssse3[] = { ALL_CFL_TX_SIZES( |
| 444 | get_predict_lbd_fn_ssse3) }; |
| 445 | |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 446 | const predict_param_hbd predict_sizes_hbd_ssse3[] = { ALL_CFL_TX_SIZES( |
| 447 | get_predict_hbd_fn_ssse3) }; |
| 448 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 449 | INSTANTIATE_TEST_CASE_P(SSSE3, CFLSubsampleTest, |
| 450 | ::testing::ValuesIn(subsample_sizes_ssse3)); |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 451 | |
| 452 | INSTANTIATE_TEST_CASE_P(SSSE3, CFLPredictTest, |
| 453 | ::testing::ValuesIn(predict_sizes_ssse3)); |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 454 | |
| 455 | INSTANTIATE_TEST_CASE_P(SSSE3, CFLPredictHBDTest, |
| 456 | ::testing::ValuesIn(predict_sizes_hbd_ssse3)); |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 457 | #endif |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 458 | |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 459 | #if HAVE_AVX2 |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 460 | const sub_avg_param sub_avg_sizes_avx2[] = { ALL_CFL_TX_SIZES( |
| 461 | get_subtract_average_fn_avx2) }; |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 462 | |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 463 | const subsample_param subsample_sizes_avx2[] = { CHROMA_420_CFL_SIZES( |
| 464 | get_subsample_lbd_fn_avx2) }; |
| 465 | |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 466 | const predict_param predict_sizes_avx2[] = { ALL_CFL_TX_SIZES( |
| 467 | get_predict_lbd_fn_avx2) }; |
| 468 | |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 469 | const predict_param_hbd predict_sizes_hbd_avx2[] = { ALL_CFL_TX_SIZES( |
| 470 | get_predict_hbd_fn_avx2) }; |
| 471 | |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 472 | INSTANTIATE_TEST_CASE_P(AVX2, CFLSubAvgTest, |
| 473 | ::testing::ValuesIn(sub_avg_sizes_avx2)); |
Luc Trudeau | 9bd4278 | 2017-12-19 23:15:28 -0500 | [diff] [blame] | 474 | |
| 475 | INSTANTIATE_TEST_CASE_P(AVX2, CFLSubsampleTest, |
| 476 | ::testing::ValuesIn(subsample_sizes_avx2)); |
David Michael Barr | 16f38c2 | 2017-12-21 01:56:03 +0900 | [diff] [blame] | 477 | |
| 478 | INSTANTIATE_TEST_CASE_P(AVX2, CFLPredictTest, |
| 479 | ::testing::ValuesIn(predict_sizes_avx2)); |
David Michael Barr | c363ab7 | 2018-01-12 16:53:38 +0900 | [diff] [blame] | 480 | |
| 481 | INSTANTIATE_TEST_CASE_P(AVX2, CFLPredictHBDTest, |
| 482 | ::testing::ValuesIn(predict_sizes_hbd_avx2)); |
Luc Trudeau | b4faea7 | 2017-12-15 16:44:01 -0500 | [diff] [blame] | 483 | #endif |
| 484 | } // namespace |