OLD | NEW |
1 //===- subzero/crosstest/test_bitmanip_main.cpp - Driver for tests. -------===// | 1 //===- subzero/crosstest/test_bitmanip_main.cpp - Driver for tests. -------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Driver for cross testing bit manipulation intrinsics. | 10 // Driver for cross testing bit manipulation intrinsics. |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // Include test_bitmanip.h twice - once normally, and once within the | 22 // Include test_bitmanip.h twice - once normally, and once within the |
23 // Subzero_ namespace, corresponding to the llc and Subzero translated | 23 // Subzero_ namespace, corresponding to the llc and Subzero translated |
24 // object files, respectively. | 24 // object files, respectively. |
25 #include "test_bitmanip.h" | 25 #include "test_bitmanip.h" |
26 namespace Subzero_ { | 26 namespace Subzero_ { |
27 #include "test_bitmanip.h" | 27 #include "test_bitmanip.h" |
28 } | 28 } |
29 | 29 |
30 volatile uint64_t Values[] = { | 30 volatile uint64_t Values[] = { |
31 0, 1, 0x7e, | 31 0, 1, |
32 0x7f, 0x80, 0x81, | 32 0x7e, 0x7f, |
33 0xfe, 0xff, 0x7ffe, | 33 0x80, 0x81, |
34 0x7fff, 0x8000, 0x8001, | 34 0xfe, 0xff, |
35 0xfffe, 0xffff, | 35 0x7ffe, 0x7fff, |
36 0x007fffff /*Max subnormal + */, | 36 0x8000, 0x8001, |
37 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, | 37 0xfffe, 0xffff, |
38 0x7f800000 /*+Inf*/, 0xff800000 /*-Inf*/, | 38 0xc0de, 0xabcd, |
39 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, | 39 0xdcba, 0x007fffff /*Max subnormal + */, |
40 0x7ffffffe, 0x7fffffff, 0x80000000, | 40 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, |
41 0x80000001, 0xfffffffe, 0xffffffff, | 41 0x7f800000 /*+Inf*/, 0xff800000 /*-Inf*/, |
42 0x100000000ll, 0x100000001ll, | 42 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, |
43 0x000fffffffffffffll /*Max subnormal + */, | 43 0x7ffffffe, 0x7fffffff, |
44 0x0010000000000000ll /*Min+ */, | 44 0x80000000, 0x80000001, |
45 0x7fefffffffffffffll /*Max+ */, | 45 0xfffffffe, 0xffffffff, |
46 0x7ff0000000000000ll /*+Inf*/, | 46 0x12345678, 0xabcd1234, |
47 0xfff0000000000000ll /*-Inf*/, | 47 0x1234dcba, 0x100000000ll, |
48 0x7ff0000000000001ll /*SNaN*/, | 48 0x100000001ll, 0x123456789abcdef1ll, |
49 0x7ff8000000000000ll /*QNaN*/, | 49 0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */, |
50 0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, | 50 0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */, |
51 0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll }; | 51 0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/, |
| 52 0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/, |
| 53 0x7ffffffffffffffell, 0x7fffffffffffffffll, |
| 54 0x8000000000000000ll, 0x8000000000000001ll, |
| 55 0xfffffffffffffffell, 0xffffffffffffffffll}; |
52 | 56 |
53 const static size_t NumValues = sizeof(Values) / sizeof(*Values); | 57 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
54 | 58 |
55 template <typename Type> | 59 template <typename Type> |
56 void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 60 void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
57 typedef Type (*FuncType)(Type); | 61 typedef Type (*FuncType)(Type); |
58 static struct { | 62 static struct { |
59 const char *Name; | 63 const char *Name; |
60 FuncType FuncLlc; | 64 FuncType FuncLlc; |
61 FuncType FuncSz; | 65 FuncType FuncSz; |
(...skipping 27 matching lines...) Expand all Loading... |
89 << (CHAR_BIT * sizeof(Type)) << "(" | 93 << (CHAR_BIT * sizeof(Type)) << "(" |
90 << static_cast<uint64_t>(Value) | 94 << static_cast<uint64_t>(Value) |
91 << "): sz=" << static_cast<uint64_t>(ResultSz) | 95 << "): sz=" << static_cast<uint64_t>(ResultSz) |
92 << " llc=" << static_cast<uint64_t>(ResultLlc) | 96 << " llc=" << static_cast<uint64_t>(ResultLlc) |
93 << "\n"; | 97 << "\n"; |
94 } | 98 } |
95 } | 99 } |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
| 103 template <typename Type> |
| 104 void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 105 for (size_t i = 0; i < NumValues; ++i) { |
| 106 Type Value = static_cast<Type>(Values[i]); |
| 107 ++TotalTests; |
| 108 Type ResultSz = test_bswap(Value); |
| 109 Type ResultLlc = Subzero_::test_bswap(Value); |
| 110 if (ResultSz == ResultLlc) { |
| 111 ++Passes; |
| 112 } else { |
| 113 ++Failures; |
| 114 std::cout << "test_bswap" << (CHAR_BIT * sizeof(Type)) << "(" |
| 115 << static_cast<uint64_t>(Value) |
| 116 << "): sz=" << static_cast<uint64_t>(ResultSz) |
| 117 << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n"; |
| 118 } |
| 119 } |
| 120 } |
| 121 |
99 int main(int argc, char **argv) { | 122 int main(int argc, char **argv) { |
100 size_t TotalTests = 0; | 123 size_t TotalTests = 0; |
101 size_t Passes = 0; | 124 size_t Passes = 0; |
102 size_t Failures = 0; | 125 size_t Failures = 0; |
103 | 126 |
104 testBitManip<uint32_t>(TotalTests, Passes, Failures); | 127 testBitManip<uint32_t>(TotalTests, Passes, Failures); |
105 testBitManip<uint64_t>(TotalTests, Passes, Failures); | 128 testBitManip<uint64_t>(TotalTests, Passes, Failures); |
| 129 testByteSwap<uint16_t>(TotalTests, Passes, Failures); |
| 130 testByteSwap<uint32_t>(TotalTests, Passes, Failures); |
| 131 testByteSwap<uint64_t>(TotalTests, Passes, Failures); |
106 | 132 |
107 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | 133 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
108 << " Failures=" << Failures << "\n"; | 134 << " Failures=" << Failures << "\n"; |
109 return Failures; | 135 return Failures; |
110 } | 136 } |
OLD | NEW |