OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Test arithmetic on 64-bit integers. | |
6 | |
7 test_and_1() { | |
8 try { // Avoid optimizing this function. | |
9 f(a, b) { | |
10 var s = b; | |
11 var t = a & s; | |
12 return t == b; | |
13 } | |
14 var x = 0xffffffff; | |
15 for (var i = 0; i < 10000; i++) f(x, 0); | |
16 Expect.equals(true, f(x, 0)); | |
17 Expect.equals(false, f(x, -1)); // Triggers deoptimization. | |
18 } finally { } | |
19 } | |
20 | |
21 test_and_2() { | |
22 try { // Avoid optimizing this function. | |
23 f(a, b) { | |
24 return a & b; | |
25 } | |
26 var x = 0xffffffff; | |
27 for (var i = 0; i < 10000; i++) f(x, x); | |
28 Expect.equals(x, f(x, x)); | |
29 Expect.equals(1234, f(0xffffffff, 1234)); | |
30 Expect.equals(0x100000001, f(0x100000001,-1)); | |
31 Expect.equals(-0x40000000, f(-0x40000000, -1)); | |
32 Expect.equals(0x40000000, f(0x40000000, -1)); | |
33 Expect.equals(0x3fffffff, f(0x3fffffff, -1)); | |
34 } finally { } | |
35 } | |
36 | |
37 test_xor_1() { | |
38 try { // Avoid optimizing this function. | |
39 f(a, b) { | |
40 var s = b; | |
41 var t = a ^ s; | |
42 return t; | |
43 } | |
44 var x = 0xffffffff; | |
45 for (var i = 0; i < 10000; i++) f(x, x); | |
46 Expect.equals(0, f(x, x)); | |
47 Expect.equals(-x - 1, f(x, -1)); | |
48 var y = 0xffffffffffffffff; | |
49 Expect.equals(-y - 1, f(y, -1)); // Triggers deoptimization. | |
50 } finally { } | |
51 } | |
52 | |
53 test_or_1() { | |
54 try { // Avoid optimizing this function. | |
55 f(a, b) { | |
56 var s = b; | |
57 var t = a | s; | |
58 return t; | |
59 } | |
60 var x = 0xffffffff; | |
61 for (var i = 0; i < 10000; i++) f(x, x); | |
62 Expect.equals(x, f(x, x)); | |
63 Expect.equals(-1, f(x, -1)); | |
64 var y = 0xffffffffffffffff; | |
65 Expect.equals(-1, f(y, -1)); // Triggers deoptimization. | |
66 } finally { } | |
67 } | |
68 | |
69 test_func(x, y) => (x & y) + 1.0; | |
70 | |
71 test_mint_double_op() { | |
72 for (var i=0; i<10000; i++) test_func(4294967295, 1); | |
73 Expect.equals(2.0, test_func(4294967295, 1)); | |
74 Expect.equals(4294967296.0, test_func(4294967295, 1)); | |
75 } | |
76 | |
77 main() { | |
78 for (var i = 0; i < 5; i++) { | |
79 test_and_1(); | |
80 test_and_2(); | |
81 test_xor_1(); | |
82 test_or_1(); | |
83 test_mint_double_op(); | |
84 } | |
85 } | |
OLD | NEW |