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

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

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

Powered by Google App Engine
This is Rietveld 408576698