OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 using namespace v8::internal::wasm; | 23 using namespace v8::internal::wasm; |
24 | 24 |
25 namespace v8 { | 25 namespace v8 { |
26 namespace internal { | 26 namespace internal { |
27 namespace wasm { | 27 namespace wasm { |
28 | 28 |
29 TEST(Run_WasmInt8Const_i) { | 29 TEST(Run_WasmInt8Const_i) { |
30 WasmRunner<int32_t> r(kExecuteInterpreted); | 30 WasmRunner<int32_t> r(kExecuteInterpreted); |
31 const byte kExpectedValue = 109; | 31 const byte kExpectedValue = 109; |
32 // return(kExpectedValue) | 32 // return(kExpectedValue) |
33 BUILD(r, WASM_I8(kExpectedValue)); | 33 BUILD(r, WASM_I32V_2(kExpectedValue)); |
34 CHECK_EQ(kExpectedValue, r.Call()); | 34 CHECK_EQ(kExpectedValue, r.Call()); |
35 } | 35 } |
36 | 36 |
37 TEST(Run_WasmIfElse) { | 37 TEST(Run_WasmIfElse) { |
38 WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); | 38 WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); |
39 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10))); | 39 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(10))); |
40 CHECK_EQ(10, r.Call(0)); | 40 CHECK_EQ(10, r.Call(0)); |
41 CHECK_EQ(9, r.Call(1)); | 41 CHECK_EQ(9, r.Call(1)); |
42 } | 42 } |
43 | 43 |
44 TEST(Run_WasmIfReturn) { | 44 TEST(Run_WasmIfReturn) { |
45 WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); | 45 WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); |
46 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65)); | 46 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I32V_2(77))), |
| 47 WASM_I32V_2(65)); |
47 CHECK_EQ(65, r.Call(0)); | 48 CHECK_EQ(65, r.Call(0)); |
48 CHECK_EQ(77, r.Call(1)); | 49 CHECK_EQ(77, r.Call(1)); |
49 } | 50 } |
50 | 51 |
51 TEST(Run_WasmNopsN) { | 52 TEST(Run_WasmNopsN) { |
52 const int kMaxNops = 10; | 53 const int kMaxNops = 10; |
53 byte code[kMaxNops + 2]; | 54 byte code[kMaxNops + 2]; |
54 for (int nops = 0; nops < kMaxNops; nops++) { | 55 for (int nops = 0; nops < kMaxNops; nops++) { |
55 byte expected = static_cast<byte>(20 + nops); | 56 byte expected = static_cast<byte>(20 + nops); |
56 memset(code, kExprNop, sizeof(code)); | 57 memset(code, kExprNop, sizeof(code)); |
57 code[nops] = kExprI8Const; | 58 code[nops] = kExprI32Const; |
58 code[nops + 1] = expected; | 59 code[nops + 1] = expected; |
59 | 60 |
60 WasmRunner<int32_t> r(kExecuteInterpreted); | 61 WasmRunner<int32_t> r(kExecuteInterpreted); |
61 r.Build(code, code + nops + 2); | 62 r.Build(code, code + nops + 2); |
62 CHECK_EQ(expected, r.Call()); | 63 CHECK_EQ(expected, r.Call()); |
63 } | 64 } |
64 } | 65 } |
65 | 66 |
66 TEST(Run_WasmConstsN) { | 67 TEST(Run_WasmConstsN) { |
67 const int kMaxConsts = 10; | 68 const int kMaxConsts = 5; |
68 byte code[kMaxConsts * 3]; | 69 byte code[kMaxConsts * 3]; |
69 int32_t expected = 0; | 70 int32_t expected = 0; |
70 for (int count = 1; count < kMaxConsts; count++) { | 71 for (int count = 1; count < kMaxConsts; count++) { |
71 for (int i = 0; i < count; i++) { | 72 for (int i = 0; i < count; i++) { |
72 byte val = static_cast<byte>(count * 10 + i); | 73 byte val = static_cast<byte>(count * 10 + i); |
73 code[i * 3] = kExprI8Const; | 74 code[i * 3] = kExprI32Const; |
74 code[i * 3 + 1] = val; | 75 code[i * 3 + 1] = val; |
75 if (i == (count - 1)) { | 76 if (i == (count - 1)) { |
76 code[i * 3 + 2] = kExprNop; | 77 code[i * 3 + 2] = kExprNop; |
77 expected = val; | 78 expected = val; |
78 } else { | 79 } else { |
79 code[i * 3 + 2] = kExprDrop; | 80 code[i * 3 + 2] = kExprDrop; |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 WasmRunner<int32_t> r(kExecuteInterpreted); | 84 WasmRunner<int32_t> r(kExecuteInterpreted); |
84 r.Build(code, code + (count * 3)); | 85 r.Build(code, code + (count * 3)); |
85 CHECK_EQ(expected, r.Call()); | 86 CHECK_EQ(expected, r.Call()); |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 TEST(Run_WasmBlocksN) { | 90 TEST(Run_WasmBlocksN) { |
90 const int kMaxNops = 10; | 91 const int kMaxNops = 10; |
91 const int kExtra = 5; | 92 const int kExtra = 5; |
92 byte code[kMaxNops + kExtra]; | 93 byte code[kMaxNops + kExtra]; |
93 for (int nops = 0; nops < kMaxNops; nops++) { | 94 for (int nops = 0; nops < kMaxNops; nops++) { |
94 byte expected = static_cast<byte>(30 + nops); | 95 byte expected = static_cast<byte>(30 + nops); |
95 memset(code, kExprNop, sizeof(code)); | 96 memset(code, kExprNop, sizeof(code)); |
96 code[0] = kExprBlock; | 97 code[0] = kExprBlock; |
97 code[1] = kLocalI32; | 98 code[1] = kLocalI32; |
98 code[2 + nops] = kExprI8Const; | 99 code[2 + nops] = kExprI32Const; |
99 code[2 + nops + 1] = expected; | 100 code[2 + nops + 1] = expected; |
100 code[2 + nops + 2] = kExprEnd; | 101 code[2 + nops + 2] = kExprEnd; |
101 | 102 |
102 WasmRunner<int32_t> r(kExecuteInterpreted); | 103 WasmRunner<int32_t> r(kExecuteInterpreted); |
103 r.Build(code, code + nops + kExtra); | 104 r.Build(code, code + nops + kExtra); |
104 CHECK_EQ(expected, r.Call()); | 105 CHECK_EQ(expected, r.Call()); |
105 } | 106 } |
106 } | 107 } |
107 | 108 |
108 TEST(Run_WasmBlockBreakN) { | 109 TEST(Run_WasmBlockBreakN) { |
109 const int kMaxNops = 10; | 110 const int kMaxNops = 10; |
110 const int kExtra = 6; | 111 const int kExtra = 6; |
| 112 int run = 0; |
111 byte code[kMaxNops + kExtra]; | 113 byte code[kMaxNops + kExtra]; |
112 for (int nops = 0; nops < kMaxNops; nops++) { | 114 for (int nops = 0; nops < kMaxNops; nops++) { |
113 // Place the break anywhere within the block. | 115 // Place the break anywhere within the block. |
114 for (int index = 0; index < nops; index++) { | 116 for (int index = 0; index < nops; index++) { |
115 memset(code, kExprNop, sizeof(code)); | 117 memset(code, kExprNop, sizeof(code)); |
116 code[0] = kExprBlock; | 118 code[0] = kExprBlock; |
117 code[1] = kLocalI32; | 119 code[1] = kLocalI32; |
118 code[sizeof(code) - 1] = kExprEnd; | 120 code[sizeof(code) - 1] = kExprEnd; |
119 | 121 |
120 int expected = nops * 11 + index; | 122 int expected = run++; |
121 code[2 + index + 0] = kExprI8Const; | 123 code[2 + index + 0] = kExprI32Const; |
122 code[2 + index + 1] = static_cast<byte>(expected); | 124 code[2 + index + 1] = static_cast<byte>(expected); |
123 code[2 + index + 2] = kExprBr; | 125 code[2 + index + 2] = kExprBr; |
124 code[2 + index + 3] = 0; | 126 code[2 + index + 3] = 0; |
125 | 127 |
126 WasmRunner<int32_t> r(kExecuteInterpreted); | 128 WasmRunner<int32_t> r(kExecuteInterpreted); |
127 r.Build(code, code + kMaxNops + kExtra); | 129 r.Build(code, code + kMaxNops + kExtra); |
128 CHECK_EQ(expected, r.Call()); | 130 CHECK_EQ(expected, r.Call()); |
129 } | 131 } |
130 } | 132 } |
131 } | 133 } |
132 | 134 |
133 TEST(Run_Wasm_nested_ifs_i) { | 135 TEST(Run_Wasm_nested_ifs_i) { |
134 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted); | 136 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted); |
135 | 137 |
136 BUILD(r, WASM_IF_ELSE_I( | 138 BUILD( |
137 WASM_GET_LOCAL(0), | 139 r, |
138 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), | 140 WASM_IF_ELSE_I( |
139 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); | 141 WASM_GET_LOCAL(0), |
| 142 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)), |
| 143 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14)))); |
140 | 144 |
141 CHECK_EQ(11, r.Call(1, 1)); | 145 CHECK_EQ(11, r.Call(1, 1)); |
142 CHECK_EQ(12, r.Call(1, 0)); | 146 CHECK_EQ(12, r.Call(1, 0)); |
143 CHECK_EQ(13, r.Call(0, 1)); | 147 CHECK_EQ(13, r.Call(0, 1)); |
144 CHECK_EQ(14, r.Call(0, 0)); | 148 CHECK_EQ(14, r.Call(0, 0)); |
145 } | 149 } |
146 | 150 |
147 // Make tests more robust by not hard-coding offsets of various operations. | 151 // Make tests more robust by not hard-coding offsets of various operations. |
148 // The {Find} method finds the offsets for the given bytecodes, returning | 152 // The {Find} method finds the offsets for the given bytecodes, returning |
149 // the offsets in an array. | 153 // the offsets in an array. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 383 BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
380 r.Call(1048575.5, 2.5); | 384 r.Call(1048575.5, 2.5); |
381 CHECK(!r.possible_nondeterminism()); | 385 CHECK(!r.possible_nondeterminism()); |
382 r.Call(std::numeric_limits<double>::infinity(), 0.0); | 386 r.Call(std::numeric_limits<double>::infinity(), 0.0); |
383 CHECK(r.possible_nondeterminism()); | 387 CHECK(r.possible_nondeterminism()); |
384 } | 388 } |
385 } | 389 } |
386 } // namespace wasm | 390 } // namespace wasm |
387 } // namespace internal | 391 } // namespace internal |
388 } // namespace v8 | 392 } // namespace v8 |
OLD | NEW |