| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // VMOptions=--optimization-counter-threshold=10 | 4 // VMOptions=--optimization-counter-threshold=10 |
| 5 | 5 |
| 6 // Library tag to be able to run in html test framework. | 6 // Library tag to be able to run in html test framework. |
| 7 library float32x4_cross_test; | 7 library float32x4_cross_test; |
| 8 | 8 |
| 9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 | 11 |
| 12 Float32x4 cross(Float32x4 a, Float32x4 b) { | 12 Float32x4 cross(Float32x4 a, Float32x4 b) { |
| 13 var t0 = a.shuffle(Float32x4.YZXW); | 13 var t0 = a.shuffle(Float32x4.YZXW); |
| 14 var t1 = b.shuffle(Float32x4.ZXYW); | 14 var t1 = b.shuffle(Float32x4.ZXYW); |
| 15 var l = t0 * t1; | 15 var l = t0 * t1; |
| 16 t0 = a.shuffle(Float32x4.ZXYW); | 16 t0 = a.shuffle(Float32x4.ZXYW); |
| 17 t1 = b.shuffle(Float32x4.YZXW); | 17 t1 = b.shuffle(Float32x4.YZXW); |
| 18 var r = t0 * t1; | 18 var r = t0 * t1; |
| 19 return l-r; | 19 return l - r; |
| 20 } | 20 } |
| 21 | 21 |
| 22 void testCross(Float32x4 a, Float32x4 b, Float32x4 r) { | 22 void testCross(Float32x4 a, Float32x4 b, Float32x4 r) { |
| 23 var x = cross(a, b); | 23 var x = cross(a, b); |
| 24 Expect.equals(r.x, x.x); | 24 Expect.equals(r.x, x.x); |
| 25 Expect.equals(r.y, x.y); | 25 Expect.equals(r.y, x.y); |
| 26 Expect.equals(r.z, x.z); | 26 Expect.equals(r.z, x.z); |
| 27 Expect.equals(r.w, x.w); | 27 Expect.equals(r.w, x.w); |
| 28 } | 28 } |
| 29 | 29 |
| 30 main() { | 30 main() { |
| 31 var x = new Float32x4(1.0, 0.0, 0.0, 0.0); | 31 var x = new Float32x4(1.0, 0.0, 0.0, 0.0); |
| 32 var y = new Float32x4(0.0, 1.0, 0.0, 0.0); | 32 var y = new Float32x4(0.0, 1.0, 0.0, 0.0); |
| 33 var z = new Float32x4(0.0, 0.0, 1.0, 0.0); | 33 var z = new Float32x4(0.0, 0.0, 1.0, 0.0); |
| 34 var zero = new Float32x4.zero(); | 34 var zero = new Float32x4.zero(); |
| 35 | 35 |
| 36 for (int i = 0; i < 20; i++) { | 36 for (int i = 0; i < 20; i++) { |
| 37 testCross(x, y, z); | 37 testCross(x, y, z); |
| 38 testCross(z, x, y); | 38 testCross(z, x, y); |
| 39 testCross(y, z, x); | 39 testCross(y, z, x); |
| 40 testCross(z, y, -x); | 40 testCross(z, y, -x); |
| 41 testCross(x, z, -y); | 41 testCross(x, z, -y); |
| 42 testCross(y, x, -z); | 42 testCross(y, x, -z); |
| 43 testCross(x, x, zero); | 43 testCross(x, x, zero); |
| 44 testCross(y, y, zero); | 44 testCross(y, y, zero); |
| 45 testCross(z, z, zero); | 45 testCross(z, z, zero); |
| 46 testCross(x, y, cross(-y, x)); | 46 testCross(x, y, cross(-y, x)); |
| 47 testCross(x, y+z, cross(x, y) + cross(x, z)); | 47 testCross(x, y + z, cross(x, y) + cross(x, z)); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | |
| OLD | NEW |