Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 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. |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 15 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "./aom_dsp_rtcd.h" |
| 18 | #include "aom/aom_integer.h" |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 19 | |
| 20 | #include "test/acm_random.h" |
| 21 | #include "test/register_state_check.h" |
| 22 | |
| 23 | namespace { |
| 24 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | using ::libaom_test::ACMRandom; |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 26 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 27 | typedef void (*MinMaxFunc)(const uint8_t *a, int a_stride, const uint8_t *b, |
| 28 | int b_stride, int *min, int *max); |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 29 | |
| 30 | class MinMaxTest : public ::testing::TestWithParam<MinMaxFunc> { |
| 31 | public: |
| 32 | virtual void SetUp() { |
| 33 | mm_func_ = GetParam(); |
| 34 | rnd_.Reset(ACMRandom::DeterministicSeed()); |
| 35 | } |
| 36 | |
| 37 | protected: |
| 38 | MinMaxFunc mm_func_; |
| 39 | ACMRandom rnd_; |
| 40 | }; |
| 41 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 42 | void reference_minmax(const uint8_t *a, int a_stride, const uint8_t *b, |
| 43 | int b_stride, int *min_ret, int *max_ret) { |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 44 | int min = 255; |
| 45 | int max = 0; |
| 46 | for (int i = 0; i < 8; i++) { |
| 47 | for (int j = 0; j < 8; j++) { |
| 48 | const int diff = abs(a[i * a_stride + j] - b[i * b_stride + j]); |
| 49 | if (min > diff) min = diff; |
| 50 | if (max < diff) max = diff; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | *min_ret = min; |
| 55 | *max_ret = max; |
| 56 | } |
| 57 | |
| 58 | TEST_P(MinMaxTest, MinValue) { |
| 59 | for (int i = 0; i < 64; i++) { |
| 60 | uint8_t a[64], b[64]; |
| 61 | memset(a, 0, sizeof(a)); |
| 62 | memset(b, 255, sizeof(b)); |
| 63 | b[i] = i; // Set a minimum difference of i. |
| 64 | |
| 65 | int min, max; |
| 66 | ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max)); |
| 67 | EXPECT_EQ(255, max); |
| 68 | EXPECT_EQ(i, min); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | TEST_P(MinMaxTest, MaxValue) { |
| 73 | for (int i = 0; i < 64; i++) { |
| 74 | uint8_t a[64], b[64]; |
| 75 | memset(a, 0, sizeof(a)); |
| 76 | memset(b, 0, sizeof(b)); |
| 77 | b[i] = i; // Set a maximum difference of i. |
| 78 | |
| 79 | int min, max; |
| 80 | ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max)); |
| 81 | EXPECT_EQ(i, max); |
| 82 | EXPECT_EQ(0, min); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | TEST_P(MinMaxTest, CompareReference) { |
| 87 | uint8_t a[64], b[64]; |
| 88 | for (int j = 0; j < 64; j++) { |
| 89 | a[j] = rnd_.Rand8(); |
| 90 | b[j] = rnd_.Rand8(); |
| 91 | } |
| 92 | |
| 93 | int min_ref, max_ref, min, max; |
| 94 | reference_minmax(a, 8, b, 8, &min_ref, &max_ref); |
| 95 | ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max)); |
| 96 | EXPECT_EQ(max_ref, max); |
| 97 | EXPECT_EQ(min_ref, min); |
| 98 | } |
| 99 | |
| 100 | TEST_P(MinMaxTest, CompareReferenceAndVaryStride) { |
| 101 | uint8_t a[8 * 64], b[8 * 64]; |
| 102 | for (int i = 0; i < 8 * 64; i++) { |
| 103 | a[i] = rnd_.Rand8(); |
| 104 | b[i] = rnd_.Rand8(); |
| 105 | } |
| 106 | for (int a_stride = 8; a_stride <= 64; a_stride += 8) { |
| 107 | for (int b_stride = 8; b_stride <= 64; b_stride += 8) { |
| 108 | int min_ref, max_ref, min, max; |
| 109 | reference_minmax(a, a_stride, b, b_stride, &min_ref, &max_ref); |
| 110 | ASM_REGISTER_STATE_CHECK(mm_func_(a, a_stride, b, b_stride, &min, &max)); |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 111 | EXPECT_EQ(max_ref, max) |
| 112 | << "when a_stride = " << a_stride << " and b_stride = " << b_stride; |
| 113 | EXPECT_EQ(min_ref, min) |
| 114 | << "when a_stride = " << a_stride << " and b_stride = " << b_stride; |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 119 | INSTANTIATE_TEST_CASE_P(C, MinMaxTest, ::testing::Values(&aom_minmax_8x8_c)); |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 120 | |
| 121 | #if HAVE_SSE2 |
| 122 | INSTANTIATE_TEST_CASE_P(SSE2, MinMaxTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 123 | ::testing::Values(&aom_minmax_8x8_sse2)); |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 124 | #endif |
| 125 | |
| 126 | #if HAVE_NEON |
| 127 | INSTANTIATE_TEST_CASE_P(NEON, MinMaxTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 128 | ::testing::Values(&aom_minmax_8x8_neon)); |
Johann | 2f5840d | 2016-04-14 14:26:32 -0700 | [diff] [blame] | 129 | #endif |
| 130 | |
| 131 | } // namespace |