| 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 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation | 4 // VMOptions=--optimization-counter-threshold=10 --no-background-compilation |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 // Note: in --limit-ints-to-64-bits mode all integers are 64-bit already. |
| 9 // Still, it is harmless to apply _uint64Mask because (1 << 64) is 0 (all bits |
| 10 // are shifted out), so _uint64Mask is -1 (its bit pattern is 0xffffffffffffffff
). |
| 11 const _uint64Mask = (1 << 64) - 1; |
| 12 |
| 8 constants() { | 13 constants() { |
| 9 Expect.equals(0, 499 >> 33); | 14 Expect.equals(0, 499 >> 33); |
| 10 Expect.equals(0, (499 << 33) & 0xFFFFFFFF); | 15 Expect.equals(0, (499 << 33) & 0xFFFFFFFF); |
| 11 Expect.equals(0, (499 << 32) >> 65); | 16 Expect.equals(0, (499 << 32) >> 65); |
| 12 Expect.equals(0, ((499 << 32) << 65) & 0xFFFFFFFFFFFFFFFF); | 17 Expect.equals(0, ((499 << 32) << 65) & _uint64Mask); |
| 13 } | 18 } |
| 14 | 19 |
| 15 foo(i) { | 20 foo(i) { |
| 16 if (i != 0) { | 21 if (i != 0) { |
| 17 y--; | 22 y--; |
| 18 foo(i - 1); | 23 foo(i - 1); |
| 19 y++; | 24 y++; |
| 20 } | 25 } |
| 21 } | 26 } |
| 22 | 27 |
| 23 var y; | 28 var y; |
| 24 | 29 |
| 25 // id returns [x] in a way that should be difficult to predict statically. | 30 // id returns [x] in a way that should be difficult to predict statically. |
| 26 id(x) { | 31 id(x) { |
| 27 y = x; | 32 y = x; |
| 28 foo(10); | 33 foo(10); |
| 29 return y; | 34 return y; |
| 30 } | 35 } |
| 31 | 36 |
| 32 interceptors() { | 37 interceptors() { |
| 33 Expect.equals(0, id(499) >> 33); | 38 Expect.equals(0, id(499) >> 33); |
| 34 Expect.equals(0, (id(499) << 33) & 0xFFFFFFFF); | 39 Expect.equals(0, (id(499) << 33) & 0xFFFFFFFF); |
| 35 Expect.equals(0, id(499 << 32) >> 65); | 40 Expect.equals(0, id(499 << 32) >> 65); |
| 36 Expect.equals(0, (id(499 << 32) << 65) & 0xFFFFFFFFFFFFFFFF); | 41 Expect.equals(0, (id(499 << 32) << 65) & _uint64Mask); |
| 37 } | 42 } |
| 38 | 43 |
| 39 speculative() { | 44 speculative() { |
| 40 var a = id(499); | 45 var a = id(499); |
| 41 var b = id(499 << 32); | 46 var b = id(499 << 32); |
| 42 for (int i = 0; i < 1; i++) { | 47 for (int i = 0; i < 1; i++) { |
| 43 Expect.equals(0, a >> 33); | 48 Expect.equals(0, a >> 33); |
| 44 Expect.equals(0, (a << 33) & 0xFFFFFFFF); | 49 Expect.equals(0, (a << 33) & 0xFFFFFFFF); |
| 45 Expect.equals(0, b >> 65); | 50 Expect.equals(0, b >> 65); |
| 46 Expect.equals(0, (b << 65) & 0xFFFFFFFFFFFFFFFF); | 51 Expect.equals(0, (b << 65) & _uint64Mask); |
| 47 } | 52 } |
| 48 } | 53 } |
| 49 | 54 |
| 50 // JavaScript shifts by the amount modulo 32. That is x << y is equivalent to | 55 // JavaScript shifts by the amount modulo 32. That is x << y is equivalent to |
| 51 // x << (y & 0x1F). Dart does not. | 56 // x << (y & 0x1F). Dart does not. |
| 52 main() { | 57 main() { |
| 53 for (var i = 0; i < 10; ++i) { | 58 for (var i = 0; i < 10; ++i) { |
| 54 constants(); | 59 constants(); |
| 55 interceptors(); | 60 interceptors(); |
| 56 speculative(); | 61 speculative(); |
| 57 } | 62 } |
| 58 } | 63 } |
| OLD | NEW |