BytecodeInterpreter.cpp 99 KB

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