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.
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"
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
> {
32 virtual void SetUp() {
33 mm_func_
= GetParam();
34 rnd_
.Reset(ACMRandom::DeterministicSeed());
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
) {
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
;
58 TEST_P(MinMaxTest
, MinValue
) {
59 for (int i
= 0; i
< 64; i
++) {
61 memset(a
, 0, sizeof(a
));
62 memset(b
, 255, sizeof(b
));
63 b
[i
] = i
; // Set a minimum difference of i.
66 ASM_REGISTER_STATE_CHECK(mm_func_(a
, 8, b
, 8, &min
, &max
));
72 TEST_P(MinMaxTest
, MaxValue
) {
73 for (int i
= 0; i
< 64; i
++) {
75 memset(a
, 0, sizeof(a
));
76 memset(b
, 0, sizeof(b
));
77 b
[i
] = i
; // Set a maximum difference of i.
80 ASM_REGISTER_STATE_CHECK(mm_func_(a
, 8, b
, 8, &min
, &max
));
86 TEST_P(MinMaxTest
, CompareReference
) {
88 for (int j
= 0; j
< 64; j
++) {
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
++) {
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
));
122 INSTANTIATE_TEST_CASE_P(SSE2
, MinMaxTest
,
123 ::testing::Values(&aom_minmax_8x8_sse2
));
127 INSTANTIATE_TEST_CASE_P(NEON
, MinMaxTest
,
128 ::testing::Values(&aom_minmax_8x8_neon
));