| 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 --no-background-co
mpilation |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 for (int i = -30; i < 30; i++) { | 11 for (int i = -30; i < 30; i++) { |
| 12 Expect.equals(i % 9, foo(i, 9)); | 12 Expect.equals(i % 9, foo(i, 9)); |
| 13 // Zero test is done outside the loop. | 13 // Zero test is done outside the loop. |
| 14 if (i < 0) { | 14 if (i < 0) { |
| 15 Expect.equals(i ~/ -i, foo2(i)); | 15 Expect.equals(i ~/ -i, foo2(i)); |
| 16 } else if (i > 0) { | 16 } else if (i > 0) { |
| 17 Expect.equals(i ~/ i, foo2(i)); | 17 Expect.equals(i ~/ i, foo2(i)); |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 Expect.throws(() => foo(12, 0), (e) => e is IntegerDivisionByZeroException); | 20 Expect.throws(() => foo(12, 0), (e) => e is IntegerDivisionByZeroException); |
| 21 Expect.throws(() => foo2(0), (e) => e is IntegerDivisionByZeroException); | 21 Expect.throws(() => foo2(0), (e) => e is IntegerDivisionByZeroException); |
| 22 } | 22 } |
| 23 | 23 |
| 24 foo(i, x) => i % x; | 24 foo(i, x) => i % x; |
| 25 | 25 |
| 26 foo2(i) { | 26 foo2(i) { |
| 27 // Make sure x has a range computed. | 27 // Make sure x has a range computed. |
| 28 var x = 0; | 28 var x = 0; |
| 29 if (i < 0) { | 29 if (i < 0) { |
| 30 x = -i; | 30 x = -i; |
| 31 } else { | 31 } else { |
| 32 x = i; | 32 x = i; |
| 33 } | 33 } |
| 34 return i ~/ x; | 34 return i ~/ x; |
| 35 } | 35 } |
| OLD | NEW |