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 "wels_func_ptr_def.h"
10 #include "../../codec/encoder/core/src/encoder.cpp"
11
12 using namespace WelsEnc;
13 #define MEMORYZEROTEST_NUM 1000
14
TEST(SetMemZeroFunTest,WelsSetMemZero)15 TEST (SetMemZeroFunTest, WelsSetMemZero) {
16 int32_t iLen = 64;
17 int32_t iCpuCores = 0;
18 SWelsFuncPtrList sFuncPtrList;
19 uint32_t uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores);
20 /* Functionality utilization of CPU instructions dependency */
21 sFuncPtrList.pfSetMemZeroSize8 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage
22 sFuncPtrList.pfSetMemZeroSize64Aligned16 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage
23 sFuncPtrList.pfSetMemZeroSize64 = WelsSetMemZero_c; // confirmed_safe_unsafe_usage
24 #if defined(X86_ASM)
25 if (uiCpuFlag & WELS_CPU_MMXEXT) {
26 sFuncPtrList.pfSetMemZeroSize8 = WelsSetMemZeroSize8_mmx; // confirmed_safe_unsafe_usage
27 sFuncPtrList.pfSetMemZeroSize64Aligned16 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage
28 sFuncPtrList.pfSetMemZeroSize64 = WelsSetMemZeroSize64_mmx; // confirmed_safe_unsafe_usage
29 }
30 if (uiCpuFlag & WELS_CPU_SSE2) {
31 sFuncPtrList.pfSetMemZeroSize64Aligned16 = WelsSetMemZeroAligned64_sse2; // confirmed_safe_unsafe_usage
32 }
33 #else
34 (void) uiCpuFlag; // Avoid warnings if no assembly is enabled
35 #endif//X86_ASM
36
37 #if defined(HAVE_NEON)
38 if (uiCpuFlag & WELS_CPU_NEON) {
39 sFuncPtrList.pfSetMemZeroSize8 = WelsSetMemZero_neon;
40 sFuncPtrList.pfSetMemZeroSize64Aligned16 = WelsSetMemZero_neon;
41 sFuncPtrList.pfSetMemZeroSize64 = WelsSetMemZero_neon;
42 }
43 #endif
44
45 #if defined(HAVE_NEON_AARCH64)
46 if (uiCpuFlag & WELS_CPU_NEON) {
47 sFuncPtrList.pfSetMemZeroSize8 = WelsSetMemZero_AArch64_neon;
48 sFuncPtrList.pfSetMemZeroSize64Aligned16 = WelsSetMemZero_AArch64_neon;
49 sFuncPtrList.pfSetMemZeroSize64 = WelsSetMemZero_AArch64_neon;
50 }
51 #endif
52
53 ENFORCE_STACK_ALIGN_2D (uint8_t, pInputAlign, 2, 64 * 101, 16)
54
55 for (int32_t k = 0; k < MEMORYZEROTEST_NUM; k++) {
56 memset (pInputAlign[0], 255, 64 * 101);
57 memset (pInputAlign[1], 255, 64 * 101);
58 iLen = 64 * (1 + (rand() % 100));
59 WelsSetMemZero_c (pInputAlign[0], iLen);
60 sFuncPtrList.pfSetMemZeroSize64Aligned16 (pInputAlign[1], iLen);
61 for (int32_t i = 0 ; i < 64 * 101; i++) {
62 ASSERT_EQ (pInputAlign[0][i], pInputAlign[1][i]);
63 }
64 }
65
66 for (int32_t k = 0; k < MEMORYZEROTEST_NUM; k++) {
67 memset (pInputAlign[0], 255, 64 * 101);
68 memset (pInputAlign[1], 255, 64 * 101);
69 iLen = 64 * (1 + (rand() % 100));
70 WelsSetMemZero_c (pInputAlign[0] + 1, iLen);
71 sFuncPtrList.pfSetMemZeroSize64 (pInputAlign[1] + 1, iLen);
72 for (int32_t i = 0 ; i < 64 * 101; i++) {
73 ASSERT_EQ (pInputAlign[0][i], pInputAlign[1][i]);
74 }
75 }
76
77 memset (pInputAlign[0], 255, 64 * 101);
78 memset (pInputAlign[1], 255, 64 * 101);
79 iLen = 32;
80 WelsSetMemZero_c (pInputAlign[0] + 1, iLen);
81 sFuncPtrList.pfSetMemZeroSize8 (pInputAlign[1] + 1, iLen);
82 for (int32_t i = 0 ; i < 64 * 101; i++) {
83 ASSERT_EQ (pInputAlign[0][i], pInputAlign[1][i]);
84 }
85
86 memset (pInputAlign[0], 255, 64 * 101);
87 memset (pInputAlign[1], 255, 64 * 101);
88 iLen = 24;
89 WelsSetMemZero_c (pInputAlign[0] + 1, iLen);
90 sFuncPtrList.pfSetMemZeroSize8 (pInputAlign[1] + 1, iLen);
91 for (int32_t i = 0 ; i < 64 * 101; i++) {
92 ASSERT_EQ (pInputAlign[0][i], pInputAlign[1][i]);
93 }
94 }
95
96
97