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

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

Issue 79653002: Merge TRUNCDIV and MOD into one instruction. Icorporated feedback from CL https://codereview.chromi… (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 | « tests/language/arithmetic_test.dart ('k') | no next file » | 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.
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 }
27 Expect.equals((i ~/ 10) + (i ~/ 10) + (i % 10), threeOp(i));
28 Expect.equals((i ~/ 10) + (i ~/ 12) + (i % 10) + (i % 12), fourOp(i));
18 } 29 }
19 } 30 }
20 31
21 foo(i) { 32 foo(i) => i % 256; // This will get optimized to AND instruction.
22 return i % 256; // This will get optimized to AND instruction. 33 boo(i) => i % -256;
34 hoo(i) => i % 0;
35
36 fooTwo(i) => i ~/ 254 + i % 254;
37 booTwo(i) => i ~/ -254 + i % -254;
38 hooTwo(i) => i ~/ 0 + i % 0;
39
40 noDom(a) {
41 var x;
42 if (a > 0) {
43 x = a % 10;
44 } else {
45 x = a ~/ 10;
46 }
47 return x;
48 }
49
50 threeOp(a) {
51 var x = a ~/ 10;
52 var y = a ~/ 10;
53 var z = a % 10;
54 return x + y + z;
23 } 55 }
24 56
25 57
26 boo(i) { 58 fourOp(a) {
27 return i % -256; 59 var x0 = a ~/ 10;
28 } 60 var x1 = a ~/ 12;
29 61 var y0 = a % 10;
30 62 var y1 = a % 12;
31 hoo(i) { 63 return x0 + x1 + y0 + y1;
32 return i % 0; 64 }
33 }
OLDNEW
« no previous file with comments | « tests/language/arithmetic_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698