Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: tests/language/modulo_test.dart

Issue 81623003: Use range information to omit checks in TRUNCDIV/MOD operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | tests/language/truncdiv_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. 11 // Prime IC cache.
12 noDom(1); 12 noDom(1);
13 noDom(-1); 13 noDom(-1);
14 for (int i = -30; i < 30; i++) { 14 for (int i = -30; i < 30; i++) {
15 Expect.equals(i % 256, foo(i)); 15 Expect.equals(i % 256, foo(i));
16 Expect.equals(i % -256, boo(i)); 16 Expect.equals(i % -256, boo(i));
17 Expect.throws(() => hoo(i), (e) => e is IntegerDivisionByZeroException); 17 Expect.throws(() => hoo(i), (e) => e is IntegerDivisionByZeroException);
18 18
19 Expect.equals(i ~/ 254 + i % 254, fooTwo(i)); 19 Expect.equals(i ~/ 254 + i % 254, fooTwo(i));
20 Expect.equals(i ~/ -254 + i % -254, booTwo(i)); 20 Expect.equals(i ~/ -254 + i % -254, booTwo(i));
21 Expect.throws(() => hooTwo(i), (e) => e is IntegerDivisionByZeroException); 21 Expect.throws(() => hooTwo(i), (e) => e is IntegerDivisionByZeroException);
22 if (i > 0) { 22 if (i > 0) {
23 Expect.equals(i % 10, noDom(i)); 23 Expect.equals(i % 10, noDom(i));
24 } else { 24 } else {
25 Expect.equals(i ~/ 10, noDom(i)); 25 Expect.equals(i ~/ 10, noDom(i));
26 } 26 }
27 Expect.equals((i ~/ 10) + (i ~/ 10) + (i % 10), threeOp(i)); 27 Expect.equals((i ~/ 10) + (i ~/ 10) + (i % 10), threeOp(i));
28 Expect.equals((i ~/ 10) + (i ~/ 12) + (i % 10) + (i % 12), fourOp(i)); 28 Expect.equals((i ~/ 10) + (i ~/ 12) + (i % 10) + (i % 12), fourOp(i));
29
30 // Zero test is done outside the loop.
31 if (i < 0) {
32 Expect.equals(i % -i, foo2(i));
33 Expect.equals(i ~/ -i + i % -i, fooTwo2(i));
34 } else if (i > 0) {
35 Expect.equals(i % i, foo2(i));
36 Expect.equals(i ~/ i + i % i, fooTwo2(i));
37 }
29 } 38 }
39 Expect.throws(() => foo2(0), (e) => e is IntegerDivisionByZeroException);
40 Expect.throws(() => fooTwo2(0), (e) => e is IntegerDivisionByZeroException);
30 } 41 }
31 42
32 foo(i) => i % 256; // This will get optimized to AND instruction. 43 foo(i) => i % 256; // This will get optimized to AND instruction.
33 boo(i) => i % -256; 44 boo(i) => i % -256;
34 hoo(i) => i % 0; 45 hoo(i) => i % 0;
35 46
36 fooTwo(i) => i ~/ 254 + i % 254; 47 fooTwo(i) => i ~/ 254 + i % 254;
37 booTwo(i) => i ~/ -254 + i % -254; 48 booTwo(i) => i ~/ -254 + i % -254;
38 hooTwo(i) => i ~/ 0 + i % 0; 49 hooTwo(i) => i ~/ 0 + i % 0;
39 50
(...skipping 14 matching lines...) Expand all
54 return x + y + z; 65 return x + y + z;
55 } 66 }
56 67
57 68
58 fourOp(a) { 69 fourOp(a) {
59 var x0 = a ~/ 10; 70 var x0 = a ~/ 10;
60 var x1 = a ~/ 12; 71 var x1 = a ~/ 12;
61 var y0 = a % 10; 72 var y0 = a % 10;
62 var y1 = a % 12; 73 var y1 = a % 12;
63 return x0 + x1 + y0 + y1; 74 return x0 + x1 + y0 + y1;
64 } 75 }
76
77 foo2(i) {
78 // Make sure x has a range computed.
79 var x = 0;
80 if (i < 0) {
81 x = -i;
82 } else {
83 x = i;
84 }
85 return i % x;
86 }
87
88
89 fooTwo2(i) {
90 // Make sure x has a range computed.
91 var x = 0;
92 if (i < 0) {
93 x = -i;
94 } else {
95 x = i;
96 }
97 return i ~/ x + i % x;
98 }
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | tests/language/truncdiv_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698