OLD | NEW |
(Empty) | |
| 1 /* crosstest.py --test=test_icmp.cpp --driver=test_icmp_main.cpp \ |
| 2 --prefix=Subzero_ --output=test_icmp */ |
| 3 |
| 4 #include <stdint.h> |
| 5 #include <iostream> |
| 6 |
| 7 // Include test_icmp.h twice - once normally, and once within the |
| 8 // Subzero_ namespace, corresponding to the llc and Subzero translated |
| 9 // object files, respectively. |
| 10 #include "test_icmp.h" |
| 11 namespace Subzero_ { |
| 12 #include "test_icmp.h" |
| 13 } |
| 14 |
| 15 volatile unsigned Values[] = { 0x0, 0x1, 0x7ffffffe, 0x7fffffff, |
| 16 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, |
| 17 0x7e, 0x7f, 0x80, 0x81, |
| 18 0xfe, 0xff, 0x100, 0x101, |
| 19 0x7ffe, 0x7fff, 0x8000, 0x8001, |
| 20 0xfffe, 0xffff, 0x10000, 0x10001, }; |
| 21 const static size_t NumValues = sizeof(Values) / sizeof(*Values); |
| 22 |
| 23 template <typename TypeUnsigned, typename TypeSigned> |
| 24 void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 25 typedef bool (*FuncTypeUnsigned)(TypeUnsigned, TypeUnsigned); |
| 26 typedef bool (*FuncTypeSigned)(TypeSigned, TypeSigned); |
| 27 static struct { |
| 28 const char *Name; |
| 29 FuncTypeUnsigned FuncLlc; |
| 30 FuncTypeUnsigned FuncSz; |
| 31 } Funcs[] = { |
| 32 #define X(cmp, op) \ |
| 33 { \ |
| 34 STR(inst), (FuncTypeUnsigned)icmp##cmp, \ |
| 35 (FuncTypeUnsigned)Subzero_::icmp##cmp \ |
| 36 } \ |
| 37 , |
| 38 ICMP_U_TABLE |
| 39 #undef X |
| 40 #define X(cmp, op) \ |
| 41 { \ |
| 42 STR(inst), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ |
| 43 (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \ |
| 44 } \ |
| 45 , |
| 46 ICMP_S_TABLE |
| 47 #undef X |
| 48 }; |
| 49 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 50 |
| 51 if (sizeof(TypeUnsigned) <= sizeof(uint32_t)) { |
| 52 // This is the "normal" version of the loop nest, for 32-bit or |
| 53 // narrower types. |
| 54 for (size_t f = 0; f < NumFuncs; ++f) { |
| 55 for (size_t i = 0; i < NumValues; ++i) { |
| 56 for (size_t j = 0; j < NumValues; ++j) { |
| 57 TypeUnsigned Value1 = Values[i]; |
| 58 TypeUnsigned Value2 = Values[j]; |
| 59 ++TotalTests; |
| 60 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 61 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| 62 if (ResultSz == ResultLlc) { |
| 63 ++Passes; |
| 64 } else { |
| 65 ++Failures; |
| 66 std::cout << "icmp" << Funcs[f].Name << (8 * sizeof(TypeUnsigned)) |
| 67 << "(" << Value1 << ", " << Value2 << "): sz=" << ResultSz |
| 68 << " llc=" << ResultLlc << std::endl; |
| 69 } |
| 70 } |
| 71 } |
| 72 } |
| 73 } else { |
| 74 // This is the 64-bit version. Test values are synthesized from |
| 75 // the 32-bit values in Values[]. |
| 76 for (size_t f = 0; f < NumFuncs; ++f) { |
| 77 for (size_t iLo = 0; iLo < NumValues; ++iLo) { |
| 78 for (size_t iHi = 0; iHi < NumValues; ++iHi) { |
| 79 for (size_t jLo = 0; jLo < NumValues; ++jLo) { |
| 80 for (size_t jHi = 0; jHi < NumValues; ++jHi) { |
| 81 TypeUnsigned Value1 = |
| 82 (((TypeUnsigned)Values[iHi]) << 32) + Values[iLo]; |
| 83 TypeUnsigned Value2 = |
| 84 (((TypeUnsigned)Values[jHi]) << 32) + Values[jLo]; |
| 85 ++TotalTests; |
| 86 bool ResultSz = Funcs[f].FuncSz(Value1, Value2); |
| 87 bool ResultLlc = Funcs[f].FuncLlc(Value1, Value2); |
| 88 if (ResultSz == ResultLlc) { |
| 89 ++Passes; |
| 90 } else { |
| 91 ++Failures; |
| 92 std::cout << "icmp" << Funcs[f].Name |
| 93 << (8 * sizeof(TypeUnsigned)) << "(" << Value1 << ", " |
| 94 << Value2 << "): sz=" << ResultSz |
| 95 << " llc=" << ResultLlc << std::endl; |
| 96 } |
| 97 } |
| 98 } |
| 99 } |
| 100 } |
| 101 } |
| 102 } |
| 103 } |
| 104 |
| 105 int main(int argc, char **argv) { |
| 106 size_t TotalTests = 0; |
| 107 size_t Passes = 0; |
| 108 size_t Failures = 0; |
| 109 |
| 110 testsInt<uint8_t, int8_t>(TotalTests, Passes, Failures); |
| 111 testsInt<uint16_t, int16_t>(TotalTests, Passes, Failures); |
| 112 testsInt<uint32_t, int32_t>(TotalTests, Passes, Failures); |
| 113 testsInt<uint64_t, int64_t>(TotalTests, Passes, Failures); |
| 114 |
| 115 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 116 << " Failures=" << Failures << "\n"; |
| 117 return Failures; |
| 118 } |
OLD | NEW |