Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Side by Side Diff: runtime/tests/vm/dart/simd128float32_test.dart

Issue 12303013: Simd128Float32, Simd128Mask, and Simd128Float32List additions for dart:scalarlist (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix strict aliasing warning Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/tests/vm/dart/simd128float32_array_test.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:scalarlist';
6
7 testAdd() {
8 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
9 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
10 var o = m + n;
11 Expect.equals(0.0, o.x);
12 Expect.equals(0.0, o.y);
13 Expect.equals(0.0, o.z);
14 Expect.equals(0.0, o.w);
15 }
16
17 testNegate() {
18 var m = new Float32x4(1.0, 2.0, -3.0, -4.0);
19 m = -m;
20 Expect.equals(-1.0, m.x);
21 Expect.equals(-2.0, m.y);
22 Expect.equals(3.0, m.z);
23 Expect.equals(4.0, m.w);
24 }
25
26 testSub() {
27 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
28 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
29 var o = m - n;
30 Expect.equals(-2.0, o.x);
31 Expect.equals(-4.0, o.y);
32 Expect.equals(-6.0, o.z);
33 Expect.equals(-8.0, o.w);
34 }
35
36 testMul() {
37 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
38 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
39 var o = m * n;
40 Expect.equals(-1.0, o.x);
41 Expect.equals(-4.0, o.y);
42 Expect.equals(-9.0, o.z);
43 Expect.equals(-16.0, o.w);
44 }
45
46 testDiv() {
47 var m = new Float32x4(-1.0, -2.0, -3.0, -4.0);
48 var n = new Float32x4(1.0, 2.0, 3.0, 4.0);
49 var o = m / n;
50 Expect.equals(-1.0, o.x);
51 Expect.equals(-1.0, o.y);
52 Expect.equals(-1.0, o.z);
53 Expect.equals(-1.0, o.w);
54 }
55
56 testComparison() {
57 var m = new Float32x4(1.0, 2.0, 0.1, 0.001);
58 var n = new Float32x4(2.0, 2.0, 0.001, 0.1);
59 var cmp;
60 cmp = m.lessThan(n);
61 Expect.equals(0xFFFFFFFF, cmp.x);
62 Expect.equals(0x0, cmp.y);
63 Expect.equals(0x0, cmp.z);
64 Expect.equals(0xFFFFFFFF, cmp.w);
65
66 cmp = m.lessThanOrEqual(n);
67 Expect.equals(0xFFFFFFFF, cmp.x);
68 Expect.equals(0xFFFFFFFF, cmp.y);
69 Expect.equals(0x0, cmp.z);
70 Expect.equals(0xFFFFFFFF, cmp.w);
71
72 cmp = m.equal(n);
73 Expect.equals(0x0, cmp.x);
74 Expect.equals(0xFFFFFFFF, cmp.y);
75 Expect.equals(0x0, cmp.z);
76 Expect.equals(0x0, cmp.w);
77
78 cmp = m.notEqual(n);
79 Expect.equals(0xFFFFFFFF, cmp.x);
80 Expect.equals(0x0, cmp.y);
81 Expect.equals(0xFFFFFFFF, cmp.z);
82 Expect.equals(0xFFFFFFFF, cmp.w);
83
84 cmp = m.greaterThanOrEqual(n);
85 Expect.equals(0x0, cmp.x);
86 Expect.equals(0xFFFFFFFF, cmp.y);
87 Expect.equals(0xFFFFFFFF, cmp.z);
88 Expect.equals(0x0, cmp.w);
89
90 cmp = m.greaterThan(n);
91 Expect.equals(0x0, cmp.x);
92 Expect.equals(0x0, cmp.y);
93 Expect.equals(0xFFFFFFFF, cmp.z);
94 Expect.equals(0x0, cmp.w);
95 }
96
97 testAbs() {
98 var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
99 m = m.abs();
100 Expect.equals(1.0, m.x);
101 Expect.equals(2.0, m.y);
102 Expect.equals(3.0, m.z);
103 Expect.equals(4.0, m.w);
104 }
105
106 testScale() {
107 var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
108 m = m.scale(20.0);
109 Expect.equals(20.0, m.x);
110 Expect.equals(-40.0, m.y);
111 Expect.equals(60.0, m.z);
112 Expect.equals(-80.0, m.w);
113 }
114
115 testClamp() {
116 var m = new Float32x4(1.0, -2.0, 3.0, -4.0);
117 var lo = new Float32x4(0.0, 0.0, 0.0, 0.0);
118 var hi = new Float32x4(2.0, 2.0, 2.0, 2.0);
119 m = m.clamp(lo, hi);
120 Expect.equals(1.0, m.x);
121 Expect.equals(0.0, m.y);
122 Expect.equals(2.0, m.z);
123 Expect.equals(0.0, m.w);
124 }
125
126 testShuffle() {
127 var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
128 var xxxx = m.xxxx;
129 Expect.equals(1.0, xxxx.x);
130 Expect.equals(1.0, xxxx.y);
131 Expect.equals(1.0, xxxx.z);
132 Expect.equals(1.0, xxxx.w);
133 var yyyy = m.yyyy;
134 Expect.equals(2.0, yyyy.x);
135 Expect.equals(2.0, yyyy.y);
136 Expect.equals(2.0, yyyy.z);
137 Expect.equals(2.0, yyyy.w);
138 var zzzz = m.zzzz;
139 Expect.equals(3.0, zzzz.x);
140 Expect.equals(3.0, zzzz.y);
141 Expect.equals(3.0, zzzz.z);
142 Expect.equals(3.0, zzzz.w);
143 var wwww = m.wwww;
144 Expect.equals(4.0, wwww.x);
145 Expect.equals(4.0, wwww.y);
146 Expect.equals(4.0, wwww.z);
147 Expect.equals(4.0, wwww.w);
148 }
149
150 testMin() {
151 var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
152 var n = new Float32x4(1.0, 0.0, 2.5, 5.0);
153 m = m.min(n);
154 Expect.equals(1.0, m.x);
155 Expect.equals(0.0, m.y);
156 Expect.equals(2.5, m.z);
157 Expect.equals(4.0, m.w);
158 }
159
160 testMax() {
161 var m = new Float32x4(1.0, 2.0, 3.0, 4.0);
162 var n = new Float32x4(1.0, 0.0, 2.5, 5.0);
163 m = m.max(n);
164 Expect.equals(1.0, m.x);
165 Expect.equals(2.0, m.y);
166 Expect.equals(3.0, m.z);
167 Expect.equals(5.0, m.w);
168 }
169
170 testSqrt() {
171 var m = new Float32x4(1.0, 4.0, 9.0, 16.0);
172 m = m.sqrt();
173 Expect.equals(1.0, m.x);
174 Expect.equals(2.0, m.y);
175 Expect.equals(3.0, m.z);
176 Expect.equals(4.0, m.w);
177 }
178
179 testReciprocal() {
180 var m = new Float32x4(1.0, 4.0, 9.0, 16.0);
181 m = m.reciprocal();
182 Expect.approxEquals(1.0, m.x);
183 Expect.approxEquals(0.25, m.y);
184 Expect.approxEquals(0.1111111, m.z);
185 Expect.approxEquals(0.0625, m.w);
186 }
187
188 testReciprocalSqrt() {
189 var m = new Float32x4(1.0, 0.25, 0.111111, 0.0625);
190 m = m.reciprocalSqrt();
191 Expect.approxEquals(1.0, m.x);
192 Expect.approxEquals(2.0, m.y);
193 Expect.approxEquals(3.0, m.z);
194 Expect.approxEquals(4.0, m.w);
195 }
196
197 testSelect() {
198 var m = new Uint32x4.bool(true, true, false, false);
199 var t = new Float32x4(1.0, 2.0, 3.0, 4.0);
200 var f = new Float32x4(5.0, 6.0, 7.0, 8.0);
201 var s = m.select(t, f);
202 Expect.equals(1.0, s.x);
203 Expect.equals(2.0, s.y);
204 Expect.equals(7.0, s.z);
205 Expect.equals(8.0, s.w);
206 }
207
208 testConversions() {
209 var m = new Uint32x4(0x3F800000, 0x40000000, 0x40400000, 0x40800000);
210 var n = m.toFloat32x4();
211 Expect.equals(1.0, n.x);
212 Expect.equals(2.0, n.y);
213 Expect.equals(3.0, n.z);
214 Expect.equals(4.0, n.w);
215 n = new Float32x4(5.0, 6.0, 7.0, 8.0);
216 m = n.toUint32x4();
217 Expect.equals(0x40A00000, m.x);
218 Expect.equals(0x40C00000, m.y);
219 Expect.equals(0x40E00000, m.z);
220 Expect.equals(0x41000000, m.w);
221 // Flip sign using bit-wise operators.
222 n = new Float32x4(9.0, 10.0, 11.0, 12.0);
223 m = new Uint32x4(0x80000000, 0x80000000, 0x80000000, 0x80000000);
224 var nMask = n.toUint32x4();
225 nMask = nMask ^ m; // flip sign.
226 n = nMask.toFloat32x4();
227 Expect.equals(-9.0, n.x);
228 Expect.equals(-10.0, n.y);
229 Expect.equals(-11.0, n.z);
230 Expect.equals(-12.0, n.w);
231 nMask = n.toUint32x4();
232 nMask = nMask ^ m; // flip sign.
233 n = nMask.toFloat32x4();
234 Expect.equals(9.0, n.x);
235 Expect.equals(10.0, n.y);
236 Expect.equals(11.0, n.z);
237 Expect.equals(12.0, n.w);
238 }
239
240
241 testBitOperators() {
242 var m = new Uint32x4(0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA);
243 var n = new Uint32x4(0x55555555, 0x55555555, 0x55555555, 0x55555555);
244 Expect.equals(0xAAAAAAAA, m.x);
245 Expect.equals(0xAAAAAAAA, m.y);
246 Expect.equals(0xAAAAAAAA, m.z);
247 Expect.equals(0xAAAAAAAA, m.w);
248 Expect.equals(0x55555555, n.x);
249 Expect.equals(0x55555555, n.y);
250 Expect.equals(0x55555555, n.z);
251 Expect.equals(0x55555555, n.w);
252 Expect.equals(true, n.flagX);
253 Expect.equals(true, n.flagY);
254 Expect.equals(true, n.flagZ);
255 Expect.equals(true, n.flagW);
256 var o = m|n; // or
257 Expect.equals(0xFFFFFFFF, o.x);
258 Expect.equals(0xFFFFFFFF, o.y);
259 Expect.equals(0xFFFFFFFF, o.z);
260 Expect.equals(0xFFFFFFFF, o.w);
261 Expect.equals(true, o.flagX);
262 Expect.equals(true, o.flagY);
263 Expect.equals(true, o.flagZ);
264 Expect.equals(true, o.flagW);
265 o = m&n; // and
266 Expect.equals(0x0, o.x);
267 Expect.equals(0x0, o.y);
268 Expect.equals(0x0, o.z);
269 Expect.equals(0x0, o.w);
270 n = n.withX(0xAAAAAAAA);
271 n = n.withY(0xAAAAAAAA);
272 n = n.withZ(0xAAAAAAAA);
273 n = n.withW(0xAAAAAAAA);
274 Expect.equals(0xAAAAAAAA, n.x);
275 Expect.equals(0xAAAAAAAA, n.y);
276 Expect.equals(0xAAAAAAAA, n.z);
277 Expect.equals(0xAAAAAAAA, n.w);
278 o = m^n; // xor
279 Expect.equals(0x0, o.x);
280 Expect.equals(0x0, o.y);
281 Expect.equals(0x0, o.z);
282 Expect.equals(0x0, o.w);
283 Expect.equals(false, o.flagX);
284 Expect.equals(false, o.flagY);
285 Expect.equals(false, o.flagZ);
286 Expect.equals(false, o.flagW);
287 }
288
289 testSetters() {
290 var f = new Float32x4.zero();
291 Expect.equals(0.0, f.x);
292 Expect.equals(0.0, f.y);
293 Expect.equals(0.0, f.z);
294 Expect.equals(0.0, f.w);
295 f = f.withX(4.0);
296 Expect.equals(4.0, f.x);
297 f = f.withY(3.0);
298 Expect.equals(3.0, f.y);
299 f = f.withZ(2.0);
300 Expect.equals(2.0, f.z);
301 f = f.withW(1.0);
302 Expect.equals(1.0, f.w);
303 f = new Float32x4.zero();
304 f = f.withX(4.0).withZ(2.0).withW(1.0).withY(3.0);
305 Expect.equals(4.0, f.x);
306 Expect.equals(3.0, f.y);
307 Expect.equals(2.0, f.z);
308 Expect.equals(1.0, f.w);
309 var m = new Uint32x4.bool(false, false, false, false);
310 Expect.equals(false, m.flagX);
311 Expect.equals(false, m.flagY);
312 Expect.equals(false, m.flagZ);
313 Expect.equals(false, m.flagW);
314 m = m.withFlagX(true);
315 Expect.equals(true, m.flagX);
316 Expect.equals(false, m.flagY);
317 Expect.equals(false, m.flagZ);
318 Expect.equals(false, m.flagW);
319 m = m.withFlagY(true);
320 Expect.equals(true, m.flagX);
321 Expect.equals(true, m.flagY);
322 Expect.equals(false, m.flagZ);
323 Expect.equals(false, m.flagW);
324 m = m.withFlagZ(true);
325 Expect.equals(true, m.flagX);
326 Expect.equals(true, m.flagY);
327 Expect.equals(true, m.flagZ);
328 Expect.equals(false, m.flagW);
329 m = m.withFlagW(true);
330 Expect.equals(true, m.flagX);
331 Expect.equals(true, m.flagY);
332 Expect.equals(true, m.flagZ);
333 Expect.equals(true, m.flagW);
334 }
335
336 testGetters() {
337 var f = new Float32x4(1.0, 2.0, 3.0, 4.0);
338 Expect.equals(1.0, f.x);
339 Expect.equals(2.0, f.y);
340 Expect.equals(3.0, f.z);
341 Expect.equals(4.0, f.w);
342 var m = new Uint32x4.bool(false, true, true, false);
343 Expect.equals(false, m.flagX);
344 Expect.equals(true, m.flagY);
345 Expect.equals(true, m.flagZ);
346 Expect.equals(false, m.flagW);
347 }
348
349 main() {
350 for (int i = 0; i < 3000; i++) {
351 testGetters();
352 testSetters();
353 testBitOperators();
354 testConversions();
355 testSelect();
356 testShuffle();
357 testAdd();
358 testSub();
359 testNegate();
360 testMul();
361 testDiv();
362 testComparison();
363 testScale();
364 testClamp();
365 testAbs();
366 testMin();
367 testMax();
368 testSqrt();
369 testReciprocal();
370 testReciprocalSqrt();
371 }
372 }
OLDNEW
« no previous file with comments | « runtime/tests/vm/dart/simd128float32_array_test.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698