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

Side by Side Diff: test/mjsunit/asm/switch.js

Issue 931623002: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addrssed comments. Created 5 years, 10 months 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
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var stdlib = this;
6 var foreign = {};
7 var heap = new ArrayBuffer(64 * 1024);
8
9
10 var switch1 = (function(stdlib, foreign, heap) {
11 "use asm";
12 function switch1(i) {
13 i = i|0;
14 switch (i) {
15 case 0: return 1;
16 case 1: return 2;
17 default: return i|0;
18 }
19 }
20 return { switch1: switch1 };
21 })(stdlib, foreign, heap).switch1;
22
23 assertEquals(1, switch1(0));
24 assertEquals(2, switch1(1));
25 for (var i = -2147483648; i < 2147483648; i += 3999773) {
26 assertEquals(i, switch1(i));
27 }
28
29
30 var switch2 = (function(stdlib, foreign, heap) {
31 "use asm";
32 function switch2(i) {
33 i = i|0;
34 var j = 0;
35 switch (i) {
36 case 0: j = 1; break;
37 case 1: j = 2; break;
38 case 2: j = 3; break;
39 default: j = i|0; break;
40 }
41 return j|0;
42 }
43 return { switch2: switch2 };
44 })(stdlib, foreign, heap).switch2;
45
46 assertEquals(1, switch2(0));
47 assertEquals(2, switch2(1));
48 assertEquals(3, switch2(2));
49 for (var i = -2147483648; i < 2147483648; i += 3999773) {
50 assertEquals(i, switch2(i));
51 }
52
53
54 var switch3 = (function(stdlib, foreign, heap) {
55 "use asm";
56 function switch3(i) {
57 i = i|0;
58 var j = 0;
59 switch (i) {
60 case 0:
61 case 1: j = 1; break;
62 case 2:
63 case 3: j = 2; break;
64 case 4:
65 case 5: j = 3; break;
66 default: j = 0; break;
67 }
68 return j|0;
69 }
70 return { switch3: switch3 };
71 })(stdlib, foreign, heap).switch3;
72
73 assertEquals(1, switch3(0));
74 assertEquals(1, switch3(1));
75 assertEquals(2, switch3(2));
76 assertEquals(2, switch3(3));
77 assertEquals(3, switch3(4));
78 assertEquals(3, switch3(5));
79 for (var i = -2147483648; i < 2147483648; i += 3999773) {
80 assertEquals(0, switch3(i));
81 }
82
83
84 var switch4 = (function(stdlib, foreign, heap) {
85 "use asm";
86 function switch4(i) {
87 i = i|0;
88 switch (i) {
89 case -1:
90 case 1:
91 return 0;
92
93 case -2:
94 case 2:
95 return 1;
96
97 case -3:
98 case 3:
99 return 2;
100
101 case -8:
102 case 8:
103 return 3;
104
105 default:
106 return 4;
107 }
108 }
109 return { switch4: switch4 };
110 })(stdlib, foreign, heap).switch4;
111
112 assertEquals(4, switch4(0));
113 assertEquals(0, switch4(-1));
114 assertEquals(0, switch4(1));
115 assertEquals(1, switch4(-2));
116 assertEquals(1, switch4(2));
117 assertEquals(3, switch4(-8));
118 assertEquals(3, switch4(8));
119 assertEquals(4, switch4(-123456789));
120 assertEquals(4, switch4(123456789));
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-run-machops.cc ('k') | test/unittests/compiler/common-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698