predict_test.cc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * Copyright (c) 2013 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 "./vp8_rtcd.h"
  14. #include "./vpx_config.h"
  15. #include "test/acm_random.h"
  16. #include "test/clear_system_state.h"
  17. #include "test/register_state_check.h"
  18. #include "test/util.h"
  19. #include "vpx/vpx_integer.h"
  20. #include "vpx_mem/vpx_mem.h"
  21. namespace {
  22. using libvpx_test::ACMRandom;
  23. using std::tr1::make_tuple;
  24. typedef void (*PredictFunc)(uint8_t *src_ptr, int src_pixels_per_line,
  25. int xoffset, int yoffset, uint8_t *dst_ptr,
  26. int dst_pitch);
  27. typedef std::tr1::tuple<int, int, PredictFunc> PredictParam;
  28. class PredictTestBase : public ::testing::TestWithParam<PredictParam> {
  29. public:
  30. PredictTestBase()
  31. : width_(GET_PARAM(0)), height_(GET_PARAM(1)), predict_(GET_PARAM(2)),
  32. src_(NULL), padded_dst_(NULL), dst_(NULL), dst_c_(NULL) {}
  33. virtual void SetUp() {
  34. src_ = new uint8_t[kSrcSize];
  35. ASSERT_TRUE(src_ != NULL);
  36. // padded_dst_ provides a buffer of kBorderSize around the destination
  37. // memory to facilitate detecting out of bounds writes.
  38. dst_stride_ = kBorderSize + width_ + kBorderSize;
  39. padded_dst_size_ = dst_stride_ * (kBorderSize + height_ + kBorderSize);
  40. padded_dst_ =
  41. reinterpret_cast<uint8_t *>(vpx_memalign(16, padded_dst_size_));
  42. ASSERT_TRUE(padded_dst_ != NULL);
  43. dst_ = padded_dst_ + (kBorderSize * dst_stride_) + kBorderSize;
  44. dst_c_ = new uint8_t[16 * 16];
  45. ASSERT_TRUE(dst_c_ != NULL);
  46. memset(src_, 0, kSrcSize);
  47. memset(padded_dst_, 128, padded_dst_size_);
  48. memset(dst_c_, 0, 16 * 16);
  49. }
  50. virtual void TearDown() {
  51. delete[] src_;
  52. src_ = NULL;
  53. vpx_free(padded_dst_);
  54. padded_dst_ = NULL;
  55. dst_ = NULL;
  56. delete[] dst_c_;
  57. dst_c_ = NULL;
  58. libvpx_test::ClearSystemState();
  59. }
  60. protected:
  61. // Make reference arrays big enough for 16x16 functions. Six-tap filters need
  62. // 5 extra pixels outside of the macroblock.
  63. static const int kSrcStride = 21;
  64. static const int kSrcSize = kSrcStride * kSrcStride;
  65. static const int kBorderSize = 16;
  66. int width_;
  67. int height_;
  68. PredictFunc predict_;
  69. uint8_t *src_;
  70. uint8_t *padded_dst_;
  71. uint8_t *dst_;
  72. int padded_dst_size_;
  73. uint8_t *dst_c_;
  74. int dst_stride_;
  75. bool CompareBuffers(const uint8_t *a, int a_stride, const uint8_t *b,
  76. int b_stride) const {
  77. for (int height = 0; height < height_; ++height) {
  78. EXPECT_EQ(0, memcmp(a + height * a_stride, b + height * b_stride,
  79. sizeof(*a) * width_))
  80. << "Row " << height << " does not match.";
  81. }
  82. return !HasFailure();
  83. }
  84. // Given a block of memory 'a' with size 'a_size', determine if all regions
  85. // excepting block 'b' described by 'b_stride', 'b_height', and 'b_width'
  86. // match pixel value 'c'.
  87. bool CheckBorder(const uint8_t *a, int a_size, const uint8_t *b, int b_width,
  88. int b_height, int b_stride, uint8_t c) const {
  89. const uint8_t *a_end = a + a_size;
  90. const int b_size = (b_stride * b_height) + b_width;
  91. const uint8_t *b_end = b + b_size;
  92. const int left_border = (b_stride - b_width) / 2;
  93. const int right_border = left_border + ((b_stride - b_width) % 2);
  94. EXPECT_GE(b - left_border, a) << "'b' does not start within 'a'";
  95. EXPECT_LE(b_end + right_border, a_end) << "'b' does not end within 'a'";
  96. // Top border.
  97. for (int pixel = 0; pixel < b - a - left_border; ++pixel) {
  98. EXPECT_EQ(c, a[pixel]) << "Mismatch at " << pixel << " in top border.";
  99. }
  100. // Left border.
  101. for (int height = 0; height < b_height; ++height) {
  102. for (int width = left_border; width > 0; --width) {
  103. EXPECT_EQ(c, b[height * b_stride - width])
  104. << "Mismatch at row " << height << " column " << left_border - width
  105. << " in left border.";
  106. }
  107. }
  108. // Right border.
  109. for (int height = 0; height < b_height; ++height) {
  110. for (int width = b_width; width < b_width + right_border; ++width) {
  111. EXPECT_EQ(c, b[height * b_stride + width])
  112. << "Mismatch at row " << height << " column " << width - b_width
  113. << " in right border.";
  114. }
  115. }
  116. // Bottom border.
  117. for (int pixel = static_cast<int>(b - a + b_size); pixel < a_size;
  118. ++pixel) {
  119. EXPECT_EQ(c, a[pixel]) << "Mismatch at " << pixel << " in bottom border.";
  120. }
  121. return !HasFailure();
  122. }
  123. void TestWithRandomData(PredictFunc reference) {
  124. ACMRandom rnd(ACMRandom::DeterministicSeed());
  125. // Run tests for almost all possible offsets.
  126. for (int xoffset = 0; xoffset < 8; ++xoffset) {
  127. for (int yoffset = 0; yoffset < 8; ++yoffset) {
  128. if (xoffset == 0 && yoffset == 0) {
  129. // This represents a copy which is not required to be handled by this
  130. // module.
  131. continue;
  132. }
  133. for (int i = 0; i < kSrcSize; ++i) {
  134. src_[i] = rnd.Rand8();
  135. }
  136. reference(&src_[kSrcStride * 2 + 2], kSrcStride, xoffset, yoffset,
  137. dst_c_, 16);
  138. ASM_REGISTER_STATE_CHECK(predict_(&src_[kSrcStride * 2 + 2], kSrcStride,
  139. xoffset, yoffset, dst_, dst_stride_));
  140. ASSERT_TRUE(CompareBuffers(dst_c_, 16, dst_, dst_stride_));
  141. ASSERT_TRUE(CheckBorder(padded_dst_, padded_dst_size_, dst_, width_,
  142. height_, dst_stride_, 128));
  143. }
  144. }
  145. }
  146. void TestWithUnalignedDst(PredictFunc reference) {
  147. ACMRandom rnd(ACMRandom::DeterministicSeed());
  148. // Only the 4x4 need to be able to handle unaligned writes.
  149. if (width_ == 4 && height_ == 4) {
  150. for (int xoffset = 0; xoffset < 8; ++xoffset) {
  151. for (int yoffset = 0; yoffset < 8; ++yoffset) {
  152. if (xoffset == 0 && yoffset == 0) {
  153. continue;
  154. }
  155. for (int i = 0; i < kSrcSize; ++i) {
  156. src_[i] = rnd.Rand8();
  157. }
  158. reference(&src_[kSrcStride * 2 + 2], kSrcStride, xoffset, yoffset,
  159. dst_c_, 16);
  160. for (int i = 1; i < 4; ++i) {
  161. memset(padded_dst_, 128, padded_dst_size_);
  162. ASM_REGISTER_STATE_CHECK(predict_(&src_[kSrcStride * 2 + 2],
  163. kSrcStride, xoffset, yoffset,
  164. dst_ + i, dst_stride_ + i));
  165. ASSERT_TRUE(CompareBuffers(dst_c_, 16, dst_ + i, dst_stride_ + i));
  166. ASSERT_TRUE(CheckBorder(padded_dst_, padded_dst_size_, dst_ + i,
  167. width_, height_, dst_stride_ + i, 128));
  168. }
  169. }
  170. }
  171. }
  172. }
  173. };
  174. class SixtapPredictTest : public PredictTestBase {};
  175. TEST_P(SixtapPredictTest, TestWithRandomData) {
  176. TestWithRandomData(vp8_sixtap_predict16x16_c);
  177. }
  178. TEST_P(SixtapPredictTest, TestWithUnalignedDst) {
  179. TestWithUnalignedDst(vp8_sixtap_predict16x16_c);
  180. }
  181. TEST_P(SixtapPredictTest, TestWithPresetData) {
  182. // Test input
  183. static const uint8_t kTestData[kSrcSize] = {
  184. 184, 4, 191, 82, 92, 41, 0, 1, 226, 236, 172, 20, 182, 42, 226,
  185. 177, 79, 94, 77, 179, 203, 206, 198, 22, 192, 19, 75, 17, 192, 44,
  186. 233, 120, 48, 168, 203, 141, 210, 203, 143, 180, 184, 59, 201, 110, 102,
  187. 171, 32, 182, 10, 109, 105, 213, 60, 47, 236, 253, 67, 55, 14, 3,
  188. 99, 247, 124, 148, 159, 71, 34, 114, 19, 177, 38, 203, 237, 239, 58,
  189. 83, 155, 91, 10, 166, 201, 115, 124, 5, 163, 104, 2, 231, 160, 16,
  190. 234, 4, 8, 103, 153, 167, 174, 187, 26, 193, 109, 64, 141, 90, 48,
  191. 200, 174, 204, 36, 184, 114, 237, 43, 238, 242, 207, 86, 245, 182, 247,
  192. 6, 161, 251, 14, 8, 148, 182, 182, 79, 208, 120, 188, 17, 6, 23,
  193. 65, 206, 197, 13, 242, 126, 128, 224, 170, 110, 211, 121, 197, 200, 47,
  194. 188, 207, 208, 184, 221, 216, 76, 148, 143, 156, 100, 8, 89, 117, 14,
  195. 112, 183, 221, 54, 197, 208, 180, 69, 176, 94, 180, 131, 215, 121, 76,
  196. 7, 54, 28, 216, 238, 249, 176, 58, 142, 64, 215, 242, 72, 49, 104,
  197. 87, 161, 32, 52, 216, 230, 4, 141, 44, 181, 235, 224, 57, 195, 89,
  198. 134, 203, 144, 162, 163, 126, 156, 84, 185, 42, 148, 145, 29, 221, 194,
  199. 134, 52, 100, 166, 105, 60, 140, 110, 201, 184, 35, 181, 153, 93, 121,
  200. 243, 227, 68, 131, 134, 232, 2, 35, 60, 187, 77, 209, 76, 106, 174,
  201. 15, 241, 227, 115, 151, 77, 175, 36, 187, 121, 221, 223, 47, 118, 61,
  202. 168, 105, 32, 237, 236, 167, 213, 238, 202, 17, 170, 24, 226, 247, 131,
  203. 145, 6, 116, 117, 121, 11, 194, 41, 48, 126, 162, 13, 93, 209, 131,
  204. 154, 122, 237, 187, 103, 217, 99, 60, 200, 45, 78, 115, 69, 49, 106,
  205. 200, 194, 112, 60, 56, 234, 72, 251, 19, 120, 121, 182, 134, 215, 135,
  206. 10, 114, 2, 247, 46, 105, 209, 145, 165, 153, 191, 243, 12, 5, 36,
  207. 119, 206, 231, 231, 11, 32, 209, 83, 27, 229, 204, 149, 155, 83, 109,
  208. 35, 93, 223, 37, 84, 14, 142, 37, 160, 52, 191, 96, 40, 204, 101,
  209. 77, 67, 52, 53, 43, 63, 85, 253, 147, 113, 226, 96, 6, 125, 179,
  210. 115, 161, 17, 83, 198, 101, 98, 85, 139, 3, 137, 75, 99, 178, 23,
  211. 201, 255, 91, 253, 52, 134, 60, 138, 131, 208, 251, 101, 48, 2, 227,
  212. 228, 118, 132, 245, 202, 75, 91, 44, 160, 231, 47, 41, 50, 147, 220,
  213. 74, 92, 219, 165, 89, 16
  214. };
  215. // Expected results for xoffset = 2 and yoffset = 2.
  216. static const int kExpectedDstStride = 16;
  217. static const uint8_t kExpectedDst[256] = {
  218. 117, 102, 74, 135, 42, 98, 175, 206, 70, 73, 222, 197, 50, 24, 39,
  219. 49, 38, 105, 90, 47, 169, 40, 171, 215, 200, 73, 109, 141, 53, 85,
  220. 177, 164, 79, 208, 124, 89, 212, 18, 81, 145, 151, 164, 217, 153, 91,
  221. 154, 102, 102, 159, 75, 164, 152, 136, 51, 213, 219, 186, 116, 193, 224,
  222. 186, 36, 231, 208, 84, 211, 155, 167, 35, 59, 42, 76, 216, 149, 73,
  223. 201, 78, 149, 184, 100, 96, 196, 189, 198, 188, 235, 195, 117, 129, 120,
  224. 129, 49, 25, 133, 113, 69, 221, 114, 70, 143, 99, 157, 108, 189, 140,
  225. 78, 6, 55, 65, 240, 255, 245, 184, 72, 90, 100, 116, 131, 39, 60,
  226. 234, 167, 33, 160, 88, 185, 200, 157, 159, 176, 127, 151, 138, 102, 168,
  227. 106, 170, 86, 82, 219, 189, 76, 33, 115, 197, 106, 96, 198, 136, 97,
  228. 141, 237, 151, 98, 137, 191, 185, 2, 57, 95, 142, 91, 255, 185, 97,
  229. 137, 76, 162, 94, 173, 131, 193, 161, 81, 106, 72, 135, 222, 234, 137,
  230. 66, 137, 106, 243, 210, 147, 95, 15, 137, 110, 85, 66, 16, 96, 167,
  231. 147, 150, 173, 203, 140, 118, 196, 84, 147, 160, 19, 95, 101, 123, 74,
  232. 132, 202, 82, 166, 12, 131, 166, 189, 170, 159, 85, 79, 66, 57, 152,
  233. 132, 203, 194, 0, 1, 56, 146, 180, 224, 156, 28, 83, 181, 79, 76,
  234. 80, 46, 160, 175, 59, 106, 43, 87, 75, 136, 85, 189, 46, 71, 200,
  235. 90
  236. };
  237. ASM_REGISTER_STATE_CHECK(
  238. predict_(const_cast<uint8_t *>(kTestData) + kSrcStride * 2 + 2,
  239. kSrcStride, 2, 2, dst_, dst_stride_));
  240. ASSERT_TRUE(
  241. CompareBuffers(kExpectedDst, kExpectedDstStride, dst_, dst_stride_));
  242. }
  243. INSTANTIATE_TEST_CASE_P(
  244. C, SixtapPredictTest,
  245. ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_c),
  246. make_tuple(8, 8, &vp8_sixtap_predict8x8_c),
  247. make_tuple(8, 4, &vp8_sixtap_predict8x4_c),
  248. make_tuple(4, 4, &vp8_sixtap_predict4x4_c)));
  249. #if HAVE_NEON
  250. INSTANTIATE_TEST_CASE_P(
  251. NEON, SixtapPredictTest,
  252. ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_neon),
  253. make_tuple(8, 8, &vp8_sixtap_predict8x8_neon),
  254. make_tuple(8, 4, &vp8_sixtap_predict8x4_neon),
  255. make_tuple(4, 4, &vp8_sixtap_predict4x4_neon)));
  256. #endif
  257. #if HAVE_MMX
  258. INSTANTIATE_TEST_CASE_P(
  259. MMX, SixtapPredictTest,
  260. ::testing::Values(make_tuple(4, 4, &vp8_sixtap_predict4x4_mmx)));
  261. #endif
  262. #if HAVE_SSE2
  263. INSTANTIATE_TEST_CASE_P(
  264. SSE2, SixtapPredictTest,
  265. ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_sse2),
  266. make_tuple(8, 8, &vp8_sixtap_predict8x8_sse2),
  267. make_tuple(8, 4, &vp8_sixtap_predict8x4_sse2)));
  268. #endif
  269. #if HAVE_SSSE3
  270. INSTANTIATE_TEST_CASE_P(
  271. SSSE3, SixtapPredictTest,
  272. ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_ssse3),
  273. make_tuple(8, 8, &vp8_sixtap_predict8x8_ssse3),
  274. make_tuple(8, 4, &vp8_sixtap_predict8x4_ssse3),
  275. make_tuple(4, 4, &vp8_sixtap_predict4x4_ssse3)));
  276. #endif
  277. #if HAVE_MSA
  278. INSTANTIATE_TEST_CASE_P(
  279. MSA, SixtapPredictTest,
  280. ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_msa),
  281. make_tuple(8, 8, &vp8_sixtap_predict8x8_msa),
  282. make_tuple(8, 4, &vp8_sixtap_predict8x4_msa),
  283. make_tuple(4, 4, &vp8_sixtap_predict4x4_msa)));
  284. #endif
  285. #if HAVE_MMI
  286. INSTANTIATE_TEST_CASE_P(
  287. MMI, SixtapPredictTest,
  288. ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_mmi),
  289. make_tuple(8, 8, &vp8_sixtap_predict8x8_mmi),
  290. make_tuple(8, 4, &vp8_sixtap_predict8x4_mmi),
  291. make_tuple(4, 4, &vp8_sixtap_predict4x4_mmi)));
  292. #endif
  293. class BilinearPredictTest : public PredictTestBase {};
  294. TEST_P(BilinearPredictTest, TestWithRandomData) {
  295. TestWithRandomData(vp8_bilinear_predict16x16_c);
  296. }
  297. TEST_P(BilinearPredictTest, TestWithUnalignedDst) {
  298. TestWithUnalignedDst(vp8_bilinear_predict16x16_c);
  299. }
  300. INSTANTIATE_TEST_CASE_P(
  301. C, BilinearPredictTest,
  302. ::testing::Values(make_tuple(16, 16, &vp8_bilinear_predict16x16_c),
  303. make_tuple(8, 8, &vp8_bilinear_predict8x8_c),
  304. make_tuple(8, 4, &vp8_bilinear_predict8x4_c),
  305. make_tuple(4, 4, &vp8_bilinear_predict4x4_c)));
  306. #if HAVE_NEON
  307. INSTANTIATE_TEST_CASE_P(
  308. NEON, BilinearPredictTest,
  309. ::testing::Values(make_tuple(16, 16, &vp8_bilinear_predict16x16_neon),
  310. make_tuple(8, 8, &vp8_bilinear_predict8x8_neon),
  311. make_tuple(8, 4, &vp8_bilinear_predict8x4_neon),
  312. make_tuple(4, 4, &vp8_bilinear_predict4x4_neon)));
  313. #endif
  314. #if HAVE_MMX
  315. INSTANTIATE_TEST_CASE_P(
  316. MMX, BilinearPredictTest,
  317. ::testing::Values(make_tuple(8, 4, &vp8_bilinear_predict8x4_mmx),
  318. make_tuple(4, 4, &vp8_bilinear_predict4x4_mmx)));
  319. #endif
  320. #if HAVE_SSE2
  321. INSTANTIATE_TEST_CASE_P(
  322. SSE2, BilinearPredictTest,
  323. ::testing::Values(make_tuple(16, 16, &vp8_bilinear_predict16x16_sse2),
  324. make_tuple(8, 8, &vp8_bilinear_predict8x8_sse2)));
  325. #endif
  326. #if HAVE_SSSE3
  327. INSTANTIATE_TEST_CASE_P(
  328. SSSE3, BilinearPredictTest,
  329. ::testing::Values(make_tuple(16, 16, &vp8_bilinear_predict16x16_ssse3),
  330. make_tuple(8, 8, &vp8_bilinear_predict8x8_ssse3)));
  331. #endif
  332. #if HAVE_MSA
  333. INSTANTIATE_TEST_CASE_P(
  334. MSA, BilinearPredictTest,
  335. ::testing::Values(make_tuple(16, 16, &vp8_bilinear_predict16x16_msa),
  336. make_tuple(8, 8, &vp8_bilinear_predict8x8_msa),
  337. make_tuple(8, 4, &vp8_bilinear_predict8x4_msa),
  338. make_tuple(4, 4, &vp8_bilinear_predict4x4_msa)));
  339. #endif
  340. } // namespace