blob: aaac72c6516d3ab1e6923ff5d32cf602818731b0 [file] [log] [blame]
Johann2f5840d2016-04-14 14:26:32 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Johann2f5840d2016-04-14 14:26:32 -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.
Johann2f5840d2016-04-14 14:26:32 -070010 */
11
12#include <stdlib.h>
13#include <string.h>
14
Tom Finegan7a07ece2017-02-07 17:14:05 -080015#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Johann2f5840d2016-04-14 14:26:32 -070016
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "./aom_dsp_rtcd.h"
18#include "aom/aom_integer.h"
Johann2f5840d2016-04-14 14:26:32 -070019
20#include "test/acm_random.h"
21#include "test/register_state_check.h"
22
23namespace {
24
Yaowu Xuc27fc142016-08-22 16:08:15 -070025using ::libaom_test::ACMRandom;
Johann2f5840d2016-04-14 14:26:32 -070026
clang-format3a826f12016-08-11 17:46:05 -070027typedef void (*MinMaxFunc)(const uint8_t *a, int a_stride, const uint8_t *b,
28 int b_stride, int *min, int *max);
Johann2f5840d2016-04-14 14:26:32 -070029
30class 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-format3a826f12016-08-11 17:46:05 -070042void reference_minmax(const uint8_t *a, int a_stride, const uint8_t *b,
43 int b_stride, int *min_ret, int *max_ret) {
Johann2f5840d2016-04-14 14:26:32 -070044 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
58TEST_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
72TEST_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
86TEST_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
100TEST_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-format4eafefe2017-09-04 12:51:20 -0700111 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;
Johann2f5840d2016-04-14 14:26:32 -0700115 }
116 }
117}
118
Yaowu Xuf883b422016-08-30 14:01:10 -0700119INSTANTIATE_TEST_CASE_P(C, MinMaxTest, ::testing::Values(&aom_minmax_8x8_c));
Johann2f5840d2016-04-14 14:26:32 -0700120
121#if HAVE_SSE2
122INSTANTIATE_TEST_CASE_P(SSE2, MinMaxTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700123 ::testing::Values(&aom_minmax_8x8_sse2));
Johann2f5840d2016-04-14 14:26:32 -0700124#endif
125
126#if HAVE_NEON
127INSTANTIATE_TEST_CASE_P(NEON, MinMaxTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 ::testing::Values(&aom_minmax_8x8_neon));
Johann2f5840d2016-04-14 14:26:32 -0700129#endif
130
131} // namespace