Improved aom_smooth_predictor_16x 32,16,8
[aom.git] / test / minmax_test.cc
blobaaac72c6516d3ab1e6923ff5d32cf602818731b0
1 /*
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.
12 #include <stdlib.h>
13 #include <string.h>
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17 #include "./aom_dsp_rtcd.h"
18 #include "aom/aom_integer.h"
20 #include "test/acm_random.h"
21 #include "test/register_state_check.h"
23 namespace {
25 using ::libaom_test::ACMRandom;
27 typedef void (*MinMaxFunc)(const uint8_t *a, int a_stride, const uint8_t *b,
28 int b_stride, int *min, int *max);
30 class MinMaxTest : public ::testing::TestWithParam<MinMaxFunc> {
31 public:
32 virtual void SetUp() {
33 mm_func_ = GetParam();
34 rnd_.Reset(ACMRandom::DeterministicSeed());
37 protected:
38 MinMaxFunc mm_func_;
39 ACMRandom rnd_;
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) {
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;
54 *min_ret = min;
55 *max_ret = max;
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.
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);
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.
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);
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();
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);
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();
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));
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;
119 INSTANTIATE_TEST_CASE_P(C, MinMaxTest, ::testing::Values(&aom_minmax_8x8_c));
121 #if HAVE_SSE2
122 INSTANTIATE_TEST_CASE_P(SSE2, MinMaxTest,
123 ::testing::Values(&aom_minmax_8x8_sse2));
124 #endif
126 #if HAVE_NEON
127 INSTANTIATE_TEST_CASE_P(NEON, MinMaxTest,
128 ::testing::Values(&aom_minmax_8x8_neon));
129 #endif
131 } // namespace