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

Side by Side Diff: test/mjsunit/wasm/asm-wasm.js

Issue 2106683003: [wasm] Making compare and conditionals more correct. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Created 4 years, 5 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/regress/regress-wasm-crbug-599413.js ('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 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 // Flags: --expose-wasm 5 // Flags: --expose-wasm
6 6
7 function assertWasm(expected, func, ffi) { 7 function assertWasm(expected, func, ffi) {
8 print("Testing " + func.name + "..."); 8 print("Testing " + func.name + "...");
9 assertEquals(expected, Wasm.instantiateModuleFromAsm( 9 assertEquals(expected, Wasm.instantiateModuleFromAsm(
10 func.toString(), ffi).caller()); 10 func.toString(), ffi).caller());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 assertWasm(1, TestAddSimple); 140 assertWasm(1, TestAddSimple);
141 141
142 142
143 function TestWhileSimple() { 143 function TestWhileSimple() {
144 "use asm"; 144 "use asm";
145 145
146 function caller() { 146 function caller() {
147 var x = 0; 147 var x = 0;
148 while(x < 5) { 148 while((x|0) < 5) {
149 x = (x + 1)|0; 149 x = (x + 1)|0;
150 } 150 }
151 return x|0; 151 return x|0;
152 } 152 }
153 153
154 return {caller: caller}; 154 return {caller: caller};
155 } 155 }
156 156
157 assertWasm(5, TestWhileSimple); 157 assertWasm(5, TestWhileSimple);
158 158
159 159
160 function TestWhileWithoutBraces() { 160 function TestWhileWithoutBraces() {
161 "use asm"; 161 "use asm";
162 162
163 function caller() { 163 function caller() {
164 var x = 0; 164 var x = 0;
165 while(x <= 3) 165 while((x|0) <= 3)
166 x = (x + 1)|0; 166 x = (x + 1)|0;
167 return x|0; 167 return x|0;
168 } 168 }
169 169
170 return {caller: caller}; 170 return {caller: caller};
171 } 171 }
172 172
173 assertWasm(4, TestWhileWithoutBraces); 173 assertWasm(4, TestWhileWithoutBraces);
174 174
175 175
176 function TestReturnInWhile() { 176 function TestReturnInWhile() {
177 "use asm"; 177 "use asm";
178 178
179 function caller() { 179 function caller() {
180 var x = 0; 180 var x = 0;
181 while(x < 10) { 181 while((x|0) < 10) {
182 x = (x + 6)|0; 182 x = (x + 6)|0;
183 return x|0; 183 return x|0;
184 } 184 }
185 return x|0; 185 return x|0;
186 } 186 }
187 187
188 return {caller: caller}; 188 return {caller: caller};
189 } 189 }
190 190
191 assertWasm(6, TestReturnInWhile); 191 assertWasm(6, TestReturnInWhile);
192 192
193 193
194 function TestReturnInWhileWithoutBraces() { 194 function TestReturnInWhileWithoutBraces() {
195 "use asm"; 195 "use asm";
196 196
197 function caller() { 197 function caller() {
198 var x = 0; 198 var x = 0;
199 while(x < 5) 199 while((x|0) < 5)
200 return 7; 200 return 7;
201 return x|0; 201 return x|0;
202 } 202 }
203 203
204 return {caller: caller}; 204 return {caller: caller};
205 } 205 }
206 206
207 assertWasm(7, TestReturnInWhileWithoutBraces); 207 assertWasm(7, TestReturnInWhileWithoutBraces);
208 208
209 209
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 assertWasm(9, TestBreakInNestedWhile); 311 assertWasm(9, TestBreakInNestedWhile);
312 312
313 313
314 function TestBreakInBlock() { 314 function TestBreakInBlock() {
315 "use asm"; 315 "use asm";
316 316
317 function caller() { 317 function caller() {
318 var x = 0; 318 var x = 0;
319 abc: { 319 abc: {
320 x = 10; 320 x = 10;
321 if (x == 10) { 321 if ((x|0) == 10) {
322 break abc; 322 break abc;
323 } 323 }
324 x = 20; 324 x = 20;
325 } 325 }
326 return x|0; 326 return x|0;
327 } 327 }
328 328
329 return {caller: caller}; 329 return {caller: caller};
330 } 330 }
331 331
332 assertWasm(10, TestBreakInBlock); 332 assertWasm(10, TestBreakInBlock);
333 333
334 334
335 function TestBreakInNamedWhile() { 335 function TestBreakInNamedWhile() {
336 "use asm"; 336 "use asm";
337 337
338 function caller() { 338 function caller() {
339 var x = 0; 339 var x = 0;
340 outer: while (1) { 340 outer: while (1) {
341 x = (x + 1)|0; 341 x = (x + 1)|0;
342 while (x == 11) { 342 while ((x|0) == 11) {
343 break outer; 343 break outer;
344 } 344 }
345 } 345 }
346 return x|0; 346 return x|0;
347 } 347 }
348 348
349 return {caller: caller}; 349 return {caller: caller};
350 } 350 }
351 351
352 assertWasm(11, TestBreakInNamedWhile); 352 assertWasm(11, TestBreakInNamedWhile);
353 353
354 354
355 function TestContinue() { 355 function TestContinue() {
356 "use asm"; 356 "use asm";
357 357
358 function caller() { 358 function caller() {
359 var x = 5; 359 var x = 5;
360 var ret = 0; 360 var ret = 0;
361 while (x >= 0) { 361 while ((x|0) >= 0) {
362 x = (x - 1)|0; 362 x = (x - 1)|0;
363 if (x == 2) { 363 if ((x|0) == 2) {
364 continue; 364 continue;
365 } 365 }
366 ret = (ret - 1)|0; 366 ret = (ret - 1)|0;
367 } 367 }
368 return ret|0; 368 return ret|0;
369 } 369 }
370 370
371 return {caller: caller}; 371 return {caller: caller};
372 } 372 }
373 373
374 assertWasm(-5, TestContinue); 374 assertWasm(-5, TestContinue);
375 375
376 376
377 function TestContinueInNamedWhile() { 377 function TestContinueInNamedWhile() {
378 "use asm"; 378 "use asm";
379 379
380 function caller() { 380 function caller() {
381 var x = 5; 381 var x = 5;
382 var y = 0; 382 var y = 0;
383 var ret = 0; 383 var ret = 0;
384 outer: while (x > 0) { 384 outer: while ((x|0) > 0) {
385 x = (x - 1)|0; 385 x = (x - 1)|0;
386 y = 0; 386 y = 0;
387 while (y < 5) { 387 while ((y|0) < 5) {
388 if (x == 3) { 388 if ((x|0) == 3) {
389 continue outer; 389 continue outer;
390 } 390 }
391 ret = (ret + 1)|0; 391 ret = (ret + 1)|0;
392 y = (y + 1)|0; 392 y = (y + 1)|0;
393 } 393 }
394 } 394 }
395 return ret|0; 395 return ret|0;
396 } 396 }
397 397
398 return {caller: caller}; 398 return {caller: caller};
(...skipping 14 matching lines...) Expand all
413 } 413 }
414 414
415 assertWasm(1, TestNot); 415 assertWasm(1, TestNot);
416 416
417 417
418 function TestNotEquals() { 418 function TestNotEquals() {
419 "use asm"; 419 "use asm";
420 420
421 function caller() { 421 function caller() {
422 var a = 3; 422 var a = 3;
423 if (a != 2) { 423 if ((a|0) != 2) {
424 return 21; 424 return 21;
425 } 425 }
426 return 0; 426 return 0;
427 } 427 }
428 428
429 return {caller:caller}; 429 return {caller:caller};
430 } 430 }
431 431
432 assertWasm(21, TestNotEquals); 432 assertWasm(21, TestNotEquals);
433 433
(...skipping 17 matching lines...) Expand all
451 451
452 function TestMixedAdd() { 452 function TestMixedAdd() {
453 "use asm"; 453 "use asm";
454 454
455 function caller() { 455 function caller() {
456 var a = 0x80000000; 456 var a = 0x80000000;
457 var b = 0x7fffffff; 457 var b = 0x7fffffff;
458 var c = 0; 458 var c = 0;
459 c = ((a>>>0) + b)|0; 459 c = ((a>>>0) + b)|0;
460 if ((c >>> 0) > (0>>>0)) { 460 if ((c >>> 0) > (0>>>0)) {
461 if (c < 0) { 461 if ((c|0) < 0) {
462 return 23; 462 return 23;
463 } 463 }
464 } 464 }
465 return 0; 465 return 0;
466 } 466 }
467 467
468 return {caller:caller}; 468 return {caller:caller};
469 } 469 }
470 470
471 assertWasm(23, TestMixedAdd); 471 assertWasm(23, TestMixedAdd);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 var module = Wasm.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); 726 var module = Wasm.instantiateModuleFromAsm(TestGlobalsWithInit.toString());
727 assertEquals(77.5, module.add()); 727 assertEquals(77.5, module.add());
728 })(); 728 })();
729 729
730 function TestForLoop() { 730 function TestForLoop() {
731 "use asm" 731 "use asm"
732 732
733 function caller() { 733 function caller() {
734 var ret = 0; 734 var ret = 0;
735 var i = 0; 735 var i = 0;
736 for (i = 2; i <= 10; i = (i+1)|0) { 736 for (i = 2; (i|0) <= 10; i = (i+1)|0) {
737 ret = (ret + i) | 0; 737 ret = (ret + i) | 0;
738 } 738 }
739 return ret|0; 739 return ret|0;
740 } 740 }
741 741
742 return {caller:caller}; 742 return {caller:caller};
743 } 743 }
744 744
745 assertWasm(54, TestForLoop); 745 assertWasm(54, TestForLoop);
746 746
747 747
748 function TestForLoopWithoutInit() { 748 function TestForLoopWithoutInit() {
749 "use asm" 749 "use asm"
750 750
751 function caller() { 751 function caller() {
752 var ret = 0; 752 var ret = 0;
753 var i = 0; 753 var i = 0;
754 for (; i < 10; i = (i+1)|0) { 754 for (; (i|0) < 10; i = (i+1)|0) {
755 ret = (ret + 10) | 0; 755 ret = (ret + 10) | 0;
756 } 756 }
757 return ret|0; 757 return ret|0;
758 } 758 }
759 759
760 return {caller:caller}; 760 return {caller:caller};
761 } 761 }
762 762
763 assertWasm(100,TestForLoopWithoutInit); 763 assertWasm(100,TestForLoopWithoutInit);
764 764
765 765
766 function TestForLoopWithoutCondition() { 766 function TestForLoopWithoutCondition() {
767 "use asm" 767 "use asm"
768 768
769 function caller() { 769 function caller() {
770 var ret = 0; 770 var ret = 0;
771 var i = 0; 771 var i = 0;
772 for (i=1;; i = (i+1)|0) { 772 for (i=1;; i = (i+1)|0) {
773 ret = (ret + i) | 0; 773 ret = (ret + i) | 0;
774 if (i == 11) { 774 if ((i|0) == 11) {
775 break; 775 break;
776 } 776 }
777 } 777 }
778 return ret|0; 778 return ret|0;
779 } 779 }
780 780
781 return {caller:caller}; 781 return {caller:caller};
782 } 782 }
783 783
784 assertWasm(66, TestForLoopWithoutCondition); 784 assertWasm(66, TestForLoopWithoutCondition);
785 785
786 786
787 function TestForLoopWithoutNext() { 787 function TestForLoopWithoutNext() {
788 "use asm" 788 "use asm"
789 789
790 function caller() { 790 function caller() {
791 var i = 0; 791 var i = 0;
792 for (i=1; i < 41;) { 792 for (i=1; (i|0) < 41;) {
793 i = (i + 1) | 0; 793 i = (i + 1) | 0;
794 } 794 }
795 return i|0; 795 return i|0;
796 } 796 }
797 797
798 return {caller:caller}; 798 return {caller:caller};
799 } 799 }
800 800
801 assertWasm(41, TestForLoopWithoutNext); 801 assertWasm(41, TestForLoopWithoutNext);
802 802
803 803
804 function TestForLoopWithoutBody() { 804 function TestForLoopWithoutBody() {
805 "use asm" 805 "use asm"
806 806
807 function caller() { 807 function caller() {
808 var i = 0; 808 var i = 0;
809 for (i=1; i < 45 ; i = (i+1)|0) { 809 for (i=1; (i|0) < 45 ; i = (i+1)|0) {
810 } 810 }
811 return i|0; 811 return i|0;
812 } 812 }
813 813
814 return {caller:caller}; 814 return {caller:caller};
815 } 815 }
816 816
817 assertWasm(45, TestForLoopWithoutBody); 817 assertWasm(45, TestForLoopWithoutBody);
818 818
819 819
820 function TestDoWhile() { 820 function TestDoWhile() {
821 "use asm" 821 "use asm"
822 822
823 function caller() { 823 function caller() {
824 var i = 0; 824 var i = 0;
825 var ret = 21; 825 var ret = 21;
826 do { 826 do {
827 ret = (ret + ret)|0; 827 ret = (ret + ret)|0;
828 i = (i + 1)|0; 828 i = (i + 1)|0;
829 } while (i < 2); 829 } while ((i|0) < 2);
830 return ret|0; 830 return ret|0;
831 } 831 }
832 832
833 return {caller:caller}; 833 return {caller:caller};
834 } 834 }
835 835
836 assertWasm(84, TestDoWhile); 836 assertWasm(84, TestDoWhile);
837 837
838 838
839 function TestConditional() { 839 function TestConditional() {
840 "use asm" 840 "use asm"
841 841
842 function caller() { 842 function caller() {
843 var x = 1; 843 var x = 1;
844 return ((x > 0) ? 41 : 71)|0; 844 return (((x|0) > 0) ? 41 : 71)|0;
845 } 845 }
846 846
847 return {caller:caller}; 847 return {caller:caller};
848 } 848 }
849 849
850 assertWasm(41, TestConditional); 850 assertWasm(41, TestConditional);
851 851
852 852
853 (function () { 853 (function () {
854 function TestInitFunctionWithNoGlobals() { 854 function TestInitFunctionWithNoGlobals() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 x = x|0; 904 x = x|0;
905 return (x+1)|0; 905 return (x+1)|0;
906 } 906 }
907 907
908 function inc2(x) { 908 function inc2(x) {
909 x = x|0; 909 x = x|0;
910 return (x+2)|0; 910 return (x+2)|0;
911 } 911 }
912 912
913 function caller() { 913 function caller() {
914 if (function_table[0&1](50) == 51) { 914 if ((function_table[0&1](50)|0) == 51) {
915 if (function_table[1&1](60) == 62) { 915 if ((function_table[1&1](60)|0) == 62) {
916 return 73; 916 return 73;
917 } 917 }
918 } 918 }
919 return 0; 919 return 0;
920 } 920 }
921 921
922 var function_table = [inc1, inc2] 922 var function_table = [inc1, inc2]
923 923
924 return {caller:caller}; 924 return {caller:caller};
925 } 925 }
(...skipping 20 matching lines...) Expand all
946 function inc(a) { 946 function inc(a) {
947 a = a|0; 947 a = a|0;
948 return (a+1)|0; 948 return (a+1)|0;
949 } 949 }
950 950
951 function caller(table_id, fun_id, arg1, arg2) { 951 function caller(table_id, fun_id, arg1, arg2) {
952 table_id = table_id|0; 952 table_id = table_id|0;
953 fun_id = fun_id|0; 953 fun_id = fun_id|0;
954 arg1 = arg1|0; 954 arg1 = arg1|0;
955 arg2 = arg2|0; 955 arg2 = arg2|0;
956 if (table_id == 0) { 956 if ((table_id|0) == 0) {
957 return funBin[fun_id&3](arg1, arg2)|0; 957 return funBin[fun_id&3](arg1, arg2)|0;
958 } else if (table_id == 1) { 958 } else if ((table_id|0) == 1) {
959 return fun[fun_id&0](arg1)|0; 959 return fun[fun_id&0](arg1)|0;
960 } 960 }
961 return 0; 961 return 0;
962 } 962 }
963 963
964 var funBin = [add, sub, sub, add]; 964 var funBin = [add, sub, sub, add];
965 var fun = [inc]; 965 var fun = [inc];
966 966
967 return {caller:caller}; 967 return {caller:caller};
968 } 968 }
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 assertThrows(function() { 1535 assertThrows(function() {
1536 Wasm.instantiateModuleFromAsm('33;'); 1536 Wasm.instantiateModuleFromAsm('33;');
1537 }); 1537 });
1538 })(); 1538 })();
1539 1539
1540 (function TestBadVarDeclaration() { 1540 (function TestBadVarDeclaration() {
1541 assertThrows(function() { 1541 assertThrows(function() {
1542 Wasm.instantiateModuleFromAsm('var x = 3;'); 1542 Wasm.instantiateModuleFromAsm('var x = 3;');
1543 }); 1543 });
1544 })(); 1544 })();
OLDNEW
« no previous file with comments | « test/mjsunit/regress/regress-wasm-crbug-599413.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698