blob: 009f4b0c392f34a3fca101cf161e50acfa747452 [file] [log] [blame]
James Berry0c1cec22012-02-21 11:57:14 -05001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
James Berry0c1cec22012-02-21 11:57:14 -05003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
10*/
James Berry0c1cec22012-02-21 11:57:14 -050011
Yaowu Xuf883b422016-08-30 14:01:10 -070012#include "./aom_config.h"
13#include "./aom_rtcd.h"
Jingning Han097d59c2015-07-29 14:51:36 -070014
John Koleszare82d2612012-05-16 16:25:51 -070015#include "third_party/googletest/src/include/gtest/gtest.h"
16
Jingning Han097d59c2015-07-29 14:51:36 -070017#include "test/clear_system_state.h"
18#include "test/register_state_check.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070019#include "aom/aom_integer.h"
James Zern563c2732013-09-09 22:20:41 -070020
James Zern75d56b32014-07-16 18:57:11 -070021typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr,
22 int pred_stride, unsigned char *dst_ptr,
23 int dst_stride);
John Koleszare82d2612012-05-16 16:25:51 -070024namespace {
James Zern75d56b32014-07-16 18:57:11 -070025class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
James Zern36b882e2013-07-18 15:42:06 -070026 protected:
27 virtual void SetUp() {
28 int i;
John Koleszare82d2612012-05-16 16:25:51 -070029
James Zern36b882e2013-07-18 15:42:06 -070030 UUT = GetParam();
31 memset(input, 0, sizeof(input));
32 /* Set up guard blocks */
33 for (i = 0; i < 256; i++) output[i] = ((i & 0xF) < 4 && (i < 64)) ? 0 : -1;
34 }
John Koleszare82d2612012-05-16 16:25:51 -070035
Yaowu Xuc27fc142016-08-22 16:08:15 -070036 virtual void TearDown() { libaom_test::ClearSystemState(); }
James Zern5b756742013-06-17 22:58:40 -070037
James Zern75d56b32014-07-16 18:57:11 -070038 IdctFunc UUT;
Yaowu Xuafffa3d2013-09-05 08:45:56 -070039 int16_t input[16];
James Zern36b882e2013-07-18 15:42:06 -070040 unsigned char output[256];
41 unsigned char predict[256];
John Koleszare82d2612012-05-16 16:25:51 -070042};
43
Yaowu Xu00555262013-03-12 11:24:04 -070044TEST_P(IDCTTest, TestGuardBlocks) {
James Zern36b882e2013-07-18 15:42:06 -070045 int i;
John Koleszare82d2612012-05-16 16:25:51 -070046
James Zern36b882e2013-07-18 15:42:06 -070047 for (i = 0; i < 256; i++)
48 if ((i & 0xF) < 4 && i < 64)
49 EXPECT_EQ(0, output[i]) << i;
50 else
51 EXPECT_EQ(255, output[i]);
James Berry0c1cec22012-02-21 11:57:14 -050052}
53
Yaowu Xu00555262013-03-12 11:24:04 -070054TEST_P(IDCTTest, TestAllZeros) {
James Zern36b882e2013-07-18 15:42:06 -070055 int i;
John Koleszare82d2612012-05-16 16:25:51 -070056
James Zern29e1b1a2014-07-09 21:02:02 -070057 ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
John Koleszare82d2612012-05-16 16:25:51 -070058
James Zern36b882e2013-07-18 15:42:06 -070059 for (i = 0; i < 256; i++)
60 if ((i & 0xF) < 4 && i < 64)
61 EXPECT_EQ(0, output[i]) << "i==" << i;
62 else
63 EXPECT_EQ(255, output[i]) << "i==" << i;
John Koleszare82d2612012-05-16 16:25:51 -070064}
65
Yaowu Xu00555262013-03-12 11:24:04 -070066TEST_P(IDCTTest, TestAllOnes) {
James Zern36b882e2013-07-18 15:42:06 -070067 int i;
John Koleszare82d2612012-05-16 16:25:51 -070068
James Zern36b882e2013-07-18 15:42:06 -070069 input[0] = 4;
James Zern29e1b1a2014-07-09 21:02:02 -070070 ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
John Koleszare82d2612012-05-16 16:25:51 -070071
James Zern36b882e2013-07-18 15:42:06 -070072 for (i = 0; i < 256; i++)
73 if ((i & 0xF) < 4 && i < 64)
74 EXPECT_EQ(1, output[i]) << "i==" << i;
75 else
76 EXPECT_EQ(255, output[i]) << "i==" << i;
John Koleszare82d2612012-05-16 16:25:51 -070077}
78
Yaowu Xu00555262013-03-12 11:24:04 -070079TEST_P(IDCTTest, TestAddOne) {
James Zern36b882e2013-07-18 15:42:06 -070080 int i;
John Koleszare82d2612012-05-16 16:25:51 -070081
James Zern36b882e2013-07-18 15:42:06 -070082 for (i = 0; i < 256; i++) predict[i] = i;
83 input[0] = 4;
James Zern29e1b1a2014-07-09 21:02:02 -070084 ASM_REGISTER_STATE_CHECK(UUT(input, predict, 16, output, 16));
John Koleszare82d2612012-05-16 16:25:51 -070085
James Zern36b882e2013-07-18 15:42:06 -070086 for (i = 0; i < 256; i++)
87 if ((i & 0xF) < 4 && i < 64)
88 EXPECT_EQ(i + 1, output[i]) << "i==" << i;
89 else
90 EXPECT_EQ(255, output[i]) << "i==" << i;
John Koleszare82d2612012-05-16 16:25:51 -070091}
92
Yaowu Xu00555262013-03-12 11:24:04 -070093TEST_P(IDCTTest, TestWithData) {
James Zern36b882e2013-07-18 15:42:06 -070094 int i;
John Koleszare82d2612012-05-16 16:25:51 -070095
James Zern36b882e2013-07-18 15:42:06 -070096 for (i = 0; i < 16; i++) input[i] = i;
John Koleszare82d2612012-05-16 16:25:51 -070097
James Zern29e1b1a2014-07-09 21:02:02 -070098 ASM_REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
John Koleszare82d2612012-05-16 16:25:51 -070099
James Zern36b882e2013-07-18 15:42:06 -0700100 for (i = 0; i < 256; i++)
101 if ((i & 0xF) > 3 || i > 63)
102 EXPECT_EQ(255, output[i]) << "i==" << i;
103 else if (i == 0)
104 EXPECT_EQ(11, output[i]) << "i==" << i;
105 else if (i == 34)
106 EXPECT_EQ(1, output[i]) << "i==" << i;
107 else if (i == 2 || i == 17 || i == 32)
108 EXPECT_EQ(3, output[i]) << "i==" << i;
109 else
110 EXPECT_EQ(0, output[i]) << "i==" << i;
John Koleszare82d2612012-05-16 16:25:51 -0700111}
James Berry0c1cec22012-02-21 11:57:14 -0500112
Yaowu Xuf883b422016-08-30 14:01:10 -0700113INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(aom_short_idct4x4llm_c));
John Koleszare82d2612012-05-16 16:25:51 -0700114#if HAVE_MMX
115INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700116 ::testing::Values(aom_short_idct4x4llm_mmx));
John Koleszare82d2612012-05-16 16:25:51 -0700117#endif
Parag Salasakar3d938d72015-07-02 18:08:06 +0530118#if HAVE_MSA
119INSTANTIATE_TEST_CASE_P(MSA, IDCTTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700120 ::testing::Values(aom_short_idct4x4llm_msa));
Parag Salasakar3d938d72015-07-02 18:08:06 +0530121#endif
James Berry0c1cec22012-02-21 11:57:14 -0500122}