• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* crosstest.py --test=mem_intrin.cpp --driver=mem_intrin_main.cpp \
2    --prefix=Subzero_ --output=mem_intrin */
3 
4 #include <stdint.h> /* cstdint requires -std=c++0x or higher */
5 #include <cstdio>
6 
7 #include "mem_intrin.h"
8 #include "xdefs.h"
9 
10 namespace Subzero_ {
11 #include "mem_intrin.h"
12 }
13 
14 #define XSTR(s) STR(s)
15 #define STR(s) #s
16 
testVariableLen(SizeT & TotalTests,SizeT & Passes,SizeT & Failures)17 void testVariableLen(SizeT &TotalTests, SizeT &Passes, SizeT &Failures) {
18   uint8_t buf[256];
19   uint8_t buf2[256];
20 #define do_test_variable(test_func)                                            \
21   for (SizeT len = 4; len < 128; ++len) {                                      \
22     for (uint8_t init_val = 0; init_val < 100; ++init_val) {                   \
23       ++TotalTests;                                                            \
24       int llc_result = test_func(buf, buf2, init_val, len);                    \
25       int sz_result = Subzero_::test_func(buf, buf2, init_val, len);           \
26       if (llc_result == sz_result) {                                           \
27         ++Passes;                                                              \
28       } else {                                                                 \
29         ++Failures;                                                            \
30         printf("Failure (%s): init_val=%d, len=%d, llc=%d, sz=%d\n",           \
31                STR(test_func), init_val, len, llc_result, sz_result);          \
32       }                                                                        \
33     }                                                                          \
34   }
35 
36   do_test_variable(memcpy_test);
37   do_test_variable(memmove_test);
38   do_test_variable(memset_test)
39 #undef do_test_variable
40 }
41 
testFixedLen(SizeT & TotalTests,SizeT & Passes,SizeT & Failures)42 void testFixedLen(SizeT &TotalTests, SizeT &Passes, SizeT &Failures) {
43 #define do_test_fixed(test_func, NBYTES)                                       \
44   for (uint8_t init_val = 0; init_val < 100; ++init_val) {                     \
45     ++TotalTests;                                                              \
46     int llc_result = test_func##_##NBYTES(init_val);                           \
47     int sz_result = Subzero_::test_func##_##NBYTES(init_val);                  \
48     if (llc_result == sz_result) {                                             \
49       ++Passes;                                                                \
50     } else {                                                                   \
51       ++Failures;                                                              \
52       printf("Failure (%s): init_val=%d, len=%d, llc=%d, sz=%d\n",             \
53              STR(test_func), init_val, NBYTES, llc_result, sz_result);         \
54     }                                                                          \
55   }
56 
57 #define X(NBYTES)                                                              \
58   do_test_fixed(memcpy_test_fixed_len, NBYTES);                                \
59   do_test_fixed(memmove_test_fixed_len, NBYTES);                               \
60   do_test_fixed(memset_test_fixed_len, NBYTES);
61   MEMINTRIN_SIZE_TABLE
62 #undef X
63 #undef do_test_fixed
64 }
65 
main(int argc,char * argv[])66 int main(int argc, char *argv[]) {
67   unsigned TotalTests = 0;
68   unsigned Passes = 0;
69   unsigned Failures = 0;
70   testFixedLen(TotalTests, Passes, Failures);
71   testVariableLen(TotalTests, Passes, Failures);
72   printf("TotalTests=%u Passes=%u Failures=%u\n", TotalTests, Passes, Failures);
73   return Failures;
74 }
75