blob: 63d701cf56287140c1ecb153a37577b7f6223f8c [file] [log] [blame]
Matt Wala9cb61e22014-07-24 09:44:42 -07001//===- subzero/crosstest/test_select_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 crosstesting the select bitcode instruction
11//
12//===----------------------------------------------------------------------===//
13
14/* crosstest.py --test=test_select.ll --driver=test_select_main.cpp \
15 --prefix=Subzero_ --output=test_select */
16
17#include <cfloat>
18#include <cstring>
19#include <iostream>
20
Jan Voung109fa152014-10-07 17:22:51 -070021#include "test_arith.def"
Matt Wala9cb61e22014-07-24 09:44:42 -070022#include "test_select.h"
23
24namespace Subzero_ {
25#include "test_select.h"
26}
27
Jim Stichnoth57a8aab2016-01-06 09:34:36 -080028#include "insertelement.h"
29
Matt Wala9cb61e22014-07-24 09:44:42 -070030static const size_t MaxTestsPerFunc = 100000;
31
32template <typename T, typename TI1>
33void testSelect(size_t &TotalTests, size_t &Passes, size_t &Failures) {
34 typedef typename Vectors<T>::Ty Ty;
35 typedef typename Vectors<TI1>::Ty TyI1;
36 volatile unsigned Values[] = {
Jim Stichnothdd842db2015-01-27 12:53:53 -080037 0x0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001,
38 0xfffffffe, 0xffffffff, 0x7e, 0x7f, 0x80, 0x81,
39 0xfe, 0xff, 0x100, 0x101, 0x7ffe, 0x7fff,
40 0x8000, 0x8001, 0xfffe, 0xffff, 0x10000, 0x10001};
Matt Wala9cb61e22014-07-24 09:44:42 -070041 static const size_t NumValues = sizeof(Values) / sizeof(*Values);
42 static const size_t NumElements = Vectors<T>::NumElements;
43 PRNG Index;
44 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
45 TyI1 Cond;
46 Ty Value1, Value2;
47 for (size_t j = 0; j < NumElements; ++j) {
Jim Stichnoth57a8aab2016-01-06 09:34:36 -080048 setElement(Cond, j, Index() % 2);
49 setElement(Value1, j, Values[Index() % NumValues]);
50 setElement(Value2, j, Values[Index() % NumValues]);
Matt Wala9cb61e22014-07-24 09:44:42 -070051 }
52 Ty ResultLlc = select(Cond, Value1, Value2);
53 Ty ResultSz = Subzero_::select(Cond, Value1, Value2);
54 ++TotalTests;
55 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) {
56 ++Passes;
57 } else {
58 ++Failures;
59 std::cout << "select<" << Vectors<T>::TypeName << ">(Cond=";
60 std::cout << vectAsString<TI1>(Cond)
61 << ", Value1=" << vectAsString<T>(Value1)
62 << ", Value2=" << vectAsString<T>(Value2) << ")\n";
63 std::cout << "llc=" << vectAsString<T>(ResultLlc) << "\n";
64 std::cout << "sz =" << vectAsString<T>(ResultSz) << "\n";
65 }
66 }
67}
68
Jim Stichnothdd842db2015-01-27 12:53:53 -080069template <>
70void testSelect<v4f32, v4i1>(size_t &TotalTests, size_t &Passes,
71 size_t &Failures) {
Matt Wala9cb61e22014-07-24 09:44:42 -070072 static const float NegInf = -1.0 / 0.0;
73 static const float PosInf = 1.0 / 0.0;
74 static const float Nan = 0.0 / 0.0;
75 static const float NegNan = -0.0 / 0.0;
Jan Voung109fa152014-10-07 17:22:51 -070076 volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
Matt Wala9cb61e22014-07-24 09:44:42 -070077 static const size_t NumValues = sizeof(Values) / sizeof(*Values);
78 static const size_t NumElements = 4;
79 PRNG Index;
80 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
81 v4si32 Cond;
82 v4f32 Value1, Value2;
83 for (size_t j = 0; j < NumElements; ++j) {
Jim Stichnoth57a8aab2016-01-06 09:34:36 -080084 setElement(Cond, j, Index() % 2);
85 setElement(Value1, j, Values[Index() % NumValues]);
86 setElement(Value2, j, Values[Index() % NumValues]);
Matt Wala9cb61e22014-07-24 09:44:42 -070087 }
88 v4f32 ResultLlc = select(Cond, Value1, Value2);
89 v4f32 ResultSz = Subzero_::select(Cond, Value1, Value2);
90 ++TotalTests;
91 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) {
92 ++Passes;
93 } else {
94 ++Failures;
95 std::cout << "select<v4f32>(Cond=";
96 std::cout << vectAsString<v4i1>(Cond)
97 << ", Value1=" << vectAsString<v4f32>(Value1)
98 << ", Value2=" << vectAsString<v4f32>(Value2) << ")\n";
99 std::cout << "llc=" << vectAsString<v4f32>(ResultLlc) << "\n";
100 std::cout << "sz =" << vectAsString<v4f32>(ResultSz) << "\n";
101 }
102 }
103}
104
Jim Stichnothdd842db2015-01-27 12:53:53 -0800105template <typename T>
Matt Wala9cb61e22014-07-24 09:44:42 -0700106void testSelectI1(size_t &TotalTests, size_t &Passes, size_t &Failures) {
107 typedef typename Vectors<T>::Ty Ty;
108 static const size_t NumElements = Vectors<T>::NumElements;
109 PRNG Index;
110 for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
111 Ty Cond;
112 Ty Value1, Value2;
113 for (size_t j = 0; j < NumElements; ++j) {
Jim Stichnoth57a8aab2016-01-06 09:34:36 -0800114 setElement(Cond, j, Index() % 2);
115 setElement(Value1, j, Index() % 2);
116 setElement(Value2, j, Index() % 2);
Matt Wala9cb61e22014-07-24 09:44:42 -0700117 }
118 Ty ResultLlc = select_i1(Cond, Value1, Value2);
119 Ty ResultSz = Subzero_::select_i1(Cond, Value1, Value2);
120 ++TotalTests;
121 if (!memcmp(&ResultLlc, &ResultSz, sizeof(ResultLlc))) {
122 ++Passes;
123 } else {
124 ++Failures;
125 std::cout << "select<" << Vectors<T>::TypeName << ">(Cond=";
126 std::cout << vectAsString<T>(Cond)
127 << ", Value1=" << vectAsString<T>(Value1)
128 << ", Value2=" << vectAsString<T>(Value2) << ")\n";
129 std::cout << "llc=" << vectAsString<T>(ResultLlc) << "\n";
130 std::cout << "sz =" << vectAsString<T>(ResultSz) << "\n";
131 }
132 }
133}
134
135int main(int argc, char *argv[]) {
Matt Wala9cb61e22014-07-24 09:44:42 -0700136 size_t TotalTests = 0;
137 size_t Passes = 0;
138 size_t Failures = 0;
139
140 testSelect<v4f32, v4i1>(TotalTests, Passes, Failures);
141 testSelect<v4si32, v4i1>(TotalTests, Passes, Failures);
142 testSelect<v4ui32, v4i1>(TotalTests, Passes, Failures);
143 testSelect<v8si16, v8i1>(TotalTests, Passes, Failures);
144 testSelect<v8ui16, v8i1>(TotalTests, Passes, Failures);
145 testSelect<v16si8, v16i1>(TotalTests, Passes, Failures);
146 testSelect<v16ui8, v16i1>(TotalTests, Passes, Failures);
147 testSelectI1<v4i1>(TotalTests, Passes, Failures);
148 testSelectI1<v8i1>(TotalTests, Passes, Failures);
149 testSelectI1<v16i1>(TotalTests, Passes, Failures);
150
151 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
152 << " Failures=" << Failures << "\n";
153
154 return Failures;
155}