-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLanguageTestUtils.h
181 lines (136 loc) · 5.32 KB
/
LanguageTestUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#pragma once
#include "VirtualMachine.h"
#include <MemAlloc.h>
#include <string>
#if BUILD_TESTS
namespace Winter
{
// Flag values
const uint32 INVALID_OPENCL = 1;
const uint32 ALLOW_UNSAFE = 2;
const uint32 ALLOW_TIME_BOUND_FAILURE = 4;
const uint32 ALLOW_SPACE_BOUND_FAILURE = 8;
const uint32 INCLUDE_EXTERNAL_MATHS_FUNCS = 32;
const uint32 DISABLE_CONSTANT_FOLDING = 64;
struct TestResults
{
ProgramStats stats;
Reference<FunctionDefinition> maindef;
};
SSE_CLASS_ALIGN float4
{
public:
float e[4];
inline bool operator == (const float4& other) const
{
return
(e[0] == other.e[0]) &&
(e[1] == other.e[1]) &&
(e[2] == other.e[2]) &&
(e[3] == other.e[3]);
}
};
SSE_CLASS_ALIGN Float4Struct
{
public:
Float4Struct(){}
Float4Struct(float x, float y, float z, float w) { v.e[0] = x; v.e[1] = y; v.e[2] = z; v.e[3] = w; }
float4 v;
inline bool operator == (const Float4Struct& other)
{
return v == other.v;
}
};
SSE_CLASS_ALIGN Float4StructPair
{
public:
Float4StructPair(const Float4Struct& a_, const Float4Struct& b_) : a(a_), b(b_) {}
inline bool operator == (const Float4StructPair& other)
{
return a == other.a && b == other.b;
}
Float4Struct a, b;
};
AVX_CLASS_ALIGN float8
{
public:
float e[8];
inline bool operator == (const float8& other) const
{
return
(e[0] == other.e[0]) &&
(e[1] == other.e[1]) &&
(e[2] == other.e[2]) &&
(e[3] == other.e[3]) &&
(e[4] == other.e[4]) &&
(e[5] == other.e[5]) &&
(e[6] == other.e[6]) &&
(e[7] == other.e[7]);
}
};
AVX_CLASS_ALIGN Float8Struct
{
public:
float8 v;
inline bool operator == (const Float8Struct& other)
{
return v == other.v;
}
};
struct StructWithVec
{
//int data;
float4 a;
float4 b;
float data2;
inline bool operator == (const StructWithVec& other)
{
return (a == other.a) && (b == other.b) && (data2 == other.data2);
}
};
struct TestStruct
{
float a;
float b;
float c;
float d;
bool operator == (const TestStruct& other) const { return (a == other.a) && (b == other.b); }
};
struct TestStructIn
{
float x;
float y;
};
bool epsEqual(const float4& a, const float4& b);
bool epsEqual(const StructWithVec& a, const StructWithVec& b);
bool epsEqual(const Float4Struct& a, const Float4Struct& b);
bool epsEqual(const Float8Struct& a, const Float8Struct& b);
size_t getTimeBoundForMainFloatArg(const std::string& src, uint32 test_flags = 0);
void testTimeBoundInvalidForMainFloatArg(const std::string& src, uint32 test_flags = 0);
TestResults testMainFloat(const std::string& src, float target_return_val);
void testMainFloatArgInvalidProgram(const std::string& src);
TestResults testMainFloatArg(const std::string& src, float argument, float target_return_val, uint32 test_flags = 0, const std::vector<ExternalFunctionRef>* external_funcs = NULL);
TestResults testMainDoubleArg(const std::string& src, double argument, double target_return_val, uint32 test_flags = 0);
TestResults testMainFloatArgAllowUnsafe(const std::string& src, float argument, float target_return_val, uint32 test_flags = 0);
TestResults testMainFloatArgCheckConstantFolded(const std::string& src, float argument, float target_return_val, uint32 test_flags = 0, const std::vector<ExternalFunctionRef>* external_funcs = NULL);
void testMainInteger(const std::string& src, int target_return_val);
void testMainStringArg(const std::string& src, const std::string& arg, const std::string& target_return_val, uint32 test_flags = 0);
TestResults testMainIntegerArg(const std::string& src, int x, int target_return_val, uint32 test_flags = 0);
void testMainInt64Arg(const std::string& src, int64 x, int64 target_return_val, uint32 test_flags = 0);
void testMainInt16Arg(const std::string& src, int16 x, int16 target_return_val, uint32 test_flags = 0);
void testMainUInt32Arg(const std::string& src, uint32 x, uint32 target_return_val, uint32 test_flags = 0);
void testMainBoolArg(const std::string& src, bool x, bool target_return_val, uint32 test_flags = 0);
void testMainIntegerArgInvalidProgram(const std::string& src);
void testMainInt64ArgInvalidProgram(const std::string& src);
void testFloat4StructPairRetFloat(const std::string& src, const Float4StructPair& a, const Float4StructPair& b, float target_return_val);
void testVectorInStruct(const std::string& src, const StructWithVec& struct_in, const StructWithVec& target_return_val);
void testFloat4Struct(const std::string& src, const Float4Struct& a, const Float4Struct& b, const Float4Struct& target_return_val);
void testFloat8Struct(const std::string& src, const Float8Struct& a, const Float8Struct& b, const Float8Struct& target_return_val);
void testIntArray(const std::string& src, const int* a, const int* b, const int* target_return_val, size_t len, uint32 test_flags = 0);
void testFloatArray(const std::string& src, const float* a, const float* b, const float* target_return_val, size_t len);
template <class StructType>
void testMainStruct(const std::string& src, const StructType& target_return_val);
template <class InStructType, class OutStructType>
void testMainStructInputAndOutput(const std::string& src, const InStructType& struct_in, const OutStructType& target_return_val);
} // end namespace Winter
#endif // BUILD_TESTS