/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 | 27.3M | Expect<OpCode> Loader::loadOpCode() { |
15 | 27.3M | EXPECTED_TRY(uint8_t Prefix, FMgr.readByte()); |
16 | | |
17 | 27.3M | if (Prefix >= 0xFBU && Prefix <= 0xFEU) { |
18 | | // Multi-byte OpCode case. |
19 | 1.67M | EXPECTED_TRY(uint32_t Extend, FMgr.readU32()); |
20 | 1.67M | if (Prefix == 0xFBU) { |
21 | 80.6k | switch (Extend) { |
22 | 0 | #define UseOpCode |
23 | 0 | #define Line(NAME, STRING, PREFIX) |
24 | 0 | #define Line_FB(NAME, STRING, PREFIX, EXTEND) \ |
25 | 80.6k | case EXTEND: \ |
26 | 80.6k | 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 | 31 | default: |
38 | 31 | return Unexpect(ErrCode::Value::IllegalOpCode); |
39 | 80.6k | } |
40 | 1.59M | } else if (Prefix == 0xFCU) { |
41 | 53.5k | 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 | 53.5k | case EXTEND: \ |
47 | 53.5k | 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 | 29 | default: |
58 | 29 | return Unexpect(ErrCode::Value::IllegalOpCode); |
59 | 53.5k | } |
60 | 1.54M | } else if (Prefix == 0xFDU) { |
61 | 1.53M | 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.53M | case EXTEND: \ |
68 | 1.53M | 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 | 231 | default: |
78 | 231 | return Unexpect(ErrCode::Value::IllegalOpCode); |
79 | 1.53M | } |
80 | 1.53M | } else { |
81 | 12.0k | 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 | 12.0k | case EXTEND: \ |
89 | 12.0k | 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 | 16 | default: |
98 | 16 | return Unexpect(ErrCode::Value::IllegalOpCode); |
99 | 12.0k | } |
100 | 12.0k | } |
101 | 25.7M | } else { |
102 | | // Single-byte OpCode case. |
103 | 25.7M | switch (Prefix) { |
104 | 0 | #define UseOpCode |
105 | 0 | #define Line(NAME, STRING, PREFIX) \ |
106 | 25.7M | case PREFIX: \ |
107 | 25.7M | 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 | 585 | default: |
120 | 585 | return Unexpect(ErrCode::Value::IllegalOpCode); |
121 | 25.7M | } |
122 | 25.7M | } |
123 | 27.3M | } |
124 | | |
125 | | // Load instruction sequence. See "include/loader/loader.h". |
126 | 47.9k | Expect<AST::InstrVec> Loader::loadInstrSeq(std::optional<uint64_t> SizeBound) { |
127 | 47.9k | AST::InstrVec Instrs; |
128 | 47.9k | std::vector<std::pair<OpCode, uint32_t>> BlockStack; |
129 | 47.9k | uint32_t Cnt = 0; |
130 | 47.9k | bool IsReachEnd = false; |
131 | | // Read opcode until the End code of the top block. |
132 | 27.3M | do { |
133 | | // Read the opcode and check for errors. |
134 | 27.3M | uint64_t Offset = FMgr.getOffset(); |
135 | 27.3M | EXPECTED_TRY(OpCode Code, loadOpCode().map_error([this](auto E) { |
136 | 27.3M | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
137 | 27.3M | })); |
138 | | |
139 | | // Check with proposals. |
140 | 27.3M | if (auto Res = Conf.isInstrNeedProposal(Code); unlikely(!!Res)) { |
141 | 233 | return logNeedProposal(ErrCode::Value::IllegalOpCode, Res.value(), Offset, |
142 | 233 | ASTNodeAttr::Instruction); |
143 | 233 | } |
144 | | |
145 | 27.3M | auto logIllegalOpCode = [this, &Offset, |
146 | 27.3M | &SizeBound]() -> Unexpected<ErrCode> { |
147 | 122 | if (SizeBound.has_value() && FMgr.getOffset() > SizeBound.value()) { |
148 | 44 | return logLoadError(ErrCode::Value::ENDCodeExpected, Offset, |
149 | 44 | ASTNodeAttr::Instruction); |
150 | 78 | } else { |
151 | 78 | return logLoadError(ErrCode::Value::IllegalOpCode, Offset, |
152 | 78 | ASTNodeAttr::Instruction); |
153 | 78 | } |
154 | 122 | }; |
155 | | |
156 | | // Process the instruction that contains a block. |
157 | 27.3M | switch (Code) { |
158 | 359k | case OpCode::Block: |
159 | 1.01M | case OpCode::Loop: |
160 | 1.18M | case OpCode::If: |
161 | 1.21M | case OpCode::Try_table: |
162 | 1.21M | BlockStack.emplace_back(Code, Cnt); |
163 | 1.21M | break; |
164 | 5.86k | case OpCode::Else: { |
165 | 5.86k | if (BlockStack.size() == 0 || BlockStack.back().first != OpCode::If) { |
166 | | // An Else instruction appeared outside the If-block. |
167 | 102 | return logIllegalOpCode(); |
168 | 102 | } |
169 | 5.76k | uint32_t Pos = BlockStack.back().second; |
170 | 5.76k | if (Instrs[Pos].getJumpElse() > 0) { |
171 | | // An Else instruction appeared before in this If-block. |
172 | 20 | return logIllegalOpCode(); |
173 | 20 | } |
174 | 5.74k | Instrs[Pos].setJumpElse(Cnt - Pos); |
175 | 5.74k | break; |
176 | 5.76k | } |
177 | 26.1M | default: |
178 | 26.1M | break; |
179 | 27.3M | } |
180 | | |
181 | | // Create the instruction node and load contents. |
182 | 27.3M | Instrs.emplace_back(Code, static_cast<uint32_t>(Offset)); |
183 | 27.3M | EXPECTED_TRY(loadInstruction(Instrs.back())); |
184 | | |
185 | 27.3M | if (Code == OpCode::End) { |
186 | | // Post process the End instruction. |
187 | 87.3k | if (BlockStack.size() > 0) { |
188 | 47.2k | Instrs.back().setExprLast(false); |
189 | 47.2k | const auto &[BackOp, Pos] = BlockStack.back(); |
190 | 47.2k | if (BackOp == OpCode::Block || BackOp == OpCode::Loop || |
191 | 39.7k | BackOp == OpCode::If) { |
192 | 39.7k | Instrs.back().setTryBlockLast(false); |
193 | 39.7k | Instrs[Pos].setJumpEnd(Cnt - Pos); |
194 | 39.7k | if (BackOp == OpCode::If) { |
195 | 17.0k | if (Instrs[Pos].getJumpElse() == 0) { |
196 | | // For an if block without an else branch, set the else jump to |
197 | | // the end jump. |
198 | 13.8k | Instrs[Pos].setJumpElse(Cnt - Pos); |
199 | 13.8k | } else { |
200 | 3.20k | const uint32_t ElsePos = Pos + Instrs[Pos].getJumpElse(); |
201 | 3.20k | Instrs[ElsePos].setJumpEnd(Cnt - ElsePos); |
202 | 3.20k | } |
203 | 17.0k | } |
204 | 39.7k | } else if (BackOp == OpCode::Try_table) { |
205 | 7.50k | Instrs.back().setTryBlockLast(true); |
206 | 7.50k | Instrs[Pos].getTryCatch().JumpEnd = Cnt - Pos; |
207 | 7.50k | } |
208 | 47.2k | BlockStack.pop_back(); |
209 | 47.2k | } else { |
210 | 40.0k | Instrs.back().setExprLast(true); |
211 | 40.0k | IsReachEnd = true; |
212 | 40.0k | } |
213 | 87.3k | } |
214 | 27.3M | Cnt++; |
215 | 27.3M | } while (!IsReachEnd); |
216 | | |
217 | | // Check the loaded offset should match the segment boundary. |
218 | 40.0k | if (SizeBound.has_value()) { |
219 | 19.4k | auto Offset = FMgr.getOffset(); |
220 | 19.4k | if (Offset < SizeBound.value()) { |
221 | 13 | return logLoadError(ErrCode::Value::JunkSection, Offset, |
222 | 13 | ASTNodeAttr::Instruction); |
223 | 19.4k | } else if (Offset > SizeBound.value()) { |
224 | 79 | return logLoadError(ErrCode::Value::SectionSizeMismatch, Offset, |
225 | 79 | ASTNodeAttr::Instruction); |
226 | 79 | } |
227 | 19.4k | } |
228 | 39.9k | return Instrs; |
229 | 40.0k | } |
230 | | |
231 | | // Load instruction node. See "include/loader/loader.h". |
232 | 27.4M | Expect<void> Loader::loadInstruction(AST::Instruction &Instr) { |
233 | | // Node: The instruction has checked for the proposals. Need to check their |
234 | | // immediates. |
235 | | |
236 | 27.4M | auto ReportError = [this](auto E) { |
237 | 1.82k | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
238 | 1.82k | }; |
239 | | |
240 | 27.4M | auto readU8 = [this, ReportError](uint8_t &Dst) -> Expect<void> { |
241 | 82.4k | EXPECTED_TRY(Dst, FMgr.readByte().map_error(ReportError)); |
242 | 82.3k | return {}; |
243 | 82.4k | }; |
244 | | |
245 | 27.4M | auto readU32 = [this, ReportError](uint32_t &Dst) -> Expect<void> { |
246 | 1.35M | EXPECTED_TRY(Dst, FMgr.readU32().map_error(ReportError)); |
247 | 1.35M | return {}; |
248 | 1.35M | }; |
249 | | |
250 | 27.4M | auto readU64 = [this, ReportError](uint64_t &Dst) -> Expect<void> { |
251 | 459k | EXPECTED_TRY(Dst, FMgr.readU64().map_error(ReportError)); |
252 | 459k | return {}; |
253 | 459k | }; |
254 | | |
255 | 27.4M | auto readMemImmediate = [this, readU32, readU64, &Instr]() -> Expect<void> { |
256 | 459k | Instr.getTargetIndex() = 0; |
257 | 459k | EXPECTED_TRY(readU32(Instr.getMemoryAlign())); |
258 | 459k | if (Conf.hasProposal(Proposal::MultiMemories) && |
259 | 459k | Instr.getMemoryAlign() >= 64) { |
260 | 32.0k | Instr.getMemoryAlign() -= 64; |
261 | 32.0k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
262 | 32.0k | } |
263 | 459k | uint32_t MaxAlign = Conf.hasProposal(Proposal::Memory64) ? 64U : 32U; |
264 | 459k | if (unlikely(Instr.getMemoryAlign() >= MaxAlign)) { |
265 | 159 | return logLoadError(ErrCode::Value::MalformedMemoryOpFlags, |
266 | 159 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
267 | 159 | } |
268 | 459k | if (Conf.hasProposal(Proposal::Memory64)) { |
269 | 459k | EXPECTED_TRY(readU64(Instr.getMemoryOffset())); |
270 | 459k | } else { |
271 | 0 | uint32_t Offset; |
272 | 0 | EXPECTED_TRY(readU32(Offset)); |
273 | 0 | Instr.getMemoryOffset() = static_cast<uint64_t>(Offset); |
274 | 0 | } |
275 | 459k | return {}; |
276 | 459k | }; |
277 | | |
278 | 27.4M | auto readCheckZero = [this, readU8](uint32_t &Dst) -> Expect<void> { |
279 | 1.34k | uint8_t C = 0; |
280 | 1.34k | EXPECTED_TRY(readU8(C)); |
281 | 1.33k | if (C != UINT8_C(0)) { |
282 | 6 | return logLoadError(ErrCode::Value::ExpectedZeroByte, |
283 | 6 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
284 | 6 | } |
285 | 1.33k | Dst = 0; |
286 | 1.33k | return {}; |
287 | 1.33k | }; |
288 | | |
289 | 27.4M | auto readBlockType = [this, ReportError](BlockType &Dst) -> Expect<void> { |
290 | 1.21M | auto StartOffset = FMgr.getOffset(); |
291 | | // Read the block return type. |
292 | 1.21M | EXPECTED_TRY(int64_t Code, FMgr.readS33().map_error(ReportError)); |
293 | 1.21M | 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 | 538k | if (Code < -64) { |
299 | 63 | return logLoadError(ErrCode::Value::MalformedValType, |
300 | 63 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
301 | 63 | } |
302 | 538k | TypeCode TypeByte = static_cast<TypeCode>(Code & INT64_C(0x7F)); |
303 | 538k | if (TypeByte == TypeCode::Epsilon) { |
304 | | // Empty case. |
305 | 8.94k | Dst.setEmpty(); |
306 | 529k | } else { |
307 | | // Value type case. Seek back to the origin offset and read the |
308 | | // valtype. |
309 | 529k | FMgr.seek(StartOffset); |
310 | | // The AST node information is handled. |
311 | 529k | EXPECTED_TRY(auto Type, loadValType(ASTNodeAttr::Instruction)); |
312 | 529k | Dst.setData(Type); |
313 | 529k | } |
314 | 678k | } else { |
315 | | // Type index case. |
316 | 678k | 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 | 678k | Dst.setData(static_cast<uint32_t>(Code)); |
322 | 678k | } |
323 | 1.21M | return {}; |
324 | 1.21M | }; |
325 | | |
326 | 27.4M | switch (Instr.getOpCode()) { |
327 | | // Control instructions. |
328 | 12.5M | case OpCode::Unreachable: |
329 | 13.3M | case OpCode::Nop: |
330 | 13.5M | case OpCode::Return: |
331 | 13.5M | case OpCode::Throw_ref: |
332 | 13.6M | case OpCode::End: |
333 | 13.6M | case OpCode::Else: |
334 | 13.6M | return {}; |
335 | | |
336 | 359k | case OpCode::Block: |
337 | 1.01M | case OpCode::Loop: |
338 | 1.18M | case OpCode::If: |
339 | 1.18M | return readBlockType(Instr.getBlockType()); |
340 | | |
341 | 34.8k | case OpCode::Try_table: { |
342 | 34.8k | Instr.setTryCatch(); |
343 | | // Read the result type. |
344 | 34.8k | EXPECTED_TRY(readBlockType(Instr.getTryCatch().ResType)); |
345 | 69.7k | EXPECTED_TRY(uint32_t VecCnt, loadVecCnt().map_error(ReportError)); |
346 | 69.7k | Instr.getTryCatch().Catch.resize(VecCnt); |
347 | 69.7k | for (uint32_t I = 0; I < VecCnt; ++I) { |
348 | 9.39k | auto &Desc = Instr.getTryCatch().Catch[I]; |
349 | | // Read the catch flag. |
350 | 9.39k | EXPECTED_TRY(uint8_t Flag, FMgr.readByte().map_error(ReportError)); |
351 | 9.38k | if (unlikely(Flag > 0x03U)) { |
352 | 33 | return logLoadError(ErrCode::Value::MalformedCatchFlags, |
353 | 33 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
354 | 33 | } |
355 | 9.35k | Desc.IsRef = (Flag & 0x01U) ? true : false; |
356 | 9.35k | Desc.IsAll = (Flag & 0x02U) ? true : false; |
357 | 9.35k | if (!Desc.IsAll) { |
358 | | // Read the tag index. |
359 | 1.63k | EXPECTED_TRY(readU32(Desc.TagIndex)); |
360 | 1.63k | } |
361 | | // Read the label index. |
362 | 9.34k | EXPECTED_TRY(readU32(Desc.LabelIndex)); |
363 | 9.34k | } |
364 | 34.8k | return {}; |
365 | 69.7k | } |
366 | | |
367 | 24.9k | case OpCode::Throw: |
368 | 24.9k | return readU32(Instr.getTargetIndex()); |
369 | | |
370 | 88.9k | case OpCode::Br: |
371 | 123k | case OpCode::Br_if: |
372 | 129k | case OpCode::Br_on_null: |
373 | 131k | case OpCode::Br_on_non_null: |
374 | 131k | return readU32(Instr.getJump().TargetIndex); |
375 | | |
376 | 24.7k | case OpCode::Br_table: { |
377 | | // Read the vector of labels. |
378 | 24.7k | EXPECTED_TRY(uint32_t VecCnt, loadVecCnt().map_error(ReportError)); |
379 | 24.6k | Instr.setLabelListSize(VecCnt + 1); |
380 | 296k | for (uint32_t I = 0; I < VecCnt; ++I) { |
381 | 272k | EXPECTED_TRY(readU32(Instr.getLabelList()[I].TargetIndex)); |
382 | 272k | } |
383 | | // Read default label. |
384 | 24.6k | return readU32(Instr.getLabelList()[VecCnt].TargetIndex); |
385 | 24.6k | } |
386 | | |
387 | 24.4k | case OpCode::Call: |
388 | 29.7k | case OpCode::Return_call: |
389 | 50.7k | case OpCode::Call_ref: |
390 | 58.3k | case OpCode::Return_call_ref: |
391 | 58.3k | return readU32(Instr.getTargetIndex()); |
392 | | |
393 | 25.0k | case OpCode::Call_indirect: |
394 | 29.9k | case OpCode::Return_call_indirect: { |
395 | | // Read the type index. |
396 | 29.9k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
397 | 29.9k | uint64_t SrcIdxOffset = FMgr.getOffset(); |
398 | | // Read the table index. |
399 | 29.9k | EXPECTED_TRY(readU32(Instr.getSourceIndex())); |
400 | 29.9k | if ((Instr.getSourceIndex() > 0 || FMgr.getOffset() - SrcIdxOffset > 1) && |
401 | 22.6k | !Conf.hasProposal(Proposal::ReferenceTypes)) { |
402 | 0 | return logNeedProposal(ErrCode::Value::ExpectedZeroByte, |
403 | 0 | Proposal::ReferenceTypes, FMgr.getLastOffset(), |
404 | 0 | ASTNodeAttr::Instruction); |
405 | 0 | } |
406 | 29.9k | return {}; |
407 | 29.9k | } |
408 | | |
409 | | // Reference Instructions. |
410 | 26.0k | case OpCode::Ref__null: |
411 | 27.5k | case OpCode::Ref__test_null: |
412 | 28.8k | case OpCode::Ref__cast_null: { |
413 | | // The AST node information is handled. |
414 | 28.8k | EXPECTED_TRY(auto Type, |
415 | 28.7k | loadHeapType(TypeCode::RefNull, ASTNodeAttr::Instruction)); |
416 | 28.7k | Instr.setValType(Type); |
417 | 28.7k | return {}; |
418 | 28.8k | } |
419 | 3.35k | case OpCode::Ref__test: |
420 | 8.21k | case OpCode::Ref__cast: { |
421 | | // The AST node information is handled. |
422 | 8.21k | EXPECTED_TRY(auto Type, |
423 | 8.20k | loadHeapType(TypeCode::Ref, ASTNodeAttr::Instruction)); |
424 | 8.20k | Instr.setValType(Type); |
425 | 8.20k | return {}; |
426 | 8.21k | } |
427 | 9.72k | case OpCode::Ref__is_null: |
428 | 34.4k | case OpCode::Ref__eq: |
429 | 39.5k | case OpCode::Ref__as_non_null: |
430 | 39.5k | return {}; |
431 | 23.3k | case OpCode::Ref__func: |
432 | 29.9k | case OpCode::Struct__new: |
433 | 46.0k | case OpCode::Struct__new_default: |
434 | 47.1k | case OpCode::Array__new: |
435 | 47.6k | case OpCode::Array__new_default: |
436 | 48.9k | case OpCode::Array__get: |
437 | 50.0k | case OpCode::Array__get_s: |
438 | 63.9k | case OpCode::Array__get_u: |
439 | 64.5k | case OpCode::Array__set: |
440 | 65.8k | case OpCode::Array__fill: |
441 | 65.8k | return readU32(Instr.getTargetIndex()); |
442 | 906 | case OpCode::Struct__get: |
443 | 2.57k | case OpCode::Struct__get_s: |
444 | 3.23k | case OpCode::Struct__get_u: |
445 | 3.80k | case OpCode::Struct__set: |
446 | 5.96k | case OpCode::Array__new_fixed: |
447 | 6.43k | case OpCode::Array__new_data: |
448 | 6.79k | case OpCode::Array__new_elem: |
449 | 8.18k | case OpCode::Array__copy: |
450 | 8.73k | case OpCode::Array__init_data: |
451 | 9.61k | case OpCode::Array__init_elem: |
452 | 9.61k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
453 | 9.54k | return readU32(Instr.getSourceIndex()); |
454 | 238 | case OpCode::Br_on_cast: |
455 | 319 | case OpCode::Br_on_cast_fail: { |
456 | | // Read the flag. |
457 | 319 | uint8_t Flag = 0U; |
458 | 319 | EXPECTED_TRY(readU8(Flag).map_error(ReportError)); |
459 | 312 | if (unlikely(Flag > 0x03U)) { |
460 | 85 | return logLoadError(ErrCode::Value::MalformedCastFlags, |
461 | 85 | FMgr.getLastOffset(), ASTNodeAttr::Instruction); |
462 | 85 | } |
463 | | // Read the label index. |
464 | 227 | uint32_t LabelIdx = 0U; |
465 | 227 | EXPECTED_TRY(readU32(LabelIdx).map_error(ReportError)); |
466 | | // Read the heap types. |
467 | 225 | Instr.setBrCast(LabelIdx); |
468 | 225 | TypeCode TC = ((Flag & 0x01U) ? TypeCode::RefNull : TypeCode::Ref); |
469 | 225 | EXPECTED_TRY( |
470 | 222 | Instr.getBrCast().RType1, |
471 | 222 | loadHeapType(TC, ASTNodeAttr::Instruction).map_error(ReportError)); |
472 | 222 | TC = ((Flag & 0x02U) ? TypeCode::RefNull : TypeCode::Ref); |
473 | 222 | EXPECTED_TRY( |
474 | 218 | Instr.getBrCast().RType2, |
475 | 218 | loadHeapType(TC, ASTNodeAttr::Instruction).map_error(ReportError)); |
476 | 218 | return {}; |
477 | 222 | } |
478 | 2.84k | case OpCode::Array__len: |
479 | 3.80k | case OpCode::Any__convert_extern: |
480 | 6.08k | case OpCode::Extern__convert_any: |
481 | 15.9k | case OpCode::Ref__i31: |
482 | 16.8k | case OpCode::I31__get_s: |
483 | 17.1k | case OpCode::I31__get_u: |
484 | 17.1k | return {}; |
485 | | |
486 | | // Parametric Instructions. |
487 | 1.11M | case OpCode::Drop: |
488 | 1.22M | case OpCode::Select: |
489 | 1.22M | return {}; |
490 | 4.94k | case OpCode::Select_t: { |
491 | | // Read the vector of value types. |
492 | 4.94k | EXPECTED_TRY(uint32_t VecCnt, loadVecCnt().map_error(ReportError)); |
493 | 4.91k | Instr.setValTypeListSize(VecCnt); |
494 | 81.9k | for (uint32_t I = 0; I < VecCnt; ++I) { |
495 | | // The AST node information is handled. |
496 | 77.0k | EXPECTED_TRY(Instr.getValTypeList()[I], |
497 | 77.0k | loadValType(ASTNodeAttr::Instruction)); |
498 | 77.0k | } |
499 | 4.86k | return {}; |
500 | 4.91k | } |
501 | | |
502 | | // Variable Instructions. |
503 | 29.4k | case OpCode::Local__get: |
504 | 61.0k | case OpCode::Local__set: |
505 | 69.8k | case OpCode::Local__tee: |
506 | 76.4k | case OpCode::Global__get: |
507 | 103k | case OpCode::Global__set: |
508 | 103k | return readU32(Instr.getTargetIndex()); |
509 | | |
510 | | // Table Instructions. |
511 | 2.16k | case OpCode::Table__init: |
512 | 2.16k | EXPECTED_TRY(readU32(Instr.getSourceIndex())); |
513 | 2.16k | [[fallthrough]]; |
514 | 8.07k | case OpCode::Table__get: |
515 | 13.8k | case OpCode::Table__set: |
516 | 17.8k | case OpCode::Table__grow: |
517 | 19.4k | case OpCode::Table__size: |
518 | 20.1k | case OpCode::Table__fill: |
519 | 23.1k | case OpCode::Elem__drop: |
520 | 23.1k | return readU32(Instr.getTargetIndex()); |
521 | 1.51k | case OpCode::Table__copy: |
522 | 1.51k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
523 | 1.51k | return readU32(Instr.getSourceIndex()); |
524 | | |
525 | | // Memory Instructions. |
526 | 11.2k | case OpCode::I32__load: |
527 | 20.1k | case OpCode::I64__load: |
528 | 27.1k | case OpCode::F32__load: |
529 | 39.9k | case OpCode::F64__load: |
530 | 48.2k | case OpCode::I32__load8_s: |
531 | 57.2k | case OpCode::I32__load8_u: |
532 | 62.3k | case OpCode::I32__load16_s: |
533 | 132k | case OpCode::I32__load16_u: |
534 | 142k | case OpCode::I64__load8_s: |
535 | 150k | case OpCode::I64__load8_u: |
536 | 160k | case OpCode::I64__load16_s: |
537 | 178k | case OpCode::I64__load16_u: |
538 | 184k | case OpCode::I64__load32_s: |
539 | 201k | case OpCode::I64__load32_u: |
540 | 206k | case OpCode::I32__store: |
541 | 235k | case OpCode::I64__store: |
542 | 240k | case OpCode::F32__store: |
543 | 245k | case OpCode::F64__store: |
544 | 252k | case OpCode::I32__store8: |
545 | 257k | case OpCode::I32__store16: |
546 | 262k | case OpCode::I64__store8: |
547 | 282k | case OpCode::I64__store16: |
548 | 285k | case OpCode::I64__store32: |
549 | 285k | return readMemImmediate(); |
550 | | |
551 | 1.09k | case OpCode::Memory__init: |
552 | 1.09k | if (!HasDataSection) { |
553 | 7 | return logLoadError(ErrCode::Value::DataCountRequired, Instr.getOffset(), |
554 | 7 | ASTNodeAttr::Instruction); |
555 | 7 | } |
556 | 1.09k | EXPECTED_TRY(readU32(Instr.getSourceIndex())); |
557 | 1.08k | [[fallthrough]]; |
558 | 41.5k | case OpCode::Memory__grow: |
559 | 53.3k | case OpCode::Memory__size: |
560 | 56.9k | case OpCode::Memory__fill: |
561 | 56.9k | if (Conf.hasProposal(Proposal::MultiMemories)) { |
562 | 56.9k | return readU32(Instr.getTargetIndex()); |
563 | 56.9k | } |
564 | 0 | return readCheckZero(Instr.getTargetIndex()); |
565 | 2.53k | case OpCode::Memory__copy: |
566 | 2.53k | if (Conf.hasProposal(Proposal::MultiMemories)) { |
567 | 2.53k | EXPECTED_TRY(readU32(Instr.getTargetIndex())); |
568 | 2.52k | return readU32(Instr.getSourceIndex()); |
569 | 2.53k | } |
570 | 0 | EXPECTED_TRY(readCheckZero(Instr.getTargetIndex())); |
571 | 0 | return readCheckZero(Instr.getSourceIndex()); |
572 | 819 | case OpCode::Data__drop: |
573 | 819 | if (!HasDataSection) { |
574 | 4 | return logLoadError(ErrCode::Value::DataCountRequired, Instr.getOffset(), |
575 | 4 | ASTNodeAttr::Instruction); |
576 | 4 | } |
577 | 815 | return readU32(Instr.getTargetIndex()); |
578 | | |
579 | | // Const Instructions. |
580 | 2.38M | case OpCode::I32__const: |
581 | 2.38M | EXPECTED_TRY(FMgr.readS32().map_error(ReportError).map([&](int32_t Num) { |
582 | | // Should clear the higher bits. |
583 | 2.38M | Instr.setNum(static_cast<uint128_t>(0U)); |
584 | 2.38M | Instr.setNum(static_cast<uint32_t>(Num)); |
585 | 2.38M | })); |
586 | 2.38M | return {}; |
587 | 833k | case OpCode::I64__const: |
588 | 833k | EXPECTED_TRY(FMgr.readS64().map_error(ReportError).map([&](int64_t Num) { |
589 | | // Should clear the higher bits. |
590 | 833k | Instr.setNum(static_cast<uint128_t>(0U)); |
591 | 833k | Instr.setNum(static_cast<uint64_t>(Num)); |
592 | 833k | })); |
593 | 833k | return {}; |
594 | 45.7k | case OpCode::F32__const: |
595 | 45.7k | EXPECTED_TRY(FMgr.readF32().map_error(ReportError).map([&](float Num) { |
596 | 45.7k | Instr.setNum(Num); |
597 | 45.7k | })); |
598 | 45.7k | return {}; |
599 | 22.0k | case OpCode::F64__const: |
600 | 22.0k | EXPECTED_TRY(FMgr.readF64().map_error(ReportError).map([&](double Num) { |
601 | 22.0k | Instr.setNum(Num); |
602 | 22.0k | })); |
603 | 22.0k | return {}; |
604 | | |
605 | | // Unary Numeric Instructions. |
606 | 28.9k | case OpCode::I32__eqz: |
607 | 44.0k | case OpCode::I32__clz: |
608 | 572k | case OpCode::I32__ctz: |
609 | 681k | case OpCode::I32__popcnt: |
610 | 710k | case OpCode::I64__eqz: |
611 | 743k | case OpCode::I64__clz: |
612 | 811k | case OpCode::I64__ctz: |
613 | 920k | case OpCode::I64__popcnt: |
614 | 928k | case OpCode::F32__abs: |
615 | 939k | case OpCode::F32__neg: |
616 | 953k | case OpCode::F32__ceil: |
617 | 979k | case OpCode::F32__floor: |
618 | 987k | case OpCode::F32__trunc: |
619 | 1.00M | case OpCode::F32__nearest: |
620 | 1.01M | case OpCode::F32__sqrt: |
621 | 1.01M | case OpCode::F64__abs: |
622 | 1.02M | case OpCode::F64__neg: |
623 | 1.05M | case OpCode::F64__ceil: |
624 | 1.06M | case OpCode::F64__floor: |
625 | 1.07M | case OpCode::F64__trunc: |
626 | 1.09M | case OpCode::F64__nearest: |
627 | 1.17M | case OpCode::F64__sqrt: |
628 | 1.18M | case OpCode::I32__wrap_i64: |
629 | 1.19M | case OpCode::I32__trunc_f32_s: |
630 | 1.20M | case OpCode::I32__trunc_f32_u: |
631 | 1.21M | case OpCode::I32__trunc_f64_s: |
632 | 1.47M | case OpCode::I32__trunc_f64_u: |
633 | 1.49M | case OpCode::I64__extend_i32_s: |
634 | 1.50M | case OpCode::I64__extend_i32_u: |
635 | 1.50M | case OpCode::I64__trunc_f32_s: |
636 | 1.51M | case OpCode::I64__trunc_f32_u: |
637 | 1.52M | case OpCode::I64__trunc_f64_s: |
638 | 1.53M | case OpCode::I64__trunc_f64_u: |
639 | 1.54M | case OpCode::F32__convert_i32_s: |
640 | 1.56M | case OpCode::F32__convert_i32_u: |
641 | 1.58M | case OpCode::F32__convert_i64_s: |
642 | 1.59M | case OpCode::F32__convert_i64_u: |
643 | 1.60M | case OpCode::F32__demote_f64: |
644 | 1.66M | case OpCode::F64__convert_i32_s: |
645 | 1.67M | case OpCode::F64__convert_i32_u: |
646 | 1.70M | case OpCode::F64__convert_i64_s: |
647 | 1.71M | case OpCode::F64__convert_i64_u: |
648 | 1.73M | case OpCode::F64__promote_f32: |
649 | 1.73M | case OpCode::I32__reinterpret_f32: |
650 | 1.76M | case OpCode::I64__reinterpret_f64: |
651 | 1.81M | case OpCode::F32__reinterpret_i32: |
652 | 1.84M | case OpCode::F64__reinterpret_i64: |
653 | 1.87M | case OpCode::I32__extend8_s: |
654 | 1.88M | case OpCode::I32__extend16_s: |
655 | 1.89M | case OpCode::I64__extend8_s: |
656 | 1.92M | case OpCode::I64__extend16_s: |
657 | 2.09M | case OpCode::I64__extend32_s: |
658 | 2.10M | case OpCode::I32__trunc_sat_f32_s: |
659 | 2.11M | case OpCode::I32__trunc_sat_f32_u: |
660 | 2.11M | case OpCode::I32__trunc_sat_f64_s: |
661 | 2.11M | case OpCode::I32__trunc_sat_f64_u: |
662 | 2.12M | case OpCode::I64__trunc_sat_f32_s: |
663 | 2.12M | case OpCode::I64__trunc_sat_f32_u: |
664 | 2.12M | case OpCode::I64__trunc_sat_f64_s: |
665 | 2.12M | case OpCode::I64__trunc_sat_f64_u: |
666 | | |
667 | | // Binary Numeric Instructions. |
668 | 2.14M | case OpCode::I32__eq: |
669 | 2.15M | case OpCode::I32__ne: |
670 | 2.16M | case OpCode::I32__lt_s: |
671 | 2.20M | case OpCode::I32__lt_u: |
672 | 2.25M | case OpCode::I32__gt_s: |
673 | 2.28M | case OpCode::I32__gt_u: |
674 | 2.29M | case OpCode::I32__le_s: |
675 | 2.43M | case OpCode::I32__le_u: |
676 | 2.45M | case OpCode::I32__ge_s: |
677 | 2.46M | case OpCode::I32__ge_u: |
678 | 2.47M | case OpCode::I64__eq: |
679 | 2.48M | case OpCode::I64__ne: |
680 | 2.50M | case OpCode::I64__lt_s: |
681 | 2.51M | case OpCode::I64__lt_u: |
682 | 2.52M | case OpCode::I64__gt_s: |
683 | 2.52M | case OpCode::I64__gt_u: |
684 | 2.53M | case OpCode::I64__le_s: |
685 | 2.54M | case OpCode::I64__le_u: |
686 | 2.55M | case OpCode::I64__ge_s: |
687 | 2.59M | case OpCode::I64__ge_u: |
688 | 2.62M | case OpCode::F32__eq: |
689 | 2.65M | case OpCode::F32__ne: |
690 | 2.68M | case OpCode::F32__lt: |
691 | 2.90M | case OpCode::F32__gt: |
692 | 2.94M | case OpCode::F32__le: |
693 | 2.97M | case OpCode::F32__ge: |
694 | 3.09M | case OpCode::F64__eq: |
695 | 3.10M | case OpCode::F64__ne: |
696 | 3.14M | case OpCode::F64__lt: |
697 | 3.16M | case OpCode::F64__gt: |
698 | 3.18M | case OpCode::F64__le: |
699 | 3.19M | case OpCode::F64__ge: |
700 | | |
701 | 3.36M | case OpCode::I32__add: |
702 | 3.38M | case OpCode::I32__sub: |
703 | 3.39M | case OpCode::I32__mul: |
704 | 3.59M | case OpCode::I32__div_s: |
705 | 3.86M | case OpCode::I32__div_u: |
706 | 3.88M | case OpCode::I32__rem_s: |
707 | 3.90M | case OpCode::I32__rem_u: |
708 | 3.93M | case OpCode::I32__and: |
709 | 3.97M | case OpCode::I32__or: |
710 | 4.94M | case OpCode::I32__xor: |
711 | 4.97M | case OpCode::I32__shl: |
712 | 4.98M | case OpCode::I32__shr_s: |
713 | 5.03M | case OpCode::I32__shr_u: |
714 | 5.06M | case OpCode::I32__rotl: |
715 | 5.07M | case OpCode::I32__rotr: |
716 | 5.09M | case OpCode::I64__add: |
717 | 5.13M | case OpCode::I64__sub: |
718 | 5.15M | case OpCode::I64__mul: |
719 | 5.17M | case OpCode::I64__div_s: |
720 | 5.26M | case OpCode::I64__div_u: |
721 | 5.27M | case OpCode::I64__rem_s: |
722 | 5.28M | case OpCode::I64__rem_u: |
723 | 5.29M | case OpCode::I64__and: |
724 | 5.31M | case OpCode::I64__or: |
725 | 5.31M | case OpCode::I64__xor: |
726 | 5.32M | case OpCode::I64__shl: |
727 | 5.33M | case OpCode::I64__shr_s: |
728 | 5.34M | case OpCode::I64__shr_u: |
729 | 5.35M | case OpCode::I64__rotl: |
730 | 5.37M | case OpCode::I64__rotr: |
731 | 5.37M | case OpCode::F32__add: |
732 | 5.38M | case OpCode::F32__sub: |
733 | 5.39M | case OpCode::F32__mul: |
734 | 5.41M | case OpCode::F32__div: |
735 | 5.44M | case OpCode::F32__min: |
736 | 5.44M | case OpCode::F32__max: |
737 | 5.45M | case OpCode::F32__copysign: |
738 | 5.45M | case OpCode::F64__add: |
739 | 5.47M | case OpCode::F64__sub: |
740 | 5.52M | case OpCode::F64__mul: |
741 | 5.52M | case OpCode::F64__div: |
742 | 5.53M | case OpCode::F64__min: |
743 | 5.53M | case OpCode::F64__max: |
744 | 5.54M | case OpCode::F64__copysign: |
745 | 5.54M | return {}; |
746 | | |
747 | | // SIMD Memory Instruction. |
748 | 58.7k | case OpCode::V128__load: |
749 | 64.2k | case OpCode::V128__load8x8_s: |
750 | 67.6k | case OpCode::V128__load8x8_u: |
751 | 69.0k | case OpCode::V128__load16x4_s: |
752 | 72.8k | case OpCode::V128__load16x4_u: |
753 | 75.4k | case OpCode::V128__load32x2_s: |
754 | 99.1k | case OpCode::V128__load32x2_u: |
755 | 110k | case OpCode::V128__load8_splat: |
756 | 123k | case OpCode::V128__load16_splat: |
757 | 126k | case OpCode::V128__load32_splat: |
758 | 128k | case OpCode::V128__load64_splat: |
759 | 133k | case OpCode::V128__load32_zero: |
760 | 138k | case OpCode::V128__load64_zero: |
761 | 140k | case OpCode::V128__store: |
762 | 140k | return readMemImmediate(); |
763 | 959 | case OpCode::V128__load8_lane: |
764 | 6.98k | case OpCode::V128__load16_lane: |
765 | 8.64k | case OpCode::V128__load32_lane: |
766 | 11.8k | case OpCode::V128__load64_lane: |
767 | 13.9k | case OpCode::V128__store8_lane: |
768 | 15.2k | case OpCode::V128__store16_lane: |
769 | 21.8k | case OpCode::V128__store32_lane: |
770 | 23.6k | case OpCode::V128__store64_lane: |
771 | | // Read memory immediate. |
772 | 23.6k | EXPECTED_TRY(readMemImmediate()); |
773 | | // Read lane index. |
774 | 23.5k | return readU8(Instr.getMemoryLane()); |
775 | | |
776 | | // SIMD Const Instruction. |
777 | 14.0k | case OpCode::V128__const: |
778 | | // SIMD Shuffle Instruction. |
779 | 15.6k | case OpCode::I8x16__shuffle: { |
780 | | // Read value. |
781 | 15.6k | uint128_t Value = 0U; |
782 | 265k | for (uint32_t I = 0U; I < 16U; ++I) { |
783 | 249k | EXPECTED_TRY(FMgr.readByte().map_error(ReportError).map([&](uint8_t B) { |
784 | 249k | Value |= static_cast<uint128_t>(static_cast<uint32_t>(B)) << (I * 8U); |
785 | 249k | })); |
786 | 249k | } |
787 | 15.6k | Instr.setNum(Value); |
788 | 15.6k | return {}; |
789 | 15.6k | } |
790 | | |
791 | | // SIMD Lane Instructions. |
792 | 13.2k | case OpCode::I8x16__extract_lane_s: |
793 | 14.0k | case OpCode::I8x16__extract_lane_u: |
794 | 17.7k | case OpCode::I8x16__replace_lane: |
795 | 21.4k | case OpCode::I16x8__extract_lane_s: |
796 | 23.7k | case OpCode::I16x8__extract_lane_u: |
797 | 28.2k | case OpCode::I16x8__replace_lane: |
798 | 34.8k | case OpCode::I32x4__extract_lane: |
799 | 38.6k | case OpCode::I32x4__replace_lane: |
800 | 40.4k | case OpCode::I64x2__extract_lane: |
801 | 42.7k | case OpCode::I64x2__replace_lane: |
802 | 44.0k | case OpCode::F32x4__extract_lane: |
803 | 47.6k | case OpCode::F32x4__replace_lane: |
804 | 52.3k | case OpCode::F64x2__extract_lane: |
805 | 57.1k | case OpCode::F64x2__replace_lane: |
806 | | // Read lane index. |
807 | 57.1k | return readU8(Instr.getMemoryLane()); |
808 | | |
809 | | // SIMD Numeric Instructions. |
810 | 5.10k | case OpCode::I8x16__swizzle: |
811 | 185k | case OpCode::I8x16__splat: |
812 | 230k | case OpCode::I16x8__splat: |
813 | 240k | case OpCode::I32x4__splat: |
814 | 243k | case OpCode::I64x2__splat: |
815 | 244k | case OpCode::F32x4__splat: |
816 | 249k | case OpCode::F64x2__splat: |
817 | | |
818 | 260k | case OpCode::I8x16__eq: |
819 | 263k | case OpCode::I8x16__ne: |
820 | 266k | case OpCode::I8x16__lt_s: |
821 | 268k | case OpCode::I8x16__lt_u: |
822 | 275k | case OpCode::I8x16__gt_s: |
823 | 279k | case OpCode::I8x16__gt_u: |
824 | 280k | case OpCode::I8x16__le_s: |
825 | 283k | case OpCode::I8x16__le_u: |
826 | 285k | case OpCode::I8x16__ge_s: |
827 | 288k | case OpCode::I8x16__ge_u: |
828 | | |
829 | 294k | case OpCode::I16x8__eq: |
830 | 300k | case OpCode::I16x8__ne: |
831 | 308k | case OpCode::I16x8__lt_s: |
832 | 313k | case OpCode::I16x8__lt_u: |
833 | 319k | case OpCode::I16x8__gt_s: |
834 | 327k | case OpCode::I16x8__gt_u: |
835 | 332k | case OpCode::I16x8__le_s: |
836 | 333k | case OpCode::I16x8__le_u: |
837 | 337k | case OpCode::I16x8__ge_s: |
838 | 342k | case OpCode::I16x8__ge_u: |
839 | | |
840 | 347k | case OpCode::I32x4__eq: |
841 | 349k | case OpCode::I32x4__ne: |
842 | 357k | case OpCode::I32x4__lt_s: |
843 | 367k | case OpCode::I32x4__lt_u: |
844 | 368k | case OpCode::I32x4__gt_s: |
845 | 371k | case OpCode::I32x4__gt_u: |
846 | 378k | case OpCode::I32x4__le_s: |
847 | 386k | case OpCode::I32x4__le_u: |
848 | 388k | case OpCode::I32x4__ge_s: |
849 | 392k | case OpCode::I32x4__ge_u: |
850 | | |
851 | 458k | case OpCode::F32x4__eq: |
852 | 460k | case OpCode::F32x4__ne: |
853 | 462k | case OpCode::F32x4__lt: |
854 | 465k | case OpCode::F32x4__gt: |
855 | 469k | case OpCode::F32x4__le: |
856 | 470k | case OpCode::F32x4__ge: |
857 | | |
858 | 479k | case OpCode::F64x2__eq: |
859 | 484k | case OpCode::F64x2__ne: |
860 | 486k | case OpCode::F64x2__lt: |
861 | 492k | case OpCode::F64x2__gt: |
862 | 494k | case OpCode::F64x2__le: |
863 | 498k | case OpCode::F64x2__ge: |
864 | | |
865 | 528k | case OpCode::V128__not: |
866 | 530k | case OpCode::V128__and: |
867 | 531k | case OpCode::V128__andnot: |
868 | 533k | case OpCode::V128__or: |
869 | 535k | case OpCode::V128__xor: |
870 | 542k | case OpCode::V128__bitselect: |
871 | 544k | case OpCode::V128__any_true: |
872 | | |
873 | 566k | case OpCode::I8x16__abs: |
874 | 596k | case OpCode::I8x16__neg: |
875 | 606k | case OpCode::I8x16__popcnt: |
876 | 611k | case OpCode::I8x16__all_true: |
877 | 620k | case OpCode::I8x16__bitmask: |
878 | 654k | case OpCode::I8x16__narrow_i16x8_s: |
879 | 655k | case OpCode::I8x16__narrow_i16x8_u: |
880 | 659k | case OpCode::I8x16__shl: |
881 | 662k | case OpCode::I8x16__shr_s: |
882 | 665k | case OpCode::I8x16__shr_u: |
883 | 666k | case OpCode::I8x16__add: |
884 | 710k | case OpCode::I8x16__add_sat_s: |
885 | 712k | case OpCode::I8x16__add_sat_u: |
886 | 715k | case OpCode::I8x16__sub: |
887 | 718k | case OpCode::I8x16__sub_sat_s: |
888 | 728k | case OpCode::I8x16__sub_sat_u: |
889 | 731k | case OpCode::I8x16__min_s: |
890 | 742k | case OpCode::I8x16__min_u: |
891 | 743k | case OpCode::I8x16__max_s: |
892 | 747k | case OpCode::I8x16__max_u: |
893 | 749k | case OpCode::I8x16__avgr_u: |
894 | | |
895 | 751k | case OpCode::I16x8__abs: |
896 | 753k | case OpCode::I16x8__neg: |
897 | 755k | case OpCode::I16x8__all_true: |
898 | 758k | case OpCode::I16x8__bitmask: |
899 | 759k | case OpCode::I16x8__narrow_i32x4_s: |
900 | 762k | case OpCode::I16x8__narrow_i32x4_u: |
901 | 769k | case OpCode::I16x8__extend_low_i8x16_s: |
902 | 770k | case OpCode::I16x8__extend_high_i8x16_s: |
903 | 772k | case OpCode::I16x8__extend_low_i8x16_u: |
904 | 775k | case OpCode::I16x8__extend_high_i8x16_u: |
905 | 776k | case OpCode::I16x8__shl: |
906 | 777k | case OpCode::I16x8__shr_s: |
907 | 779k | case OpCode::I16x8__shr_u: |
908 | 792k | case OpCode::I16x8__add: |
909 | 794k | case OpCode::I16x8__add_sat_s: |
910 | 796k | case OpCode::I16x8__add_sat_u: |
911 | 799k | case OpCode::I16x8__sub: |
912 | 803k | case OpCode::I16x8__sub_sat_s: |
913 | 805k | case OpCode::I16x8__sub_sat_u: |
914 | 806k | case OpCode::I16x8__mul: |
915 | 809k | case OpCode::I16x8__min_s: |
916 | 810k | case OpCode::I16x8__min_u: |
917 | 814k | case OpCode::I16x8__max_s: |
918 | 817k | case OpCode::I16x8__max_u: |
919 | 821k | case OpCode::I16x8__avgr_u: |
920 | 823k | case OpCode::I16x8__extmul_low_i8x16_s: |
921 | 826k | case OpCode::I16x8__extmul_high_i8x16_s: |
922 | 827k | case OpCode::I16x8__extmul_low_i8x16_u: |
923 | 831k | case OpCode::I16x8__extmul_high_i8x16_u: |
924 | 834k | case OpCode::I16x8__q15mulr_sat_s: |
925 | 836k | case OpCode::I16x8__extadd_pairwise_i8x16_s: |
926 | 843k | case OpCode::I16x8__extadd_pairwise_i8x16_u: |
927 | | |
928 | 858k | case OpCode::I32x4__abs: |
929 | 898k | case OpCode::I32x4__neg: |
930 | 901k | case OpCode::I32x4__all_true: |
931 | 912k | case OpCode::I32x4__bitmask: |
932 | 914k | case OpCode::I32x4__extend_low_i16x8_s: |
933 | 916k | case OpCode::I32x4__extend_high_i16x8_s: |
934 | 925k | case OpCode::I32x4__extend_low_i16x8_u: |
935 | 928k | case OpCode::I32x4__extend_high_i16x8_u: |
936 | 932k | case OpCode::I32x4__shl: |
937 | 933k | case OpCode::I32x4__shr_s: |
938 | 938k | case OpCode::I32x4__shr_u: |
939 | 940k | case OpCode::I32x4__add: |
940 | 942k | case OpCode::I32x4__sub: |
941 | 943k | case OpCode::I32x4__mul: |
942 | 945k | case OpCode::I32x4__min_s: |
943 | 951k | case OpCode::I32x4__min_u: |
944 | 952k | case OpCode::I32x4__max_s: |
945 | 954k | case OpCode::I32x4__max_u: |
946 | 957k | case OpCode::I32x4__extmul_low_i16x8_s: |
947 | 965k | case OpCode::I32x4__extmul_high_i16x8_s: |
948 | 966k | case OpCode::I32x4__extmul_low_i16x8_u: |
949 | 967k | case OpCode::I32x4__extmul_high_i16x8_u: |
950 | 973k | case OpCode::I32x4__extadd_pairwise_i16x8_s: |
951 | 996k | case OpCode::I32x4__extadd_pairwise_i16x8_u: |
952 | | |
953 | 998k | case OpCode::I64x2__abs: |
954 | 1.00M | case OpCode::I64x2__neg: |
955 | 1.00M | case OpCode::I64x2__bitmask: |
956 | 1.00M | case OpCode::I64x2__extend_low_i32x4_s: |
957 | 1.00M | case OpCode::I64x2__extend_high_i32x4_s: |
958 | 1.01M | case OpCode::I64x2__extend_low_i32x4_u: |
959 | 1.01M | case OpCode::I64x2__extend_high_i32x4_u: |
960 | 1.02M | case OpCode::I64x2__shl: |
961 | 1.02M | case OpCode::I64x2__shr_s: |
962 | 1.02M | case OpCode::I64x2__shr_u: |
963 | 1.02M | case OpCode::I64x2__add: |
964 | 1.02M | case OpCode::I64x2__sub: |
965 | 1.02M | case OpCode::I64x2__mul: |
966 | 1.03M | case OpCode::I64x2__eq: |
967 | 1.03M | case OpCode::I64x2__ne: |
968 | 1.03M | case OpCode::I64x2__lt_s: |
969 | 1.04M | case OpCode::I64x2__gt_s: |
970 | 1.04M | case OpCode::I64x2__le_s: |
971 | 1.04M | case OpCode::I64x2__ge_s: |
972 | 1.04M | case OpCode::I64x2__all_true: |
973 | 1.05M | case OpCode::I64x2__extmul_low_i32x4_s: |
974 | 1.05M | case OpCode::I64x2__extmul_high_i32x4_s: |
975 | 1.05M | case OpCode::I64x2__extmul_low_i32x4_u: |
976 | 1.05M | case OpCode::I64x2__extmul_high_i32x4_u: |
977 | | |
978 | 1.06M | case OpCode::F32x4__abs: |
979 | 1.06M | case OpCode::F32x4__neg: |
980 | 1.06M | case OpCode::F32x4__sqrt: |
981 | 1.06M | case OpCode::F32x4__add: |
982 | 1.07M | case OpCode::F32x4__sub: |
983 | 1.07M | case OpCode::F32x4__mul: |
984 | 1.07M | case OpCode::F32x4__div: |
985 | 1.07M | case OpCode::F32x4__min: |
986 | 1.07M | case OpCode::F32x4__max: |
987 | 1.08M | case OpCode::F32x4__pmin: |
988 | 1.09M | case OpCode::F32x4__pmax: |
989 | | |
990 | 1.09M | case OpCode::F64x2__abs: |
991 | 1.09M | case OpCode::F64x2__neg: |
992 | 1.10M | case OpCode::F64x2__sqrt: |
993 | 1.10M | case OpCode::F64x2__add: |
994 | 1.11M | case OpCode::F64x2__sub: |
995 | 1.11M | case OpCode::F64x2__mul: |
996 | 1.11M | case OpCode::F64x2__div: |
997 | 1.11M | case OpCode::F64x2__min: |
998 | 1.11M | case OpCode::F64x2__max: |
999 | 1.11M | case OpCode::F64x2__pmin: |
1000 | 1.12M | case OpCode::F64x2__pmax: |
1001 | | |
1002 | 1.12M | case OpCode::I32x4__trunc_sat_f32x4_s: |
1003 | 1.14M | case OpCode::I32x4__trunc_sat_f32x4_u: |
1004 | 1.14M | case OpCode::F32x4__convert_i32x4_s: |
1005 | 1.15M | case OpCode::F32x4__convert_i32x4_u: |
1006 | 1.15M | case OpCode::I32x4__trunc_sat_f64x2_s_zero: |
1007 | 1.16M | case OpCode::I32x4__trunc_sat_f64x2_u_zero: |
1008 | 1.17M | case OpCode::F64x2__convert_low_i32x4_s: |
1009 | 1.17M | case OpCode::F64x2__convert_low_i32x4_u: |
1010 | 1.18M | case OpCode::F32x4__demote_f64x2_zero: |
1011 | 1.20M | case OpCode::F64x2__promote_low_f32x4: |
1012 | | |
1013 | 1.21M | case OpCode::I32x4__dot_i16x8_s: |
1014 | 1.21M | case OpCode::F32x4__ceil: |
1015 | 1.22M | case OpCode::F32x4__floor: |
1016 | 1.23M | case OpCode::F32x4__trunc: |
1017 | 1.23M | case OpCode::F32x4__nearest: |
1018 | 1.23M | case OpCode::F64x2__ceil: |
1019 | 1.24M | case OpCode::F64x2__floor: |
1020 | 1.24M | case OpCode::F64x2__trunc: |
1021 | 1.25M | case OpCode::F64x2__nearest: |
1022 | 1.25M | return {}; |
1023 | | |
1024 | 568 | case OpCode::I8x16__relaxed_swizzle: |
1025 | 1.17k | case OpCode::I32x4__relaxed_trunc_f32x4_s: |
1026 | 2.34k | case OpCode::I32x4__relaxed_trunc_f32x4_u: |
1027 | 3.56k | case OpCode::I32x4__relaxed_trunc_f64x2_s_zero: |
1028 | 3.91k | case OpCode::I32x4__relaxed_trunc_f64x2_u_zero: |
1029 | 4.78k | case OpCode::F32x4__relaxed_madd: |
1030 | 5.78k | case OpCode::F32x4__relaxed_nmadd: |
1031 | 6.58k | case OpCode::F64x2__relaxed_madd: |
1032 | 10.1k | case OpCode::F64x2__relaxed_nmadd: |
1033 | 10.8k | case OpCode::I8x16__relaxed_laneselect: |
1034 | 14.4k | case OpCode::I16x8__relaxed_laneselect: |
1035 | 15.4k | case OpCode::I32x4__relaxed_laneselect: |
1036 | 16.2k | case OpCode::I64x2__relaxed_laneselect: |
1037 | 16.9k | case OpCode::F32x4__relaxed_min: |
1038 | 18.5k | case OpCode::F32x4__relaxed_max: |
1039 | 19.4k | case OpCode::F64x2__relaxed_min: |
1040 | 39.0k | case OpCode::F64x2__relaxed_max: |
1041 | 41.0k | case OpCode::I16x8__relaxed_q15mulr_s: |
1042 | 42.2k | case OpCode::I16x8__relaxed_dot_i8x16_i7x16_s: |
1043 | 44.4k | case OpCode::I32x4__relaxed_dot_i8x16_i7x16_add_s: |
1044 | 44.4k | return {}; |
1045 | | |
1046 | | // Atomic Memory Instructions. |
1047 | 1.34k | case OpCode::Atomic__fence: |
1048 | 1.34k | return readCheckZero(Instr.getTargetIndex()); |
1049 | | |
1050 | 5.09k | case OpCode::Memory__atomic__notify: |
1051 | 10.0k | case OpCode::Memory__atomic__wait32: |
1052 | 10.4k | case OpCode::Memory__atomic__wait64: |
1053 | | |
1054 | 10.4k | case OpCode::I32__atomic__load: |
1055 | 10.4k | case OpCode::I64__atomic__load: |
1056 | 10.4k | case OpCode::I32__atomic__load8_u: |
1057 | 10.4k | case OpCode::I32__atomic__load16_u: |
1058 | 10.4k | case OpCode::I64__atomic__load8_u: |
1059 | 10.4k | case OpCode::I64__atomic__load16_u: |
1060 | 10.4k | case OpCode::I64__atomic__load32_u: |
1061 | 10.4k | case OpCode::I32__atomic__store: |
1062 | 10.4k | case OpCode::I64__atomic__store: |
1063 | 10.4k | case OpCode::I32__atomic__store8: |
1064 | 10.4k | case OpCode::I32__atomic__store16: |
1065 | 10.4k | case OpCode::I64__atomic__store8: |
1066 | 10.4k | case OpCode::I64__atomic__store16: |
1067 | 10.4k | case OpCode::I64__atomic__store32: |
1068 | 10.4k | case OpCode::I32__atomic__rmw__add: |
1069 | 10.4k | case OpCode::I64__atomic__rmw__add: |
1070 | 10.4k | case OpCode::I32__atomic__rmw8__add_u: |
1071 | 10.4k | case OpCode::I32__atomic__rmw16__add_u: |
1072 | 10.4k | case OpCode::I64__atomic__rmw8__add_u: |
1073 | 10.4k | case OpCode::I64__atomic__rmw16__add_u: |
1074 | 10.4k | case OpCode::I64__atomic__rmw32__add_u: |
1075 | 10.4k | case OpCode::I32__atomic__rmw__sub: |
1076 | 10.4k | case OpCode::I64__atomic__rmw__sub: |
1077 | 10.4k | case OpCode::I32__atomic__rmw8__sub_u: |
1078 | 10.4k | case OpCode::I32__atomic__rmw16__sub_u: |
1079 | 10.4k | case OpCode::I64__atomic__rmw8__sub_u: |
1080 | 10.4k | case OpCode::I64__atomic__rmw16__sub_u: |
1081 | 10.4k | case OpCode::I64__atomic__rmw32__sub_u: |
1082 | 10.4k | case OpCode::I32__atomic__rmw__and: |
1083 | 10.4k | case OpCode::I64__atomic__rmw__and: |
1084 | 10.4k | case OpCode::I32__atomic__rmw8__and_u: |
1085 | 10.4k | case OpCode::I32__atomic__rmw16__and_u: |
1086 | 10.4k | case OpCode::I64__atomic__rmw8__and_u: |
1087 | 10.4k | case OpCode::I64__atomic__rmw16__and_u: |
1088 | 10.4k | case OpCode::I64__atomic__rmw32__and_u: |
1089 | 10.4k | case OpCode::I32__atomic__rmw__or: |
1090 | 10.4k | case OpCode::I64__atomic__rmw__or: |
1091 | 10.4k | case OpCode::I32__atomic__rmw8__or_u: |
1092 | 10.4k | case OpCode::I32__atomic__rmw16__or_u: |
1093 | 10.4k | case OpCode::I64__atomic__rmw8__or_u: |
1094 | 10.4k | case OpCode::I64__atomic__rmw16__or_u: |
1095 | 10.4k | case OpCode::I64__atomic__rmw32__or_u: |
1096 | 10.4k | case OpCode::I32__atomic__rmw__xor: |
1097 | 10.4k | case OpCode::I64__atomic__rmw__xor: |
1098 | 10.4k | case OpCode::I32__atomic__rmw8__xor_u: |
1099 | 10.4k | case OpCode::I32__atomic__rmw16__xor_u: |
1100 | 10.4k | case OpCode::I64__atomic__rmw8__xor_u: |
1101 | 10.4k | case OpCode::I64__atomic__rmw16__xor_u: |
1102 | 10.4k | case OpCode::I64__atomic__rmw32__xor_u: |
1103 | 10.4k | case OpCode::I32__atomic__rmw__xchg: |
1104 | 10.4k | case OpCode::I64__atomic__rmw__xchg: |
1105 | 10.4k | case OpCode::I32__atomic__rmw8__xchg_u: |
1106 | 10.4k | case OpCode::I32__atomic__rmw16__xchg_u: |
1107 | 10.4k | case OpCode::I64__atomic__rmw8__xchg_u: |
1108 | 10.4k | case OpCode::I64__atomic__rmw16__xchg_u: |
1109 | 10.4k | case OpCode::I64__atomic__rmw32__xchg_u: |
1110 | 10.4k | case OpCode::I32__atomic__rmw__cmpxchg: |
1111 | 10.4k | case OpCode::I64__atomic__rmw__cmpxchg: |
1112 | 10.4k | case OpCode::I32__atomic__rmw8__cmpxchg_u: |
1113 | 10.4k | case OpCode::I32__atomic__rmw16__cmpxchg_u: |
1114 | 10.4k | case OpCode::I64__atomic__rmw8__cmpxchg_u: |
1115 | 10.4k | case OpCode::I64__atomic__rmw16__cmpxchg_u: |
1116 | 10.4k | case OpCode::I64__atomic__rmw32__cmpxchg_u: |
1117 | 10.4k | return readMemImmediate(); |
1118 | | |
1119 | 0 | default: |
1120 | 0 | assumingUnreachable(); |
1121 | 27.4M | } |
1122 | 27.4M | } |
1123 | | |
1124 | | } // namespace Loader |
1125 | | } // namespace WasmEdge |