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

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 1764723002: [wasm] Remove TableSwitch and replace with br_table. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 | « src/wasm/wasm-opcodes.h ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('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 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "src/wasm/wasm-macro-gen.h" 9 #include "src/wasm/wasm-macro-gen.h"
10 10
11 #include "test/cctest/cctest.h" 11 #include "test/cctest/cctest.h"
12 #include "test/cctest/compiler/value-helper.h" 12 #include "test/cctest/compiler/value-helper.h"
13 #include "test/cctest/wasm/test-signatures.h" 13 #include "test/cctest/wasm/test-signatures.h"
14 #include "test/cctest/wasm/wasm-run-utils.h" 14 #include "test/cctest/wasm/wasm-run-utils.h"
15 15
16 using namespace v8::base; 16 using namespace v8::base;
17 using namespace v8::internal; 17 using namespace v8::internal;
18 using namespace v8::internal::compiler; 18 using namespace v8::internal::compiler;
19 using namespace v8::internal::wasm; 19 using namespace v8::internal::wasm;
20 20
21 // for even shorter tests.
22 #define B2(a, b) kExprBlock, 2, a, b
23 #define B1(a) kExprBlock, 1, a
24 #define RET(x) kExprReturn, x
25 #define RET_I8(x) kExprReturn, kExprI8Const, x
26
21 TEST(Run_WasmInt8Const) { 27 TEST(Run_WasmInt8Const) {
22 WasmRunner<int32_t> r; 28 WasmRunner<int32_t> r;
23 const byte kExpectedValue = 121; 29 const byte kExpectedValue = 121;
24 // return(kExpectedValue) 30 // return(kExpectedValue)
25 BUILD(r, WASM_I8(kExpectedValue)); 31 BUILD(r, WASM_I8(kExpectedValue));
26 CHECK_EQ(kExpectedValue, r.Call()); 32 CHECK_EQ(kExpectedValue, r.Call());
27 } 33 }
28 34
29 35
30 TEST(Run_WasmInt8Const_fallthru1) { 36 TEST(Run_WasmInt8Const_fallthru1) {
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // -- 875 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // --
870 WASM_UNREACHABLE, // -- 876 WASM_UNREACHABLE, // --
871 WASM_I8(27))); // -- 877 WASM_I8(27))); // --
872 CHECK_EQ(27, r.Call()); 878 CHECK_EQ(27, r.Call());
873 } 879 }
874 880
875 881
876 TEST(Run_Wasm_Return12) { 882 TEST(Run_Wasm_Return12) {
877 WasmRunner<int32_t> r; 883 WasmRunner<int32_t> r;
878 884
879 BUILD(r, WASM_RETURN(WASM_I8(12))); 885 BUILD(r, RET_I8(12));
880 CHECK_EQ(12, r.Call()); 886 CHECK_EQ(12, r.Call());
881 } 887 }
882 888
883 889
884 TEST(Run_Wasm_Return17) { 890 TEST(Run_Wasm_Return17) {
885 WasmRunner<int32_t> r; 891 WasmRunner<int32_t> r;
886 892
887 BUILD(r, WASM_BLOCK(1, WASM_RETURN(WASM_I8(17)))); 893 BUILD(r, B1(RET_I8(17)));
888 CHECK_EQ(17, r.Call()); 894 CHECK_EQ(17, r.Call());
889 } 895 }
890 896
891 897
892 TEST(Run_Wasm_Return_I32) { 898 TEST(Run_Wasm_Return_I32) {
893 WasmRunner<int32_t> r(MachineType::Int32()); 899 WasmRunner<int32_t> r(MachineType::Int32());
894 900
895 BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0))); 901 BUILD(r, RET(WASM_GET_LOCAL(0)));
896 902
897 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 903 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
898 } 904 }
899 905
900 906
901 #if WASM_64 907 #if WASM_64
902 TEST(Run_Wasm_Return_I64) { 908 TEST(Run_Wasm_Return_I64) {
903 WasmRunner<int64_t> r(MachineType::Int64()); 909 WasmRunner<int64_t> r(MachineType::Int64());
904 910
905 BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0))); 911 BUILD(r, RET(WASM_GET_LOCAL(0)));
906 912
907 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 913 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
908 } 914 }
909 #endif 915 #endif
910 916
911 917
912 TEST(Run_Wasm_Return_F32) { 918 TEST(Run_Wasm_Return_F32) {
913 WasmRunner<float> r(MachineType::Float32()); 919 WasmRunner<float> r(MachineType::Float32());
914 920
915 BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0))); 921 BUILD(r, RET(WASM_GET_LOCAL(0)));
916 922
917 FOR_FLOAT32_INPUTS(i) { 923 FOR_FLOAT32_INPUTS(i) {
918 float expect = *i; 924 float expect = *i;
919 float result = r.Call(expect); 925 float result = r.Call(expect);
920 if (std::isnan(expect)) { 926 if (std::isnan(expect)) {
921 CHECK(std::isnan(result)); 927 CHECK(std::isnan(result));
922 } else { 928 } else {
923 CHECK_EQ(expect, result); 929 CHECK_EQ(expect, result);
924 } 930 }
925 } 931 }
926 } 932 }
927 933
928 934
929 TEST(Run_Wasm_Return_F64) { 935 TEST(Run_Wasm_Return_F64) {
930 WasmRunner<double> r(MachineType::Float64()); 936 WasmRunner<double> r(MachineType::Float64());
931 937
932 BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0))); 938 BUILD(r, RET(WASM_GET_LOCAL(0)));
933 939
934 FOR_FLOAT64_INPUTS(i) { 940 FOR_FLOAT64_INPUTS(i) {
935 double expect = *i; 941 double expect = *i;
936 double result = r.Call(expect); 942 double result = r.Call(expect);
937 if (std::isnan(expect)) { 943 if (std::isnan(expect)) {
938 CHECK(std::isnan(result)); 944 CHECK(std::isnan(result));
939 } else { 945 } else {
940 CHECK_EQ(expect, result); 946 CHECK_EQ(expect, result);
941 } 947 }
942 } 948 }
943 } 949 }
944 950
945 951
946 TEST(Run_Wasm_Select) { 952 TEST(Run_Wasm_Select) {
947 WasmRunner<int32_t> r(MachineType::Int32()); 953 WasmRunner<int32_t> r(MachineType::Int32());
948 // return select(11, 22, a); 954 // return select(11, 22, a);
949 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); 955 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0)));
950 FOR_INT32_INPUTS(i) { 956 FOR_INT32_INPUTS(i) {
951 int32_t expected = *i ? 11 : 22; 957 int32_t expected = *i ? 11 : 22;
952 CHECK_EQ(expected, r.Call(*i)); 958 CHECK_EQ(expected, r.Call(*i));
953 } 959 }
954 } 960 }
955 961
956 962
957 TEST(Run_Wasm_Select_strict1) { 963 TEST(Run_Wasm_Select_strict1) {
958 WasmRunner<int32_t> r(MachineType::Int32()); 964 WasmRunner<int32_t> r(MachineType::Int32());
959 // select(a=0, a=1, a=2); return a 965 // select(a=0, a=1, a=2); return a
960 BUILD(r, WASM_BLOCK(2, WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), 966 BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)),
961 WASM_SET_LOCAL(0, WASM_I8(1)), 967 WASM_SET_LOCAL(0, WASM_I8(1)),
962 WASM_SET_LOCAL(0, WASM_I8(2))), 968 WASM_SET_LOCAL(0, WASM_I8(2))),
963 WASM_GET_LOCAL(0))); 969 WASM_GET_LOCAL(0)));
964 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } 970 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); }
965 } 971 }
966 972
967 973
968 TEST(Run_Wasm_Select_strict2) { 974 TEST(Run_Wasm_Select_strict2) {
969 WasmRunner<int32_t> r(MachineType::Int32()); 975 WasmRunner<int32_t> r(MachineType::Int32());
970 r.env()->AddLocals(kAstI32, 2); 976 r.env()->AddLocals(kAstI32, 2);
971 // select(b=5, c=6, a) 977 // select(b=5, c=6, a)
972 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), 978 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)),
973 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); 979 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0)));
(...skipping 12 matching lines...) Expand all
986 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); 992 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1))));
987 FOR_INT32_INPUTS(i) { 993 FOR_INT32_INPUTS(i) {
988 int32_t expected = 5; 994 int32_t expected = 5;
989 CHECK_EQ(expected, r.Call(*i)); 995 CHECK_EQ(expected, r.Call(*i));
990 } 996 }
991 } 997 }
992 998
993 999
994 TEST(Run_Wasm_BrIf_strict) { 1000 TEST(Run_Wasm_BrIf_strict) {
995 WasmRunner<int32_t> r(MachineType::Int32()); 1001 WasmRunner<int32_t> r(MachineType::Int32());
996 BUILD(r, WASM_BLOCK( 1002 BUILD(
997 2, WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), 1003 r,
998 WASM_SET_LOCAL(0, WASM_I8(99)))), 1004 B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))),
999 WASM_GET_LOCAL(0))); 1005 WASM_GET_LOCAL(0)));
1000 1006
1001 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); } 1007 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); }
1002 } 1008 }
1003 1009
1004 TEST(Run_Wasm_TableSwitch0a) { 1010 TEST(Run_Wasm_BrTable0a) {
1005 WasmRunner<int32_t> r(MachineType::Int32()); 1011 WasmRunner<int32_t> r(MachineType::Int32());
1006 BUILD(r, WASM_BLOCK(2, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(0)), 1012 BUILD(r,
1007 WASM_TABLESWITCH_BODY0(WASM_GET_LOCAL(0)), WASM_I8(91))); 1013 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91)));
1008 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } 1014 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); }
1009 } 1015 }
1010 1016
1011 TEST(Run_Wasm_TableSwitch0b) { 1017 TEST(Run_Wasm_BrTable0b) {
1012 WasmRunner<int32_t> r(MachineType::Int32()); 1018 WasmRunner<int32_t> r(MachineType::Int32());
1013 BUILD(r, WASM_BLOCK( 1019 BUILD(r,
1014 2, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), WASM_CASE_BR(0)), 1020 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))),
1015 WASM_TABLESWITCH_BODY0(WASM_GET_LOCAL(0)), WASM_I8(92))); 1021 WASM_I8(92)));
1016 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } 1022 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); }
1017 } 1023 }
1018 1024
1019 TEST(Run_Wasm_TableSwitch0c) { 1025 TEST(Run_Wasm_BrTable0c) {
1020 WasmRunner<int32_t> r(MachineType::Int32()); 1026 WasmRunner<int32_t> r(MachineType::Int32());
1021 BUILD(r, 1027 BUILD(
1022 WASM_BLOCK(2, WASM_BLOCK(2, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), 1028 r,
1023 WASM_CASE_BR(1)), 1029 B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))),
1024 WASM_TABLESWITCH_BODY0(WASM_GET_LOCAL(0)), 1030 RET_I8(76)),
1025 WASM_RETURN(WASM_I8(76))), 1031 WASM_I8(77)));
1026 WASM_I8(77)));
1027 FOR_INT32_INPUTS(i) { 1032 FOR_INT32_INPUTS(i) {
1028 int32_t expected = *i == 0 ? 76 : 77; 1033 int32_t expected = *i == 0 ? 76 : 77;
1029 CHECK_EQ(expected, r.Call(*i)); 1034 CHECK_EQ(expected, r.Call(*i));
1030 } 1035 }
1031 } 1036 }
1032 1037
1033 TEST(Run_Wasm_TableSwitch1) { 1038 TEST(Run_Wasm_BrTable1) {
1034 WasmRunner<int32_t> r(MachineType::Int32()); 1039 WasmRunner<int32_t> r(MachineType::Int32());
1035 BUILD(r, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1040 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93));
1036 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(93))));
1037 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } 1041 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); }
1038 } 1042 }
1039 1043
1044 TEST(Run_Wasm_BrTable_loop) {
1045 WasmRunner<int32_t> r(MachineType::Int32());
1046 BUILD(r,
1047 B2(WASM_LOOP(1, WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2),
1048 BR_TARGET(1), BR_TARGET(0))),
1049 RET_I8(99)),
1050 WASM_I8(98));
1051 CHECK_EQ(99, r.Call(0));
1052 CHECK_EQ(98, r.Call(-1));
1053 CHECK_EQ(98, r.Call(-2));
1054 CHECK_EQ(98, r.Call(-3));
1055 CHECK_EQ(98, r.Call(-100));
1056 }
1040 1057
1041 TEST(Run_Wasm_TableSwitch_br) { 1058 TEST(Run_Wasm_BrTable_br) {
1042 WasmRunner<int32_t> r(MachineType::Int32()); 1059 WasmRunner<int32_t> r(MachineType::Int32());
1043 BUILD(r, WASM_TABLESWITCH_OP(1, 2, WASM_CASE_BR(0), WASM_CASE(0)), 1060 BUILD(r,
1044 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(91))), 1061 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))),
1062 RET_I8(91)),
1045 WASM_I8(99)); 1063 WASM_I8(99));
1046 CHECK_EQ(99, r.Call(0)); 1064 CHECK_EQ(99, r.Call(0));
1047 CHECK_EQ(91, r.Call(1)); 1065 CHECK_EQ(91, r.Call(1));
1048 CHECK_EQ(91, r.Call(2)); 1066 CHECK_EQ(91, r.Call(2));
1049 CHECK_EQ(91, r.Call(3)); 1067 CHECK_EQ(91, r.Call(3));
1050 } 1068 }
1051 1069
1070 TEST(Run_Wasm_BrTable_br2) {
1071 WasmRunner<int32_t> r(MachineType::Int32());
1052 1072
1053 TEST(Run_Wasm_TableSwitch_br2) { 1073 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1),
1054 WasmRunner<int32_t> r(MachineType::Int32()); 1074 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))),
1055 BUILD(r, WASM_BLOCK( 1075 RET_I8(85)),
1056 2, WASM_BLOCK(2, WASM_TABLESWITCH_OP( 1076 RET_I8(86)),
1057 1, 4, WASM_CASE_BR(0), WASM_CASE_BR(1), 1077 RET_I8(87)),
1058 WASM_CASE_BR(2), WASM_CASE(0)),
1059 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0),
1060 WASM_RETURN(WASM_I8(85))),
1061 WASM_RETURN(WASM_I8(86))),
1062 WASM_RETURN(WASM_I8(87))),
1063 WASM_I8(88)); 1078 WASM_I8(88));
1064 CHECK_EQ(86, r.Call(0)); 1079 CHECK_EQ(86, r.Call(0));
1065 CHECK_EQ(87, r.Call(1)); 1080 CHECK_EQ(87, r.Call(1));
1066 CHECK_EQ(88, r.Call(2)); 1081 CHECK_EQ(88, r.Call(2));
1067 CHECK_EQ(85, r.Call(3)); 1082 CHECK_EQ(85, r.Call(3));
1068 CHECK_EQ(85, r.Call(4)); 1083 CHECK_EQ(85, r.Call(4));
1069 CHECK_EQ(85, r.Call(5)); 1084 CHECK_EQ(85, r.Call(5));
1070 } 1085 }
1071 1086
1087 TEST(Run_Wasm_BrTable4) {
1088 for (int i = 0; i < 4; i++) {
1089 for (int t = 0; t < 4; t++) {
1090 uint16_t cases[] = {0, 1, 2, 3};
1091 cases[i] = t;
1092 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE(
1093 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]),
1094 BR_TARGET(cases[1]), BR_TARGET(cases[2]),
1095 BR_TARGET(cases[3]))),
1096 RET_I8(70)),
1097 RET_I8(71)),
1098 RET_I8(72)),
1099 RET_I8(73)),
1100 WASM_I8(75)};
1072 1101
1073 TEST(Run_Wasm_TableSwitch2) { 1102 WasmRunner<int32_t> r(MachineType::Int32());
1074 WasmRunner<int32_t> r(MachineType::Int32()); 1103 r.Build(code, code + arraysize(code));
1075 BUILD(r, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1076 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(91)),
1077 WASM_RETURN(WASM_I8(92))));
1078 FOR_INT32_INPUTS(i) {
1079 int32_t expected = *i == 0 ? 91 : 92;
1080 CHECK_EQ(expected, r.Call(*i));
1081 }
1082 }
1083 1104
1084 1105 for (int x = -3; x < 50; x++) {
1085 TEST(Run_Wasm_TableSwitch2b) { 1106 int index = (x > 3 || x < 0) ? 3 : x;
1086 WasmRunner<int32_t> r(MachineType::Int32()); 1107 int32_t expected = 70 + cases[index];
1087 BUILD(r, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(1), WASM_CASE(0)), 1108 CHECK_EQ(expected, r.Call(x));
1088 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(81)), 1109 }
1089 WASM_RETURN(WASM_I8(82))));
1090 FOR_INT32_INPUTS(i) {
1091 int32_t expected = *i == 0 ? 82 : 81;
1092 CHECK_EQ(expected, r.Call(*i));
1093 }
1094 }
1095
1096
1097 TEST(Run_Wasm_TableSwitch4) {
1098 for (int i = 0; i < 4; i++) {
1099 const uint16_t br = 0x8000u;
1100 uint16_t c = 0;
1101 uint16_t cases[] = {i == 0 ? br : c++, i == 1 ? br : c++, i == 2 ? br : c++,
1102 i == 3 ? br : c++};
1103 byte code[] = {
1104 WASM_BLOCK(1, WASM_TABLESWITCH_OP(
1105 3, 4, WASM_CASE(cases[0]), WASM_CASE(cases[1]),
1106 WASM_CASE(cases[2]), WASM_CASE(cases[3])),
1107 WASM_TABLESWITCH_BODY(
1108 WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(71)),
1109 WASM_RETURN(WASM_I8(72)), WASM_RETURN(WASM_I8(73)))),
1110 WASM_RETURN(WASM_I8(74))};
1111
1112 WasmRunner<int32_t> r(MachineType::Int32());
1113 r.Build(code, code + arraysize(code));
1114
1115 FOR_INT32_INPUTS(i) {
1116 int index = (*i < 0 || *i > 3) ? 3 : *i;
1117 int32_t expected = 71 + cases[index];
1118 if (expected >= 0x8000) expected = 74;
1119 CHECK_EQ(expected, r.Call(*i));
1120 } 1110 }
1121 } 1111 }
1122 } 1112 }
1123 1113
1114 TEST(Run_Wasm_BrTable4x4) {
1115 for (byte a = 0; a < 4; a++) {
1116 for (byte b = 0; b < 4; b++) {
1117 for (byte c = 0; c < 4; c++) {
1118 for (byte d = 0; d < 4; d++) {
1119 for (int i = 0; i < 4; i++) {
1120 uint16_t cases[] = {a, b, c, d};
1121 byte code[] = {
1122 B2(B2(B2(B2(B1(WASM_BR_TABLE(
1123 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]),
1124 BR_TARGET(cases[1]), BR_TARGET(cases[2]),
1125 BR_TARGET(cases[3]))),
1126 RET_I8(50)),
1127 RET_I8(51)),
1128 RET_I8(52)),
1129 RET_I8(53)),
1130 WASM_I8(55)};
1124 1131
1125 TEST(Run_Wasm_TableSwitch4b) { 1132 WasmRunner<int32_t> r(MachineType::Int32());
1126 for (int a = 0; a < 2; a++) { 1133 r.Build(code, code + arraysize(code));
1127 for (int b = 0; b < 2; b++) {
1128 for (int c = 0; c < 2; c++) {
1129 for (int d = 0; d < 2; d++) {
1130 if (a + b + c + d == 0) continue;
1131 if (a + b + c + d == 4) continue;
1132 1134
1133 byte code[] = { 1135 for (int x = -6; x < 47; x++) {
1134 WASM_TABLESWITCH_OP(2, 4, WASM_CASE(a), WASM_CASE(b), 1136 int index = (x > 3 || x < 0) ? 3 : x;
1135 WASM_CASE(c), WASM_CASE(d)), 1137 int32_t expected = 50 + cases[index];
1136 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(61)), 1138 CHECK_EQ(expected, r.Call(x));
1137 WASM_RETURN(WASM_I8(62)))}; 1139 }
1138 1140 }
1139 WasmRunner<int32_t> r(MachineType::Int32());
1140 r.Build(code, code + arraysize(code));
1141
1142 CHECK_EQ(61 + a, r.Call(0));
1143 CHECK_EQ(61 + b, r.Call(1));
1144 CHECK_EQ(61 + c, r.Call(2));
1145 CHECK_EQ(61 + d, r.Call(3));
1146 CHECK_EQ(61 + d, r.Call(4));
1147 } 1141 }
1148 } 1142 }
1149 } 1143 }
1150 } 1144 }
1151 } 1145 }
1152 1146
1153 1147 TEST(Run_Wasm_BrTable4_fallthru) {
1154 TEST(Run_Wasm_TableSwitch4_fallthru) {
1155 byte code[] = { 1148 byte code[] = {
1156 WASM_TABLESWITCH_OP(4, 4, WASM_CASE(0), WASM_CASE(1), WASM_CASE(2), 1149 B2(B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(0),
1157 WASM_CASE(3)), 1150 BR_TARGET(1), BR_TARGET(2), BR_TARGET(3))),
1158 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_INC_LOCAL_BY(1, 1), 1151 WASM_INC_LOCAL_BY(1, 1)),
1159 WASM_INC_LOCAL_BY(1, 2), WASM_INC_LOCAL_BY(1, 4), 1152 WASM_INC_LOCAL_BY(1, 2)),
1160 WASM_INC_LOCAL_BY(1, 8)), 1153 WASM_INC_LOCAL_BY(1, 4)),
1154 WASM_INC_LOCAL_BY(1, 8)),
1161 WASM_GET_LOCAL(1)}; 1155 WASM_GET_LOCAL(1)};
1162 1156
1163 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); 1157 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
1164 r.Build(code, code + arraysize(code)); 1158 r.Build(code, code + arraysize(code));
1165 1159
1166 CHECK_EQ(15, r.Call(0, 0)); 1160 CHECK_EQ(15, r.Call(0, 0));
1167 CHECK_EQ(14, r.Call(1, 0)); 1161 CHECK_EQ(14, r.Call(1, 0));
1168 CHECK_EQ(12, r.Call(2, 0)); 1162 CHECK_EQ(12, r.Call(2, 0));
1169 CHECK_EQ(8, r.Call(3, 0)); 1163 CHECK_EQ(8, r.Call(3, 0));
1170 CHECK_EQ(8, r.Call(4, 0)); 1164 CHECK_EQ(8, r.Call(4, 0));
1171 1165
1172 CHECK_EQ(115, r.Call(0, 100)); 1166 CHECK_EQ(115, r.Call(0, 100));
1173 CHECK_EQ(114, r.Call(1, 100)); 1167 CHECK_EQ(114, r.Call(1, 100));
1174 CHECK_EQ(112, r.Call(2, 100)); 1168 CHECK_EQ(112, r.Call(2, 100));
1175 CHECK_EQ(108, r.Call(3, 100)); 1169 CHECK_EQ(108, r.Call(3, 100));
1176 CHECK_EQ(108, r.Call(4, 100)); 1170 CHECK_EQ(108, r.Call(4, 100));
1177 } 1171 }
1178 1172
1179
1180 TEST(Run_Wasm_TableSwitch4_fallthru_br) {
1181 byte code[] = {
1182 WASM_TABLESWITCH_OP(4, 4, WASM_CASE(0), WASM_CASE(1), WASM_CASE(2),
1183 WASM_CASE(3)),
1184 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_INC_LOCAL_BY(1, 1),
1185 WASM_BRV(0, WASM_INC_LOCAL_BY(1, 2)),
1186 WASM_INC_LOCAL_BY(1, 4),
1187 WASM_BRV(0, WASM_INC_LOCAL_BY(1, 8))),
1188 WASM_GET_LOCAL(1)};
1189
1190 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
1191 r.Build(code, code + arraysize(code));
1192
1193 CHECK_EQ(3, r.Call(0, 0));
1194 CHECK_EQ(2, r.Call(1, 0));
1195 CHECK_EQ(12, r.Call(2, 0));
1196 CHECK_EQ(8, r.Call(3, 0));
1197 CHECK_EQ(8, r.Call(4, 0));
1198
1199 CHECK_EQ(203, r.Call(0, 200));
1200 CHECK_EQ(202, r.Call(1, 200));
1201 CHECK_EQ(212, r.Call(2, 200));
1202 CHECK_EQ(208, r.Call(3, 200));
1203 CHECK_EQ(208, r.Call(4, 200));
1204 }
1205
1206
1207 TEST(Run_Wasm_F32ReinterpretI32) { 1173 TEST(Run_Wasm_F32ReinterpretI32) {
1208 TestingModule module; 1174 TestingModule module;
1209 int32_t* memory = module.AddMemoryElems<int32_t>(8); 1175 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1210 WasmRunner<int32_t> r(&module); 1176 WasmRunner<int32_t> r(&module);
1211 1177
1212 BUILD(r, WASM_I32_REINTERPRET_F32( 1178 BUILD(r, WASM_I32_REINTERPRET_F32(
1213 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); 1179 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)));
1214 1180
1215 FOR_INT32_INPUTS(i) { 1181 FOR_INT32_INPUTS(i) {
1216 int32_t expected = *i; 1182 int32_t expected = *i;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 TestSignatures sigs; 1227 TestSignatures sigs;
1262 TestingModule module; 1228 TestingModule module;
1263 WasmFunctionCompiler t(sigs.v_v(), &module); 1229 WasmFunctionCompiler t(sigs.v_v(), &module);
1264 BUILD(t, kExprNop); 1230 BUILD(t, kExprNop);
1265 uint32_t index = t.CompileAndAdd(); 1231 uint32_t index = t.CompileAndAdd();
1266 1232
1267 const int32_t kExpected = -414444; 1233 const int32_t kExpected = -414444;
1268 // Build the calling function. 1234 // Build the calling function.
1269 WasmRunner<int32_t> r; 1235 WasmRunner<int32_t> r;
1270 r.env()->module = &module; 1236 r.env()->module = &module;
1271 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); 1237 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
1272 1238
1273 int32_t result = r.Call(); 1239 int32_t result = r.Call();
1274 CHECK_EQ(kExpected, result); 1240 CHECK_EQ(kExpected, result);
1275 } 1241 }
1276 1242
1277 1243
1278 TEST(Run_Wasm_VoidReturn2) { 1244 TEST(Run_Wasm_VoidReturn2) {
1279 // We use a wrapper function because WasmRunner<void> does not exist. 1245 // We use a wrapper function because WasmRunner<void> does not exist.
1280 // Build the test function. 1246 // Build the test function.
1281 TestSignatures sigs; 1247 TestSignatures sigs;
1282 TestingModule module; 1248 TestingModule module;
1283 WasmFunctionCompiler t(sigs.v_v(), &module); 1249 WasmFunctionCompiler t(sigs.v_v(), &module);
1284 BUILD(t, WASM_RETURN0); 1250 BUILD(t, WASM_RETURN0);
1285 uint32_t index = t.CompileAndAdd(); 1251 uint32_t index = t.CompileAndAdd();
1286 1252
1287 const int32_t kExpected = -414444; 1253 const int32_t kExpected = -414444;
1288 // Build the calling function. 1254 // Build the calling function.
1289 WasmRunner<int32_t> r; 1255 WasmRunner<int32_t> r;
1290 r.env()->module = &module; 1256 r.env()->module = &module;
1291 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); 1257 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
1292 1258
1293 int32_t result = r.Call(); 1259 int32_t result = r.Call();
1294 CHECK_EQ(kExpected, result); 1260 CHECK_EQ(kExpected, result);
1295 } 1261 }
1296 1262
1297 1263
1298 TEST(Run_Wasm_Block_If_P) { 1264 TEST(Run_Wasm_Block_If_P) {
1299 WasmRunner<int32_t> r(MachineType::Int32()); 1265 WasmRunner<int32_t> r(MachineType::Int32());
1300 // { if (p0) return 51; return 52; } 1266 // { if (p0) return 51; return 52; }
1301 BUILD(r, WASM_BLOCK(2, // -- 1267 BUILD(r, B2( // --
1302 WASM_IF(WASM_GET_LOCAL(0), // -- 1268 WASM_IF(WASM_GET_LOCAL(0), // --
1303 WASM_BRV(0, WASM_I8(51))), // -- 1269 WASM_BRV(0, WASM_I8(51))), // --
1304 WASM_I8(52))); // -- 1270 WASM_I8(52))); // --
1305 FOR_INT32_INPUTS(i) { 1271 FOR_INT32_INPUTS(i) {
1306 int32_t expected = *i ? 51 : 52; 1272 int32_t expected = *i ? 51 : 52;
1307 CHECK_EQ(expected, r.Call(*i)); 1273 CHECK_EQ(expected, r.Call(*i));
1308 } 1274 }
1309 } 1275 }
1310 1276
1311 1277
1312 TEST(Run_Wasm_Block_BrIf_P) { 1278 TEST(Run_Wasm_Block_BrIf_P) {
1313 WasmRunner<int32_t> r(MachineType::Int32()); 1279 WasmRunner<int32_t> r(MachineType::Int32());
1314 BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), 1280 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52)));
1315 WASM_I8(52)));
1316 FOR_INT32_INPUTS(i) { 1281 FOR_INT32_INPUTS(i) {
1317 int32_t expected = *i ? 51 : 52; 1282 int32_t expected = *i ? 51 : 52;
1318 CHECK_EQ(expected, r.Call(*i)); 1283 CHECK_EQ(expected, r.Call(*i));
1319 } 1284 }
1320 } 1285 }
1321 1286
1322 1287
1323 TEST(Run_Wasm_Block_IfElse_P_assign) { 1288 TEST(Run_Wasm_Block_IfElse_P_assign) {
1324 WasmRunner<int32_t> r(MachineType::Int32()); 1289 WasmRunner<int32_t> r(MachineType::Int32());
1325 // { if (p0) p0 = 71; else p0 = 72; return p0; } 1290 // { if (p0) p0 = 71; else p0 = 72; return p0; }
1326 BUILD(r, WASM_BLOCK(2, // -- 1291 BUILD(r, B2( // --
1327 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- 1292 WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1328 WASM_SET_LOCAL(0, WASM_I8(71)), // -- 1293 WASM_SET_LOCAL(0, WASM_I8(71)), // --
1329 WASM_SET_LOCAL(0, WASM_I8(72))), // -- 1294 WASM_SET_LOCAL(0, WASM_I8(72))), // --
1330 WASM_GET_LOCAL(0))); 1295 WASM_GET_LOCAL(0)));
1331 FOR_INT32_INPUTS(i) { 1296 FOR_INT32_INPUTS(i) {
1332 int32_t expected = *i ? 71 : 72; 1297 int32_t expected = *i ? 71 : 72;
1333 CHECK_EQ(expected, r.Call(*i)); 1298 CHECK_EQ(expected, r.Call(*i));
1334 } 1299 }
1335 } 1300 }
1336 1301
1337 1302
1338 TEST(Run_Wasm_Block_IfElse_P_return) { 1303 TEST(Run_Wasm_Block_IfElse_P_return) {
1339 WasmRunner<int32_t> r(MachineType::Int32()); 1304 WasmRunner<int32_t> r(MachineType::Int32());
1340 // if (p0) return 81; else return 82; 1305 // if (p0) return 81; else return 82;
1341 BUILD(r, // -- 1306 BUILD(r, // --
1342 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- 1307 WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1343 WASM_RETURN(WASM_I8(81)), // -- 1308 RET_I8(81), // --
1344 WASM_RETURN(WASM_I8(82)))); // -- 1309 RET_I8(82))); // --
1345 FOR_INT32_INPUTS(i) { 1310 FOR_INT32_INPUTS(i) {
1346 int32_t expected = *i ? 81 : 82; 1311 int32_t expected = *i ? 81 : 82;
1347 CHECK_EQ(expected, r.Call(*i)); 1312 CHECK_EQ(expected, r.Call(*i));
1348 } 1313 }
1349 } 1314 }
1350 1315
1351 1316
1352 TEST(Run_Wasm_Block_If_P_assign) { 1317 TEST(Run_Wasm_Block_If_P_assign) {
1353 WasmRunner<int32_t> r(MachineType::Int32()); 1318 WasmRunner<int32_t> r(MachineType::Int32());
1354 // { if (p0) p0 = 61; p0; } 1319 // { if (p0) p0 = 61; p0; }
1355 BUILD(r, WASM_BLOCK( 1320 BUILD(r, WASM_BLOCK(
1356 2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), 1321 2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))),
1357 WASM_GET_LOCAL(0))); 1322 WASM_GET_LOCAL(0)));
1358 FOR_INT32_INPUTS(i) { 1323 FOR_INT32_INPUTS(i) {
1359 int32_t expected = *i ? 61 : *i; 1324 int32_t expected = *i ? 61 : *i;
1360 CHECK_EQ(expected, r.Call(*i)); 1325 CHECK_EQ(expected, r.Call(*i));
1361 } 1326 }
1362 } 1327 }
1363 1328
1364 1329
1365 TEST(Run_Wasm_DanglingAssign) { 1330 TEST(Run_Wasm_DanglingAssign) {
1366 WasmRunner<int32_t> r(MachineType::Int32()); 1331 WasmRunner<int32_t> r(MachineType::Int32());
1367 // { return 0; p0 = 0; } 1332 // { return 0; p0 = 0; }
1368 BUILD(r, 1333 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO)));
1369 WASM_BLOCK(2, WASM_RETURN(WASM_I8(99)), WASM_SET_LOCAL(0, WASM_ZERO)));
1370 CHECK_EQ(99, r.Call(1)); 1334 CHECK_EQ(99, r.Call(1));
1371 } 1335 }
1372 1336
1373 1337
1374 TEST(Run_Wasm_ExprIf_P) { 1338 TEST(Run_Wasm_ExprIf_P) {
1375 WasmRunner<int32_t> r(MachineType::Int32()); 1339 WasmRunner<int32_t> r(MachineType::Int32());
1376 // p0 ? 11 : 22; 1340 // p0 ? 11 : 22;
1377 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- 1341 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1378 WASM_I8(11), // -- 1342 WASM_I8(11), // --
1379 WASM_I8(22))); // -- 1343 WASM_I8(22))); // --
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 WASM_I8(1)))), 1400 WASM_I8(1)))),
1437 WASM_GET_LOCAL(0))); 1401 WASM_GET_LOCAL(0)));
1438 CHECK_EQ(0, r.Call(1)); 1402 CHECK_EQ(0, r.Call(1));
1439 CHECK_EQ(0, r.Call(10)); 1403 CHECK_EQ(0, r.Call(10));
1440 CHECK_EQ(0, r.Call(100)); 1404 CHECK_EQ(0, r.Call(100));
1441 } 1405 }
1442 1406
1443 1407
1444 TEST(Run_Wasm_Loop_if_break1) { 1408 TEST(Run_Wasm_Loop_if_break1) {
1445 WasmRunner<int32_t> r(MachineType::Int32()); 1409 WasmRunner<int32_t> r(MachineType::Int32());
1446 BUILD(r, WASM_BLOCK(2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(0)), 1410 BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(0)),
1447 WASM_SET_LOCAL(0, WASM_I8(99))), 1411 WASM_SET_LOCAL(0, WASM_I8(99))),
1448 WASM_GET_LOCAL(0))); 1412 WASM_GET_LOCAL(0)));
1449 CHECK_EQ(99, r.Call(0)); 1413 CHECK_EQ(99, r.Call(0));
1450 CHECK_EQ(3, r.Call(3)); 1414 CHECK_EQ(3, r.Call(3));
1451 CHECK_EQ(10000, r.Call(10000)); 1415 CHECK_EQ(10000, r.Call(10000));
1452 CHECK_EQ(-29, r.Call(-29)); 1416 CHECK_EQ(-29, r.Call(-29));
1453 } 1417 }
1454 1418
1455 1419
1456 TEST(Run_Wasm_Loop_if_break2) { 1420 TEST(Run_Wasm_Loop_if_break2) {
1457 WasmRunner<int32_t> r(MachineType::Int32()); 1421 WasmRunner<int32_t> r(MachineType::Int32());
1458 BUILD(r, WASM_BLOCK(2, WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)), 1422 BUILD(r, B2(WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)),
1459 WASM_SET_LOCAL(0, WASM_I8(99))), 1423 WASM_SET_LOCAL(0, WASM_I8(99))),
1460 WASM_GET_LOCAL(0))); 1424 WASM_GET_LOCAL(0)));
1461 CHECK_EQ(99, r.Call(0)); 1425 CHECK_EQ(99, r.Call(0));
1462 CHECK_EQ(3, r.Call(3)); 1426 CHECK_EQ(3, r.Call(3));
1463 CHECK_EQ(10000, r.Call(10000)); 1427 CHECK_EQ(10000, r.Call(10000));
1464 CHECK_EQ(-29, r.Call(-29)); 1428 CHECK_EQ(-29, r.Call(-29));
1465 } 1429 }
1466 1430
1467 1431
1468 TEST(Run_Wasm_Loop_if_break_fallthru) { 1432 TEST(Run_Wasm_Loop_if_break_fallthru) {
1469 WasmRunner<int32_t> r(MachineType::Int32()); 1433 WasmRunner<int32_t> r(MachineType::Int32());
1470 BUILD(r, WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), 1434 BUILD(r, B1(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)),
1471 WASM_SET_LOCAL(0, WASM_I8(93)))), 1435 WASM_SET_LOCAL(0, WASM_I8(93)))),
1472 WASM_GET_LOCAL(0)); 1436 WASM_GET_LOCAL(0));
1473 CHECK_EQ(93, r.Call(0)); 1437 CHECK_EQ(93, r.Call(0));
1474 CHECK_EQ(3, r.Call(3)); 1438 CHECK_EQ(3, r.Call(3));
1475 CHECK_EQ(10001, r.Call(10001)); 1439 CHECK_EQ(10001, r.Call(10001));
1476 CHECK_EQ(-22, r.Call(-22)); 1440 CHECK_EQ(-22, r.Call(-22));
1477 } 1441 }
1478 1442
1479 1443
1480 TEST(Run_Wasm_LoadMemI32) { 1444 TEST(Run_Wasm_LoadMemI32) {
1481 TestingModule module; 1445 TestingModule module;
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 module.AddMemoryElems<int8_t>(16); 1907 module.AddMemoryElems<int8_t>(16);
1944 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1908 WasmRunner<int32_t> r(&module, MachineType::Int32());
1945 1909
1946 // Only build the graph and compile, don't run. 1910 // Only build the graph and compile, don't run.
1947 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); 1911 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)));
1948 } 1912 }
1949 1913
1950 1914
1951 TEST(Run_Wasm_Unreachable0a) { 1915 TEST(Run_Wasm_Unreachable0a) {
1952 WasmRunner<int32_t> r(MachineType::Int32()); 1916 WasmRunner<int32_t> r(MachineType::Int32());
1953 BUILD(r, 1917 BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0))));
1954 WASM_BLOCK(2, WASM_BRV(0, WASM_I8(9)), WASM_RETURN(WASM_GET_LOCAL(0))));
1955 CHECK_EQ(9, r.Call(0)); 1918 CHECK_EQ(9, r.Call(0));
1956 CHECK_EQ(9, r.Call(1)); 1919 CHECK_EQ(9, r.Call(1));
1957 } 1920 }
1958 1921
1959 1922
1960 TEST(Run_Wasm_Unreachable0b) { 1923 TEST(Run_Wasm_Unreachable0b) {
1961 WasmRunner<int32_t> r(MachineType::Int32()); 1924 WasmRunner<int32_t> r(MachineType::Int32());
1962 BUILD(r, WASM_BLOCK(2, WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); 1925 BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE));
1963 CHECK_EQ(7, r.Call(0)); 1926 CHECK_EQ(7, r.Call(0));
1964 CHECK_EQ(7, r.Call(1)); 1927 CHECK_EQ(7, r.Call(1));
1965 } 1928 }
1966 1929
1967 1930
1968 TEST(Build_Wasm_Unreachable1) { 1931 TEST(Build_Wasm_Unreachable1) {
1969 WasmRunner<int32_t> r(MachineType::Int32()); 1932 WasmRunner<int32_t> r(MachineType::Int32());
1970 BUILD(r, WASM_UNREACHABLE); 1933 BUILD(r, WASM_UNREACHABLE);
1971 } 1934 }
1972 1935
(...skipping 18 matching lines...) Expand all
1991 1954
1992 TEST(Build_Wasm_UnreachableIf2) { 1955 TEST(Build_Wasm_UnreachableIf2) {
1993 WasmRunner<int32_t> r(MachineType::Int32()); 1956 WasmRunner<int32_t> r(MachineType::Int32());
1994 BUILD(r, WASM_UNREACHABLE, 1957 BUILD(r, WASM_UNREACHABLE,
1995 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); 1958 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
1996 } 1959 }
1997 1960
1998 1961
1999 TEST(Run_Wasm_Unreachable_Load) { 1962 TEST(Run_Wasm_Unreachable_Load) {
2000 WasmRunner<int32_t> r(MachineType::Int32()); 1963 WasmRunner<int32_t> r(MachineType::Int32());
2001 BUILD(r, WASM_BLOCK(2, WASM_BRV(0, WASM_GET_LOCAL(0)), 1964 BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)),
2002 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); 1965 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))));
2003 CHECK_EQ(11, r.Call(11)); 1966 CHECK_EQ(11, r.Call(11));
2004 CHECK_EQ(21, r.Call(21)); 1967 CHECK_EQ(21, r.Call(21));
2005 } 1968 }
2006 1969
2007 1970
2008 TEST(Run_Wasm_Infinite_Loop_not_taken1) { 1971 TEST(Run_Wasm_Infinite_Loop_not_taken1) {
2009 WasmRunner<int32_t> r(MachineType::Int32()); 1972 WasmRunner<int32_t> r(MachineType::Int32());
2010 BUILD(r, WASM_BLOCK(2, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), 1973 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)));
2011 WASM_I8(45)));
2012 // Run the code, but don't go into the infinite loop. 1974 // Run the code, but don't go into the infinite loop.
2013 CHECK_EQ(45, r.Call(0)); 1975 CHECK_EQ(45, r.Call(0));
2014 } 1976 }
2015 1977
2016 1978
2017 TEST(Run_Wasm_Infinite_Loop_not_taken2) { 1979 TEST(Run_Wasm_Infinite_Loop_not_taken2) {
2018 WasmRunner<int32_t> r(MachineType::Int32()); 1980 WasmRunner<int32_t> r(MachineType::Int32());
2019 BUILD(r, 1981 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(45)),
2020 WASM_BLOCK(1, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(45)), 1982 WASM_INFINITE_LOOP)));
2021 WASM_INFINITE_LOOP)));
2022 // Run the code, but don't go into the infinite loop. 1983 // Run the code, but don't go into the infinite loop.
2023 CHECK_EQ(45, r.Call(1)); 1984 CHECK_EQ(45, r.Call(1));
2024 } 1985 }
2025 1986
2026 1987
2027 TEST(Run_Wasm_Infinite_Loop_not_taken2_brif) { 1988 TEST(Run_Wasm_Infinite_Loop_not_taken2_brif) {
2028 WasmRunner<int32_t> r(MachineType::Int32()); 1989 WasmRunner<int32_t> r(MachineType::Int32());
2029 BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), 1990 BUILD(r,
2030 WASM_INFINITE_LOOP)); 1991 B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP));
2031 // Run the code, but don't go into the infinite loop. 1992 // Run the code, but don't go into the infinite loop.
2032 CHECK_EQ(45, r.Call(1)); 1993 CHECK_EQ(45, r.Call(1));
2033 } 1994 }
2034 1995
2035 1996
2036 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { 1997 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
2037 if (!WasmOpcodes::IsSupported(opcode)) return; 1998 if (!WasmOpcodes::IsSupported(opcode)) return;
2038 1999
2039 Zone zone; 2000 Zone zone;
2040 Isolate* isolate = CcTest::InitIsolateOnce(); 2001 Isolate* isolate = CcTest::InitIsolateOnce();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 } 2140 }
2180 } 2141 }
2181 2142
2182 2143
2183 #if WASM_64 2144 #if WASM_64
2184 TEST(Run_WasmInt64Global) { 2145 TEST(Run_WasmInt64Global) {
2185 TestingModule module; 2146 TestingModule module;
2186 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); 2147 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
2187 WasmRunner<int32_t> r(&module, MachineType::Int32()); 2148 WasmRunner<int32_t> r(&module, MachineType::Int32());
2188 // global = global + p0 2149 // global = global + p0
2189 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( 2150 BUILD(r, B2(WASM_STORE_GLOBAL(
2190 0, WASM_I64_ADD( 2151 0, WASM_I64_ADD(WASM_LOAD_GLOBAL(0),
2191 WASM_LOAD_GLOBAL(0), 2152 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2192 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), 2153 WASM_ZERO));
2193 WASM_ZERO));
2194 2154
2195 *global = 0xFFFFFFFFFFFFFFFFLL; 2155 *global = 0xFFFFFFFFFFFFFFFFLL;
2196 for (int i = 9; i < 444444; i += 111111) { 2156 for (int i = 9; i < 444444; i += 111111) {
2197 int64_t expected = *global + i; 2157 int64_t expected = *global + i;
2198 r.Call(i); 2158 r.Call(i);
2199 CHECK_EQ(expected, *global); 2159 CHECK_EQ(expected, *global);
2200 } 2160 }
2201 } 2161 }
2202 #endif 2162 #endif
2203 2163
2204 2164
2205 TEST(Run_WasmFloat32Global) { 2165 TEST(Run_WasmFloat32Global) {
2206 TestingModule module; 2166 TestingModule module;
2207 float* global = module.AddGlobal<float>(MachineType::Float32()); 2167 float* global = module.AddGlobal<float>(MachineType::Float32());
2208 WasmRunner<int32_t> r(&module, MachineType::Int32()); 2168 WasmRunner<int32_t> r(&module, MachineType::Int32());
2209 // global = global + p0 2169 // global = global + p0
2210 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( 2170 BUILD(r, B2(WASM_STORE_GLOBAL(
2211 0, WASM_F32_ADD( 2171 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0),
2212 WASM_LOAD_GLOBAL(0), 2172 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2213 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), 2173 WASM_ZERO));
2214 WASM_ZERO));
2215 2174
2216 *global = 1.25; 2175 *global = 1.25;
2217 for (int i = 9; i < 4444; i += 1111) { 2176 for (int i = 9; i < 4444; i += 1111) {
2218 volatile float expected = *global + i; 2177 volatile float expected = *global + i;
2219 r.Call(i); 2178 r.Call(i);
2220 CHECK_EQ(expected, *global); 2179 CHECK_EQ(expected, *global);
2221 } 2180 }
2222 } 2181 }
2223 2182
2224 2183
2225 TEST(Run_WasmFloat64Global) { 2184 TEST(Run_WasmFloat64Global) {
2226 TestingModule module; 2185 TestingModule module;
2227 double* global = module.AddGlobal<double>(MachineType::Float64()); 2186 double* global = module.AddGlobal<double>(MachineType::Float64());
2228 WasmRunner<int32_t> r(&module, MachineType::Int32()); 2187 WasmRunner<int32_t> r(&module, MachineType::Int32());
2229 // global = global + p0 2188 // global = global + p0
2230 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( 2189 BUILD(r, B2(WASM_STORE_GLOBAL(
2231 0, WASM_F64_ADD( 2190 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0),
2232 WASM_LOAD_GLOBAL(0), 2191 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2233 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), 2192 WASM_ZERO));
2234 WASM_ZERO));
2235 2193
2236 *global = 1.25; 2194 *global = 1.25;
2237 for (int i = 9; i < 4444; i += 1111) { 2195 for (int i = 9; i < 4444; i += 1111) {
2238 volatile double expected = *global + i; 2196 volatile double expected = *global + i;
2239 r.Call(i); 2197 r.Call(i);
2240 CHECK_EQ(expected, *global); 2198 CHECK_EQ(expected, *global);
2241 } 2199 }
2242 } 2200 }
2243 2201
2244 2202
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 2598
2641 TEST(Run_Wasm_AddCall) { 2599 TEST(Run_Wasm_AddCall) {
2642 TestSignatures sigs; 2600 TestSignatures sigs;
2643 TestingModule module; 2601 TestingModule module;
2644 WasmFunctionCompiler t1(sigs.i_ii(), &module); 2602 WasmFunctionCompiler t1(sigs.i_ii(), &module);
2645 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2603 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2646 t1.CompileAndAdd(); 2604 t1.CompileAndAdd();
2647 2605
2648 WasmRunner<int32_t> r(&module, MachineType::Int32()); 2606 WasmRunner<int32_t> r(&module, MachineType::Int32());
2649 byte local = r.AllocateLocal(kAstI32); 2607 byte local = r.AllocateLocal(kAstI32);
2650 BUILD(r, 2608 BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)),
2651 WASM_BLOCK(2, WASM_SET_LOCAL(local, WASM_I8(99)), 2609 WASM_I32_ADD(
2652 WASM_I32_ADD( 2610 WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(0),
2653 WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(0), 2611 WASM_GET_LOCAL(0)),
2654 WASM_GET_LOCAL(0)), 2612 WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(1),
2655 WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(1), 2613 WASM_GET_LOCAL(local)))));
2656 WASM_GET_LOCAL(local)))));
2657 2614
2658 CHECK_EQ(198, r.Call(0)); 2615 CHECK_EQ(198, r.Call(0));
2659 CHECK_EQ(200, r.Call(1)); 2616 CHECK_EQ(200, r.Call(1));
2660 CHECK_EQ(100, r.Call(-49)); 2617 CHECK_EQ(100, r.Call(-49));
2661 } 2618 }
2662 2619
2663 TEST(Run_Wasm_CountDown_expr) { 2620 TEST(Run_Wasm_CountDown_expr) {
2664 WasmRunner<int32_t> r(MachineType::Int32()); 2621 WasmRunner<int32_t> r(MachineType::Int32());
2665 BUILD(r, WASM_LOOP( 2622 BUILD(r, WASM_LOOP(
2666 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), 2623 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)),
2667 WASM_BREAKV(0, WASM_GET_LOCAL(0))), 2624 WASM_BREAKV(0, WASM_GET_LOCAL(0))),
2668 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), 2625 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))),
2669 WASM_CONTINUE(0))); 2626 WASM_CONTINUE(0)));
2670 CHECK_EQ(0, r.Call(1)); 2627 CHECK_EQ(0, r.Call(1));
2671 CHECK_EQ(0, r.Call(10)); 2628 CHECK_EQ(0, r.Call(10));
2672 CHECK_EQ(0, r.Call(100)); 2629 CHECK_EQ(0, r.Call(100));
2673 } 2630 }
2674 2631
2675 2632
2676 TEST(Run_Wasm_ExprBlock2a) { 2633 TEST(Run_Wasm_ExprBlock2a) {
2677 WasmRunner<int32_t> r(MachineType::Int32()); 2634 WasmRunner<int32_t> r(MachineType::Int32());
2678 BUILD(r, WASM_BLOCK(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))), 2635 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))), WASM_I8(1)));
2679 WASM_I8(1)));
2680 CHECK_EQ(1, r.Call(0)); 2636 CHECK_EQ(1, r.Call(0));
2681 CHECK_EQ(1, r.Call(1)); 2637 CHECK_EQ(1, r.Call(1));
2682 } 2638 }
2683 2639
2684 2640
2685 TEST(Run_Wasm_ExprBlock2b) { 2641 TEST(Run_Wasm_ExprBlock2b) {
2686 WasmRunner<int32_t> r(MachineType::Int32()); 2642 WasmRunner<int32_t> r(MachineType::Int32());
2687 BUILD(r, WASM_BLOCK(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))), 2643 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))), WASM_I8(2)));
2688 WASM_I8(2)));
2689 CHECK_EQ(2, r.Call(0)); 2644 CHECK_EQ(2, r.Call(0));
2690 CHECK_EQ(1, r.Call(1)); 2645 CHECK_EQ(1, r.Call(1));
2691 } 2646 }
2692 2647
2693 2648
2694 TEST(Run_Wasm_ExprBlock2c) { 2649 TEST(Run_Wasm_ExprBlock2c) {
2695 WasmRunner<int32_t> r(MachineType::Int32()); 2650 WasmRunner<int32_t> r(MachineType::Int32());
2696 BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), 2651 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1)));
2697 WASM_I8(1)));
2698 CHECK_EQ(1, r.Call(0)); 2652 CHECK_EQ(1, r.Call(0));
2699 CHECK_EQ(1, r.Call(1)); 2653 CHECK_EQ(1, r.Call(1));
2700 } 2654 }
2701 2655
2702 2656
2703 TEST(Run_Wasm_ExprBlock2d) { 2657 TEST(Run_Wasm_ExprBlock2d) {
2704 WasmRunner<int32_t> r(MachineType::Int32()); 2658 WasmRunner<int32_t> r(MachineType::Int32());
2705 BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), 2659 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2)));
2706 WASM_I8(2)));
2707 CHECK_EQ(2, r.Call(0)); 2660 CHECK_EQ(2, r.Call(0));
2708 CHECK_EQ(1, r.Call(1)); 2661 CHECK_EQ(1, r.Call(1));
2709 } 2662 }
2710 2663
2711 2664
2712 TEST(Run_Wasm_ExprBlock_ManualSwitch) { 2665 TEST(Run_Wasm_ExprBlock_ManualSwitch) {
2713 WasmRunner<int32_t> r(MachineType::Int32()); 2666 WasmRunner<int32_t> r(MachineType::Int32());
2714 BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), 2667 BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)),
2715 WASM_BRV(0, WASM_I8(11))), 2668 WASM_BRV(0, WASM_I8(11))),
2716 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), 2669 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 CHECK_EQ(11, r.Call(1, 1)); 2721 CHECK_EQ(11, r.Call(1, 1));
2769 CHECK_EQ(12, r.Call(1, 0)); 2722 CHECK_EQ(12, r.Call(1, 0));
2770 CHECK_EQ(13, r.Call(0, 1)); 2723 CHECK_EQ(13, r.Call(0, 1));
2771 CHECK_EQ(14, r.Call(0, 0)); 2724 CHECK_EQ(14, r.Call(0, 0));
2772 } 2725 }
2773 2726
2774 2727
2775 TEST(Run_Wasm_ExprBlock_if) { 2728 TEST(Run_Wasm_ExprBlock_if) {
2776 WasmRunner<int32_t> r(MachineType::Int32()); 2729 WasmRunner<int32_t> r(MachineType::Int32());
2777 2730
2778 BUILD(r, 2731 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)),
2779 WASM_BLOCK(1, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), 2732 WASM_BRV(0, WASM_I8(14)))));
2780 WASM_BRV(0, WASM_I8(14)))));
2781 2733
2782 CHECK_EQ(11, r.Call(1)); 2734 CHECK_EQ(11, r.Call(1));
2783 CHECK_EQ(14, r.Call(0)); 2735 CHECK_EQ(14, r.Call(0));
2784 } 2736 }
2785 2737
2786 2738
2787 TEST(Run_Wasm_ExprBlock_nested_ifs) { 2739 TEST(Run_Wasm_ExprBlock_nested_ifs) {
2788 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); 2740 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
2789 2741
2790 BUILD(r, WASM_BLOCK( 2742 BUILD(r, WASM_BLOCK(
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 3342
3391 #if WASM_64 3343 #if WASM_64
3392 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } 3344 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); }
3393 #endif 3345 #endif
3394 3346
3395 3347
3396 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } 3348 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
3397 3349
3398 3350
3399 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } 3351 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698