1 #include <gtest/gtest.h>
2 #include <math.h>
3 #include <stdlib.h>
4 #include <time.h>
5
6 #include "cpu_core.h"
7 #include "cpu.h"
8 #include "macros.h"
9 #include "encode_mb_aux.h"
10 #include "wels_func_ptr_def.h"
11 #include "copy_mb.h"
12
13 using namespace WelsEnc;
14 #define MBCOPYTEST_NUM 1000
FillWithRandomData(uint8_t * p,int32_t Len)15 static void FillWithRandomData (uint8_t* p, int32_t Len) {
16 for (int32_t i = 0; i < Len; i++) {
17 p[i] = rand() % 256;
18 }
19 }
20
21
TEST(MBCopyFunTest,pfCopy8x8Aligned)22 TEST (MBCopyFunTest, pfCopy8x8Aligned) {
23 ENFORCE_STACK_ALIGN_1D (uint8_t, pSrcAlign, 16 * 64 + 1, 16)
24 ENFORCE_STACK_ALIGN_2D (uint8_t, pDstAlign, 2, 16 * 32 + 16, 16)
25
26 int32_t iCpuCores = 0;
27 SWelsFuncPtrList sFuncPtrList;
28 uint32_t m_uiCpuFeatureFlag = WelsCPUFeatureDetect (&iCpuCores);
29 WelsInitEncodingFuncs (&sFuncPtrList, m_uiCpuFeatureFlag);
30
31 for (int32_t k = 0; k < MBCOPYTEST_NUM; k++) {
32 memset (pDstAlign[0], 0, 16 * 32 + 1);
33 memset (pDstAlign[1], 0, 16 * 32 + 1);
34 FillWithRandomData ((uint8_t*)pSrcAlign, 16 * 64 + 1);
35 WelsCopy8x8_c (pDstAlign[0], 32, pSrcAlign, 64);
36 sFuncPtrList.pfCopy8x8Aligned (pDstAlign[1], 32, pSrcAlign, 64);
37
38 for (int32_t i = 0; i < 16 * 32 + 1; i++) {
39 ASSERT_EQ (pDstAlign[0][i], pDstAlign[1][i]);
40 }
41
42 }
43
44 }
45
TEST(MBCopyFunTest,pfCopy8x16Aligned)46 TEST (MBCopyFunTest, pfCopy8x16Aligned) {
47 ENFORCE_STACK_ALIGN_1D (uint8_t, pSrcAlign, 16 * 64 + 1, 16)
48 ENFORCE_STACK_ALIGN_2D (uint8_t, pDstAlign, 2, 16 * 32 + 16, 16)
49
50 int32_t iCpuCores = 0;
51 SWelsFuncPtrList sFuncPtrList;
52 uint32_t m_uiCpuFeatureFlag = WelsCPUFeatureDetect (&iCpuCores);
53 WelsInitEncodingFuncs (&sFuncPtrList, m_uiCpuFeatureFlag);
54
55 for (int32_t k = 0; k < MBCOPYTEST_NUM; k++) {
56 memset (pDstAlign[0], 0, 16 * 32 + 1);
57 memset (pDstAlign[1], 0, 16 * 32 + 1);
58 FillWithRandomData ((uint8_t*)pSrcAlign, 16 * 64 + 1);
59 WelsCopy8x16_c (pDstAlign[0], 32, pSrcAlign, 64);
60 sFuncPtrList.pfCopy8x16Aligned (pDstAlign[1], 32, pSrcAlign, 64);
61
62 for (int32_t i = 0; i < 16 * 32 + 1; i++) {
63 ASSERT_EQ (pDstAlign[0][i], pDstAlign[1][i]);
64 }
65
66 }
67
68 }
69
TEST(MBCopyFunTest,pfCopy16x16Aligned)70 TEST (MBCopyFunTest, pfCopy16x16Aligned) {
71 ENFORCE_STACK_ALIGN_1D (uint8_t, pSrcAlign, 16 * 64 + 1, 16)
72 ENFORCE_STACK_ALIGN_2D (uint8_t, pDstAlign, 2, 16 * 32 + 16, 16)
73
74 int32_t iCpuCores = 0;
75 SWelsFuncPtrList sFuncPtrList;
76 uint32_t m_uiCpuFeatureFlag = WelsCPUFeatureDetect (&iCpuCores);
77 WelsInitEncodingFuncs (&sFuncPtrList, m_uiCpuFeatureFlag);
78
79 for (int32_t k = 0; k < MBCOPYTEST_NUM; k++) {
80 memset (pDstAlign[0], 0, 16 * 32 + 1);
81 memset (pDstAlign[1], 0, 16 * 32 + 1);
82 FillWithRandomData ((uint8_t*)pSrcAlign, 16 * 64 + 1);
83 WelsCopy16x16_c (pDstAlign[0], 32, pSrcAlign, 64);
84 sFuncPtrList.pfCopy16x16Aligned (pDstAlign[1], 32, pSrcAlign, 64);
85
86 for (int32_t i = 0; i < 16 * 32 + 1; i++) {
87 ASSERT_EQ (pDstAlign[0][i], pDstAlign[1][i]);
88 }
89
90 }
91
92 }
93
TEST(MBCopyFunTest,pfCopy16x8NotAligned)94 TEST (MBCopyFunTest, pfCopy16x8NotAligned) {
95 ENFORCE_STACK_ALIGN_1D (uint8_t, pSrcAlign, 16 * 64 + 1, 16)
96 ENFORCE_STACK_ALIGN_2D (uint8_t, pDstAlign, 2, 16 * 32 + 16, 16)
97
98 int32_t iCpuCores = 0;
99 SWelsFuncPtrList sFuncPtrList;
100 uint32_t m_uiCpuFeatureFlag = WelsCPUFeatureDetect (&iCpuCores);
101 WelsInitEncodingFuncs (&sFuncPtrList, m_uiCpuFeatureFlag);
102
103 for (int32_t k = 0; k < MBCOPYTEST_NUM; k++) {
104 memset (pDstAlign[0], 0, 16 * 32 + 1);
105 memset (pDstAlign[1], 0, 16 * 32 + 1);
106 FillWithRandomData ((uint8_t*)pSrcAlign, 16 * 64 + 1);
107 WelsCopy16x8_c (pDstAlign[0], 32, pSrcAlign + 1, 64);
108 sFuncPtrList.pfCopy16x8NotAligned (pDstAlign[1], 32, pSrcAlign + 1, 64);
109
110 for (int32_t i = 0; i < 16 * 32 + 1; i++) {
111 ASSERT_EQ (pDstAlign[0][i], pDstAlign[1][i]);
112 }
113
114 }
115
116 }
117
TEST(MBCopyFunTest,pfCopy16x16NotAligned)118 TEST (MBCopyFunTest, pfCopy16x16NotAligned) {
119 ENFORCE_STACK_ALIGN_1D (uint8_t, pSrcAlign, 16 * 64 + 1, 16)
120 ENFORCE_STACK_ALIGN_2D (uint8_t, pDstAlign, 2, 16 * 32 + 16, 16)
121
122 int32_t iCpuCores = 0;
123 SWelsFuncPtrList sFuncPtrList;
124 uint32_t m_uiCpuFeatureFlag = WelsCPUFeatureDetect (&iCpuCores);
125 WelsInitEncodingFuncs (&sFuncPtrList, m_uiCpuFeatureFlag);
126
127 for (int32_t k = 0; k < MBCOPYTEST_NUM; k++) {
128 memset (pDstAlign[0], 0, 16 * 32 + 1);
129 memset (pDstAlign[1], 0, 16 * 32 + 1);
130 FillWithRandomData ((uint8_t*)pSrcAlign, 16 * 64 + 1);
131 WelsCopy16x16_c (pDstAlign[0], 32, pSrcAlign + 1, 64);
132 sFuncPtrList.pfCopy16x16NotAligned (pDstAlign[1], 32, pSrcAlign + 1, 64);
133
134 for (int32_t i = 0; i < 16 * 32 + 1; i++) {
135 ASSERT_EQ (pDstAlign[0][i], pDstAlign[1][i]);
136 }
137
138 }
139
140 }
141