| 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 // Dart test optimization of modulo operator on Smi. | 4 // Dart test optimization of modulo operator on Smi. |
| 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 // Prime IC cache. |
| 12 noDom(1); |
| 13 noDom(-1); |
| 11 for (int i = -30; i < 30; i++) { | 14 for (int i = -30; i < 30; i++) { |
| 12 Expect.equals(i % 256, foo(i)); | 15 Expect.equals(i % 256, foo(i)); |
| 13 Expect.equals(i % -256, boo(i)); | 16 Expect.equals(i % -256, boo(i)); |
| 14 try { | 17 Expect.throws(() => hoo(i), (e) => e is IntegerDivisionByZeroException); |
| 15 hoo(i); | 18 |
| 16 Expect.fail("Exception expected."); | 19 Expect.equals(i ~/ 254 + i % 254, fooTwo(i)); |
| 17 } catch (e) {} | 20 Expect.equals(i ~/ -254 + i % -254, booTwo(i)); |
| 21 Expect.throws(() => hooTwo(i), (e) => e is IntegerDivisionByZeroException); |
| 22 if (i > 0) { |
| 23 Expect.equals(i % 10, noDom(i)); |
| 24 } else { |
| 25 Expect.equals(i ~/ 10, noDom(i)); |
| 26 } |
| 18 } | 27 } |
| 19 } | 28 } |
| 20 | 29 |
| 21 foo(i) { | 30 foo(i) => i % 256; // This will get optimized to AND instruction. |
| 22 return i % 256; // This will get optimized to AND instruction. | 31 boo(i) => i % -256; |
| 23 } | 32 hoo(i) => i % 0; |
| 24 | 33 |
| 34 fooTwo(i) => i ~/ 254 + i % 254; |
| 35 booTwo(i) => i ~/ -254 + i % -254; |
| 36 hooTwo(i) => i ~/ 0 + i % 0; |
| 25 | 37 |
| 26 boo(i) { | 38 noDom(a) { |
| 27 return i % -256; | 39 var x; |
| 28 } | 40 if (a > 0) { |
| 29 | 41 x = a % 10; |
| 30 | 42 } else { |
| 31 hoo(i) { | 43 x = a ~/ 10; |
| 32 return i % 0; | 44 } |
| 33 } | 45 return x; |
| 46 } |
| OLD | NEW |