Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 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[] = { |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 31 | 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, |
| 32 | 0xfffe, 0xffff, 0xc0de, 0xabcd, 0xdcba, 0x007fffff /*Max subnormal + */, |
| 33 | 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, 0x7f800000 /*+Inf*/, |
| 34 | 0xff800000 /*-Inf*/, 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, 0x7ffffffe, |
| 35 | 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x12345678, |
| 36 | 0xabcd1234, 0x1234dcba, 0x100000000ll, 0x100000001ll, 0x123456789abcdef1ll, |
| 37 | 0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */, |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 38 | 0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */, |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 39 | 0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/, |
| 40 | 0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/, |
| 41 | 0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, |
| 42 | 0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll}; |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 43 | |
| 44 | const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 45 | |
| 46 | template <typename Type> |
| 47 | void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 48 | typedef Type (*FuncType)(Type); |
| 49 | static struct { |
| 50 | const char *Name; |
| 51 | FuncType FuncLlc; |
| 52 | FuncType FuncSz; |
| 53 | } Funcs[] = { |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 54 | #define X(inst) \ |
| 55 | { STR(inst), test_##inst, Subzero_::test_##inst } \ |
| 56 | , {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \ |
| 57 | {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst}, |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 58 | BMI_OPS |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 59 | #undef X |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 60 | }; |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 61 | const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 62 | |
| 63 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 64 | for (size_t i = 0; i < NumValues; ++i) { |
| 65 | Type Value = static_cast<Type>(Values[i]); |
| 66 | ++TotalTests; |
| 67 | Type ResultSz = Funcs[f].FuncSz(Value); |
| 68 | Type ResultLlc = Funcs[f].FuncLlc(Value); |
| 69 | if (ResultSz == ResultLlc) { |
| 70 | ++Passes; |
| 71 | } else { |
| 72 | ++Failures; |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 73 | std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type)) |
| 74 | << "(" << static_cast<uint64_t>(Value) |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 75 | << "): sz=" << static_cast<uint64_t>(ResultSz) |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 76 | << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n"; |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 82 | template <typename Type> |
| 83 | void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 84 | typedef Type (*FuncType)(Type); |
| 85 | static struct { |
| 86 | const char *Name; |
| 87 | FuncType FuncLlc; |
| 88 | FuncType FuncSz; |
| 89 | } Funcs[] = { |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 90 | {"bswap", test_bswap, Subzero_::test_bswap}, |
| 91 | {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}}; |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 92 | const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 93 | for (size_t f = 0; f < NumFuncs; ++f) { |
| 94 | for (size_t i = 0; i < NumValues; ++i) { |
| 95 | Type Value = static_cast<Type>(Values[i]); |
| 96 | ++TotalTests; |
| 97 | Type ResultSz = Funcs[f].FuncSz(Value); |
| 98 | Type ResultLlc = Funcs[f].FuncLlc(Value); |
| 99 | if (ResultSz == ResultLlc) { |
| 100 | ++Passes; |
| 101 | } else { |
| 102 | ++Failures; |
| 103 | std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type)) |
| 104 | << "(" << static_cast<uint64_t>(Value) |
| 105 | << "): sz=" << static_cast<uint64_t>(ResultSz) |
| 106 | << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n"; |
| 107 | } |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 112 | int main(int argc, char **argv) { |
| 113 | size_t TotalTests = 0; |
| 114 | size_t Passes = 0; |
| 115 | size_t Failures = 0; |
| 116 | |
| 117 | testBitManip<uint32_t>(TotalTests, Passes, Failures); |
| 118 | testBitManip<uint64_t>(TotalTests, Passes, Failures); |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 119 | testByteSwap<uint16_t>(TotalTests, Passes, Failures); |
| 120 | testByteSwap<uint32_t>(TotalTests, Passes, Failures); |
| 121 | testByteSwap<uint64_t>(TotalTests, Passes, Failures); |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 122 | |
| 123 | std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 124 | << " Failures=" << Failures << "\n"; |
| 125 | return Failures; |
| 126 | } |