summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_7/SIMD/check.js
blob: 77ef381be5f1c792a99f46aacff8d15188d0bed3 (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
// |reftest| skip-if(!this.hasOwnProperty("SIMD"))

function test() {

  var i4 = SIMD.Int32x4(1,2,3,4);
  var i8 = SIMD.Int16x8(1,2,3,4,5,6,7,8);
  var i16 = SIMD.Int8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var u4 = SIMD.Uint32x4(1,2,3,4);
  var u8 = SIMD.Uint16x8(1,2,3,4,5,6,7,8);
  var u16 = SIMD.Uint8x16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var f4 = SIMD.Float32x4(NaN, -0, Infinity, 13.37);
  var f2 = SIMD.Float64x2(-0, 13.37);
  var b2 = SIMD.Bool64x2(true, false);
  var b4 = SIMD.Bool32x4(true, true, false, false);
  var b8 = SIMD.Bool16x8(true, true, false, false, true, true, false, false);
  var b16 = SIMD.Bool8x16(true, true, false, false, true, true, false, false, true, true, false, false, true, true, false, false);

  var ci4 = SIMD.Int32x4.check(i4);
  assertEqX4(ci4, simdToArray(i4));
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int32x4.check({}), TypeError);

  var ci8 = SIMD.Int16x8.check(i8);
  assertEqX8(ci8, simdToArray(i8));
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int16x8.check({}), TypeError);

  var ci16 = SIMD.Int8x16.check(i16);
  assertEqX16(ci16, simdToArray(i16));
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Int8x16.check({}), TypeError);

  var cu4 = SIMD.Uint32x4.check(u4);
  assertEqX4(cu4, simdToArray(u4));
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint32x4.check({}), TypeError);

  var cu8 = SIMD.Uint16x8.check(u8);
  assertEqX8(cu8, simdToArray(u8));
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint16x8.check({}), TypeError);

  var cu16 = SIMD.Uint8x16.check(u16);
  assertEqX16(cu16, simdToArray(u16));
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Uint8x16.check({}), TypeError);

  var cf4 = SIMD.Float32x4.check(f4);
  assertEqX4(cf4, simdToArray(f4));
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float32x4.check({}), TypeError);

  var cf2 = SIMD.Float64x2.check(f2);
  assertEqX2(cf2, simdToArray(f2));
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Float64x2.check({}), TypeError);

  var cb2 = SIMD.Bool64x2.check(b2);
  assertEqX2(cb2, simdToArray(b2));
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool64x2.check({}), TypeError);

  var cb4 = SIMD.Bool32x4.check(b4);
  assertEqX4(cb4, simdToArray(b4));
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool32x4.check({}), TypeError);

  var cb8 = SIMD.Bool16x8.check(b8);
  assertEqX8(cb8, simdToArray(b8));
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check(b16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool16x8.check({}), TypeError);

  var cb16 = SIMD.Bool8x16.check(b16);
  assertEqX16(cb16, simdToArray(b16));
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(f4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(f2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(i4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(i8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(i16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(u4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(u8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(u16), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(b2), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(b4), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check(b8), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check("i swear i'm a vector"), TypeError);
  assertThrowsInstanceOf(() => SIMD.Bool8x16.check({}), TypeError);

  if (typeof reportCompare === "function")
    reportCompare(true, true);
}

test();