/src/WasmEdge/lib/loader/ast/instruction.cpp
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | #include "loader/loader.h" |
5 | | |
6 | | #include <utility> |
7 | | |
8 | | using namespace std::literals; |
9 | | |
10 | | namespace WasmEdge { |
11 | | namespace Loader { |
12 | | |
13 | | // OpCode loader. See "include/loader/loader.h". |
14 | 35.0M | Expect<OpCode> Loader::loadOpCode() { |
15 | 35.0M | EXPECTED_TRY(uint8_t Prefix, FMgr.readByte()); |
16 | | |
17 | 35.0M | if (Prefix >= 0xFBU && Prefix <= 0xFEU) { |
18 | | // Multi-byte OpCode case. |
19 | 1.97M | EXPECTED_TRY(uint32_t Extend, FMgr.readU32()); |
20 | 1.97M | if (Prefix == 0xFBU) { |
21 | 59.2k | switch (Extend) { |
22 | 0 | #define UseOpCode |
23 | 0 | #define Line(NAME, STRING, PREFIX) |
24 | 0 | #define Line_FB(NAME, STRING, PREFIX, EXTEND) \ |
25 | 59.2k | case EXTEND: \ |
26 | 59.2k | return OpCode::NAME; |
27 | 0 | #define Line_FC(NAME, STRING, PREFIX, EXTEND) |
28 | 0 | #define Line_FD(NAME, STRING, PREFIX, EXTEND) |
29 | 0 | #define Line_FE(NAME, STRING, PREFIX, EXTEND) |
30 | 0 | #include "common/enum.inc" |
31 | 0 | #undef Line |
32 | 0 | #undef Line_FB |
33 | 0 | #undef Line_FC |
34 | 0 | #undef Line_FD |
35 | 0 | #undef Line_FE |
36 | 0 | #undef UseOpCode |
37 | 16 | default: |
38 | 16 | return Unexpect(ErrCode::Value::IllegalOpCode); |
39 | 59.2k | } |
40 | 1.91M | } else if (Prefix == 0xFCU) { |
41 | 98.8k | switch (Extend) { |
42 | 0 | #define UseOpCode |
43 | 0 | #define Line(NAME, STRING, PREFIX) |
44 | 0 | #define Line_FB(NAME, STRING, PREFIX, EXTEND) |
45 | 0 | #define Line_FC(NAME, STRING, PREFIX, EXTEND) \ |
46 | 98.8k | case EXTEND: \ |
47 | 98.8k | return OpCode::NAME; |
48 | 0 | #define Line_FD(NAME, STRING, PREFIX, EXTEND) |
49 | 0 | #define Line_FE(NAME, STRING, PREFIX, EXTEND) |
50 | 0 | #include "common/enum.inc" |
51 | 0 | #undef Line |
52 | 0 | #undef Line_FB |
53 | 0 | #undef Line_FC |
54 | 0 | #undef Line_FD |
55 | 0 | #undef Line_FE |
56 | 0 | #undef UseOpCode |
57 | 19 | default: |
58 | 19 | return Unexpect(ErrCode::Value::IllegalOpCode); |
59 | 98.8k | } |
60 | 1.81M | } else if (Prefix == 0xFDU) { |
61 | 1.80M | switch (Extend) { |
62 | 0 | #define UseOpCode |
63 | 0 | #define Line(NAME, STRING, PREFIX) |
64 | 0 | #define Line_FB(NAME, STRING, PREFIX, EXTEND) |
65 | 0 | #define Line_FC(NAME, STRING, PREFIX, EXTEND) |
66 | 0 | #define Line_FD(NAME, STRING, PREFIX, EXTEND) \ |
67 | 1.80M | case EXTEND: \ |
68 | 1.80M | return OpCode::NAME; |
69 | 0 | #define Line_FE(NAME, STRING, PREFIX, EXTEND) |
70 | 0 | #include "common/enum.inc" |
71 | 0 | #undef Line |
72 | 0 | #undef Line_FB |
73 | 0 | #undef Line_FC |
74 | 0 | #undef Line_FD |
75 | 0 | #undef Line_FE |
76 | 0 | #undef UseOpCode |
77 | 223 | default: |
78 | 223 | return Unexpect(ErrCode::Value::IllegalOpCode); |
79 | 1.80M | } |
80 | 1.80M | } else { |
81 | 13.1k | switch (Extend) { |
82 | 0 | #define UseOpCode |
83 | 0 | #define Line(NAME, STRING, PREFIX) |
84 | 0 | #define Line_FB(NAME, STRING, PREFIX, EXTEND) |
85 | 0 | #define Line_FC(NAME, STRING, PREFIX, EXTEND) |
86 | 0 | #define Line_FD(NAME, STRING, PREFIX, EXTEND) |
87 | 0 | #define Line_FE(NAME, STRING, PREFIX, EXTEND) \ |
88 | 13.1k | case EXTEND: \ |
89 | 13.1k | return OpCode::NAME; |
90 | 0 | #include "common/enum.inc" |
91 | 0 | #undef Line |
92 | 0 | #undef Line_FB |
93 | 0 | #undef Line_FC |
94 | 0 | #undef Line_FD |
95 | 0 | #undef Line_FE |
96 | 0 | #undef UseOpCode |
97 | 18 | default: |
98 | 18 | return Unexpect(ErrCode::Value::IllegalOpCode); |
99 | 13.1k | } |
100 | 13.1k | } |
101 | 33.1M | } else { |
102 | | // Single-byte OpCode case. |
103 | 33.1M | switch (Prefix) { |
104 | 0 | #define UseOpCode |
105 | 0 | #define Line(NAME, STRING, PREFIX) \ |
106 | 33.1M | case PREFIX: \ |
107 | 33.1M | return OpCode::NAME; |
108 | 0 | #define Line_FB(NAME, STRING, PREFIX, EXTEND) |
109 | 0 | #define Line_FC(NAME, STRING, PREFIX, EXTEND) |
110 | 0 | #define Line_FD(NAME, STRING, PREFIX, EXTEND) |
111 | 0 | #define Line_FE(NAME, STRING, PREFIX, EXTEND) |
112 | 0 | #include "common/enum.inc" |
113 | 0 | #undef Line |
114 | 0 | #undef Line_FB |
115 | 0 | #undef Line_FC |
116 | 0 | #undef Line_FD |
117 | 0 | #undef Line_FE |
118 | 0 | #undef UseOpCode |
119 | 589 | default: |
120 | 589 | return Unexpect(ErrCode::Value::IllegalOpCode); |
121 | 33.1M | } |
122 | 33.1M | } |
123 | 35.0M | } |
124 | | |
125 | | // Load instruction sequence. See "include/loader/loader.h". |
126 | 82.7k | Expect<AST::InstrVec> Loader::loadInstrSeq(std::optional<uint64_t> SizeBound) { |
127 | 82.7k | AST::InstrVec Instrs; |
128 | 82.7k | std::vector<std::pair<OpCode, uint32_t>> BlockStack; |
129 | 82.7k | uint32_t Cnt = 0; |
130 | 82.7k | bool IsReachEnd = false; |
131 | | // Read opcode until the End code of the top block. |
132 | 35.0M | do { |
133 | | // Read the opcode and check for errors. |
134 | 35.0M | uint64_t Offset = FMgr.getOffset(); |
135 | 35.0M | EXPECTED_TRY(OpCode Code, loadOpCode().map_error([this](auto E) { |
136 | 35.0M | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
137 | 35.0M | })); |
138 | | |
139 | | // Check with proposals. |
140 | 35.0M | if (auto Res = Conf.isInstrNeedProposal(Code); unlikely(!!Res)) { |
141 | 243 | return logNeedProposal(ErrCode::Value::IllegalOpCode, Res.value(), Offset, |
142 | 243 | ASTNodeAttr::Instruction); |
143 | 243 | } |
144 | | |
145 | 35.0M | auto logIllegalOpCode = [this, &Offset, |
146 | 35.0M | &SizeBound]() -> Unexpected<ErrCode> { |
147 | 144 | if (SizeBound.has_value() && FMgr.getOffset() > SizeBound.value()) { |
148 | 53 | return logLoadError(ErrCode::Value::ENDCodeExpected, Offset, |
149 | 53 | ASTNodeAttr::Instruction); |
150 | 91 | } else { |
151 | 91 | return logLoadError(ErrCode::Value::IllegalOpCode, Offset, |
152 | 91 | ASTNodeAttr::Instruction); |
153 | 91 | } |
154 | 144 | }; |
155 | | |
156 | | // Process the instruction that contains a block. |
157 | 35.0M | switch (Code) { |
158 | 361k | case OpCode::Block: |
159 | 1.19M | case OpCode::Loop: |
160 | 1.35M | case OpCode::If: |
161 | 1.38M | case OpCode::Try_table: |
162 | 1.38M | BlockStack.emplace_back(Code, Cnt); |
163 | 1.38M | break; |
164 | 12.2k | case OpCode::Else: { |
165 | 12.2k | if (BlockStack.size() == 0 || BlockStack.back().first != OpCode::If) { |
166 | | // An Else instruction appeared outside the If-block. |
167 | 123 | return logIllegalOpCode(); |
168 | 123 | } |
169 | 12.0k | uint32_t Pos = BlockStack.back().second; |
170 | 12.0k | if (Instrs[Pos].getJumpElse() > 0) { |
171 | | // An Else instruction appeared before in this If-block. |
172 | 21 | return logIllegalOpCode(); |
173 | 21 | } |
174 | 12.0k | Instrs[Pos].setJumpElse(Cnt - Pos); |
175 | 12.0k | break; |
176 | 12.0k | } |
177 | 33.6M | default: |
178 | 33.6M | break; |
179 | 35.0M | } |
180 | | |
181 | | // Create the instruction node and load contents. |
182 | 35.0M | Instrs.emplace_back(Code, static_cast<uint32_t>(Offset)); |
183 | 35.0M | EXPECTED_TRY(loadInstruction(Instrs.back())); |
184 | | |
185 | 35.0M | if (Code == OpCode::End) { |
186 | | // Post process the End instruction. |
187 | 198k | if (BlockStack.size() > 0) { |
188 | 124k | Instrs.back().setExprLast(false); |
189 | 124k | const auto &[BackOp, Pos] = BlockStack.back(); |
190 | 124k | if (BackOp == OpCode::Block || BackOp == OpCode::Loop || |
191 | 101k | BackOp == OpCode::If) { |
192 | 101k | Instrs.back().setTryBlockLast(false); |
193 | 101k | Instrs[Pos].setJumpEnd(Cnt - Pos); |
194 | 101k | if (BackOp == OpCode::If) { |
195 | 33.2k | if (Instrs[Pos].getJumpElse() == 0) { |
196 | | // For an if block without an else branch, set the else jump to |
197 | | // the end jump. |
198 | 25.8k | Instrs[Pos].setJumpElse(Cnt - Pos); |
199 | 25.8k | } else { |
200 | 7.35k | const uint32_t ElsePos = Pos + Instrs[Pos].getJumpElse(); |
201 | 7.35k | Instrs[ElsePos].setJumpEnd(Cnt - ElsePos); |
202 | 7.35k | } |
203 | 33.2k | } |
204 | 101k | } else if (BackOp == OpCode::Try_table) { |
205 | 22.8k | Instrs.back().setTryBlockLast(true); |
206 | 22.8k | Instrs[Pos].getTryCatch().JumpEnd = Cnt - Pos; |
207 | 22.8k | } |
208 | 124k | BlockStack.pop_back(); |
209 | 124k | } else { |
210 | 74.1k | Instrs.back().setExprLast(true); |
211 | 74.1k | IsReachEnd = true; |
212 | 74.1k | } |
213 | 198k | } |
214 | 35.0M | Cnt++; |
215 | 35.0M | } while (!IsReachEnd); |
216 | | |
217 | | // Check the loaded offset should match the segment boundary. |
218 | 74.1k | if (SizeBound.has_value()) { |
219 | 42.9k | auto Offset = FMgr.getOffset(); |
220 | 42.9k | if (Offset < SizeBound.value()) { |
221 | 40 | return logLoadError(ErrCode::Value::JunkSection, Offset, |
222 | 40 | ASTNodeAttr::Instruction); |
223 | 42.9k | } else if (Offset > SizeBound.value()) { |
224 | 97 | return logLoadError(ErrCode::Value::SectionSizeMismatch, Offset, |
225 | 97 | ASTNodeAttr::Instruction); |
226 | 97 | } |
227 | 42.9k | } |
228 | 74.0k | return Instrs; |
229 | 74.1k | } |
230 | | |
231 | | // Load instruction node. See "include/loader/loader.h". |
232 | 35.3M | Expect<void> Loader::loadInstruction(AST::Instruction &Instr) { |
233 | | // Node: The instruction has checked for the proposals. Need to check their |
234 | | // immediates. |
235 | | |
236 | 35.3M | auto ReportError = [this](auto E) { |
237 | 2.02k | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
238 | 2.02k | }; |
239 | | |
240 | 35.3M | auto readU8 = [this, ReportError](uint8_t &Dst) -> Expect<void> { |
241 | 101k | EXPECTED_TRY(Dst, FMgr.readByte().map_error(ReportError)); |
242 | 101k | return {}; |
243 | 101k | }; |
244 | | |
245 | 35.3M | auto readU32 = [this, ReportError](uint32_t &Dst) -> Expect<void> { |
246 | 2.24M | EXPECTED_TRY(Dst, FMgr.readU32().map_error(ReportError)); |
247 | 2.24M | return {}; |
248 | 2.24M | }; |
249 | | |
250 | 35.3M | auto readU64 = [this, ReportError](uint64_t &Dst) -> Expect<void> { |
251 | 709k | EXPECTED_TRY(Dst, FMgr.readU64().map_error(ReportError)); |
252 | 709k | return {}; |
253 | 709k | }; |
254 | | |
255 | 35.3M | auto readMemImmediate = [this, readU32, readU64, &Instr]() -> Expect<void> { |
256 | 710k | Instr.getTargetIndex() = 0; |
257 | 710k | EXPECTED_TRY(readU32(Instr.getMemoryAlign())); |
258 | 710k | if (Conf.hasProposal(Proposal::MultiMemories) && |
259 | 710k | Instr.getMemoryAlign() >= 64) { |
260 | 48.4k | Instr.getMemoryAlign() -= 64; |
261 | 48.4k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
262 | 48.4k | } |
263 | 710k | uint32_t MaxAlign = Conf.hasProposal(Proposal::Memory64) ? 64U : 32U; |
264 | 710k | if (unlikely(Instr.getMemoryAlign() >= MaxAlign)) { |
265 | 145 | return logLoadError(ErrCode::Value::MalformedMemoryOpFlags, |
266 | 145 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
267 | 145 | } |
268 | 709k | if (Conf.hasProposal(Proposal::Memory64)) { |
269 | 709k | EXPECTED_TRY(readU64(Instr.getMemoryOffset())); |
270 | 709k | } else { |
271 | 0 | uint32_t Offset; |
272 | 0 | EXPECTED_TRY(readU32(Offset)); |
273 | 0 | Instr.getMemoryOffset() = static_cast<uint64_t>(Offset); |
274 | 0 | } |
275 | 709k | return {}; |
276 | 709k | }; |
277 | | |
278 | 35.3M | auto readCheckZero = [this, readU8](uint32_t &Dst) -> Expect<void> { |
279 | 1.54k | uint8_t C = 0; |
280 | 1.54k | EXPECTED_TRY(readU8(C)); |
281 | 1.53k | if (C != UINT8_C(0)) { |
282 | 7 | return logLoadError(ErrCode::Value::ExpectedZeroByte, |
283 | 7 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
284 | 7 | } |
285 | 1.53k | Dst = 0; |
286 | 1.53k | return {}; |
287 | 1.53k | }; |
288 | | |
289 | 35.3M | auto readBlockType = [this, ReportError](BlockType &Dst) -> Expect<void> { |
290 | 1.38M | auto StartOffset = FMgr.getOffset(); |
291 | | // Read the block return type. |
292 | 1.38M | EXPECTED_TRY(int64_t Code, FMgr.readS33().map_error(ReportError)); |
293 | 1.38M | if (Code < 0) { |
294 | | // The empty and valtype cases are encoded as a single-byte SLEB128, |
295 | | // i.e. the decoded value must be in [-64, -1]. Any negative value |
296 | | // smaller than -64 means a non-canonical multi-byte SLEB128 encoding, |
297 | | // which is not a valid blocktype. |
298 | 887k | if (Code < -64) { |
299 | 90 | return logLoadError(ErrCode::Value::MalformedValType, |
300 | 90 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
301 | 90 | } |
302 | 887k | TypeCode TypeByte = static_cast<TypeCode>(Code & INT64_C(0x7F)); |
303 | 887k | if (TypeByte == TypeCode::Epsilon) { |
304 | | // Empty case. |
305 | 31.0k | Dst.setEmpty(); |
306 | 856k | } else { |
307 | | // Value type case. Seek back to the origin offset and read the |
308 | | // valtype. |
309 | 856k | FMgr.seek(StartOffset); |
310 | | // The AST node information is handled. |
311 | 856k | EXPECTED_TRY(auto Type, loadValType(ASTNodeAttr::Instruction)); |
312 | 856k | Dst.setData(Type); |
313 | 856k | } |
314 | 887k | } else { |
315 | | // Type index case. |
316 | 499k | if (unlikely(!Conf.hasProposal(Proposal::MultiValue))) { |
317 | 0 | return logNeedProposal(ErrCode::Value::MalformedValType, |
318 | 0 | Proposal::MultiValue, FMgr.getLastOffset(), |
319 | 0 | ASTNodeAttr::Instruction); |
320 | 0 | } |
321 | 499k | Dst.setData(static_cast<uint32_t>(Code)); |
322 | 499k | } |
323 | 1.38M | return {}; |
324 | 1.38M | }; |
325 | | |
326 | 35.3M | switch (Instr.getOpCode()) { |
327 | | // Control instructions. |
328 | 13.8M | case OpCode::Unreachable: |
329 | 14.7M | case OpCode::Nop: |
330 | 15.1M | case OpCode::Return: |
331 | 15.2M | case OpCode::Throw_ref: |
332 | 15.4M | case OpCode::End: |
333 | 15.4M | case OpCode::Else: |
334 | 15.4M | return {}; |
335 | | |
336 | 361k | case OpCode::Block: |
337 | 1.19M | case OpCode::Loop: |
338 | 1.35M | case OpCode::If: |
339 | 1.35M | return readBlockType(Instr.getBlockType()); |
340 | | |
341 | 30.4k | case OpCode::Try_table: { |
342 | 30.4k | Instr.setTryCatch(); |
343 | | // Read the result type. |
344 | 30.4k | EXPECTED_TRY(readBlockType(Instr.getTryCatch().ResType)); |
345 | 60.9k | EXPECTED_TRY(uint32_t VecCnt, loadVecCnt().map_error(ReportError)); |
346 | 60.9k | Instr.getTryCatch().Catch.resize(VecCnt); |
347 | 96.1k | for (uint32_t I = 0; I < VecCnt; ++I) { |
348 | 65.7k | auto &Desc = Instr.getTryCatch().Catch[I]; |
349 | | // Read the catch flag. |
350 | 65.7k | EXPECTED_TRY(uint8_t Flag, FMgr.readByte().map_error(ReportError)); |
351 | 65.7k | if (unlikely(Flag > 0x03U)) { |
352 | 45 | return logLoadError(ErrCode::Value::MalformedCatchFlags, |
353 | 45 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
354 | 45 | } |
355 | 65.7k | Desc.IsRef = (Flag & 0x01U) ? true : false; |
356 | 65.7k | Desc.IsAll = (Flag & 0x02U) ? true : false; |
357 | 65.7k | if (!Desc.IsAll) { |
358 | | // Read the tag index. |
359 | 8.58k | EXPECTED_TRY(readU32(Desc.TagIndex)); |
360 | 8.58k | } |
361 | | // Read the label index. |
362 | 65.7k | EXPECTED_TRY(readU32(Desc.LabelIndex)); |
363 | 65.7k | } |
364 | 30.3k | return {}; |
365 | 60.9k | } |
366 | | |
367 | 16.7k | case OpCode::Throw: |
368 | 16.7k | return readU32(Instr.getTargetIndex()); |
369 | | |
370 | 47.9k | case OpCode::Br: |
371 | 74.7k | case OpCode::Br_if: |
372 | 80.8k | case OpCode::Br_on_null: |
373 | 111k | case OpCode::Br_on_non_null: |
374 | 111k | return readU32(Instr.getJump().TargetIndex); |
375 | | |
376 | 14.2k | case OpCode::Br_table: { |
377 | | // Read the vector of labels. |
378 | 14.2k | EXPECTED_TRY(uint32_t VecCnt, loadVecCnt().map_error(ReportError)); |
379 | 14.2k | Instr.setLabelListSize(VecCnt + 1); |
380 | 218k | for (uint32_t I = 0; I < VecCnt; ++I) { |
381 | 204k | EXPECTED_TRY(readU32(Instr.getLabelList()[I].TargetIndex)); |
382 | 204k | } |
383 | | // Read default label. |
384 | 14.2k | return readU32(Instr.getLabelList()[VecCnt].TargetIndex); |
385 | 14.2k | } |
386 | | |
387 | 19.0k | case OpCode::Call: |
388 | 28.1k | case OpCode::Return_call: |
389 | 38.1k | case OpCode::Call_ref: |
390 | 42.6k | case OpCode::Return_call_ref: |
391 | 42.6k | return readU32(Instr.getTargetIndex()); |
392 | | |
393 | 18.0k | case OpCode::Call_indirect: |
394 | 20.4k | case OpCode::Return_call_indirect: { |
395 | | // Read the type index. |
396 | 20.4k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
397 | 20.4k | uint64_t SrcIdxOffset = FMgr.getOffset(); |
398 | | // Read the table index. |
399 | 20.4k | EXPECTED_TRY(readU32(Instr.getSourceIndex())); |
400 | 20.4k | if ((Instr.getSourceIndex() > 0 || FMgr.getOffset() - SrcIdxOffset > 1) && |
401 | 13.7k | !Conf.hasProposal(Proposal::ReferenceTypes)) { |
402 | 0 | return logNeedProposal(ErrCode::Value::ExpectedZeroByte, |
403 | 0 | Proposal::ReferenceTypes, FMgr.getLastOffset(), |
404 | 0 | ASTNodeAttr::Instruction); |
405 | 0 | } |
406 | 20.4k | return {}; |
407 | 20.4k | } |
408 | | |
409 | | // Reference Instructions. |
410 | 48.5k | case OpCode::Ref__null: |
411 | 49.7k | case OpCode::Ref__test_null: |
412 | 52.1k | case OpCode::Ref__cast_null: { |
413 | | // The AST node information is handled. |
414 | 52.1k | EXPECTED_TRY(auto Type, |
415 | 52.0k | loadHeapType(TypeCode::RefNull, ASTNodeAttr::Instruction)); |
416 | 52.0k | Instr.setValType(Type); |
417 | 52.0k | return {}; |
418 | 52.1k | } |
419 | 2.16k | case OpCode::Ref__test: |
420 | 6.40k | case OpCode::Ref__cast: { |
421 | | // The AST node information is handled. |
422 | 6.40k | EXPECTED_TRY(auto Type, |
423 | 6.39k | loadHeapType(TypeCode::Ref, ASTNodeAttr::Instruction)); |
424 | 6.39k | Instr.setValType(Type); |
425 | 6.39k | return {}; |
426 | 6.40k | } |
427 | 6.43k | case OpCode::Ref__is_null: |
428 | 8.93k | case OpCode::Ref__eq: |
429 | 17.1k | case OpCode::Ref__as_non_null: |
430 | 17.1k | return {}; |
431 | 268k | case OpCode::Ref__func: |
432 | 275k | case OpCode::Struct__new: |
433 | 279k | case OpCode::Struct__new_default: |
434 | 280k | case OpCode::Array__new: |
435 | 281k | case OpCode::Array__new_default: |
436 | 284k | case OpCode::Array__get: |
437 | 284k | case OpCode::Array__get_s: |
438 | 286k | case OpCode::Array__get_u: |
439 | 286k | case OpCode::Array__set: |
440 | 287k | case OpCode::Array__fill: |
441 | 287k | return readU32(Instr.getTargetIndex()); |
442 | 533 | case OpCode::Struct__get: |
443 | 2.16k | case OpCode::Struct__get_s: |
444 | 3.11k | case OpCode::Struct__get_u: |
445 | 3.65k | case OpCode::Struct__set: |
446 | 5.98k | case OpCode::Array__new_fixed: |
447 | 6.41k | case OpCode::Array__new_data: |
448 | 7.02k | case OpCode::Array__new_elem: |
449 | 7.87k | case OpCode::Array__copy: |
450 | 8.70k | case OpCode::Array__init_data: |
451 | 9.81k | case OpCode::Array__init_elem: |
452 | 9.81k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
453 | 9.75k | return readU32(Instr.getSourceIndex()); |
454 | 805 | case OpCode::Br_on_cast: |
455 | 1.66k | case OpCode::Br_on_cast_fail: { |
456 | | // Read the flag. |
457 | 1.66k | uint8_t Flag = 0U; |
458 | 1.66k | EXPECTED_TRY(readU8(Flag).map_error(ReportError)); |
459 | 1.64k | if (unlikely(Flag > 0x03U)) { |
460 | 13 | return logLoadError(ErrCode::Value::MalformedCastFlags, |
461 | 13 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
462 | 13 | } |
463 | | // Read the label index. |
464 | 1.63k | uint32_t LabelIdx = 0U; |
465 | 1.63k | EXPECTED_TRY(readU32(LabelIdx).map_error(ReportError)); |
466 | | // Read the heap types. |
467 | 1.63k | Instr.setBrCast(LabelIdx); |
468 | 1.63k | TypeCode TC = ((Flag & 0x01U) ? TypeCode::RefNull : TypeCode::Ref); |
469 | 1.63k | EXPECTED_TRY( |
470 | 1.62k | Instr.getBrCast().RType1, |
471 | 1.62k | loadHeapType(TC, ASTNodeAttr::Instruction).map_error(ReportError)); |
472 | 1.62k | TC = ((Flag & 0x02U) ? TypeCode::RefNull : TypeCode::Ref); |
473 | 1.62k | EXPECTED_TRY( |
474 | 1.61k | Instr.getBrCast().RType2, |
475 | 1.61k | loadHeapType(TC, ASTNodeAttr::Instruction).map_error(ReportError)); |
476 | 1.61k | return {}; |
477 | 1.62k | } |
478 | 2.80k | case OpCode::Array__len: |
479 | 4.77k | case OpCode::Any__convert_extern: |
480 | 7.93k | case OpCode::Extern__convert_any: |
481 | 17.3k | case OpCode::Ref__i31: |
482 | 17.8k | case OpCode::I31__get_s: |
483 | 19.2k | case OpCode::I31__get_u: |
484 | 19.2k | return {}; |
485 | | |
486 | | // Parametric Instructions. |
487 | 3.50M | case OpCode::Drop: |
488 | 3.65M | case OpCode::Select: |
489 | 3.65M | return {}; |
490 | 2.82k | case OpCode::Select_t: { |
491 | | // Read the vector of value types. |
492 | 2.82k | EXPECTED_TRY(uint32_t VecCnt, loadVecCnt().map_error(ReportError)); |
493 | 2.79k | Instr.setValTypeListSize(VecCnt); |
494 | 70.3k | for (uint32_t I = 0; I < VecCnt; ++I) { |
495 | | // The AST node information is handled. |
496 | 67.6k | EXPECTED_TRY(Instr.getValTypeList()[I], |
497 | 67.5k | loadValType(ASTNodeAttr::Instruction)); |
498 | 67.5k | } |
499 | 2.74k | return {}; |
500 | 2.79k | } |
501 | | |
502 | | // Variable Instructions. |
503 | 127k | case OpCode::Local__get: |
504 | 165k | case OpCode::Local__set: |
505 | 185k | case OpCode::Local__tee: |
506 | 274k | case OpCode::Global__get: |
507 | 406k | case OpCode::Global__set: |
508 | 406k | return readU32(Instr.getTargetIndex()); |
509 | | |
510 | | // Table Instructions. |
511 | 894 | case OpCode::Table__init: |
512 | 894 | EXPECTED_TRY(readU32(Instr.getSourceIndex())); |
513 | 890 | [[fallthrough]]; |
514 | 9.43k | case OpCode::Table__get: |
515 | 23.2k | case OpCode::Table__set: |
516 | 27.1k | case OpCode::Table__grow: |
517 | 35.4k | case OpCode::Table__size: |
518 | 36.0k | case OpCode::Table__fill: |
519 | 63.4k | case OpCode::Elem__drop: |
520 | 63.4k | return readU32(Instr.getTargetIndex()); |
521 | 1.89k | case OpCode::Table__copy: |
522 | 1.89k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
523 | 1.89k | return readU32(Instr.getSourceIndex()); |
524 | | |
525 | | // Memory Instructions. |
526 | 42.9k | case OpCode::I32__load: |
527 | 53.8k | case OpCode::I64__load: |
528 | 62.9k | case OpCode::F32__load: |
529 | 69.1k | case OpCode::F64__load: |
530 | 77.2k | case OpCode::I32__load8_s: |
531 | 98.2k | case OpCode::I32__load8_u: |
532 | 109k | case OpCode::I32__load16_s: |
533 | 272k | case OpCode::I32__load16_u: |
534 | 289k | case OpCode::I64__load8_s: |
535 | 304k | case OpCode::I64__load8_u: |
536 | 325k | case OpCode::I64__load16_s: |
537 | 339k | case OpCode::I64__load16_u: |
538 | 350k | case OpCode::I64__load32_s: |
539 | 360k | case OpCode::I64__load32_u: |
540 | 366k | case OpCode::I32__store: |
541 | 375k | case OpCode::I64__store: |
542 | 389k | case OpCode::F32__store: |
543 | 394k | case OpCode::F64__store: |
544 | 409k | case OpCode::I32__store8: |
545 | 425k | case OpCode::I32__store16: |
546 | 432k | case OpCode::I64__store8: |
547 | 474k | case OpCode::I64__store16: |
548 | 479k | case OpCode::I64__store32: |
549 | 479k | return readMemImmediate(); |
550 | | |
551 | 1.46k | case OpCode::Memory__init: |
552 | 1.46k | if (!HasDataSection) { |
553 | 6 | return logLoadError(ErrCode::Value::DataCountRequired, Instr.getOffset(), |
554 | 6 | ASTNodeAttr::Instruction); |
555 | 6 | } |
556 | 1.45k | EXPECTED_TRY(readU32(Instr.getSourceIndex())); |
557 | 1.45k | [[fallthrough]]; |
558 | 44.7k | case OpCode::Memory__grow: |
559 | 185k | case OpCode::Memory__size: |
560 | 188k | case OpCode::Memory__fill: |
561 | 188k | if (Conf.hasProposal(Proposal::MultiMemories)) { |
562 | 188k | return readU32(Instr.getTargetIndex()); |
563 | 188k | } |
564 | 0 | return readCheckZero(Instr.getTargetIndex()); |
565 | 1.10k | case OpCode::Memory__copy: |
566 | 1.10k | if (Conf.hasProposal(Proposal::MultiMemories)) { |
567 | 1.10k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
568 | 1.10k | return readU32(Instr.getSourceIndex()); |
569 | 1.10k | } |
570 | 0 | EXPECTED_TRY(readCheckZero(Instr.getTargetIndex())); |
571 | 0 | return readCheckZero(Instr.getSourceIndex()); |
572 | 3.79k | case OpCode::Data__drop: |
573 | 3.79k | if (!HasDataSection) { |
574 | 7 | return logLoadError(ErrCode::Value::DataCountRequired, Instr.getOffset(), |
575 | 7 | ASTNodeAttr::Instruction); |
576 | 7 | } |
577 | 3.79k | return readU32(Instr.getTargetIndex()); |
578 | | |
579 | | // Const Instructions. |
580 | 2.39M | case OpCode::I32__const: |
581 | 2.39M | EXPECTED_TRY(FMgr.readS32().map_error(ReportError).map([&](int32_t Num) { |
582 | | // Should clear the higher bits. |
583 | 2.39M | Instr.setNum(static_cast<uint128_t>(0U)); |
584 | 2.39M | Instr.setNum(static_cast<uint32_t>(Num)); |
585 | 2.39M | })); |
586 | 2.39M | return {}; |
587 | 913k | case OpCode::I64__const: |
588 | 913k | EXPECTED_TRY(FMgr.readS64().map_error(ReportError).map([&](int64_t Num) { |
589 | | // Should clear the higher bits. |
590 | 913k | Instr.setNum(static_cast<uint128_t>(0U)); |
591 | 913k | Instr.setNum(static_cast<uint64_t>(Num)); |
592 | 913k | })); |
593 | 913k | return {}; |
594 | 105k | case OpCode::F32__const: |
595 | 105k | EXPECTED_TRY(FMgr.readF32().map_error(ReportError).map([&](float Num) { |
596 | 104k | Instr.setNum(Num); |
597 | 104k | })); |
598 | 104k | return {}; |
599 | 72.0k | case OpCode::F64__const: |
600 | 72.0k | EXPECTED_TRY(FMgr.readF64().map_error(ReportError).map([&](double Num) { |
601 | 72.0k | Instr.setNum(Num); |
602 | 72.0k | })); |
603 | 72.0k | return {}; |
604 | | |
605 | | // Unary Numeric Instructions. |
606 | 69.8k | case OpCode::I32__eqz: |
607 | 105k | case OpCode::I32__clz: |
608 | 1.82M | case OpCode::I32__ctz: |
609 | 1.94M | case OpCode::I32__popcnt: |
610 | 1.98M | case OpCode::I64__eqz: |
611 | 2.01M | case OpCode::I64__clz: |
612 | 2.22M | case OpCode::I64__ctz: |
613 | 2.40M | case OpCode::I64__popcnt: |
614 | 2.41M | case OpCode::F32__abs: |
615 | 2.44M | case OpCode::F32__neg: |
616 | 2.49M | case OpCode::F32__ceil: |
617 | 2.51M | case OpCode::F32__floor: |
618 | 2.53M | case OpCode::F32__trunc: |
619 | 2.54M | case OpCode::F32__nearest: |
620 | 2.57M | case OpCode::F32__sqrt: |
621 | 2.58M | case OpCode::F64__abs: |
622 | 2.59M | case OpCode::F64__neg: |
623 | 2.60M | case OpCode::F64__ceil: |
624 | 2.61M | case OpCode::F64__floor: |
625 | 2.63M | case OpCode::F64__trunc: |
626 | 2.63M | case OpCode::F64__nearest: |
627 | 2.89M | case OpCode::F64__sqrt: |
628 | 2.90M | case OpCode::I32__wrap_i64: |
629 | 2.92M | case OpCode::I32__trunc_f32_s: |
630 | 2.94M | case OpCode::I32__trunc_f32_u: |
631 | 2.96M | case OpCode::I32__trunc_f64_s: |
632 | 3.15M | case OpCode::I32__trunc_f64_u: |
633 | 3.17M | case OpCode::I64__extend_i32_s: |
634 | 3.18M | case OpCode::I64__extend_i32_u: |
635 | 3.24M | case OpCode::I64__trunc_f32_s: |
636 | 3.25M | case OpCode::I64__trunc_f32_u: |
637 | 3.26M | case OpCode::I64__trunc_f64_s: |
638 | 3.27M | case OpCode::I64__trunc_f64_u: |
639 | 3.28M | case OpCode::F32__convert_i32_s: |
640 | 3.30M | case OpCode::F32__convert_i32_u: |
641 | 3.35M | case OpCode::F32__convert_i64_s: |
642 | 3.37M | case OpCode::F32__convert_i64_u: |
643 | 3.37M | case OpCode::F32__demote_f64: |
644 | 3.55M | case OpCode::F64__convert_i32_s: |
645 | 3.57M | case OpCode::F64__convert_i32_u: |
646 | 3.60M | case OpCode::F64__convert_i64_s: |
647 | 3.62M | case OpCode::F64__convert_i64_u: |
648 | 3.63M | case OpCode::F64__promote_f32: |
649 | 3.65M | case OpCode::I32__reinterpret_f32: |
650 | 3.68M | case OpCode::I64__reinterpret_f64: |
651 | 3.70M | case OpCode::F32__reinterpret_i32: |
652 | 3.73M | case OpCode::F64__reinterpret_i64: |
653 | 3.76M | case OpCode::I32__extend8_s: |
654 | 3.78M | case OpCode::I32__extend16_s: |
655 | 3.81M | case OpCode::I64__extend8_s: |
656 | 3.86M | case OpCode::I64__extend16_s: |
657 | 4.39M | case OpCode::I64__extend32_s: |
658 | 4.40M | case OpCode::I32__trunc_sat_f32_s: |
659 | 4.41M | case OpCode::I32__trunc_sat_f32_u: |
660 | 4.41M | case OpCode::I32__trunc_sat_f64_s: |
661 | 4.42M | case OpCode::I32__trunc_sat_f64_u: |
662 | 4.43M | case OpCode::I64__trunc_sat_f32_s: |
663 | 4.43M | case OpCode::I64__trunc_sat_f32_u: |
664 | 4.44M | case OpCode::I64__trunc_sat_f64_s: |
665 | 4.44M | case OpCode::I64__trunc_sat_f64_u: |
666 | | |
667 | | // Binary Numeric Instructions. |
668 | 4.47M | case OpCode::I32__eq: |
669 | 4.47M | case OpCode::I32__ne: |
670 | 4.49M | case OpCode::I32__lt_s: |
671 | 4.52M | case OpCode::I32__lt_u: |
672 | 4.53M | case OpCode::I32__gt_s: |
673 | 4.57M | case OpCode::I32__gt_u: |
674 | 4.59M | case OpCode::I32__le_s: |
675 | 5.12M | case OpCode::I32__le_u: |
676 | 5.15M | case OpCode::I32__ge_s: |
677 | 5.17M | case OpCode::I32__ge_u: |
678 | 5.26M | case OpCode::I64__eq: |
679 | 5.27M | case OpCode::I64__ne: |
680 | 5.28M | case OpCode::I64__lt_s: |
681 | 5.29M | case OpCode::I64__lt_u: |
682 | 5.30M | case OpCode::I64__gt_s: |
683 | 5.30M | case OpCode::I64__gt_u: |
684 | 5.32M | case OpCode::I64__le_s: |
685 | 5.33M | case OpCode::I64__le_u: |
686 | 5.34M | case OpCode::I64__ge_s: |
687 | 5.36M | case OpCode::I64__ge_u: |
688 | 5.44M | case OpCode::F32__eq: |
689 | 5.46M | case OpCode::F32__ne: |
690 | 5.54M | case OpCode::F32__lt: |
691 | 5.70M | case OpCode::F32__gt: |
692 | 5.71M | case OpCode::F32__le: |
693 | 5.75M | case OpCode::F32__ge: |
694 | 5.83M | case OpCode::F64__eq: |
695 | 5.85M | case OpCode::F64__ne: |
696 | 5.88M | case OpCode::F64__lt: |
697 | 5.94M | case OpCode::F64__gt: |
698 | 5.95M | case OpCode::F64__le: |
699 | 5.96M | case OpCode::F64__ge: |
700 | | |
701 | 5.98M | case OpCode::I32__add: |
702 | 6.06M | case OpCode::I32__sub: |
703 | 6.09M | case OpCode::I32__mul: |
704 | 6.20M | case OpCode::I32__div_s: |
705 | 6.47M | case OpCode::I32__div_u: |
706 | 6.50M | case OpCode::I32__rem_s: |
707 | 6.52M | case OpCode::I32__rem_u: |
708 | 6.53M | case OpCode::I32__and: |
709 | 6.60M | case OpCode::I32__or: |
710 | 6.77M | case OpCode::I32__xor: |
711 | 6.87M | case OpCode::I32__shl: |
712 | 6.92M | case OpCode::I32__shr_s: |
713 | 6.97M | case OpCode::I32__shr_u: |
714 | 6.99M | case OpCode::I32__rotl: |
715 | 7.14M | case OpCode::I32__rotr: |
716 | 7.17M | case OpCode::I64__add: |
717 | 7.20M | case OpCode::I64__sub: |
718 | 7.21M | case OpCode::I64__mul: |
719 | 7.23M | case OpCode::I64__div_s: |
720 | 7.27M | case OpCode::I64__div_u: |
721 | 7.31M | case OpCode::I64__rem_s: |
722 | 7.32M | case OpCode::I64__rem_u: |
723 | 7.32M | case OpCode::I64__and: |
724 | 7.34M | case OpCode::I64__or: |
725 | 7.37M | case OpCode::I64__xor: |
726 | 7.37M | case OpCode::I64__shl: |
727 | 7.38M | case OpCode::I64__shr_s: |
728 | 7.39M | case OpCode::I64__shr_u: |
729 | 7.40M | case OpCode::I64__rotl: |
730 | 7.42M | case OpCode::I64__rotr: |
731 | 7.43M | case OpCode::F32__add: |
732 | 7.66M | case OpCode::F32__sub: |
733 | 7.68M | case OpCode::F32__mul: |
734 | 7.68M | case OpCode::F32__div: |
735 | 7.71M | case OpCode::F32__min: |
736 | 7.72M | case OpCode::F32__max: |
737 | 7.72M | case OpCode::F32__copysign: |
738 | 7.73M | case OpCode::F64__add: |
739 | 7.75M | case OpCode::F64__sub: |
740 | 7.79M | case OpCode::F64__mul: |
741 | 7.80M | case OpCode::F64__div: |
742 | 7.81M | case OpCode::F64__min: |
743 | 7.81M | case OpCode::F64__max: |
744 | 7.82M | case OpCode::F64__copysign: |
745 | 7.82M | return {}; |
746 | | |
747 | | // SIMD Memory Instruction. |
748 | 108k | case OpCode::V128__load: |
749 | 143k | case OpCode::V128__load8x8_s: |
750 | 146k | case OpCode::V128__load8x8_u: |
751 | 148k | case OpCode::V128__load16x4_s: |
752 | 153k | case OpCode::V128__load16x4_u: |
753 | 157k | case OpCode::V128__load32x2_s: |
754 | 160k | case OpCode::V128__load32x2_u: |
755 | 163k | case OpCode::V128__load8_splat: |
756 | 171k | case OpCode::V128__load16_splat: |
757 | 174k | case OpCode::V128__load32_splat: |
758 | 178k | case OpCode::V128__load64_splat: |
759 | 182k | case OpCode::V128__load32_zero: |
760 | 183k | case OpCode::V128__load64_zero: |
761 | 185k | case OpCode::V128__store: |
762 | 185k | return readMemImmediate(); |
763 | 1.66k | case OpCode::V128__load8_lane: |
764 | 7.48k | case OpCode::V128__load16_lane: |
765 | 9.03k | case OpCode::V128__load32_lane: |
766 | 11.1k | case OpCode::V128__load64_lane: |
767 | 24.6k | case OpCode::V128__store8_lane: |
768 | 25.7k | case OpCode::V128__store16_lane: |
769 | 31.7k | case OpCode::V128__store32_lane: |
770 | 34.1k | case OpCode::V128__store64_lane: |
771 | | // Read memory immediate. |
772 | 34.1k | EXPECTED_TRY(readMemImmediate()); |
773 | | // Read lane index. |
774 | 34.0k | return readU8(Instr.getMemoryLane()); |
775 | | |
776 | | // SIMD Const Instruction. |
777 | 23.2k | case OpCode::V128__const: |
778 | | // SIMD Shuffle Instruction. |
779 | 25.2k | case OpCode::I8x16__shuffle: { |
780 | | // Read value. |
781 | 25.2k | uint128_t Value = 0U; |
782 | 428k | for (uint32_t I = 0U; I < 16U; ++I) { |
783 | 403k | EXPECTED_TRY(FMgr.readByte().map_error(ReportError).map([&](uint8_t B) { |
784 | 403k | Value |= static_cast<uint128_t>(static_cast<uint32_t>(B)) << (I * 8U); |
785 | 403k | })); |
786 | 403k | } |
787 | 25.1k | Instr.setNum(Value); |
788 | 25.1k | return {}; |
789 | 25.2k | } |
790 | | |
791 | | // SIMD Lane Instructions. |
792 | 9.57k | case OpCode::I8x16__extract_lane_s: |
793 | 11.2k | case OpCode::I8x16__extract_lane_u: |
794 | 15.4k | case OpCode::I8x16__replace_lane: |
795 | 21.8k | case OpCode::I16x8__extract_lane_s: |
796 | 25.0k | case OpCode::I16x8__extract_lane_u: |
797 | 28.6k | case OpCode::I16x8__replace_lane: |
798 | 36.6k | case OpCode::I32x4__extract_lane: |
799 | 41.9k | case OpCode::I32x4__replace_lane: |
800 | 44.1k | case OpCode::I64x2__extract_lane: |
801 | 46.5k | case OpCode::I64x2__replace_lane: |
802 | 50.1k | case OpCode::F32x4__extract_lane: |
803 | 52.8k | case OpCode::F32x4__replace_lane: |
804 | 61.1k | case OpCode::F64x2__extract_lane: |
805 | 64.6k | case OpCode::F64x2__replace_lane: |
806 | | // Read lane index. |
807 | 64.6k | return readU8(Instr.getMemoryLane()); |
808 | | |
809 | | // SIMD Numeric Instructions. |
810 | 4.83k | case OpCode::I8x16__swizzle: |
811 | 188k | case OpCode::I8x16__splat: |
812 | 232k | case OpCode::I16x8__splat: |
813 | 244k | case OpCode::I32x4__splat: |
814 | 249k | case OpCode::I64x2__splat: |
815 | 252k | case OpCode::F32x4__splat: |
816 | 260k | case OpCode::F64x2__splat: |
817 | | |
818 | 266k | case OpCode::I8x16__eq: |
819 | 268k | case OpCode::I8x16__ne: |
820 | 271k | case OpCode::I8x16__lt_s: |
821 | 281k | case OpCode::I8x16__lt_u: |
822 | 289k | case OpCode::I8x16__gt_s: |
823 | 292k | case OpCode::I8x16__gt_u: |
824 | 294k | case OpCode::I8x16__le_s: |
825 | 296k | case OpCode::I8x16__le_u: |
826 | 299k | case OpCode::I8x16__ge_s: |
827 | 302k | case OpCode::I8x16__ge_u: |
828 | | |
829 | 309k | case OpCode::I16x8__eq: |
830 | 313k | case OpCode::I16x8__ne: |
831 | 321k | case OpCode::I16x8__lt_s: |
832 | 329k | case OpCode::I16x8__lt_u: |
833 | 334k | case OpCode::I16x8__gt_s: |
834 | 341k | case OpCode::I16x8__gt_u: |
835 | 346k | case OpCode::I16x8__le_s: |
836 | 348k | case OpCode::I16x8__le_u: |
837 | 352k | case OpCode::I16x8__ge_s: |
838 | 357k | case OpCode::I16x8__ge_u: |
839 | | |
840 | 361k | case OpCode::I32x4__eq: |
841 | 363k | case OpCode::I32x4__ne: |
842 | 367k | case OpCode::I32x4__lt_s: |
843 | 368k | case OpCode::I32x4__lt_u: |
844 | 371k | case OpCode::I32x4__gt_s: |
845 | 375k | case OpCode::I32x4__gt_u: |
846 | 389k | case OpCode::I32x4__le_s: |
847 | 391k | case OpCode::I32x4__le_u: |
848 | 392k | case OpCode::I32x4__ge_s: |
849 | 396k | case OpCode::I32x4__ge_u: |
850 | | |
851 | 589k | case OpCode::F32x4__eq: |
852 | 592k | case OpCode::F32x4__ne: |
853 | 594k | case OpCode::F32x4__lt: |
854 | 596k | case OpCode::F32x4__gt: |
855 | 599k | case OpCode::F32x4__le: |
856 | 601k | case OpCode::F32x4__ge: |
857 | | |
858 | 609k | case OpCode::F64x2__eq: |
859 | 612k | case OpCode::F64x2__ne: |
860 | 616k | case OpCode::F64x2__lt: |
861 | 621k | case OpCode::F64x2__gt: |
862 | 623k | case OpCode::F64x2__le: |
863 | 629k | case OpCode::F64x2__ge: |
864 | | |
865 | 643k | case OpCode::V128__not: |
866 | 645k | case OpCode::V128__and: |
867 | 647k | case OpCode::V128__andnot: |
868 | 649k | case OpCode::V128__or: |
869 | 659k | case OpCode::V128__xor: |
870 | 662k | case OpCode::V128__bitselect: |
871 | 664k | case OpCode::V128__any_true: |
872 | | |
873 | 686k | case OpCode::I8x16__abs: |
874 | 718k | case OpCode::I8x16__neg: |
875 | 723k | case OpCode::I8x16__popcnt: |
876 | 732k | case OpCode::I8x16__all_true: |
877 | 749k | case OpCode::I8x16__bitmask: |
878 | 752k | case OpCode::I8x16__narrow_i16x8_s: |
879 | 768k | case OpCode::I8x16__narrow_i16x8_u: |
880 | 771k | case OpCode::I8x16__shl: |
881 | 775k | case OpCode::I8x16__shr_s: |
882 | 777k | case OpCode::I8x16__shr_u: |
883 | 778k | case OpCode::I8x16__add: |
884 | 793k | case OpCode::I8x16__add_sat_s: |
885 | 795k | case OpCode::I8x16__add_sat_u: |
886 | 798k | case OpCode::I8x16__sub: |
887 | 801k | case OpCode::I8x16__sub_sat_s: |
888 | 804k | case OpCode::I8x16__sub_sat_u: |
889 | 807k | case OpCode::I8x16__min_s: |
890 | 816k | case OpCode::I8x16__min_u: |
891 | 820k | case OpCode::I8x16__max_s: |
892 | 826k | case OpCode::I8x16__max_u: |
893 | 830k | case OpCode::I8x16__avgr_u: |
894 | | |
895 | 834k | case OpCode::I16x8__abs: |
896 | 862k | case OpCode::I16x8__neg: |
897 | 865k | case OpCode::I16x8__all_true: |
898 | 869k | case OpCode::I16x8__bitmask: |
899 | 871k | case OpCode::I16x8__narrow_i32x4_s: |
900 | 874k | case OpCode::I16x8__narrow_i32x4_u: |
901 | 884k | case OpCode::I16x8__extend_low_i8x16_s: |
902 | 886k | case OpCode::I16x8__extend_high_i8x16_s: |
903 | 889k | case OpCode::I16x8__extend_low_i8x16_u: |
904 | 891k | case OpCode::I16x8__extend_high_i8x16_u: |
905 | 892k | case OpCode::I16x8__shl: |
906 | 893k | case OpCode::I16x8__shr_s: |
907 | 896k | case OpCode::I16x8__shr_u: |
908 | 901k | case OpCode::I16x8__add: |
909 | 903k | case OpCode::I16x8__add_sat_s: |
910 | 905k | case OpCode::I16x8__add_sat_u: |
911 | 908k | case OpCode::I16x8__sub: |
912 | 913k | case OpCode::I16x8__sub_sat_s: |
913 | 919k | case OpCode::I16x8__sub_sat_u: |
914 | 921k | case OpCode::I16x8__mul: |
915 | 923k | case OpCode::I16x8__min_s: |
916 | 925k | case OpCode::I16x8__min_u: |
917 | 929k | case OpCode::I16x8__max_s: |
918 | 932k | case OpCode::I16x8__max_u: |
919 | 938k | case OpCode::I16x8__avgr_u: |
920 | 940k | case OpCode::I16x8__extmul_low_i8x16_s: |
921 | 943k | case OpCode::I16x8__extmul_high_i8x16_s: |
922 | 944k | case OpCode::I16x8__extmul_low_i8x16_u: |
923 | 951k | case OpCode::I16x8__extmul_high_i8x16_u: |
924 | 954k | case OpCode::I16x8__q15mulr_sat_s: |
925 | 960k | case OpCode::I16x8__extadd_pairwise_i8x16_s: |
926 | 967k | case OpCode::I16x8__extadd_pairwise_i8x16_u: |
927 | | |
928 | 973k | case OpCode::I32x4__abs: |
929 | 987k | case OpCode::I32x4__neg: |
930 | 991k | case OpCode::I32x4__all_true: |
931 | 999k | case OpCode::I32x4__bitmask: |
932 | 1.01M | case OpCode::I32x4__extend_low_i16x8_s: |
933 | 1.01M | case OpCode::I32x4__extend_high_i16x8_s: |
934 | 1.02M | case OpCode::I32x4__extend_low_i16x8_u: |
935 | 1.02M | case OpCode::I32x4__extend_high_i16x8_u: |
936 | 1.03M | case OpCode::I32x4__shl: |
937 | 1.03M | case OpCode::I32x4__shr_s: |
938 | 1.03M | case OpCode::I32x4__shr_u: |
939 | 1.04M | case OpCode::I32x4__add: |
940 | 1.04M | case OpCode::I32x4__sub: |
941 | 1.04M | case OpCode::I32x4__mul: |
942 | 1.04M | case OpCode::I32x4__min_s: |
943 | 1.05M | case OpCode::I32x4__min_u: |
944 | 1.05M | case OpCode::I32x4__max_s: |
945 | 1.05M | case OpCode::I32x4__max_u: |
946 | 1.05M | case OpCode::I32x4__extmul_low_i16x8_s: |
947 | 1.06M | case OpCode::I32x4__extmul_high_i16x8_s: |
948 | 1.06M | case OpCode::I32x4__extmul_low_i16x8_u: |
949 | 1.06M | case OpCode::I32x4__extmul_high_i16x8_u: |
950 | 1.06M | case OpCode::I32x4__extadd_pairwise_i16x8_s: |
951 | 1.09M | case OpCode::I32x4__extadd_pairwise_i16x8_u: |
952 | | |
953 | 1.09M | case OpCode::I64x2__abs: |
954 | 1.10M | case OpCode::I64x2__neg: |
955 | 1.10M | case OpCode::I64x2__bitmask: |
956 | 1.11M | case OpCode::I64x2__extend_low_i32x4_s: |
957 | 1.11M | case OpCode::I64x2__extend_high_i32x4_s: |
958 | 1.12M | case OpCode::I64x2__extend_low_i32x4_u: |
959 | 1.13M | case OpCode::I64x2__extend_high_i32x4_u: |
960 | 1.13M | case OpCode::I64x2__shl: |
961 | 1.13M | case OpCode::I64x2__shr_s: |
962 | 1.13M | case OpCode::I64x2__shr_u: |
963 | 1.13M | case OpCode::I64x2__add: |
964 | 1.13M | case OpCode::I64x2__sub: |
965 | 1.14M | case OpCode::I64x2__mul: |
966 | 1.15M | case OpCode::I64x2__eq: |
967 | 1.15M | case OpCode::I64x2__ne: |
968 | 1.16M | case OpCode::I64x2__lt_s: |
969 | 1.16M | case OpCode::I64x2__gt_s: |
970 | 1.16M | case OpCode::I64x2__le_s: |
971 | 1.17M | case OpCode::I64x2__ge_s: |
972 | 1.17M | case OpCode::I64x2__all_true: |
973 | 1.17M | case OpCode::I64x2__extmul_low_i32x4_s: |
974 | 1.17M | case OpCode::I64x2__extmul_high_i32x4_s: |
975 | 1.17M | case OpCode::I64x2__extmul_low_i32x4_u: |
976 | 1.18M | case OpCode::I64x2__extmul_high_i32x4_u: |
977 | | |
978 | 1.18M | case OpCode::F32x4__abs: |
979 | 1.19M | case OpCode::F32x4__neg: |
980 | 1.20M | case OpCode::F32x4__sqrt: |
981 | 1.20M | case OpCode::F32x4__add: |
982 | 1.20M | case OpCode::F32x4__sub: |
983 | 1.21M | case OpCode::F32x4__mul: |
984 | 1.21M | case OpCode::F32x4__div: |
985 | 1.21M | case OpCode::F32x4__min: |
986 | 1.22M | case OpCode::F32x4__max: |
987 | 1.23M | case OpCode::F32x4__pmin: |
988 | 1.23M | case OpCode::F32x4__pmax: |
989 | | |
990 | 1.24M | case OpCode::F64x2__abs: |
991 | 1.24M | case OpCode::F64x2__neg: |
992 | 1.25M | case OpCode::F64x2__sqrt: |
993 | 1.25M | case OpCode::F64x2__add: |
994 | 1.25M | case OpCode::F64x2__sub: |
995 | 1.26M | case OpCode::F64x2__mul: |
996 | 1.26M | case OpCode::F64x2__div: |
997 | 1.27M | case OpCode::F64x2__min: |
998 | 1.27M | case OpCode::F64x2__max: |
999 | 1.27M | case OpCode::F64x2__pmin: |
1000 | 1.28M | case OpCode::F64x2__pmax: |
1001 | | |
1002 | 1.28M | case OpCode::I32x4__trunc_sat_f32x4_s: |
1003 | 1.30M | case OpCode::I32x4__trunc_sat_f32x4_u: |
1004 | 1.30M | case OpCode::F32x4__convert_i32x4_s: |
1005 | 1.31M | case OpCode::F32x4__convert_i32x4_u: |
1006 | 1.31M | case OpCode::I32x4__trunc_sat_f64x2_s_zero: |
1007 | 1.32M | case OpCode::I32x4__trunc_sat_f64x2_u_zero: |
1008 | 1.33M | case OpCode::F64x2__convert_low_i32x4_s: |
1009 | 1.34M | case OpCode::F64x2__convert_low_i32x4_u: |
1010 | 1.35M | case OpCode::F32x4__demote_f64x2_zero: |
1011 | 1.36M | case OpCode::F64x2__promote_low_f32x4: |
1012 | | |
1013 | 1.37M | case OpCode::I32x4__dot_i16x8_s: |
1014 | 1.38M | case OpCode::F32x4__ceil: |
1015 | 1.39M | case OpCode::F32x4__floor: |
1016 | 1.41M | case OpCode::F32x4__trunc: |
1017 | 1.41M | case OpCode::F32x4__nearest: |
1018 | 1.42M | case OpCode::F64x2__ceil: |
1019 | 1.43M | case OpCode::F64x2__floor: |
1020 | 1.43M | case OpCode::F64x2__trunc: |
1021 | 1.43M | case OpCode::F64x2__nearest: |
1022 | 1.43M | return {}; |
1023 | | |
1024 | 555 | case OpCode::I8x16__relaxed_swizzle: |
1025 | 4.97k | case OpCode::I32x4__relaxed_trunc_f32x4_s: |
1026 | 7.70k | case OpCode::I32x4__relaxed_trunc_f32x4_u: |
1027 | 8.81k | case OpCode::I32x4__relaxed_trunc_f64x2_s_zero: |
1028 | 9.64k | case OpCode::I32x4__relaxed_trunc_f64x2_u_zero: |
1029 | 10.7k | case OpCode::F32x4__relaxed_madd: |
1030 | 19.5k | case OpCode::F32x4__relaxed_nmadd: |
1031 | 20.1k | case OpCode::F64x2__relaxed_madd: |
1032 | 24.1k | case OpCode::F64x2__relaxed_nmadd: |
1033 | 25.5k | case OpCode::I8x16__relaxed_laneselect: |
1034 | 28.9k | case OpCode::I16x8__relaxed_laneselect: |
1035 | 30.7k | case OpCode::I32x4__relaxed_laneselect: |
1036 | 31.7k | case OpCode::I64x2__relaxed_laneselect: |
1037 | 32.6k | case OpCode::F32x4__relaxed_min: |
1038 | 33.0k | case OpCode::F32x4__relaxed_max: |
1039 | 33.9k | case OpCode::F64x2__relaxed_min: |
1040 | 48.5k | case OpCode::F64x2__relaxed_max: |
1041 | 49.2k | case OpCode::I16x8__relaxed_q15mulr_s: |
1042 | 50.8k | case OpCode::I16x8__relaxed_dot_i8x16_i7x16_s: |
1043 | 52.2k | case OpCode::I32x4__relaxed_dot_i8x16_i7x16_add_s: |
1044 | 52.2k | return {}; |
1045 | | |
1046 | | // Atomic Memory Instructions. |
1047 | 1.54k | case OpCode::Atomic__fence: |
1048 | 1.54k | return readCheckZero(Instr.getTargetIndex()); |
1049 | | |
1050 | 4.60k | case OpCode::Memory__atomic__notify: |
1051 | 9.43k | case OpCode::Memory__atomic__wait32: |
1052 | 11.3k | case OpCode::Memory__atomic__wait64: |
1053 | | |
1054 | 11.3k | case OpCode::I32__atomic__load: |
1055 | 11.3k | case OpCode::I64__atomic__load: |
1056 | 11.3k | case OpCode::I32__atomic__load8_u: |
1057 | 11.3k | case OpCode::I32__atomic__load16_u: |
1058 | 11.3k | case OpCode::I64__atomic__load8_u: |
1059 | 11.3k | case OpCode::I64__atomic__load16_u: |
1060 | 11.3k | case OpCode::I64__atomic__load32_u: |
1061 | 11.3k | case OpCode::I32__atomic__store: |
1062 | 11.3k | case OpCode::I64__atomic__store: |
1063 | 11.3k | case OpCode::I32__atomic__store8: |
1064 | 11.3k | case OpCode::I32__atomic__store16: |
1065 | 11.3k | case OpCode::I64__atomic__store8: |
1066 | 11.3k | case OpCode::I64__atomic__store16: |
1067 | 11.3k | case OpCode::I64__atomic__store32: |
1068 | 11.3k | case OpCode::I32__atomic__rmw__add: |
1069 | 11.3k | case OpCode::I64__atomic__rmw__add: |
1070 | 11.3k | case OpCode::I32__atomic__rmw8__add_u: |
1071 | 11.3k | case OpCode::I32__atomic__rmw16__add_u: |
1072 | 11.3k | case OpCode::I64__atomic__rmw8__add_u: |
1073 | 11.3k | case OpCode::I64__atomic__rmw16__add_u: |
1074 | 11.3k | case OpCode::I64__atomic__rmw32__add_u: |
1075 | 11.3k | case OpCode::I32__atomic__rmw__sub: |
1076 | 11.3k | case OpCode::I64__atomic__rmw__sub: |
1077 | 11.3k | case OpCode::I32__atomic__rmw8__sub_u: |
1078 | 11.3k | case OpCode::I32__atomic__rmw16__sub_u: |
1079 | 11.3k | case OpCode::I64__atomic__rmw8__sub_u: |
1080 | 11.3k | case OpCode::I64__atomic__rmw16__sub_u: |
1081 | 11.3k | case OpCode::I64__atomic__rmw32__sub_u: |
1082 | 11.3k | case OpCode::I32__atomic__rmw__and: |
1083 | 11.3k | case OpCode::I64__atomic__rmw__and: |
1084 | 11.3k | case OpCode::I32__atomic__rmw8__and_u: |
1085 | 11.3k | case OpCode::I32__atomic__rmw16__and_u: |
1086 | 11.3k | case OpCode::I64__atomic__rmw8__and_u: |
1087 | 11.3k | case OpCode::I64__atomic__rmw16__and_u: |
1088 | 11.3k | case OpCode::I64__atomic__rmw32__and_u: |
1089 | 11.3k | case OpCode::I32__atomic__rmw__or: |
1090 | 11.3k | case OpCode::I64__atomic__rmw__or: |
1091 | 11.3k | case OpCode::I32__atomic__rmw8__or_u: |
1092 | 11.3k | case OpCode::I32__atomic__rmw16__or_u: |
1093 | 11.3k | case OpCode::I64__atomic__rmw8__or_u: |
1094 | 11.3k | case OpCode::I64__atomic__rmw16__or_u: |
1095 | 11.3k | case OpCode::I64__atomic__rmw32__or_u: |
1096 | 11.3k | case OpCode::I32__atomic__rmw__xor: |
1097 | 11.3k | case OpCode::I64__atomic__rmw__xor: |
1098 | 11.3k | case OpCode::I32__atomic__rmw8__xor_u: |
1099 | 11.3k | case OpCode::I32__atomic__rmw16__xor_u: |
1100 | 11.3k | case OpCode::I64__atomic__rmw8__xor_u: |
1101 | 11.3k | case OpCode::I64__atomic__rmw16__xor_u: |
1102 | 11.3k | case OpCode::I64__atomic__rmw32__xor_u: |
1103 | 11.3k | case OpCode::I32__atomic__rmw__xchg: |
1104 | 11.3k | case OpCode::I64__atomic__rmw__xchg: |
1105 | 11.3k | case OpCode::I32__atomic__rmw8__xchg_u: |
1106 | 11.3k | case OpCode::I32__atomic__rmw16__xchg_u: |
1107 | 11.3k | case OpCode::I64__atomic__rmw8__xchg_u: |
1108 | 11.3k | case OpCode::I64__atomic__rmw16__xchg_u: |
1109 | 11.3k | case OpCode::I64__atomic__rmw32__xchg_u: |
1110 | 11.3k | case OpCode::I32__atomic__rmw__cmpxchg: |
1111 | 11.3k | case OpCode::I64__atomic__rmw__cmpxchg: |
1112 | 11.3k | case OpCode::I32__atomic__rmw8__cmpxchg_u: |
1113 | 11.3k | case OpCode::I32__atomic__rmw16__cmpxchg_u: |
1114 | 11.3k | case OpCode::I64__atomic__rmw8__cmpxchg_u: |
1115 | 11.3k | case OpCode::I64__atomic__rmw16__cmpxchg_u: |
1116 | 11.3k | case OpCode::I64__atomic__rmw32__cmpxchg_u: |
1117 | 11.3k | return readMemImmediate(); |
1118 | | |
1119 | 0 | default: |
1120 | 0 | assumingUnreachable(); |
1121 | 35.3M | } |
1122 | 35.3M | } |
1123 | | |
1124 | | } // namespace Loader |
1125 | | } // namespace WasmEdge |