OLD | NEW |
(Empty) | |
| 1 //===- subzero/crosstest/test_bitmanip_main.cpp - Driver for tests. -------===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // Driver for cross testing bit manipulation intrinsics. |
| 11 // |
| 12 //===----------------------------------------------------------------------===// |
| 13 |
| 14 /* crosstest.py --test=test_bitmanip.cpp --test=test_bitmanip_intrin.ll \ |
| 15 --driver=test_bitmanip_main.cpp --prefix=Subzero_ --output=test_bitmanip */ |
| 16 |
| 17 #include <stdint.h> |
| 18 |
| 19 #include <climits> |
| 20 #include <iostream> |
| 21 |
| 22 // Include test_bitmanip.h twice - once normally, and once within the |
| 23 // Subzero_ namespace, corresponding to the llc and Subzero translated |
| 24 // object files, respectively. |
| 25 #include "test_bitmanip.h" |
| 26 namespace Subzero_ { |
| 27 #include "test_bitmanip.h" |
| 28 } |
| 29 |
| 30 volatile uint64_t Values[] = { |
| 31 0, 1, 0x7e, |
| 32 0x7f, 0x80, 0x81, |
| 33 0xfe, 0xff, 0x7ffe, |
| 34 0x7fff, 0x8000, 0x8001, |
| 35 0xfffe, 0xffff, |
| 36 0x007fffff /*Max subnormal + */, |
| 37 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, |
| 38 0x7f800000 /*+Inf*/, 0xff800000 /*-Inf*/, |
| 39 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, |
| 40 0x7ffffffe, 0x7fffffff, 0x80000000, |
| 41 0x80000001, 0xfffffffe, 0xffffffff, |
| 42 0x100000000ll, 0x100000001ll, |
| 43 0x000fffffffffffffll /*Max subnormal + */, |
| 44 0x0010000000000000ll /*Min+ */, |
| 45 0x7fefffffffffffffll /*Max+ */, |
| 46 0x7ff0000000000000ll /*+Inf*/, |
| 47 0xfff0000000000000ll /*-Inf*/, |
| 48 0x7ff0000000000001ll /*SNaN*/, |
| 49 0x7ff8000000000000ll /*QNaN*/, |
| 50 0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, |
| 51 0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll }; |
| 52 |
| 53 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 54 |
| 55 template <typename Type> |
| 56 void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 57 typedef Type (*FuncType)(Type); |
| 58 static struct { |
| 59 const char *Name; |
| 60 FuncType FuncLlc; |
| 61 FuncType FuncSz; |
| 62 } Funcs[] = { |
| 63 #define X(inst) \ |
| 64 { \ |
| 65 STR(inst), test_##inst, Subzero_::test_##inst \ |
| 66 }, \ |
| 67 { \ |
| 68 STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst \ |
| 69 }, \ |
| 70 { \ |
| 71 STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst \ |
| 72 }, |
| 73 BMI_OPS |
| 74 #undef X |
| 75 }; |
| 76 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 77 |
| 78 for (size_t f = 0; f < NumFuncs; ++f) { |
| 79 for (size_t i = 0; i < NumValues; ++i) { |
| 80 Type Value = static_cast<Type>(Values[i]); |
| 81 ++TotalTests; |
| 82 Type ResultSz = Funcs[f].FuncSz(Value); |
| 83 Type ResultLlc = Funcs[f].FuncLlc(Value); |
| 84 if (ResultSz == ResultLlc) { |
| 85 ++Passes; |
| 86 } else { |
| 87 ++Failures; |
| 88 std::cout << "test_" << Funcs[f].Name |
| 89 << (CHAR_BIT * sizeof(Type)) << "(" |
| 90 << static_cast<uint64_t>(Value) |
| 91 << "): sz=" << static_cast<uint64_t>(ResultSz) |
| 92 << " llc=" << static_cast<uint64_t>(ResultLlc) |
| 93 << "\n"; |
| 94 } |
| 95 } |
| 96 } |
| 97 } |
| 98 |
| 99 int main(int argc, char **argv) { |
| 100 size_t TotalTests = 0; |
| 101 size_t Passes = 0; |
| 102 size_t Failures = 0; |
| 103 |
| 104 testBitManip<uint32_t>(TotalTests, Passes, Failures); |
| 105 testBitManip<uint64_t>(TotalTests, Passes, Failures); |
| 106 |
| 107 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 108 << " Failures=" << Failures << "\n"; |
| 109 return Failures; |
| 110 } |
OLD | NEW |