BytecodeInterpreter.cpp 99 KB

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