forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimdJsHelpers.js
More file actions
201 lines (179 loc) · 4.56 KB
/
SimdJsHelpers.js
File metadata and controls
201 lines (179 loc) · 4.56 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var DEBUG = false;
function sameValue(x, y) {
if (x == y)
{
return x != 0 || y != 0 || (1/x == 1/y); // 0.0 != -0.0
}
return (x != x) && (y != y); // NaN == NaN
}
function equal(ev, v) {
var eps = 0.000001;
if (sameValue(ev, v))
{
if(DEBUG) WScript.Echo("same value");
return true;
}
else if ((ev == 0.0 || v == 0.0) && Math.abs(v - ev) <= eps) // -0.0 covered here
{
if(DEBUG) WScript.Echo("Float 0.0 ");
return true;
}
else if (Math.abs(v - ev) / Math.abs(ev) <= eps)
{
if(DEBUG) WScript.Echo("Float values within eps");
return true;
}
else
{
WScript.Echo(">> Fail!");
WScript.Echo("Expected "+ev+" Found "+v);
return false;
}
}
function equalSimd(values, simdValue, type, msg)
{ var ok = true;
length = getLength(type);
if (Array.isArray(values))
{
for ( var i = 0; i < length; i ++)
{
if(!equal(values[i],type.extractLane(simdValue, i)))
{
ok = false;
}
}
if (ok)
return;
else
{
WScript.Echo(">> Fail!!");
if (msg !== undefined)
{
WScript.Echo(msg);
}
printSimd(simdValue, type);
}
}
else
{
type.check(values);
for ( var i = 0; i < length; i ++)
{
if(!equal(type.extractLane(values, i),type.extractLane(simdValue, i)))
{
ok = false;
}
}
if (ok)
return;
else
{
WScript.Echo(">> Fail!!");
if (msg !== undefined)
{
WScript.Echo(msg);
}
printSimd(simdValue, type);
}
}
}
function printSimd(simdValue, type)
{
var length;
var vals = "";
length = getLength(type);
for (var i = 0; i < length; i ++)
{
vals += type.extractLane(simdValue,i);
if (i < length - 1)
vals += ", "
}
WScript.Echo(type.toString() + "(" + vals + ")");
}
function printSimdBaseline(simdValue, typeName, varName, msg)
{
var length;
var vals = "";
if (typeName === "SIMD.Float32x4")
{
type = SIMD.Float32x4;
}
else if (typeName === "SIMD.Int32x4")
{
type = SIMD.Int32x4;
}
else if (typeName === "SIMD.Int16x8")
{
type = SIMD.Int16x8;
}
else if (typeName === "SIMD.Int8x16")
{
type = SIMD.Int8x16;
}
else if (typeName === "SIMD.Uint32x4")
{
type = SIMD.Uint32x4;
}
else if (typeName === "SIMD.Uint16x8")
{
type = SIMD.Uint16x8;
}
else if (typeName === "SIMD.Uint8x16")
{
type = SIMD.Uint8x16;
}
else if (typeName === "SIMD.Bool32x4")
{
type = SIMD.Bool32x4;
}
else if (typeName === "SIMD.Bool16x8")
{
type = SIMD.Bool16x8;
}
else if (typeName === "SIMD.Bool8x16")
{
type = SIMD.Bool8x16;
}
else
{
throw "Unsupported type";
}
length = getLength(type);
for (var i = 0; i < length; i ++)
{
vals += type.extractLane(simdValue,i);
if (i < length - 1)
vals += ", "
}
print("equalSimd([" + vals + "], " + varName + ", " + typeName + ", \"" + msg + "\")");
}
function getLength(type)
{
var length;
switch (type)
{
case SIMD.Float32x4:
case SIMD.Int32x4:
case SIMD.Uint32x4:
case SIMD.Bool32x4:
length = 4;
break;
case SIMD.Int16x8:
case SIMD.Uint16x8:
case SIMD.Bool16x8:
length = 8;
break;
case SIMD.Int8x16:
case SIMD.Uint8x16:
case SIMD.Bool8x16:
length = 16;
break;
default:
throw "Undefined type";
}
return length;
}