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