minmax_test.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "third_party/googletest/src/include/gtest/gtest.h"
  13. #include "./vpx_dsp_rtcd.h"
  14. #include "vpx/vpx_integer.h"
  15. #include "test/acm_random.h"
  16. #include "test/register_state_check.h"
  17. namespace {
  18. using ::libvpx_test::ACMRandom;
  19. typedef void (*MinMaxFunc)(const uint8_t *a, int a_stride, const uint8_t *b,
  20. int b_stride, int *min, int *max);
  21. class MinMaxTest : public ::testing::TestWithParam<MinMaxFunc> {
  22. public:
  23. virtual void SetUp() {
  24. mm_func_ = GetParam();
  25. rnd_.Reset(ACMRandom::DeterministicSeed());
  26. }
  27. protected:
  28. MinMaxFunc mm_func_;
  29. ACMRandom rnd_;
  30. };
  31. void reference_minmax(const uint8_t *a, int a_stride, const uint8_t *b,
  32. int b_stride, int *min_ret, int *max_ret) {
  33. int min = 255;
  34. int max = 0;
  35. for (int i = 0; i < 8; i++) {
  36. for (int j = 0; j < 8; j++) {
  37. const int diff = abs(a[i * a_stride + j] - b[i * b_stride + j]);
  38. if (min > diff) min = diff;
  39. if (max < diff) max = diff;
  40. }
  41. }
  42. *min_ret = min;
  43. *max_ret = max;
  44. }
  45. TEST_P(MinMaxTest, MinValue) {
  46. for (int i = 0; i < 64; i++) {
  47. uint8_t a[64], b[64];
  48. memset(a, 0, sizeof(a));
  49. memset(b, 255, sizeof(b));
  50. b[i] = i; // Set a minimum difference of i.
  51. int min, max;
  52. ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max));
  53. EXPECT_EQ(255, max);
  54. EXPECT_EQ(i, min);
  55. }
  56. }
  57. TEST_P(MinMaxTest, MaxValue) {
  58. for (int i = 0; i < 64; i++) {
  59. uint8_t a[64], b[64];
  60. memset(a, 0, sizeof(a));
  61. memset(b, 0, sizeof(b));
  62. b[i] = i; // Set a maximum difference of i.
  63. int min, max;
  64. ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max));
  65. EXPECT_EQ(i, max);
  66. EXPECT_EQ(0, min);
  67. }
  68. }
  69. TEST_P(MinMaxTest, CompareReference) {
  70. uint8_t a[64], b[64];
  71. for (int j = 0; j < 64; j++) {
  72. a[j] = rnd_.Rand8();
  73. b[j] = rnd_.Rand8();
  74. }
  75. int min_ref, max_ref, min, max;
  76. reference_minmax(a, 8, b, 8, &min_ref, &max_ref);
  77. ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max));
  78. EXPECT_EQ(max_ref, max);
  79. EXPECT_EQ(min_ref, min);
  80. }
  81. TEST_P(MinMaxTest, CompareReferenceAndVaryStride) {
  82. uint8_t a[8 * 64], b[8 * 64];
  83. for (int i = 0; i < 8 * 64; i++) {
  84. a[i] = rnd_.Rand8();
  85. b[i] = rnd_.Rand8();
  86. }
  87. for (int a_stride = 8; a_stride <= 64; a_stride += 8) {
  88. for (int b_stride = 8; b_stride <= 64; b_stride += 8) {
  89. int min_ref, max_ref, min, max;
  90. reference_minmax(a, a_stride, b, b_stride, &min_ref, &max_ref);
  91. ASM_REGISTER_STATE_CHECK(mm_func_(a, a_stride, b, b_stride, &min, &max));
  92. EXPECT_EQ(max_ref, max)
  93. << "when a_stride = " << a_stride << " and b_stride = " << b_stride;
  94. EXPECT_EQ(min_ref, min)
  95. << "when a_stride = " << a_stride << " and b_stride = " << b_stride;
  96. }
  97. }
  98. }
  99. INSTANTIATE_TEST_CASE_P(C, MinMaxTest, ::testing::Values(&vpx_minmax_8x8_c));
  100. #if HAVE_SSE2
  101. INSTANTIATE_TEST_CASE_P(SSE2, MinMaxTest,
  102. ::testing::Values(&vpx_minmax_8x8_sse2));
  103. #endif
  104. #if HAVE_NEON
  105. INSTANTIATE_TEST_CASE_P(NEON, MinMaxTest,
  106. ::testing::Values(&vpx_minmax_8x8_neon));
  107. #endif
  108. #if HAVE_MSA
  109. INSTANTIATE_TEST_CASE_P(MSA, MinMaxTest,
  110. ::testing::Values(&vpx_minmax_8x8_msa));
  111. #endif
  112. } // namespace