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