OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library TypedArraysSimdTest; | 5 library TypedArraysSimdTest; |
6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 if (Platform.supportsSimd) { | 30 if (Platform.supportsSimd) { |
31 final val = new Float32x4(1.0, 2.0, 3.0, 4.0); | 31 final val = new Float32x4(1.0, 2.0, 3.0, 4.0); |
32 expect(val.x, floatEquals(1.0)); | 32 expect(val.x, floatEquals(1.0)); |
33 expect(val.y, floatEquals(2.0)); | 33 expect(val.y, floatEquals(2.0)); |
34 expect(val.z, floatEquals(3.0)); | 34 expect(val.z, floatEquals(3.0)); |
35 expect(val.w, floatEquals(4.0)); | 35 expect(val.w, floatEquals(4.0)); |
36 final val2 = val + val; | 36 final val2 = val + val; |
37 expect(val2.x, floatEquals(2.0)); | 37 expect(val2.x, floatEquals(2.0)); |
38 expect(val2.y, floatEquals(4.0)); | 38 expect(val2.y, floatEquals(4.0)); |
39 expect(val2.z, floatEquals(6.0)); | 39 expect(val2.z, floatEquals(6.0)); |
40 » expect(val2.w, floatEquals(8.0));» | 40 » expect(val2.w, floatEquals(8.0)); |
41 }» | 41 } |
42 }); | 42 }); |
43 | 43 |
44 test('test Float32x4List', () { | 44 test('test Float32x4List', () { |
45 var counter; | 45 var counter; |
46 final list = new Float32List(12); | 46 final list = new Float32List(12); |
47 for (int i = 0; i < list.length; ++i) { | 47 for (int i = 0; i < list.length; ++i) { |
48 list[i] = i * 1.0; | 48 list[i] = i * 1.0; |
49 } | 49 } |
50 if (Platform.supportsSimd) { | 50 if (Platform.supportsSimd) { |
51 counter = new Float32x4.zero(); | 51 counter = new Float32x4.zero(); |
52 final simdlist = new Float32x4List.view(list.buffer); | 52 final simdlist = new Float32x4List.view(list.buffer); |
53 for (int i = 0; i < simdlist.length; ++i) { | 53 for (int i = 0; i < simdlist.length; ++i) { |
54 counter += simdlist[i]; | 54 counter += simdlist[i]; |
55 } | 55 } |
56 } else { | 56 } else { |
57 counter = new MyFloat32x4(); | 57 counter = new MyFloat32x4(); |
58 for (int i = 0; i < list.length; i += 4) { | 58 for (int i = 0; i < list.length; i += 4) { |
59 counter.x += list[i]; | 59 counter.x += list[i]; |
60 counter.y += list[i+1]; | 60 counter.y += list[i+1]; |
61 counter.z += list[i+2]; | 61 counter.z += list[i+2]; |
62 counter.w += list[i+3]; | 62 counter.w += list[i+3]; |
63 } | 63 } |
64 } | 64 } |
65 expect(counter.x, floatEquals(12.0)); | 65 expect(counter.x, floatEquals(12.0)); |
66 expect(counter.y, floatEquals(15.0)); | 66 expect(counter.y, floatEquals(15.0)); |
67 expect(counter.z, floatEquals(18.0)); | 67 expect(counter.z, floatEquals(18.0)); |
68 expect(counter.w, floatEquals(21.0)); | 68 expect(counter.w, floatEquals(21.0)); |
69 }); | 69 }); |
70 | 70 |
71 test('test Uint32x4', () { | 71 test('test Int32x4', () { |
72 if (Platform.supportsSimd) { | 72 if (Platform.supportsSimd) { |
73 » final val = new Uint32x4(1, 2, 3, 4); | 73 » final val = new Int32x4(1, 2, 3, 4); |
74 expect(val.x, equals(1)); | 74 expect(val.x, equals(1)); |
75 expect(val.y, equals(2)); | 75 expect(val.y, equals(2)); |
76 expect(val.z, equals(3)); | 76 expect(val.z, equals(3)); |
77 expect(val.w, equals(4)); | 77 expect(val.w, equals(4)); |
78 final val2 = val ^ val; | 78 final val2 = val ^ val; |
79 expect(val2.x, equals(0)); | 79 expect(val2.x, equals(0)); |
80 expect(val2.y, equals(0)); | 80 expect(val2.y, equals(0)); |
81 expect(val2.z, equals(0)); | 81 expect(val2.z, equals(0)); |
82 » expect(val2.w, equals(0));» | 82 » expect(val2.w, equals(0)); |
83 }» | 83 } |
84 }); | 84 }); |
85 } | 85 } |
OLD | NEW |