| OLD | NEW |
| 1 //===- subzero/crosstest/test_fcmp_main.cpp - Driver for tests ------------===// | 1 //===- subzero/crosstest/test_fcmp_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 the fcmp bitcode instruction | 10 // Driver for cross testing the fcmp bitcode instruction |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 /* crosstest.py --test=test_fcmp.pnacl.ll --driver=test_fcmp_main.cpp \ | 14 /* crosstest.py --test=test_fcmp.pnacl.ll --driver=test_fcmp_main.cpp \ |
| 15 --prefix=Subzero_ --output=test_fcmp */ | 15 --prefix=Subzero_ --output=test_fcmp */ |
| 16 | 16 |
| 17 #include <cassert> | 17 #include <cassert> |
| 18 #include <cfloat> | 18 #include <cfloat> |
| 19 #include <cmath> | 19 #include <cmath> |
| 20 #include <cstring> | 20 #include <cstring> |
| 21 #include <iostream> | 21 #include <iostream> |
| 22 | 22 |
| 23 #include "vectors.h" | 23 #include "vectors.h" |
| 24 #include "test_arith.def" | 24 #include "test_arith.def" |
| 25 #include "test_fcmp.def" | 25 #include "test_fcmp.def" |
| 26 | 26 |
| 27 #define X(cmp) \ | 27 #define X(cmp) \ |
| 28 extern "C" bool fcmp##cmp##Float(float a, float b); \ | 28 extern "C" bool fcmp##cmp##Float(float a, float b); \ |
| 29 extern "C" bool fcmp##cmp##Double(double a, double b); \ | 29 extern "C" bool fcmp##cmp##Double(double a, double b); \ |
| 30 extern "C" int fcmpSelect##cmp##Float(float a, float b, int c, int d); \ |
| 31 extern "C" int fcmpSelect##cmp##Double(double a, double b, int c, int d); \ |
| 30 extern "C" v4si32 fcmp##cmp##Vector(v4f32 a, v4f32 b); \ | 32 extern "C" v4si32 fcmp##cmp##Vector(v4f32 a, v4f32 b); \ |
| 31 extern "C" bool Subzero_fcmp##cmp##Float(float a, float b); \ | 33 extern "C" bool Subzero_fcmp##cmp##Float(float a, float b); \ |
| 32 extern "C" bool Subzero_fcmp##cmp##Double(double a, double b); \ | 34 extern "C" bool Subzero_fcmp##cmp##Double(double a, double b); \ |
| 35 extern "C" int Subzero_fcmpSelect##cmp##Float(float a, float b, int c, \ |
| 36 int d); \ |
| 37 extern "C" int Subzero_fcmpSelect##cmp##Double(double a, double b, int c, \ |
| 38 int d); \ |
| 33 extern "C" v4si32 Subzero_fcmp##cmp##Vector(v4f32 a, v4f32 b); | 39 extern "C" v4si32 Subzero_fcmp##cmp##Vector(v4f32 a, v4f32 b); |
| 34 FCMP_TABLE; | 40 FCMP_TABLE; |
| 35 #undef X | 41 #undef X |
| 36 | 42 |
| 37 volatile double *Values; | 43 volatile double *Values; |
| 38 size_t NumValues; | 44 size_t NumValues; |
| 39 | 45 |
| 40 void initializeValues() { | 46 void initializeValues() { |
| 41 static const double NegInf = -1.0 / 0.0; | 47 static const double NegInf = -1.0 / 0.0; |
| 42 static const double Zero = 0.0; | 48 static const double Zero = 0.0; |
| 43 static const double PosInf = 1.0 / 0.0; | 49 static const double PosInf = 1.0 / 0.0; |
| 44 static const double Nan = 0.0 / 0.0; | 50 static const double Nan = 0.0 / 0.0; |
| 45 static const double NegNan = -0.0 / 0.0; | 51 static const double NegNan = -0.0 / 0.0; |
| 46 assert(std::fpclassify(NegInf) == FP_INFINITE); | 52 assert(std::fpclassify(NegInf) == FP_INFINITE); |
| 47 assert(std::fpclassify(PosInf) == FP_INFINITE); | 53 assert(std::fpclassify(PosInf) == FP_INFINITE); |
| 48 assert(std::fpclassify(Nan) == FP_NAN); | 54 assert(std::fpclassify(Nan) == FP_NAN); |
| 49 assert(std::fpclassify(NegNan) == FP_NAN); | 55 assert(std::fpclassify(NegNan) == FP_NAN); |
| 50 assert(NegInf < Zero); | 56 assert(NegInf < Zero); |
| 51 assert(NegInf < PosInf); | 57 assert(NegInf < PosInf); |
| 52 assert(Zero < PosInf); | 58 assert(Zero < PosInf); |
| 53 static volatile double InitValues[] = | 59 static volatile double InitValues[] = |
| 54 FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); | 60 FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan); |
| 55 NumValues = sizeof(InitValues) / sizeof(*InitValues); | 61 NumValues = sizeof(InitValues) / sizeof(*InitValues); |
| 56 Values = InitValues; | 62 Values = InitValues; |
| 57 } | 63 } |
| 58 | 64 |
| 59 void testsScalar(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 65 void testsScalar(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 60 typedef bool (*FuncTypeFloat)(float, float); | 66 typedef bool (*FuncTypeFloat)(float, float); |
| 61 typedef bool (*FuncTypeDouble)(double, double); | 67 typedef bool (*FuncTypeDouble)(double, double); |
| 68 typedef int (*FuncTypeFloatSelect)(float, float, int, int); |
| 69 typedef int (*FuncTypeDoubleSelect)(double, double, int, int); |
| 62 static struct { | 70 static struct { |
| 63 const char *Name; | 71 const char *Name; |
| 64 FuncTypeFloat FuncFloatSz; | 72 FuncTypeFloat FuncFloatSz; |
| 65 FuncTypeFloat FuncFloatLlc; | 73 FuncTypeFloat FuncFloatLlc; |
| 66 FuncTypeDouble FuncDoubleSz; | 74 FuncTypeDouble FuncDoubleSz; |
| 67 FuncTypeDouble FuncDoubleLlc; | 75 FuncTypeDouble FuncDoubleLlc; |
| 76 FuncTypeFloatSelect FuncFloatSelectSz; |
| 77 FuncTypeFloatSelect FuncFloatSelectLlc; |
| 78 FuncTypeDoubleSelect FuncDoubleSelectSz; |
| 79 FuncTypeDoubleSelect FuncDoubleSelectLlc; |
| 68 } Funcs[] = { | 80 } Funcs[] = { |
| 69 #define X(cmp) \ | 81 #define X(cmp) \ |
| 70 { \ | 82 { \ |
| 71 "fcmp" STR(cmp), Subzero_fcmp##cmp##Float, fcmp##cmp##Float, \ | 83 "fcmp" STR(cmp), Subzero_fcmp##cmp##Float, fcmp##cmp##Float, \ |
| 72 Subzero_fcmp##cmp##Double, fcmp##cmp##Double \ | 84 Subzero_fcmp##cmp##Double, fcmp##cmp##Double, \ |
| 85 Subzero_fcmpSelect##cmp##Float, fcmpSelect##cmp##Float, \ |
| 86 Subzero_fcmpSelect##cmp##Double, fcmpSelect##cmp##Double \ |
| 73 } \ | 87 } \ |
| 74 , | 88 , |
| 75 FCMP_TABLE | 89 FCMP_TABLE |
| 76 #undef X | 90 #undef X |
| 77 }; | 91 }; |
| 78 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); | 92 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); |
| 79 | 93 |
| 80 bool ResultSz, ResultLlc; | 94 bool ResultSz, ResultLlc; |
| 81 | 95 |
| 82 assert(Values && NumValues); | 96 assert(Values && NumValues); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 103 ResultSz = Funcs[f].FuncDoubleSz(Value1Double, Value2Double); | 117 ResultSz = Funcs[f].FuncDoubleSz(Value1Double, Value2Double); |
| 104 ResultLlc = Funcs[f].FuncDoubleLlc(Value1Double, Value2Double); | 118 ResultLlc = Funcs[f].FuncDoubleLlc(Value1Double, Value2Double); |
| 105 if (ResultSz == ResultLlc) { | 119 if (ResultSz == ResultLlc) { |
| 106 ++Passes; | 120 ++Passes; |
| 107 } else { | 121 } else { |
| 108 ++Failures; | 122 ++Failures; |
| 109 std::cout << Funcs[f].Name << "Double(" << Value1Double << ", " | 123 std::cout << Funcs[f].Name << "Double(" << Value1Double << ", " |
| 110 << Value2Double << "): sz=" << ResultSz | 124 << Value2Double << "): sz=" << ResultSz |
| 111 << " llc=" << ResultLlc << "\n"; | 125 << " llc=" << ResultLlc << "\n"; |
| 112 } | 126 } |
| 127 ++TotalTests; |
| 128 float Value1SelectFloat = Values[i]; |
| 129 float Value2SelectFloat = Values[j]; |
| 130 ResultSz = Funcs[f].FuncFloatSelectSz(Value1Float, Value2Float, 1, 2); |
| 131 ResultLlc = Funcs[f].FuncFloatSelectLlc(Value1Float, Value2Float, 1, 2); |
| 132 if (ResultSz == ResultLlc) { |
| 133 ++Passes; |
| 134 } else { |
| 135 ++Failures; |
| 136 std::cout << Funcs[f].Name << "SelectFloat(" << Value1Float << ", " |
| 137 << Value2Float << "): sz=" << ResultSz |
| 138 << " llc=" << ResultLlc << "\n"; |
| 139 } |
| 140 ++TotalTests; |
| 141 double Value1SelectDouble = Values[i]; |
| 142 double Value2SelectDouble = Values[j]; |
| 143 ResultSz = |
| 144 Funcs[f].FuncDoubleSelectSz(Value1Double, Value2Double, 1, 2); |
| 145 ResultLlc = |
| 146 Funcs[f].FuncDoubleSelectLlc(Value1Double, Value2Double, 1, 2); |
| 147 if (ResultSz == ResultLlc) { |
| 148 ++Passes; |
| 149 } else { |
| 150 ++Failures; |
| 151 std::cout << Funcs[f].Name << "SelectDouble(" << Value1Double << ", " |
| 152 << Value2Double << "): sz=" << ResultSz |
| 153 << " llc=" << ResultLlc << "\n"; |
| 154 } |
| 113 } | 155 } |
| 114 } | 156 } |
| 115 } | 157 } |
| 116 } | 158 } |
| 117 | 159 |
| 118 void testsVector(size_t &TotalTests, size_t &Passes, size_t &Failures) { | 160 void testsVector(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 119 #ifndef ARM32 | 161 #ifndef ARM32 |
| 120 // TODO(jpp): remove this once vector support is implemented. | 162 // TODO(jpp): remove this once vector support is implemented. |
| 121 typedef v4si32 (*FuncTypeVector)(v4f32, v4f32); | 163 typedef v4si32 (*FuncTypeVector)(v4f32, v4f32); |
| 122 static struct { | 164 static struct { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 215 |
| 174 initializeValues(); | 216 initializeValues(); |
| 175 | 217 |
| 176 testsScalar(TotalTests, Passes, Failures); | 218 testsScalar(TotalTests, Passes, Failures); |
| 177 testsVector(TotalTests, Passes, Failures); | 219 testsVector(TotalTests, Passes, Failures); |
| 178 | 220 |
| 179 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | 221 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
| 180 << " Failures=" << Failures << "\n"; | 222 << " Failures=" << Failures << "\n"; |
| 181 return Failures; | 223 return Failures; |
| 182 } | 224 } |
| OLD | NEW |