BytecodeInterpreter.cpp 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/ByteReader.h>
  8. #include <AK/Debug.h>
  9. #include <AK/Endian.h>
  10. #include <AK/MemoryStream.h>
  11. #include <AK/NumericLimits.h>
  12. #include <AK/SIMDExtras.h>
  13. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  14. #include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
  15. #include <LibWasm/AbstractMachine/Configuration.h>
  16. #include <LibWasm/AbstractMachine/Operators.h>
  17. #include <LibWasm/Opcode.h>
  18. #include <LibWasm/Printer/Printer.h>
  19. using namespace AK::SIMD;
  20. namespace Wasm {
  21. #define TRAP_IF_NOT(x) \
  22. do { \
  23. if (trap_if_not(x, #x##sv)) { \
  24. dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \
  25. return; \
  26. } \
  27. } while (false)
  28. #define TRAP_IF_NOT_NORETURN(x) \
  29. do { \
  30. if (trap_if_not(x, #x##sv)) { \
  31. dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \
  32. } \
  33. } while (false)
  34. void BytecodeInterpreter::interpret(Configuration& configuration)
  35. {
  36. m_trap = Empty {};
  37. auto& instructions = configuration.frame().expression().instructions();
  38. auto max_ip_value = InstructionPointer { instructions.size() };
  39. auto& current_ip_value = configuration.ip();
  40. auto const should_limit_instruction_count = configuration.should_limit_instruction_count();
  41. u64 executed_instructions = 0;
  42. while (current_ip_value < max_ip_value) {
  43. if (should_limit_instruction_count) {
  44. if (executed_instructions++ >= Constants::max_allowed_executed_instructions_per_call) [[unlikely]] {
  45. m_trap = Trap { "Exceeded maximum allowed number of instructions" };
  46. return;
  47. }
  48. }
  49. auto& instruction = instructions[current_ip_value.value()];
  50. auto old_ip = current_ip_value;
  51. interpret(configuration, current_ip_value, instruction);
  52. if (did_trap())
  53. return;
  54. if (current_ip_value == old_ip) // If no jump occurred
  55. ++current_ip_value;
  56. }
  57. }
  58. void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelIndex index)
  59. {
  60. dbgln_if(WASM_TRACE_DEBUG, "Branch to label with index {}...", index.value());
  61. auto label = configuration.nth_label(index.value());
  62. dbgln_if(WASM_TRACE_DEBUG, "...which is actually IP {}, and has {} result(s)", label->continuation().value(), label->arity());
  63. auto results = pop_values(configuration, label->arity());
  64. size_t drop_count = index.value() + 1;
  65. for (; !configuration.stack().is_empty();) {
  66. auto& entry = configuration.stack().peek();
  67. if (entry.has<Label>()) {
  68. if (--drop_count == 0)
  69. break;
  70. }
  71. configuration.stack().pop();
  72. }
  73. for (auto& result : results.in_reverse())
  74. configuration.stack().push(move(result));
  75. configuration.ip() = label->continuation();
  76. }
  77. template<typename ReadType, typename PushType>
  78. void BytecodeInterpreter::load_and_push(Configuration& configuration, Instruction const& instruction)
  79. {
  80. auto& arg = instruction.arguments().get<Instruction::MemoryArgument>();
  81. auto& address = configuration.frame().module().memories()[arg.memory_index.value()];
  82. auto memory = configuration.store().get(address);
  83. if (!memory) {
  84. m_trap = Trap { "Nonexistent memory" };
  85. return;
  86. }
  87. auto& entry = configuration.stack().peek();
  88. auto base = entry.get<Value>().to<i32>();
  89. if (!base.has_value()) {
  90. m_trap = Trap { "Memory access out of bounds" };
  91. return;
  92. }
  93. u64 instance_address = static_cast<u64>(bit_cast<u32>(base.value())) + arg.offset;
  94. Checked addition { instance_address };
  95. addition += sizeof(ReadType);
  96. if (addition.has_overflow() || addition.value() > memory->size()) {
  97. m_trap = Trap { "Memory access out of bounds" };
  98. dbgln("LibWasm: Memory access out of bounds (expected {} to be less than or equal to {})", instance_address + sizeof(ReadType), memory->size());
  99. return;
  100. }
  101. dbgln_if(WASM_TRACE_DEBUG, "load({} : {}) -> stack", instance_address, sizeof(ReadType));
  102. auto slice = memory->data().bytes().slice(instance_address, sizeof(ReadType));
  103. configuration.stack().peek() = Value(static_cast<PushType>(read_value<ReadType>(slice)));
  104. }
  105. template<typename TDst, typename TSrc>
  106. ALWAYS_INLINE static TDst convert_vector(TSrc v)
  107. {
  108. return __builtin_convertvector(v, TDst);
  109. }
  110. template<size_t M, size_t N, template<typename> typename SetSign>
  111. void BytecodeInterpreter::load_and_push_mxn(Configuration& configuration, Instruction const& instruction)
  112. {
  113. auto& arg = instruction.arguments().get<Instruction::MemoryArgument>();
  114. auto& address = configuration.frame().module().memories()[arg.memory_index.value()];
  115. auto memory = configuration.store().get(address);
  116. if (!memory) {
  117. m_trap = Trap { "Nonexistent memory" };
  118. return;
  119. }
  120. auto& entry = configuration.stack().peek();
  121. auto base = entry.get<Value>().to<i32>();
  122. if (!base.has_value()) {
  123. m_trap = Trap { "Memory access out of bounds" };
  124. return;
  125. }
  126. u64 instance_address = static_cast<u64>(bit_cast<u32>(base.value())) + arg.offset;
  127. Checked addition { instance_address };
  128. addition += M * N / 8;
  129. if (addition.has_overflow() || addition.value() > memory->size()) {
  130. m_trap = Trap { "Memory access out of bounds" };
  131. dbgln("LibWasm: Memory access out of bounds (expected {} to be less than or equal to {})", instance_address + M * N / 8, memory->size());
  132. return;
  133. }
  134. dbgln_if(WASM_TRACE_DEBUG, "vec-load({} : {}) -> stack", instance_address, M * N / 8);
  135. auto slice = memory->data().bytes().slice(instance_address, M * N / 8);
  136. using V64 = NativeVectorType<M, N, SetSign>;
  137. using V128 = NativeVectorType<M * 2, N, SetSign>;
  138. V64 bytes { 0 };
  139. if (bit_cast<FlatPtr>(slice.data()) % sizeof(V64) == 0)
  140. bytes = *bit_cast<V64*>(slice.data());
  141. else
  142. ByteReader::load(slice.data(), bytes);
  143. configuration.stack().peek() = Value(bit_cast<u128>(convert_vector<V128>(bytes)));
  144. }
  145. template<size_t M>
  146. void BytecodeInterpreter::load_and_push_m_splat(Configuration& configuration, Instruction const& instruction)
  147. {
  148. auto& arg = instruction.arguments().get<Instruction::MemoryArgument>();
  149. auto& address = configuration.frame().module().memories()[arg.memory_index.value()];
  150. auto memory = configuration.store().get(address);
  151. if (!memory) {
  152. m_trap = Trap { "Nonexistent memory" };
  153. return;
  154. }
  155. auto& entry = configuration.stack().peek();
  156. auto base = entry.get<Value>().to<i32>();
  157. if (!base.has_value()) {
  158. m_trap = Trap { "Memory access out of bounds" };
  159. return;
  160. }
  161. u64 instance_address = static_cast<u64>(bit_cast<u32>(base.value())) + arg.offset;
  162. Checked addition { instance_address };
  163. addition += M / 8;
  164. if (addition.has_overflow() || addition.value() > memory->size()) {
  165. m_trap = Trap { "Memory access out of bounds" };
  166. dbgln("LibWasm: Memory access out of bounds (expected {} to be less than or equal to {})", instance_address + M / 8, memory->size());
  167. return;
  168. }
  169. dbgln_if(WASM_TRACE_DEBUG, "vec-splat({} : {}) -> stack", instance_address, M / 8);
  170. auto slice = memory->data().bytes().slice(instance_address, M / 8);
  171. auto value = read_value<NativeIntegralType<M>>(slice);
  172. set_top_m_splat<M, NativeIntegralType>(configuration, value);
  173. }
  174. template<size_t M, template<size_t> typename NativeType>
  175. void BytecodeInterpreter::set_top_m_splat(Wasm::Configuration& configuration, NativeType<M> value)
  176. {
  177. auto push = [&](auto result) {
  178. configuration.stack().peek() = Value(bit_cast<u128>(result));
  179. };
  180. if constexpr (IsFloatingPoint<NativeType<32>>) {
  181. if constexpr (M == 32) // 32 -> 32x4
  182. push(expand4(value));
  183. else if constexpr (M == 64) // 64 -> 64x2
  184. push(f64x2 { value, value });
  185. else
  186. static_assert(DependentFalse<NativeType<M>>, "Invalid vector size");
  187. } else {
  188. if constexpr (M == 8) // 8 -> 8x4 -> 32x4
  189. push(expand4(bit_cast<u32>(u8x4 { value, value, value, value })));
  190. else if constexpr (M == 16) // 16 -> 16x2 -> 32x4
  191. push(expand4(bit_cast<u32>(u16x2 { value, value })));
  192. else if constexpr (M == 32) // 32 -> 32x4
  193. push(expand4(value));
  194. else if constexpr (M == 64) // 64 -> 64x2
  195. push(u64x2 { value, value });
  196. else
  197. static_assert(DependentFalse<NativeType<M>>, "Invalid vector size");
  198. }
  199. }
  200. template<size_t M, template<size_t> typename NativeType>
  201. void BytecodeInterpreter::pop_and_push_m_splat(Wasm::Configuration& configuration, Instruction const&)
  202. {
  203. using PopT = Conditional<M <= 32, NativeType<32>, NativeType<64>>;
  204. using ReadT = NativeType<M>;
  205. auto entry = configuration.stack().peek();
  206. auto value = static_cast<ReadT>(*entry.get<Value>().to<PopT>());
  207. dbgln_if(WASM_TRACE_DEBUG, "stack({}) -> splat({})", value, M);
  208. set_top_m_splat<M, NativeType>(configuration, value);
  209. }
  210. template<typename M, template<typename> typename SetSign, typename VectorType>
  211. Optional<VectorType> BytecodeInterpreter::pop_vector(Configuration& configuration)
  212. {
  213. auto value = peek_vector<M, SetSign, VectorType>(configuration);
  214. if (value.has_value())
  215. configuration.stack().pop();
  216. return value;
  217. }
  218. template<typename M, template<typename> typename SetSign, typename VectorType>
  219. Optional<VectorType> BytecodeInterpreter::peek_vector(Configuration& configuration)
  220. {
  221. auto& entry = configuration.stack().peek();
  222. auto value = entry.get<Value>().value().get_pointer<u128>();
  223. if (!value)
  224. return {};
  225. auto vector = bit_cast<VectorType>(*value);
  226. dbgln_if(WASM_TRACE_DEBUG, "stack({}) peek-> vector({:x})", *value, bit_cast<u128>(vector));
  227. return vector;
  228. }
  229. template<typename VectorType>
  230. static u128 shuffle_vector(VectorType values, VectorType indices)
  231. {
  232. auto vector = bit_cast<VectorType>(values);
  233. auto indices_vector = bit_cast<VectorType>(indices);
  234. return bit_cast<u128>(shuffle(vector, indices_vector));
  235. }
  236. void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAddress address)
  237. {
  238. TRAP_IF_NOT(m_stack_info.size_free() >= Constants::minimum_stack_space_to_keep_free);
  239. auto instance = configuration.store().get(address);
  240. FunctionType const* type { nullptr };
  241. instance->visit([&](auto const& function) { type = &function.type(); });
  242. TRAP_IF_NOT(configuration.stack().entries().size() > type->parameters().size());
  243. Vector<Value> args;
  244. args.ensure_capacity(type->parameters().size());
  245. auto span = configuration.stack().entries().span().slice_from_end(type->parameters().size());
  246. for (auto& entry : span) {
  247. auto* call_argument = entry.get_pointer<Value>();
  248. TRAP_IF_NOT(call_argument);
  249. args.unchecked_append(move(*call_argument));
  250. }
  251. configuration.stack().entries().remove(configuration.stack().size() - span.size(), span.size());
  252. Result result { Trap { ""sv } };
  253. {
  254. CallFrameHandle handle { *this, configuration };
  255. result = configuration.call(*this, address, move(args));
  256. }
  257. if (result.is_trap()) {
  258. m_trap = move(result.trap());
  259. return;
  260. }
  261. if (result.is_completion()) {
  262. m_trap = move(result.completion());
  263. return;
  264. }
  265. configuration.stack().entries().ensure_capacity(configuration.stack().size() + result.values().size());
  266. for (auto& entry : result.values().in_reverse())
  267. configuration.stack().entries().unchecked_append(move(entry));
  268. }
  269. template<typename PopTypeLHS, typename PushType, typename Operator, typename PopTypeRHS, typename... Args>
  270. void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration, Args&&... args)
  271. {
  272. auto rhs_entry = configuration.stack().pop();
  273. auto& lhs_entry = configuration.stack().peek();
  274. auto rhs_ptr = rhs_entry.get_pointer<Value>();
  275. auto lhs_ptr = lhs_entry.get_pointer<Value>();
  276. auto rhs = rhs_ptr->to<PopTypeRHS>();
  277. auto lhs = lhs_ptr->to<PopTypeLHS>();
  278. PushType result;
  279. auto call_result = Operator { forward<Args>(args)... }(lhs.value(), rhs.value());
  280. if constexpr (IsSpecializationOf<decltype(call_result), AK::ErrorOr>) {
  281. if (call_result.is_error()) {
  282. trap_if_not(false, call_result.error());
  283. return;
  284. }
  285. result = call_result.release_value();
  286. } else {
  287. result = call_result;
  288. }
  289. dbgln_if(WASM_TRACE_DEBUG, "{} {} {} = {}", lhs.value(), Operator::name(), rhs.value(), result);
  290. lhs_entry = Value(result);
  291. }
  292. template<typename PopType, typename PushType, typename Operator, typename... Args>
  293. void BytecodeInterpreter::unary_operation(Configuration& configuration, Args&&... args)
  294. {
  295. auto& entry = configuration.stack().peek();
  296. auto entry_ptr = entry.get_pointer<Value>();
  297. auto value = entry_ptr->to<PopType>();
  298. auto call_result = Operator { forward<Args>(args)... }(*value);
  299. PushType result;
  300. if constexpr (IsSpecializationOf<decltype(call_result), AK::ErrorOr>) {
  301. if (call_result.is_error()) {
  302. trap_if_not(false, call_result.error());
  303. return;
  304. }
  305. result = call_result.release_value();
  306. } else {
  307. result = call_result;
  308. }
  309. dbgln_if(WASM_TRACE_DEBUG, "map({}) {} = {}", Operator::name(), *value, result);
  310. entry = Value(result);
  311. }
  312. template<typename T>
  313. struct ConvertToRaw {
  314. T operator()(T value)
  315. {
  316. return LittleEndian<T>(value);
  317. }
  318. };
  319. template<>
  320. struct ConvertToRaw<float> {
  321. u32 operator()(float value)
  322. {
  323. ReadonlyBytes bytes { &value, sizeof(float) };
  324. FixedMemoryStream stream { bytes };
  325. auto res = stream.read_value<LittleEndian<u32>>().release_value_but_fixme_should_propagate_errors();
  326. return static_cast<u32>(res);
  327. }
  328. };
  329. template<>
  330. struct ConvertToRaw<double> {
  331. u64 operator()(double value)
  332. {
  333. ReadonlyBytes bytes { &value, sizeof(double) };
  334. FixedMemoryStream stream { bytes };
  335. auto res = stream.read_value<LittleEndian<u64>>().release_value_but_fixme_should_propagate_errors();
  336. return static_cast<u64>(res);
  337. }
  338. };
  339. template<typename PopT, typename StoreT>
  340. void BytecodeInterpreter::pop_and_store(Configuration& configuration, Instruction const& instruction)
  341. {
  342. auto entry = configuration.stack().pop();
  343. auto value = ConvertToRaw<StoreT> {}(*entry.get<Value>().to<PopT>());
  344. dbgln_if(WASM_TRACE_DEBUG, "stack({}) -> temporary({}b)", value, sizeof(StoreT));
  345. auto base_entry = configuration.stack().pop();
  346. auto base = base_entry.get<Value>().to<i32>();
  347. store_to_memory(configuration, instruction, { &value, sizeof(StoreT) }, *base);
  348. }
  349. void BytecodeInterpreter::store_to_memory(Configuration& configuration, Instruction const& instruction, ReadonlyBytes data, u32 base)
  350. {
  351. auto& arg = instruction.arguments().get<Instruction::MemoryArgument>();
  352. auto& address = configuration.frame().module().memories()[arg.memory_index.value()];
  353. auto memory = configuration.store().get(address);
  354. u64 instance_address = static_cast<u64>(base) + arg.offset;
  355. Checked addition { instance_address };
  356. addition += data.size();
  357. if (addition.has_overflow() || addition.value() > memory->size()) {
  358. m_trap = Trap { "Memory access out of bounds" };
  359. dbgln("LibWasm: Memory access out of bounds (expected 0 <= {} and {} <= {})", instance_address, instance_address + data.size(), memory->size());
  360. return;
  361. }
  362. dbgln_if(WASM_TRACE_DEBUG, "temporary({}b) -> store({})", data.size(), instance_address);
  363. data.copy_to(memory->data().bytes().slice(instance_address, data.size()));
  364. }
  365. template<typename T>
  366. T BytecodeInterpreter::read_value(ReadonlyBytes data)
  367. {
  368. FixedMemoryStream stream { data };
  369. auto value_or_error = stream.read_value<LittleEndian<T>>();
  370. if (value_or_error.is_error()) {
  371. dbgln("Read from {} failed", data.data());
  372. m_trap = Trap { "Read from memory failed" };
  373. }
  374. return value_or_error.release_value();
  375. }
  376. template<>
  377. float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
  378. {
  379. FixedMemoryStream stream { data };
  380. auto raw_value_or_error = stream.read_value<LittleEndian<u32>>();
  381. if (raw_value_or_error.is_error())
  382. m_trap = Trap { "Read from memory failed" };
  383. auto raw_value = raw_value_or_error.release_value();
  384. return bit_cast<float>(static_cast<u32>(raw_value));
  385. }
  386. template<>
  387. double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
  388. {
  389. FixedMemoryStream stream { data };
  390. auto raw_value_or_error = stream.read_value<LittleEndian<u64>>();
  391. if (raw_value_or_error.is_error())
  392. m_trap = Trap { "Read from memory failed" };
  393. auto raw_value = raw_value_or_error.release_value();
  394. return bit_cast<double>(static_cast<u64>(raw_value));
  395. }
  396. template<typename V, typename T>
  397. MakeSigned<T> BytecodeInterpreter::checked_signed_truncate(V value)
  398. {
  399. if (isnan(value) || isinf(value)) { // "undefined", let's just trap.
  400. m_trap = Trap { "Signed truncation undefined behavior" };
  401. return 0;
  402. }
  403. double truncated;
  404. if constexpr (IsSame<float, V>)
  405. truncated = truncf(value);
  406. else
  407. truncated = trunc(value);
  408. using SignedT = MakeSigned<T>;
  409. if (NumericLimits<SignedT>::min() <= truncated && static_cast<double>(NumericLimits<SignedT>::max()) >= truncated)
  410. return static_cast<SignedT>(truncated);
  411. dbgln_if(WASM_TRACE_DEBUG, "Truncate out of range error");
  412. m_trap = Trap { "Signed truncation out of range" };
  413. return true;
  414. }
  415. template<typename V, typename T>
  416. MakeUnsigned<T> BytecodeInterpreter::checked_unsigned_truncate(V value)
  417. {
  418. if (isnan(value) || isinf(value)) { // "undefined", let's just trap.
  419. m_trap = Trap { "Unsigned truncation undefined behavior" };
  420. return 0;
  421. }
  422. double truncated;
  423. if constexpr (IsSame<float, V>)
  424. truncated = truncf(value);
  425. else
  426. truncated = trunc(value);
  427. using UnsignedT = MakeUnsigned<T>;
  428. if (NumericLimits<UnsignedT>::min() <= truncated && static_cast<double>(NumericLimits<UnsignedT>::max()) >= truncated)
  429. return static_cast<UnsignedT>(truncated);
  430. dbgln_if(WASM_TRACE_DEBUG, "Truncate out of range error");
  431. m_trap = Trap { "Unsigned truncation out of range" };
  432. return true;
  433. }
  434. Vector<Value> BytecodeInterpreter::pop_values(Configuration& configuration, size_t count)
  435. {
  436. Vector<Value> results;
  437. results.resize(count);
  438. for (size_t i = 0; i < count; ++i) {
  439. auto top_of_stack = configuration.stack().pop();
  440. if (auto value = top_of_stack.get_pointer<Value>())
  441. results[i] = move(*value);
  442. else
  443. TRAP_IF_NOT_NORETURN(value);
  444. }
  445. return results;
  446. }
  447. void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction)
  448. {
  449. dbgln_if(WASM_TRACE_DEBUG, "Executing instruction {} at ip {}", instruction_name(instruction.opcode()), ip.value());
  450. switch (instruction.opcode().value()) {
  451. case Instructions::unreachable.value():
  452. m_trap = Trap { "Unreachable" };
  453. return;
  454. case Instructions::nop.value():
  455. return;
  456. case Instructions::local_get.value():
  457. configuration.stack().push(Value(configuration.frame().locals()[instruction.arguments().get<LocalIndex>().value()]));
  458. return;
  459. case Instructions::local_set.value(): {
  460. auto entry = configuration.stack().pop();
  461. configuration.frame().locals()[instruction.arguments().get<LocalIndex>().value()] = move(entry.get<Value>());
  462. return;
  463. }
  464. case Instructions::i32_const.value():
  465. configuration.stack().push(Value(ValueType { ValueType::I32 }, static_cast<i64>(instruction.arguments().get<i32>())));
  466. return;
  467. case Instructions::i64_const.value():
  468. configuration.stack().push(Value(ValueType { ValueType::I64 }, instruction.arguments().get<i64>()));
  469. return;
  470. case Instructions::f32_const.value():
  471. configuration.stack().push(Value(ValueType { ValueType::F32 }, static_cast<double>(instruction.arguments().get<float>())));
  472. return;
  473. case Instructions::f64_const.value():
  474. configuration.stack().push(Value(ValueType { ValueType::F64 }, instruction.arguments().get<double>()));
  475. return;
  476. case Instructions::block.value(): {
  477. size_t arity = 0;
  478. size_t parameter_count = 0;
  479. auto& args = instruction.arguments().get<Instruction::StructuredInstructionArgs>();
  480. switch (args.block_type.kind()) {
  481. case BlockType::Empty:
  482. break;
  483. case BlockType::Type:
  484. arity = 1;
  485. break;
  486. case BlockType::Index: {
  487. auto& type = configuration.frame().module().types()[args.block_type.type_index().value()];
  488. arity = type.results().size();
  489. parameter_count = type.parameters().size();
  490. }
  491. }
  492. configuration.stack().entries().insert(configuration.stack().size() - parameter_count, Label(arity, args.end_ip));
  493. return;
  494. }
  495. case Instructions::loop.value(): {
  496. size_t arity = 0;
  497. size_t parameter_count = 0;
  498. auto& args = instruction.arguments().get<Instruction::StructuredInstructionArgs>();
  499. switch (args.block_type.kind()) {
  500. case BlockType::Empty:
  501. break;
  502. case BlockType::Type:
  503. arity = 1;
  504. break;
  505. case BlockType::Index: {
  506. auto& type = configuration.frame().module().types()[args.block_type.type_index().value()];
  507. arity = type.parameters().size();
  508. parameter_count = type.parameters().size();
  509. }
  510. }
  511. configuration.stack().entries().insert(configuration.stack().size() - parameter_count, Label(arity, ip.value() + 1));
  512. return;
  513. }
  514. case Instructions::if_.value(): {
  515. size_t arity = 0;
  516. size_t parameter_count = 0;
  517. auto& args = instruction.arguments().get<Instruction::StructuredInstructionArgs>();
  518. switch (args.block_type.kind()) {
  519. case BlockType::Empty:
  520. break;
  521. case BlockType::Type:
  522. arity = 1;
  523. break;
  524. case BlockType::Index: {
  525. auto& type = configuration.frame().module().types()[args.block_type.type_index().value()];
  526. arity = type.results().size();
  527. parameter_count = type.parameters().size();
  528. }
  529. }
  530. auto entry = configuration.stack().pop();
  531. auto value = entry.get<Value>().to<i32>();
  532. auto end_label = Label(arity, args.end_ip.value());
  533. if (value.value() == 0) {
  534. if (args.else_ip.has_value()) {
  535. configuration.ip() = args.else_ip.value();
  536. configuration.stack().entries().insert(configuration.stack().size() - parameter_count, end_label);
  537. } else {
  538. configuration.ip() = args.end_ip.value() + 1;
  539. }
  540. } else {
  541. configuration.stack().entries().insert(configuration.stack().size() - parameter_count, end_label);
  542. }
  543. return;
  544. }
  545. case Instructions::structured_end.value():
  546. case Instructions::structured_else.value(): {
  547. auto index = configuration.nth_label_index(0);
  548. auto label = configuration.stack().entries()[*index].get<Label>();
  549. configuration.stack().entries().remove(*index, 1);
  550. if (instruction.opcode() == Instructions::structured_end)
  551. return;
  552. // Jump to the end label
  553. configuration.ip() = label.continuation();
  554. return;
  555. }
  556. case Instructions::return_.value(): {
  557. auto& frame = configuration.frame();
  558. Checked checked_index { configuration.stack().size() };
  559. checked_index -= frame.arity();
  560. VERIFY(!checked_index.has_overflow());
  561. auto index = checked_index.value();
  562. size_t i = 1;
  563. for (; i <= index; ++i) {
  564. auto& entry = configuration.stack().entries()[index - i];
  565. if (entry.has<Label>()) {
  566. if (configuration.stack().entries()[index - i - 1].has<Frame>())
  567. break;
  568. }
  569. }
  570. configuration.stack().entries().remove(index - i + 1, i - 1);
  571. // Jump past the call/indirect instruction
  572. configuration.ip() = configuration.frame().expression().instructions().size();
  573. return;
  574. }
  575. case Instructions::br.value():
  576. return branch_to_label(configuration, instruction.arguments().get<LabelIndex>());
  577. case Instructions::br_if.value(): {
  578. auto entry = configuration.stack().pop();
  579. if (entry.get<Value>().to<i32>().value_or(0) == 0)
  580. return;
  581. return branch_to_label(configuration, instruction.arguments().get<LabelIndex>());
  582. }
  583. case Instructions::br_table.value(): {
  584. auto& arguments = instruction.arguments().get<Instruction::TableBranchArgs>();
  585. auto entry = configuration.stack().pop();
  586. auto maybe_i = entry.get<Value>().to<i32>();
  587. if (0 <= *maybe_i) {
  588. size_t i = *maybe_i;
  589. if (i < arguments.labels.size())
  590. return branch_to_label(configuration, arguments.labels[i]);
  591. }
  592. return branch_to_label(configuration, arguments.default_);
  593. }
  594. case Instructions::call.value(): {
  595. auto index = instruction.arguments().get<FunctionIndex>();
  596. auto address = configuration.frame().module().functions()[index.value()];
  597. dbgln_if(WASM_TRACE_DEBUG, "call({})", address.value());
  598. call_address(configuration, address);
  599. return;
  600. }
  601. case Instructions::call_indirect.value(): {
  602. auto& args = instruction.arguments().get<Instruction::IndirectCallArgs>();
  603. auto table_address = configuration.frame().module().tables()[args.table.value()];
  604. auto table_instance = configuration.store().get(table_address);
  605. auto entry = configuration.stack().pop();
  606. auto index = entry.get<Value>().to<i32>();
  607. TRAP_IF_NOT(index.value() >= 0);
  608. TRAP_IF_NOT(static_cast<size_t>(index.value()) < table_instance->elements().size());
  609. auto element = table_instance->elements()[index.value()];
  610. TRAP_IF_NOT(element.ref().has<Reference::Func>());
  611. auto address = element.ref().get<Reference::Func>().address;
  612. dbgln_if(WASM_TRACE_DEBUG, "call_indirect({} -> {})", index.value(), address.value());
  613. call_address(configuration, address);
  614. return;
  615. }
  616. case Instructions::i32_load.value():
  617. return load_and_push<i32, i32>(configuration, instruction);
  618. case Instructions::i64_load.value():
  619. return load_and_push<i64, i64>(configuration, instruction);
  620. case Instructions::f32_load.value():
  621. return load_and_push<float, float>(configuration, instruction);
  622. case Instructions::f64_load.value():
  623. return load_and_push<double, double>(configuration, instruction);
  624. case Instructions::i32_load8_s.value():
  625. return load_and_push<i8, i32>(configuration, instruction);
  626. case Instructions::i32_load8_u.value():
  627. return load_and_push<u8, i32>(configuration, instruction);
  628. case Instructions::i32_load16_s.value():
  629. return load_and_push<i16, i32>(configuration, instruction);
  630. case Instructions::i32_load16_u.value():
  631. return load_and_push<u16, i32>(configuration, instruction);
  632. case Instructions::i64_load8_s.value():
  633. return load_and_push<i8, i64>(configuration, instruction);
  634. case Instructions::i64_load8_u.value():
  635. return load_and_push<u8, i64>(configuration, instruction);
  636. case Instructions::i64_load16_s.value():
  637. return load_and_push<i16, i64>(configuration, instruction);
  638. case Instructions::i64_load16_u.value():
  639. return load_and_push<u16, i64>(configuration, instruction);
  640. case Instructions::i64_load32_s.value():
  641. return load_and_push<i32, i64>(configuration, instruction);
  642. case Instructions::i64_load32_u.value():
  643. return load_and_push<u32, i64>(configuration, instruction);
  644. case Instructions::i32_store.value():
  645. return pop_and_store<i32, i32>(configuration, instruction);
  646. case Instructions::i64_store.value():
  647. return pop_and_store<i64, i64>(configuration, instruction);
  648. case Instructions::f32_store.value():
  649. return pop_and_store<float, float>(configuration, instruction);
  650. case Instructions::f64_store.value():
  651. return pop_and_store<double, double>(configuration, instruction);
  652. case Instructions::i32_store8.value():
  653. return pop_and_store<i32, i8>(configuration, instruction);
  654. case Instructions::i32_store16.value():
  655. return pop_and_store<i32, i16>(configuration, instruction);
  656. case Instructions::i64_store8.value():
  657. return pop_and_store<i64, i8>(configuration, instruction);
  658. case Instructions::i64_store16.value():
  659. return pop_and_store<i64, i16>(configuration, instruction);
  660. case Instructions::i64_store32.value():
  661. return pop_and_store<i64, i32>(configuration, instruction);
  662. case Instructions::local_tee.value(): {
  663. auto& entry = configuration.stack().peek();
  664. auto value = entry.get<Value>();
  665. auto local_index = instruction.arguments().get<LocalIndex>();
  666. dbgln_if(WASM_TRACE_DEBUG, "stack:peek -> locals({})", local_index.value());
  667. configuration.frame().locals()[local_index.value()] = move(value);
  668. return;
  669. }
  670. case Instructions::global_get.value(): {
  671. auto global_index = instruction.arguments().get<GlobalIndex>();
  672. // This check here is for const expressions. In non-const expressions,
  673. // a validation error would have been thrown.
  674. TRAP_IF_NOT(global_index < configuration.frame().module().globals().size());
  675. auto address = configuration.frame().module().globals()[global_index.value()];
  676. dbgln_if(WASM_TRACE_DEBUG, "global({}) -> stack", address.value());
  677. auto global = configuration.store().get(address);
  678. configuration.stack().push(Value(global->value()));
  679. return;
  680. }
  681. case Instructions::global_set.value(): {
  682. auto global_index = instruction.arguments().get<GlobalIndex>();
  683. auto address = configuration.frame().module().globals()[global_index.value()];
  684. auto entry = configuration.stack().pop();
  685. auto value = entry.get<Value>();
  686. dbgln_if(WASM_TRACE_DEBUG, "stack -> global({})", address.value());
  687. auto global = configuration.store().get(address);
  688. global->set_value(move(value));
  689. return;
  690. }
  691. case Instructions::memory_size.value(): {
  692. auto& args = instruction.arguments().get<Instruction::MemoryIndexArgument>();
  693. auto address = configuration.frame().module().memories()[args.memory_index.value()];
  694. auto instance = configuration.store().get(address);
  695. auto pages = instance->size() / Constants::page_size;
  696. dbgln_if(WASM_TRACE_DEBUG, "memory.size -> stack({})", pages);
  697. configuration.stack().push(Value((i32)pages));
  698. return;
  699. }
  700. case Instructions::memory_grow.value(): {
  701. auto& args = instruction.arguments().get<Instruction::MemoryIndexArgument>();
  702. auto address = configuration.frame().module().memories()[args.memory_index.value()];
  703. auto instance = configuration.store().get(address);
  704. i32 old_pages = instance->size() / Constants::page_size;
  705. auto& entry = configuration.stack().peek();
  706. auto new_pages = entry.get<Value>().to<i32>();
  707. dbgln_if(WASM_TRACE_DEBUG, "memory.grow({}), previously {} pages...", *new_pages, old_pages);
  708. if (instance->grow(new_pages.value() * Constants::page_size))
  709. configuration.stack().peek() = Value((i32)old_pages);
  710. else
  711. configuration.stack().peek() = Value((i32)-1);
  712. return;
  713. }
  714. // https://webassembly.github.io/spec/core/bikeshed/#exec-memory-fill
  715. case Instructions::memory_fill.value(): {
  716. auto& args = instruction.arguments().get<Instruction::MemoryIndexArgument>();
  717. auto address = configuration.frame().module().memories()[args.memory_index.value()];
  718. auto instance = configuration.store().get(address);
  719. auto count = configuration.stack().pop().get<Value>().to<u32>().value();
  720. u8 value = static_cast<u8>(configuration.stack().pop().get<Value>().to<u32>().value());
  721. auto destination_offset = configuration.stack().pop().get<Value>().to<u32>().value();
  722. TRAP_IF_NOT(static_cast<size_t>(destination_offset + count) <= instance->data().size());
  723. if (count == 0)
  724. return;
  725. Instruction synthetic_store_instruction {
  726. Instructions::i32_store8,
  727. Instruction::MemoryArgument { 0, 0 }
  728. };
  729. for (u32 i = 0; i < count; ++i) {
  730. store_to_memory(configuration, synthetic_store_instruction, { &value, sizeof(value) }, destination_offset + i);
  731. }
  732. return;
  733. }
  734. // https://webassembly.github.io/spec/core/bikeshed/#exec-memory-copy
  735. case Instructions::memory_copy.value(): {
  736. auto& args = instruction.arguments().get<Instruction::MemoryCopyArgs>();
  737. auto source_address = configuration.frame().module().memories()[args.src_index.value()];
  738. auto destination_address = configuration.frame().module().memories()[args.dst_index.value()];
  739. auto source_instance = configuration.store().get(source_address);
  740. auto destination_instance = configuration.store().get(destination_address);
  741. auto count = configuration.stack().pop().get<Value>().to<i32>().value();
  742. auto source_offset = configuration.stack().pop().get<Value>().to<i32>().value();
  743. auto destination_offset = configuration.stack().pop().get<Value>().to<i32>().value();
  744. Checked<size_t> source_position = source_offset;
  745. source_position.saturating_add(count);
  746. Checked<size_t> destination_position = destination_offset;
  747. destination_position.saturating_add(count);
  748. TRAP_IF_NOT(source_position <= source_instance->data().size());
  749. TRAP_IF_NOT(destination_position <= destination_instance->data().size());
  750. if (count == 0)
  751. return;
  752. Instruction synthetic_store_instruction {
  753. Instructions::i32_store8,
  754. Instruction::MemoryArgument { 0, 0, args.dst_index }
  755. };
  756. if (destination_offset <= source_offset) {
  757. for (auto i = 0; i < count; ++i) {
  758. auto value = source_instance->data()[source_offset + i];
  759. store_to_memory(configuration, synthetic_store_instruction, { &value, sizeof(value) }, destination_offset + i);
  760. }
  761. } else {
  762. for (auto i = count - 1; i >= 0; --i) {
  763. auto value = source_instance->data()[source_offset + i];
  764. store_to_memory(configuration, synthetic_store_instruction, { &value, sizeof(value) }, destination_offset + i);
  765. }
  766. }
  767. return;
  768. }
  769. // https://webassembly.github.io/spec/core/bikeshed/#exec-memory-init
  770. case Instructions::memory_init.value(): {
  771. auto& args = instruction.arguments().get<Instruction::MemoryInitArgs>();
  772. auto& data_address = configuration.frame().module().datas()[args.data_index.value()];
  773. auto& data = *configuration.store().get(data_address);
  774. auto count = *configuration.stack().pop().get<Value>().to<u32>();
  775. auto source_offset = *configuration.stack().pop().get<Value>().to<u32>();
  776. auto destination_offset = *configuration.stack().pop().get<Value>().to<u32>();
  777. if (count == 0)
  778. return;
  779. TRAP_IF_NOT(source_offset + count > 0);
  780. TRAP_IF_NOT(static_cast<size_t>(source_offset + count) <= data.size());
  781. Instruction synthetic_store_instruction {
  782. Instructions::i32_store8,
  783. Instruction::MemoryArgument { 0, 0, args.memory_index }
  784. };
  785. for (size_t i = 0; i < (size_t)count; ++i) {
  786. auto value = data.data()[source_offset + i];
  787. store_to_memory(configuration, synthetic_store_instruction, { &value, sizeof(value) }, destination_offset + i);
  788. }
  789. return;
  790. }
  791. // https://webassembly.github.io/spec/core/bikeshed/#exec-data-drop
  792. case Instructions::data_drop.value(): {
  793. auto data_index = instruction.arguments().get<DataIndex>();
  794. auto data_address = configuration.frame().module().datas()[data_index.value()];
  795. *configuration.store().get(data_address) = DataInstance({});
  796. return;
  797. }
  798. case Instructions::elem_drop.value(): {
  799. auto elem_index = instruction.arguments().get<ElementIndex>();
  800. auto address = configuration.frame().module().elements()[elem_index.value()];
  801. auto elem = configuration.store().get(address);
  802. *configuration.store().get(address) = ElementInstance(elem->type(), {});
  803. return;
  804. }
  805. case Instructions::table_init.value(): {
  806. auto& args = instruction.arguments().get<Instruction::TableElementArgs>();
  807. auto table_address = configuration.frame().module().tables()[args.table_index.value()];
  808. auto table = configuration.store().get(table_address);
  809. auto element_address = configuration.frame().module().elements()[args.element_index.value()];
  810. auto element = configuration.store().get(element_address);
  811. auto count = *configuration.stack().pop().get<Value>().to<u32>();
  812. auto source_offset = *configuration.stack().pop().get<Value>().to<u32>();
  813. auto destination_offset = *configuration.stack().pop().get<Value>().to<u32>();
  814. Checked<u32> checked_source_offset = source_offset;
  815. Checked<u32> checked_destination_offset = destination_offset;
  816. checked_source_offset += count;
  817. checked_destination_offset += count;
  818. TRAP_IF_NOT(!checked_source_offset.has_overflow() && checked_source_offset <= (u32)element->references().size());
  819. TRAP_IF_NOT(!checked_destination_offset.has_overflow() && checked_destination_offset <= (u32)table->elements().size());
  820. for (u32 i = 0; i < count; ++i)
  821. table->elements()[destination_offset + i] = element->references()[source_offset + i];
  822. return;
  823. }
  824. case Instructions::table_copy.value(): {
  825. auto& args = instruction.arguments().get<Instruction::TableTableArgs>();
  826. auto source_address = configuration.frame().module().tables()[args.rhs.value()];
  827. auto destination_address = configuration.frame().module().tables()[args.lhs.value()];
  828. auto source_instance = configuration.store().get(source_address);
  829. auto destination_instance = configuration.store().get(destination_address);
  830. auto count = configuration.stack().pop().get<Value>().to<u32>().value();
  831. auto source_offset = configuration.stack().pop().get<Value>().to<u32>().value();
  832. auto destination_offset = configuration.stack().pop().get<Value>().to<u32>().value();
  833. Checked<size_t> source_position = source_offset;
  834. source_position.saturating_add(count);
  835. Checked<size_t> destination_position = destination_offset;
  836. destination_position.saturating_add(count);
  837. TRAP_IF_NOT(source_position <= source_instance->elements().size());
  838. TRAP_IF_NOT(destination_position <= destination_instance->elements().size());
  839. if (count == 0)
  840. return;
  841. if (destination_offset <= source_offset) {
  842. for (u32 i = 0; i < count; ++i) {
  843. auto value = source_instance->elements()[source_offset + i];
  844. destination_instance->elements()[destination_offset + i] = value;
  845. }
  846. } else {
  847. for (u32 i = count - 1; i != NumericLimits<u32>::max(); --i) {
  848. auto value = source_instance->elements()[source_offset + i];
  849. destination_instance->elements()[destination_offset + i] = value;
  850. }
  851. }
  852. return;
  853. }
  854. case Instructions::table_fill.value(): {
  855. auto table_index = instruction.arguments().get<TableIndex>();
  856. auto address = configuration.frame().module().tables()[table_index.value()];
  857. auto table = configuration.store().get(address);
  858. auto count = *configuration.stack().pop().get<Value>().to<u32>();
  859. auto value = *configuration.stack().pop().get<Value>().to<Reference>();
  860. auto start = *configuration.stack().pop().get<Value>().to<u32>();
  861. Checked<u32> checked_offset = start;
  862. checked_offset += count;
  863. TRAP_IF_NOT(!checked_offset.has_overflow() && checked_offset <= (u32)table->elements().size());
  864. for (u32 i = 0; i < count; ++i)
  865. table->elements()[start + i] = value;
  866. return;
  867. }
  868. case Instructions::table_set.value(): {
  869. auto ref = *configuration.stack().pop().get<Value>().to<Reference>();
  870. auto index = (size_t)(*configuration.stack().pop().get<Value>().to<i32>());
  871. auto table_index = instruction.arguments().get<TableIndex>();
  872. auto address = configuration.frame().module().tables()[table_index.value()];
  873. auto table = configuration.store().get(address);
  874. TRAP_IF_NOT(index < table->elements().size());
  875. table->elements()[index] = ref;
  876. return;
  877. }
  878. case Instructions::table_get.value(): {
  879. auto index = (size_t)(*configuration.stack().pop().get<Value>().to<i32>());
  880. auto table_index = instruction.arguments().get<TableIndex>();
  881. auto address = configuration.frame().module().tables()[table_index.value()];
  882. auto table = configuration.store().get(address);
  883. TRAP_IF_NOT(index < table->elements().size());
  884. auto ref = table->elements()[index];
  885. configuration.stack().push(Value(ref));
  886. return;
  887. }
  888. case Instructions::table_grow.value(): {
  889. auto size = *configuration.stack().pop().get<Value>().to<u32>();
  890. auto fill_value = *configuration.stack().pop().get<Value>().to<Reference>();
  891. auto table_index = instruction.arguments().get<TableIndex>();
  892. auto address = configuration.frame().module().tables()[table_index.value()];
  893. auto table = configuration.store().get(address);
  894. auto previous_size = table->elements().size();
  895. auto did_grow = table->grow(size, fill_value);
  896. if (!did_grow) {
  897. configuration.stack().push(Value((i32)-1));
  898. } else {
  899. configuration.stack().push(Value((i32)previous_size));
  900. }
  901. return;
  902. }
  903. case Instructions::table_size.value(): {
  904. auto table_index = instruction.arguments().get<TableIndex>();
  905. auto address = configuration.frame().module().tables()[table_index.value()];
  906. auto table = configuration.store().get(address);
  907. configuration.stack().push(Value((i32)table->elements().size()));
  908. return;
  909. }
  910. case Instructions::ref_null.value(): {
  911. auto type = instruction.arguments().get<ValueType>();
  912. configuration.stack().push(Value(Reference(Reference::Null { type })));
  913. return;
  914. };
  915. case Instructions::ref_func.value(): {
  916. auto index = instruction.arguments().get<FunctionIndex>().value();
  917. auto& functions = configuration.frame().module().functions();
  918. auto address = functions[index];
  919. configuration.stack().push(Value(ValueType(ValueType::FunctionReference), address.value()));
  920. return;
  921. }
  922. case Instructions::ref_is_null.value(): {
  923. auto top = configuration.stack().peek().get_pointer<Value>();
  924. TRAP_IF_NOT(top->type().is_reference());
  925. auto is_null = top->to<Reference::Null>().has_value();
  926. configuration.stack().peek() = Value(ValueType(ValueType::I32), static_cast<u64>(is_null ? 1 : 0));
  927. return;
  928. }
  929. case Instructions::drop.value():
  930. configuration.stack().pop();
  931. return;
  932. case Instructions::select.value():
  933. case Instructions::select_typed.value(): {
  934. // Note: The type seems to only be used for validation.
  935. auto entry = configuration.stack().pop();
  936. auto value = entry.get<Value>().to<i32>();
  937. dbgln_if(WASM_TRACE_DEBUG, "select({})", value.value());
  938. auto rhs_entry = configuration.stack().pop();
  939. auto& lhs_entry = configuration.stack().peek();
  940. auto rhs = move(rhs_entry.get<Value>());
  941. auto lhs = move(lhs_entry.get<Value>());
  942. configuration.stack().peek() = value.value() != 0 ? move(lhs) : move(rhs);
  943. return;
  944. }
  945. case Instructions::i32_eqz.value():
  946. return unary_operation<i32, i32, Operators::EqualsZero>(configuration);
  947. case Instructions::i32_eq.value():
  948. return binary_numeric_operation<i32, i32, Operators::Equals>(configuration);
  949. case Instructions::i32_ne.value():
  950. return binary_numeric_operation<i32, i32, Operators::NotEquals>(configuration);
  951. case Instructions::i32_lts.value():
  952. return binary_numeric_operation<i32, i32, Operators::LessThan>(configuration);
  953. case Instructions::i32_ltu.value():
  954. return binary_numeric_operation<u32, i32, Operators::LessThan>(configuration);
  955. case Instructions::i32_gts.value():
  956. return binary_numeric_operation<i32, i32, Operators::GreaterThan>(configuration);
  957. case Instructions::i32_gtu.value():
  958. return binary_numeric_operation<u32, i32, Operators::GreaterThan>(configuration);
  959. case Instructions::i32_les.value():
  960. return binary_numeric_operation<i32, i32, Operators::LessThanOrEquals>(configuration);
  961. case Instructions::i32_leu.value():
  962. return binary_numeric_operation<u32, i32, Operators::LessThanOrEquals>(configuration);
  963. case Instructions::i32_ges.value():
  964. return binary_numeric_operation<i32, i32, Operators::GreaterThanOrEquals>(configuration);
  965. case Instructions::i32_geu.value():
  966. return binary_numeric_operation<u32, i32, Operators::GreaterThanOrEquals>(configuration);
  967. case Instructions::i64_eqz.value():
  968. return unary_operation<i64, i32, Operators::EqualsZero>(configuration);
  969. case Instructions::i64_eq.value():
  970. return binary_numeric_operation<i64, i32, Operators::Equals>(configuration);
  971. case Instructions::i64_ne.value():
  972. return binary_numeric_operation<i64, i32, Operators::NotEquals>(configuration);
  973. case Instructions::i64_lts.value():
  974. return binary_numeric_operation<i64, i32, Operators::LessThan>(configuration);
  975. case Instructions::i64_ltu.value():
  976. return binary_numeric_operation<u64, i32, Operators::LessThan>(configuration);
  977. case Instructions::i64_gts.value():
  978. return binary_numeric_operation<i64, i32, Operators::GreaterThan>(configuration);
  979. case Instructions::i64_gtu.value():
  980. return binary_numeric_operation<u64, i32, Operators::GreaterThan>(configuration);
  981. case Instructions::i64_les.value():
  982. return binary_numeric_operation<i64, i32, Operators::LessThanOrEquals>(configuration);
  983. case Instructions::i64_leu.value():
  984. return binary_numeric_operation<u64, i32, Operators::LessThanOrEquals>(configuration);
  985. case Instructions::i64_ges.value():
  986. return binary_numeric_operation<i64, i32, Operators::GreaterThanOrEquals>(configuration);
  987. case Instructions::i64_geu.value():
  988. return binary_numeric_operation<u64, i32, Operators::GreaterThanOrEquals>(configuration);
  989. case Instructions::f32_eq.value():
  990. return binary_numeric_operation<float, i32, Operators::Equals>(configuration);
  991. case Instructions::f32_ne.value():
  992. return binary_numeric_operation<float, i32, Operators::NotEquals>(configuration);
  993. case Instructions::f32_lt.value():
  994. return binary_numeric_operation<float, i32, Operators::LessThan>(configuration);
  995. case Instructions::f32_gt.value():
  996. return binary_numeric_operation<float, i32, Operators::GreaterThan>(configuration);
  997. case Instructions::f32_le.value():
  998. return binary_numeric_operation<float, i32, Operators::LessThanOrEquals>(configuration);
  999. case Instructions::f32_ge.value():
  1000. return binary_numeric_operation<float, i32, Operators::GreaterThanOrEquals>(configuration);
  1001. case Instructions::f64_eq.value():
  1002. return binary_numeric_operation<double, i32, Operators::Equals>(configuration);
  1003. case Instructions::f64_ne.value():
  1004. return binary_numeric_operation<double, i32, Operators::NotEquals>(configuration);
  1005. case Instructions::f64_lt.value():
  1006. return binary_numeric_operation<double, i32, Operators::LessThan>(configuration);
  1007. case Instructions::f64_gt.value():
  1008. return binary_numeric_operation<double, i32, Operators::GreaterThan>(configuration);
  1009. case Instructions::f64_le.value():
  1010. return binary_numeric_operation<double, i32, Operators::LessThanOrEquals>(configuration);
  1011. case Instructions::f64_ge.value():
  1012. return binary_numeric_operation<double, i32, Operators::GreaterThanOrEquals>(configuration);
  1013. case Instructions::i32_clz.value():
  1014. return unary_operation<i32, i32, Operators::CountLeadingZeros>(configuration);
  1015. case Instructions::i32_ctz.value():
  1016. return unary_operation<i32, i32, Operators::CountTrailingZeros>(configuration);
  1017. case Instructions::i32_popcnt.value():
  1018. return unary_operation<i32, i32, Operators::PopCount>(configuration);
  1019. case Instructions::i32_add.value():
  1020. return binary_numeric_operation<u32, i32, Operators::Add>(configuration);
  1021. case Instructions::i32_sub.value():
  1022. return binary_numeric_operation<u32, i32, Operators::Subtract>(configuration);
  1023. case Instructions::i32_mul.value():
  1024. return binary_numeric_operation<u32, i32, Operators::Multiply>(configuration);
  1025. case Instructions::i32_divs.value():
  1026. return binary_numeric_operation<i32, i32, Operators::Divide>(configuration);
  1027. case Instructions::i32_divu.value():
  1028. return binary_numeric_operation<u32, i32, Operators::Divide>(configuration);
  1029. case Instructions::i32_rems.value():
  1030. return binary_numeric_operation<i32, i32, Operators::Modulo>(configuration);
  1031. case Instructions::i32_remu.value():
  1032. return binary_numeric_operation<u32, i32, Operators::Modulo>(configuration);
  1033. case Instructions::i32_and.value():
  1034. return binary_numeric_operation<i32, i32, Operators::BitAnd>(configuration);
  1035. case Instructions::i32_or.value():
  1036. return binary_numeric_operation<i32, i32, Operators::BitOr>(configuration);
  1037. case Instructions::i32_xor.value():
  1038. return binary_numeric_operation<i32, i32, Operators::BitXor>(configuration);
  1039. case Instructions::i32_shl.value():
  1040. return binary_numeric_operation<u32, i32, Operators::BitShiftLeft>(configuration);
  1041. case Instructions::i32_shrs.value():
  1042. return binary_numeric_operation<i32, i32, Operators::BitShiftRight>(configuration);
  1043. case Instructions::i32_shru.value():
  1044. return binary_numeric_operation<u32, i32, Operators::BitShiftRight>(configuration);
  1045. case Instructions::i32_rotl.value():
  1046. return binary_numeric_operation<u32, i32, Operators::BitRotateLeft>(configuration);
  1047. case Instructions::i32_rotr.value():
  1048. return binary_numeric_operation<u32, i32, Operators::BitRotateRight>(configuration);
  1049. case Instructions::i64_clz.value():
  1050. return unary_operation<i64, i64, Operators::CountLeadingZeros>(configuration);
  1051. case Instructions::i64_ctz.value():
  1052. return unary_operation<i64, i64, Operators::CountTrailingZeros>(configuration);
  1053. case Instructions::i64_popcnt.value():
  1054. return unary_operation<i64, i64, Operators::PopCount>(configuration);
  1055. case Instructions::i64_add.value():
  1056. return binary_numeric_operation<u64, i64, Operators::Add>(configuration);
  1057. case Instructions::i64_sub.value():
  1058. return binary_numeric_operation<u64, i64, Operators::Subtract>(configuration);
  1059. case Instructions::i64_mul.value():
  1060. return binary_numeric_operation<u64, i64, Operators::Multiply>(configuration);
  1061. case Instructions::i64_divs.value():
  1062. return binary_numeric_operation<i64, i64, Operators::Divide>(configuration);
  1063. case Instructions::i64_divu.value():
  1064. return binary_numeric_operation<u64, i64, Operators::Divide>(configuration);
  1065. case Instructions::i64_rems.value():
  1066. return binary_numeric_operation<i64, i64, Operators::Modulo>(configuration);
  1067. case Instructions::i64_remu.value():
  1068. return binary_numeric_operation<u64, i64, Operators::Modulo>(configuration);
  1069. case Instructions::i64_and.value():
  1070. return binary_numeric_operation<i64, i64, Operators::BitAnd>(configuration);
  1071. case Instructions::i64_or.value():
  1072. return binary_numeric_operation<i64, i64, Operators::BitOr>(configuration);
  1073. case Instructions::i64_xor.value():
  1074. return binary_numeric_operation<i64, i64, Operators::BitXor>(configuration);
  1075. case Instructions::i64_shl.value():
  1076. return binary_numeric_operation<u64, i64, Operators::BitShiftLeft>(configuration);
  1077. case Instructions::i64_shrs.value():
  1078. return binary_numeric_operation<i64, i64, Operators::BitShiftRight>(configuration);
  1079. case Instructions::i64_shru.value():
  1080. return binary_numeric_operation<u64, i64, Operators::BitShiftRight>(configuration);
  1081. case Instructions::i64_rotl.value():
  1082. return binary_numeric_operation<u64, i64, Operators::BitRotateLeft>(configuration);
  1083. case Instructions::i64_rotr.value():
  1084. return binary_numeric_operation<u64, i64, Operators::BitRotateRight>(configuration);
  1085. case Instructions::f32_abs.value():
  1086. return unary_operation<float, float, Operators::Absolute>(configuration);
  1087. case Instructions::f32_neg.value():
  1088. return unary_operation<float, float, Operators::Negate>(configuration);
  1089. case Instructions::f32_ceil.value():
  1090. return unary_operation<float, float, Operators::Ceil>(configuration);
  1091. case Instructions::f32_floor.value():
  1092. return unary_operation<float, float, Operators::Floor>(configuration);
  1093. case Instructions::f32_trunc.value():
  1094. return unary_operation<float, float, Operators::Truncate>(configuration);
  1095. case Instructions::f32_nearest.value():
  1096. return unary_operation<float, float, Operators::NearbyIntegral>(configuration);
  1097. case Instructions::f32_sqrt.value():
  1098. return unary_operation<float, float, Operators::SquareRoot>(configuration);
  1099. case Instructions::f32_add.value():
  1100. return binary_numeric_operation<float, float, Operators::Add>(configuration);
  1101. case Instructions::f32_sub.value():
  1102. return binary_numeric_operation<float, float, Operators::Subtract>(configuration);
  1103. case Instructions::f32_mul.value():
  1104. return binary_numeric_operation<float, float, Operators::Multiply>(configuration);
  1105. case Instructions::f32_div.value():
  1106. return binary_numeric_operation<float, float, Operators::Divide>(configuration);
  1107. case Instructions::f32_min.value():
  1108. return binary_numeric_operation<float, float, Operators::Minimum>(configuration);
  1109. case Instructions::f32_max.value():
  1110. return binary_numeric_operation<float, float, Operators::Maximum>(configuration);
  1111. case Instructions::f32_copysign.value():
  1112. return binary_numeric_operation<float, float, Operators::CopySign>(configuration);
  1113. case Instructions::f64_abs.value():
  1114. return unary_operation<double, double, Operators::Absolute>(configuration);
  1115. case Instructions::f64_neg.value():
  1116. return unary_operation<double, double, Operators::Negate>(configuration);
  1117. case Instructions::f64_ceil.value():
  1118. return unary_operation<double, double, Operators::Ceil>(configuration);
  1119. case Instructions::f64_floor.value():
  1120. return unary_operation<double, double, Operators::Floor>(configuration);
  1121. case Instructions::f64_trunc.value():
  1122. return unary_operation<double, double, Operators::Truncate>(configuration);
  1123. case Instructions::f64_nearest.value():
  1124. return unary_operation<double, double, Operators::NearbyIntegral>(configuration);
  1125. case Instructions::f64_sqrt.value():
  1126. return unary_operation<double, double, Operators::SquareRoot>(configuration);
  1127. case Instructions::f64_add.value():
  1128. return binary_numeric_operation<double, double, Operators::Add>(configuration);
  1129. case Instructions::f64_sub.value():
  1130. return binary_numeric_operation<double, double, Operators::Subtract>(configuration);
  1131. case Instructions::f64_mul.value():
  1132. return binary_numeric_operation<double, double, Operators::Multiply>(configuration);
  1133. case Instructions::f64_div.value():
  1134. return binary_numeric_operation<double, double, Operators::Divide>(configuration);
  1135. case Instructions::f64_min.value():
  1136. return binary_numeric_operation<double, double, Operators::Minimum>(configuration);
  1137. case Instructions::f64_max.value():
  1138. return binary_numeric_operation<double, double, Operators::Maximum>(configuration);
  1139. case Instructions::f64_copysign.value():
  1140. return binary_numeric_operation<double, double, Operators::CopySign>(configuration);
  1141. case Instructions::i32_wrap_i64.value():
  1142. return unary_operation<i64, i32, Operators::Wrap<i32>>(configuration);
  1143. case Instructions::i32_trunc_sf32.value():
  1144. return unary_operation<float, i32, Operators::CheckedTruncate<i32>>(configuration);
  1145. case Instructions::i32_trunc_uf32.value():
  1146. return unary_operation<float, i32, Operators::CheckedTruncate<u32>>(configuration);
  1147. case Instructions::i32_trunc_sf64.value():
  1148. return unary_operation<double, i32, Operators::CheckedTruncate<i32>>(configuration);
  1149. case Instructions::i32_trunc_uf64.value():
  1150. return unary_operation<double, i32, Operators::CheckedTruncate<u32>>(configuration);
  1151. case Instructions::i64_trunc_sf32.value():
  1152. return unary_operation<float, i64, Operators::CheckedTruncate<i64>>(configuration);
  1153. case Instructions::i64_trunc_uf32.value():
  1154. return unary_operation<float, i64, Operators::CheckedTruncate<u64>>(configuration);
  1155. case Instructions::i64_trunc_sf64.value():
  1156. return unary_operation<double, i64, Operators::CheckedTruncate<i64>>(configuration);
  1157. case Instructions::i64_trunc_uf64.value():
  1158. return unary_operation<double, i64, Operators::CheckedTruncate<u64>>(configuration);
  1159. case Instructions::i64_extend_si32.value():
  1160. return unary_operation<i32, i64, Operators::Extend<i64>>(configuration);
  1161. case Instructions::i64_extend_ui32.value():
  1162. return unary_operation<u32, i64, Operators::Extend<i64>>(configuration);
  1163. case Instructions::f32_convert_si32.value():
  1164. return unary_operation<i32, float, Operators::Convert<float>>(configuration);
  1165. case Instructions::f32_convert_ui32.value():
  1166. return unary_operation<u32, float, Operators::Convert<float>>(configuration);
  1167. case Instructions::f32_convert_si64.value():
  1168. return unary_operation<i64, float, Operators::Convert<float>>(configuration);
  1169. case Instructions::f32_convert_ui64.value():
  1170. return unary_operation<u64, float, Operators::Convert<float>>(configuration);
  1171. case Instructions::f32_demote_f64.value():
  1172. return unary_operation<double, float, Operators::Demote>(configuration);
  1173. case Instructions::f64_convert_si32.value():
  1174. return unary_operation<i32, double, Operators::Convert<double>>(configuration);
  1175. case Instructions::f64_convert_ui32.value():
  1176. return unary_operation<u32, double, Operators::Convert<double>>(configuration);
  1177. case Instructions::f64_convert_si64.value():
  1178. return unary_operation<i64, double, Operators::Convert<double>>(configuration);
  1179. case Instructions::f64_convert_ui64.value():
  1180. return unary_operation<u64, double, Operators::Convert<double>>(configuration);
  1181. case Instructions::f64_promote_f32.value():
  1182. return unary_operation<float, double, Operators::Promote>(configuration);
  1183. case Instructions::i32_reinterpret_f32.value():
  1184. return unary_operation<float, i32, Operators::Reinterpret<i32>>(configuration);
  1185. case Instructions::i64_reinterpret_f64.value():
  1186. return unary_operation<double, i64, Operators::Reinterpret<i64>>(configuration);
  1187. case Instructions::f32_reinterpret_i32.value():
  1188. return unary_operation<i32, float, Operators::Reinterpret<float>>(configuration);
  1189. case Instructions::f64_reinterpret_i64.value():
  1190. return unary_operation<i64, double, Operators::Reinterpret<double>>(configuration);
  1191. case Instructions::i32_extend8_s.value():
  1192. return unary_operation<i32, i32, Operators::SignExtend<i8>>(configuration);
  1193. case Instructions::i32_extend16_s.value():
  1194. return unary_operation<i32, i32, Operators::SignExtend<i16>>(configuration);
  1195. case Instructions::i64_extend8_s.value():
  1196. return unary_operation<i64, i64, Operators::SignExtend<i8>>(configuration);
  1197. case Instructions::i64_extend16_s.value():
  1198. return unary_operation<i64, i64, Operators::SignExtend<i16>>(configuration);
  1199. case Instructions::i64_extend32_s.value():
  1200. return unary_operation<i64, i64, Operators::SignExtend<i32>>(configuration);
  1201. case Instructions::i32_trunc_sat_f32_s.value():
  1202. return unary_operation<float, i32, Operators::SaturatingTruncate<i32>>(configuration);
  1203. case Instructions::i32_trunc_sat_f32_u.value():
  1204. return unary_operation<float, i32, Operators::SaturatingTruncate<u32>>(configuration);
  1205. case Instructions::i32_trunc_sat_f64_s.value():
  1206. return unary_operation<double, i32, Operators::SaturatingTruncate<i32>>(configuration);
  1207. case Instructions::i32_trunc_sat_f64_u.value():
  1208. return unary_operation<double, i32, Operators::SaturatingTruncate<u32>>(configuration);
  1209. case Instructions::i64_trunc_sat_f32_s.value():
  1210. return unary_operation<float, i64, Operators::SaturatingTruncate<i64>>(configuration);
  1211. case Instructions::i64_trunc_sat_f32_u.value():
  1212. return unary_operation<float, i64, Operators::SaturatingTruncate<u64>>(configuration);
  1213. case Instructions::i64_trunc_sat_f64_s.value():
  1214. return unary_operation<double, i64, Operators::SaturatingTruncate<i64>>(configuration);
  1215. case Instructions::i64_trunc_sat_f64_u.value():
  1216. return unary_operation<double, i64, Operators::SaturatingTruncate<u64>>(configuration);
  1217. case Instructions::v128_const.value():
  1218. configuration.stack().push(Value(instruction.arguments().get<u128>()));
  1219. return;
  1220. case Instructions::v128_load.value():
  1221. return load_and_push<u128, u128>(configuration, instruction);
  1222. case Instructions::v128_load8x8_s.value():
  1223. return load_and_push_mxn<8, 8, MakeSigned>(configuration, instruction);
  1224. case Instructions::v128_load8x8_u.value():
  1225. return load_and_push_mxn<8, 8, MakeUnsigned>(configuration, instruction);
  1226. case Instructions::v128_load16x4_s.value():
  1227. return load_and_push_mxn<16, 4, MakeSigned>(configuration, instruction);
  1228. case Instructions::v128_load16x4_u.value():
  1229. return load_and_push_mxn<16, 4, MakeUnsigned>(configuration, instruction);
  1230. case Instructions::v128_load32x2_s.value():
  1231. return load_and_push_mxn<32, 2, MakeSigned>(configuration, instruction);
  1232. case Instructions::v128_load32x2_u.value():
  1233. return load_and_push_mxn<32, 2, MakeUnsigned>(configuration, instruction);
  1234. case Instructions::v128_load8_splat.value():
  1235. return load_and_push_m_splat<8>(configuration, instruction);
  1236. case Instructions::v128_load16_splat.value():
  1237. return load_and_push_m_splat<16>(configuration, instruction);
  1238. case Instructions::v128_load32_splat.value():
  1239. return load_and_push_m_splat<32>(configuration, instruction);
  1240. case Instructions::v128_load64_splat.value():
  1241. return load_and_push_m_splat<64>(configuration, instruction);
  1242. case Instructions::i8x16_splat.value():
  1243. return pop_and_push_m_splat<8, NativeIntegralType>(configuration, instruction);
  1244. case Instructions::i16x8_splat.value():
  1245. return pop_and_push_m_splat<16, NativeIntegralType>(configuration, instruction);
  1246. case Instructions::i32x4_splat.value():
  1247. return pop_and_push_m_splat<32, NativeIntegralType>(configuration, instruction);
  1248. case Instructions::i64x2_splat.value():
  1249. return pop_and_push_m_splat<64, NativeIntegralType>(configuration, instruction);
  1250. case Instructions::f32x4_splat.value():
  1251. return pop_and_push_m_splat<32, NativeFloatingType>(configuration, instruction);
  1252. case Instructions::f64x2_splat.value():
  1253. return pop_and_push_m_splat<64, NativeFloatingType>(configuration, instruction);
  1254. case Instructions::i8x16_shuffle.value(): {
  1255. auto indices = pop_vector<u8, MakeSigned>(configuration);
  1256. TRAP_IF_NOT(indices.has_value());
  1257. auto vector = peek_vector<u8, MakeSigned>(configuration);
  1258. TRAP_IF_NOT(vector.has_value());
  1259. auto result = shuffle_vector(vector.value(), indices.value());
  1260. configuration.stack().peek() = Value(result);
  1261. return;
  1262. }
  1263. case Instructions::v128_store.value():
  1264. return pop_and_store<u128, u128>(configuration, instruction);
  1265. case Instructions::i8x16_shl.value():
  1266. return binary_numeric_operation<u128, u128, Operators::VectorShiftLeft<16>, i32>(configuration);
  1267. case Instructions::i8x16_shr_u.value():
  1268. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<16, MakeUnsigned>, i32>(configuration);
  1269. case Instructions::i8x16_shr_s.value():
  1270. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<16, MakeSigned>, i32>(configuration);
  1271. case Instructions::i16x8_shl.value():
  1272. return binary_numeric_operation<u128, u128, Operators::VectorShiftLeft<8>, i32>(configuration);
  1273. case Instructions::i16x8_shr_u.value():
  1274. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<8, MakeUnsigned>, i32>(configuration);
  1275. case Instructions::i16x8_shr_s.value():
  1276. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<8, MakeSigned>, i32>(configuration);
  1277. case Instructions::i32x4_shl.value():
  1278. return binary_numeric_operation<u128, u128, Operators::VectorShiftLeft<4>, i32>(configuration);
  1279. case Instructions::i32x4_shr_u.value():
  1280. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<4, MakeUnsigned>, i32>(configuration);
  1281. case Instructions::i32x4_shr_s.value():
  1282. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<4, MakeSigned>, i32>(configuration);
  1283. case Instructions::i64x2_shl.value():
  1284. return binary_numeric_operation<u128, u128, Operators::VectorShiftLeft<2>, i32>(configuration);
  1285. case Instructions::i64x2_shr_u.value():
  1286. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<2, MakeUnsigned>, i32>(configuration);
  1287. case Instructions::i64x2_shr_s.value():
  1288. return binary_numeric_operation<u128, u128, Operators::VectorShiftRight<2, MakeSigned>, i32>(configuration);
  1289. case Instructions::i8x16_swizzle.value():
  1290. return binary_numeric_operation<u128, u128, Operators::VectorSwizzle>(configuration);
  1291. case Instructions::i8x16_extract_lane_s.value():
  1292. return unary_operation<u128, i8, Operators::VectorExtractLane<16, MakeSigned>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1293. case Instructions::i8x16_extract_lane_u.value():
  1294. return unary_operation<u128, u8, Operators::VectorExtractLane<16, MakeUnsigned>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1295. case Instructions::i16x8_extract_lane_s.value():
  1296. return unary_operation<u128, i16, Operators::VectorExtractLane<8, MakeSigned>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1297. case Instructions::i16x8_extract_lane_u.value():
  1298. return unary_operation<u128, u16, Operators::VectorExtractLane<8, MakeUnsigned>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1299. case Instructions::i32x4_extract_lane.value():
  1300. return unary_operation<u128, i32, Operators::VectorExtractLane<4, MakeSigned>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1301. case Instructions::i64x2_extract_lane.value():
  1302. return unary_operation<u128, i64, Operators::VectorExtractLane<2, MakeSigned>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1303. case Instructions::f32x4_extract_lane.value():
  1304. return unary_operation<u128, float, Operators::VectorExtractLaneFloat<4>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1305. case Instructions::f64x2_extract_lane.value():
  1306. return unary_operation<u128, double, Operators::VectorExtractLaneFloat<2>>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1307. case Instructions::i8x16_replace_lane.value():
  1308. return binary_numeric_operation<u128, u128, Operators::VectorReplaceLane<16, i32>, i32>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1309. case Instructions::i16x8_replace_lane.value():
  1310. return binary_numeric_operation<u128, u128, Operators::VectorReplaceLane<8, i32>, i32>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1311. case Instructions::i32x4_replace_lane.value():
  1312. return binary_numeric_operation<u128, u128, Operators::VectorReplaceLane<4>, i32>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1313. case Instructions::i64x2_replace_lane.value():
  1314. return binary_numeric_operation<u128, u128, Operators::VectorReplaceLane<2>, i64>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1315. case Instructions::f32x4_replace_lane.value():
  1316. return binary_numeric_operation<u128, u128, Operators::VectorReplaceLane<4, float>, float>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1317. case Instructions::f64x2_replace_lane.value():
  1318. return binary_numeric_operation<u128, u128, Operators::VectorReplaceLane<2, double>, double>(configuration, instruction.arguments().get<Instruction::LaneIndex>().lane);
  1319. case Instructions::i8x16_eq.value():
  1320. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::Equals>>(configuration);
  1321. case Instructions::i8x16_ne.value():
  1322. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::NotEquals>>(configuration);
  1323. case Instructions::i8x16_lt_s.value():
  1324. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::LessThan, MakeSigned>>(configuration);
  1325. case Instructions::i8x16_lt_u.value():
  1326. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::LessThan, MakeUnsigned>>(configuration);
  1327. case Instructions::i8x16_gt_s.value():
  1328. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::GreaterThan, MakeSigned>>(configuration);
  1329. case Instructions::i8x16_gt_u.value():
  1330. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::GreaterThan, MakeUnsigned>>(configuration);
  1331. case Instructions::i8x16_le_s.value():
  1332. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::LessThanOrEquals, MakeSigned>>(configuration);
  1333. case Instructions::i8x16_le_u.value():
  1334. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::LessThanOrEquals, MakeUnsigned>>(configuration);
  1335. case Instructions::i8x16_ge_s.value():
  1336. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::GreaterThanOrEquals, MakeSigned>>(configuration);
  1337. case Instructions::i8x16_ge_u.value():
  1338. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<16, Operators::GreaterThanOrEquals, MakeUnsigned>>(configuration);
  1339. case Instructions::i16x8_eq.value():
  1340. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::Equals>>(configuration);
  1341. case Instructions::i16x8_ne.value():
  1342. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::NotEquals>>(configuration);
  1343. case Instructions::i16x8_lt_s.value():
  1344. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::LessThan, MakeSigned>>(configuration);
  1345. case Instructions::i16x8_lt_u.value():
  1346. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::LessThan, MakeUnsigned>>(configuration);
  1347. case Instructions::i16x8_gt_s.value():
  1348. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::GreaterThan, MakeSigned>>(configuration);
  1349. case Instructions::i16x8_gt_u.value():
  1350. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::GreaterThan, MakeUnsigned>>(configuration);
  1351. case Instructions::i16x8_le_s.value():
  1352. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::LessThanOrEquals, MakeSigned>>(configuration);
  1353. case Instructions::i16x8_le_u.value():
  1354. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::LessThanOrEquals, MakeUnsigned>>(configuration);
  1355. case Instructions::i16x8_ge_s.value():
  1356. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::GreaterThanOrEquals, MakeSigned>>(configuration);
  1357. case Instructions::i16x8_ge_u.value():
  1358. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<8, Operators::GreaterThanOrEquals, MakeUnsigned>>(configuration);
  1359. case Instructions::i32x4_eq.value():
  1360. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::Equals>>(configuration);
  1361. case Instructions::i32x4_ne.value():
  1362. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::NotEquals>>(configuration);
  1363. case Instructions::i32x4_lt_s.value():
  1364. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::LessThan, MakeSigned>>(configuration);
  1365. case Instructions::i32x4_lt_u.value():
  1366. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::LessThan, MakeUnsigned>>(configuration);
  1367. case Instructions::i32x4_gt_s.value():
  1368. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::GreaterThan, MakeSigned>>(configuration);
  1369. case Instructions::i32x4_gt_u.value():
  1370. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::GreaterThan, MakeUnsigned>>(configuration);
  1371. case Instructions::i32x4_le_s.value():
  1372. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::LessThanOrEquals, MakeSigned>>(configuration);
  1373. case Instructions::i32x4_le_u.value():
  1374. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::LessThanOrEquals, MakeUnsigned>>(configuration);
  1375. case Instructions::i32x4_ge_s.value():
  1376. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::GreaterThanOrEquals, MakeSigned>>(configuration);
  1377. case Instructions::i32x4_ge_u.value():
  1378. return binary_numeric_operation<u128, u128, Operators::VectorCmpOp<4, Operators::GreaterThanOrEquals, MakeUnsigned>>(configuration);
  1379. case Instructions::f32x4_eq.value():
  1380. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::Equals>>(configuration);
  1381. case Instructions::f32x4_ne.value():
  1382. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::NotEquals>>(configuration);
  1383. case Instructions::f32x4_lt.value():
  1384. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::LessThan>>(configuration);
  1385. case Instructions::f32x4_gt.value():
  1386. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::GreaterThan>>(configuration);
  1387. case Instructions::f32x4_le.value():
  1388. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::LessThanOrEquals>>(configuration);
  1389. case Instructions::f32x4_ge.value():
  1390. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::GreaterThanOrEquals>>(configuration);
  1391. case Instructions::f32x4_min.value():
  1392. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::Minimum>>(configuration);
  1393. case Instructions::f32x4_max.value():
  1394. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<4, Operators::Maximum>>(configuration);
  1395. case Instructions::f64x2_eq.value():
  1396. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::Equals>>(configuration);
  1397. case Instructions::f64x2_ne.value():
  1398. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::NotEquals>>(configuration);
  1399. case Instructions::f64x2_lt.value():
  1400. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::LessThan>>(configuration);
  1401. case Instructions::f64x2_gt.value():
  1402. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::GreaterThan>>(configuration);
  1403. case Instructions::f64x2_le.value():
  1404. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::LessThanOrEquals>>(configuration);
  1405. case Instructions::f64x2_ge.value():
  1406. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::GreaterThanOrEquals>>(configuration);
  1407. case Instructions::f64x2_min.value():
  1408. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::Minimum>>(configuration);
  1409. case Instructions::f64x2_max.value():
  1410. return binary_numeric_operation<u128, u128, Operators::VectorFloatCmpOp<2, Operators::Maximum>>(configuration);
  1411. case Instructions::f32x4_div.value():
  1412. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<4, Operators::Divide>>(configuration);
  1413. case Instructions::f32x4_mul.value():
  1414. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<4, Operators::Multiply>>(configuration);
  1415. case Instructions::f32x4_sub.value():
  1416. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<4, Operators::Subtract>>(configuration);
  1417. case Instructions::f32x4_add.value():
  1418. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<4, Operators::Add>>(configuration);
  1419. case Instructions::f32x4_pmin.value():
  1420. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<4, Operators::PseudoMinimum>>(configuration);
  1421. case Instructions::f32x4_pmax.value():
  1422. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<4, Operators::PseudoMaximum>>(configuration);
  1423. case Instructions::f64x2_div.value():
  1424. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<2, Operators::Divide>>(configuration);
  1425. case Instructions::f64x2_mul.value():
  1426. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<2, Operators::Multiply>>(configuration);
  1427. case Instructions::f64x2_sub.value():
  1428. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<2, Operators::Subtract>>(configuration);
  1429. case Instructions::f64x2_add.value():
  1430. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<2, Operators::Add>>(configuration);
  1431. case Instructions::f64x2_pmin.value():
  1432. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<2, Operators::PseudoMinimum>>(configuration);
  1433. case Instructions::f64x2_pmax.value():
  1434. return binary_numeric_operation<u128, u128, Operators::VectorFloatBinaryOp<2, Operators::PseudoMaximum>>(configuration);
  1435. case Instructions::f32x4_ceil.value():
  1436. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::Ceil>>(configuration);
  1437. case Instructions::f32x4_floor.value():
  1438. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::Floor>>(configuration);
  1439. case Instructions::f32x4_trunc.value():
  1440. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::Truncate>>(configuration);
  1441. case Instructions::f32x4_nearest.value():
  1442. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::NearbyIntegral>>(configuration);
  1443. case Instructions::f32x4_sqrt.value():
  1444. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::SquareRoot>>(configuration);
  1445. case Instructions::f32x4_neg.value():
  1446. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::Negate>>(configuration);
  1447. case Instructions::f32x4_abs.value():
  1448. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<4, Operators::Absolute>>(configuration);
  1449. case Instructions::f64x2_ceil.value():
  1450. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::Ceil>>(configuration);
  1451. case Instructions::f64x2_floor.value():
  1452. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::Floor>>(configuration);
  1453. case Instructions::f64x2_trunc.value():
  1454. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::Truncate>>(configuration);
  1455. case Instructions::f64x2_nearest.value():
  1456. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::NearbyIntegral>>(configuration);
  1457. case Instructions::f64x2_sqrt.value():
  1458. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::SquareRoot>>(configuration);
  1459. case Instructions::f64x2_neg.value():
  1460. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::Negate>>(configuration);
  1461. case Instructions::f64x2_abs.value():
  1462. return unary_operation<u128, u128, Operators::VectorFloatUnaryOp<2, Operators::Absolute>>(configuration);
  1463. case Instructions::v128_not.value():
  1464. case Instructions::v128_and.value():
  1465. case Instructions::v128_andnot.value():
  1466. case Instructions::v128_or.value():
  1467. case Instructions::v128_xor.value():
  1468. case Instructions::v128_bitselect.value():
  1469. case Instructions::v128_any_true.value():
  1470. case Instructions::v128_load8_lane.value():
  1471. case Instructions::v128_load16_lane.value():
  1472. case Instructions::v128_load32_lane.value():
  1473. case Instructions::v128_load64_lane.value():
  1474. case Instructions::v128_store8_lane.value():
  1475. case Instructions::v128_store16_lane.value():
  1476. case Instructions::v128_store32_lane.value():
  1477. case Instructions::v128_store64_lane.value():
  1478. case Instructions::v128_load32_zero.value():
  1479. case Instructions::v128_load64_zero.value():
  1480. case Instructions::f32x4_demote_f64x2_zero.value():
  1481. case Instructions::f64x2_promote_low_f32x4.value():
  1482. case Instructions::i8x16_abs.value():
  1483. case Instructions::i8x16_neg.value():
  1484. case Instructions::i8x16_popcnt.value():
  1485. case Instructions::i8x16_all_true.value():
  1486. case Instructions::i8x16_bitmask.value():
  1487. case Instructions::i8x16_narrow_i16x8_s.value():
  1488. case Instructions::i8x16_narrow_i16x8_u.value():
  1489. case Instructions::i8x16_add.value():
  1490. case Instructions::i8x16_add_sat_s.value():
  1491. case Instructions::i8x16_add_sat_u.value():
  1492. case Instructions::i8x16_sub.value():
  1493. case Instructions::i8x16_sub_sat_s.value():
  1494. case Instructions::i8x16_sub_sat_u.value():
  1495. case Instructions::i8x16_min_s.value():
  1496. case Instructions::i8x16_min_u.value():
  1497. case Instructions::i8x16_max_s.value():
  1498. case Instructions::i8x16_max_u.value():
  1499. case Instructions::i8x16_avgr_u.value():
  1500. case Instructions::i16x8_extadd_pairwise_i8x16_s.value():
  1501. case Instructions::i16x8_extadd_pairwise_i8x16_u.value():
  1502. case Instructions::i32x4_extadd_pairwise_i16x8_s.value():
  1503. case Instructions::i32x4_extadd_pairwise_i16x8_u.value():
  1504. case Instructions::i16x8_abs.value():
  1505. case Instructions::i16x8_neg.value():
  1506. case Instructions::i16x8_q15mulr_sat_s.value():
  1507. case Instructions::i16x8_all_true.value():
  1508. case Instructions::i16x8_bitmask.value():
  1509. case Instructions::i16x8_narrow_i32x4_s.value():
  1510. case Instructions::i16x8_narrow_i32x4_u.value():
  1511. case Instructions::i16x8_extend_low_i8x16_s.value():
  1512. case Instructions::i16x8_extend_high_i8x16_s.value():
  1513. case Instructions::i16x8_extend_low_i8x16_u.value():
  1514. case Instructions::i16x8_extend_high_i8x16_u.value():
  1515. case Instructions::i16x8_add.value():
  1516. case Instructions::i16x8_add_sat_s.value():
  1517. case Instructions::i16x8_add_sat_u.value():
  1518. case Instructions::i16x8_sub.value():
  1519. case Instructions::i16x8_sub_sat_s.value():
  1520. case Instructions::i16x8_sub_sat_u.value():
  1521. case Instructions::i16x8_mul.value():
  1522. case Instructions::i16x8_min_s.value():
  1523. case Instructions::i16x8_min_u.value():
  1524. case Instructions::i16x8_max_s.value():
  1525. case Instructions::i16x8_max_u.value():
  1526. case Instructions::i16x8_avgr_u.value():
  1527. case Instructions::i16x8_extmul_low_i8x16_s.value():
  1528. case Instructions::i16x8_extmul_high_i8x16_s.value():
  1529. case Instructions::i16x8_extmul_low_i8x16_u.value():
  1530. case Instructions::i16x8_extmul_high_i8x16_u.value():
  1531. case Instructions::i32x4_abs.value():
  1532. case Instructions::i32x4_neg.value():
  1533. case Instructions::i32x4_all_true.value():
  1534. case Instructions::i32x4_bitmask.value():
  1535. case Instructions::i32x4_extend_low_i16x8_s.value():
  1536. case Instructions::i32x4_extend_high_i16x8_s.value():
  1537. case Instructions::i32x4_extend_low_i16x8_u.value():
  1538. case Instructions::i32x4_extend_high_i16x8_u.value():
  1539. case Instructions::i32x4_add.value():
  1540. case Instructions::i32x4_sub.value():
  1541. case Instructions::i32x4_mul.value():
  1542. case Instructions::i32x4_min_s.value():
  1543. case Instructions::i32x4_min_u.value():
  1544. case Instructions::i32x4_max_s.value():
  1545. case Instructions::i32x4_max_u.value():
  1546. case Instructions::i32x4_dot_i16x8_s.value():
  1547. case Instructions::i32x4_extmul_low_i16x8_s.value():
  1548. case Instructions::i32x4_extmul_high_i16x8_s.value():
  1549. case Instructions::i32x4_extmul_low_i16x8_u.value():
  1550. case Instructions::i32x4_extmul_high_i16x8_u.value():
  1551. case Instructions::i64x2_abs.value():
  1552. case Instructions::i64x2_neg.value():
  1553. case Instructions::i64x2_all_true.value():
  1554. case Instructions::i64x2_bitmask.value():
  1555. case Instructions::i64x2_extend_low_i32x4_s.value():
  1556. case Instructions::i64x2_extend_high_i32x4_s.value():
  1557. case Instructions::i64x2_extend_low_i32x4_u.value():
  1558. case Instructions::i64x2_extend_high_i32x4_u.value():
  1559. case Instructions::i64x2_sub.value():
  1560. case Instructions::i64x2_mul.value():
  1561. case Instructions::i64x2_eq.value():
  1562. case Instructions::i64x2_ne.value():
  1563. case Instructions::i64x2_lt_s.value():
  1564. case Instructions::i64x2_gt_s.value():
  1565. case Instructions::i64x2_le_s.value():
  1566. case Instructions::i64x2_ge_s.value():
  1567. case Instructions::i64x2_extmul_low_i32x4_s.value():
  1568. case Instructions::i64x2_extmul_high_i32x4_s.value():
  1569. case Instructions::i64x2_extmul_low_i32x4_u.value():
  1570. case Instructions::i64x2_extmul_high_i32x4_u.value():
  1571. case Instructions::i32x4_trunc_sat_f32x4_s.value():
  1572. case Instructions::i32x4_trunc_sat_f32x4_u.value():
  1573. case Instructions::f32x4_convert_i32x4_s.value():
  1574. case Instructions::f32x4_convert_i32x4_u.value():
  1575. case Instructions::i32x4_trunc_sat_f64x2_s_zero.value():
  1576. case Instructions::i32x4_trunc_sat_f64x2_u_zero.value():
  1577. case Instructions::f64x2_convert_low_i32x4_s.value():
  1578. case Instructions::f64x2_convert_low_i32x4_u.value():
  1579. default:
  1580. dbgln_if(WASM_TRACE_DEBUG, "Instruction '{}' not implemented", instruction_name(instruction.opcode()));
  1581. m_trap = Trap { ByteString::formatted("Unimplemented instruction {}", instruction_name(instruction.opcode())) };
  1582. return;
  1583. }
  1584. }
  1585. void DebuggerBytecodeInterpreter::interpret(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction)
  1586. {
  1587. if (pre_interpret_hook) {
  1588. auto result = pre_interpret_hook(configuration, ip, instruction);
  1589. if (!result) {
  1590. m_trap = Trap { "Trapped by user request" };
  1591. return;
  1592. }
  1593. }
  1594. BytecodeInterpreter::interpret(configuration, ip, instruction);
  1595. if (post_interpret_hook) {
  1596. auto result = post_interpret_hook(configuration, ip, instruction, *this);
  1597. if (!result) {
  1598. m_trap = Trap { "Trapped by user request" };
  1599. return;
  1600. }
  1601. }
  1602. }
  1603. }