summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWasm
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-06-09 17:13:38 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-09 23:05:32 +0430
commit3a44011cd4b82aa5bea64e7993900d51cbd9bce2 (patch)
tree87c175db4804a2747b694d5fd16561a31bffea79 /Userland/Libraries/LibWasm
parenta4c4dd928b1ac19f61fc0400a1f36e7ff4d223ee (diff)
downloadserenity-3a44011cd4b82aa5bea64e7993900d51cbd9bce2.zip
LibWasm: Implement sign extension instructions
Diffstat (limited to 'Userland/Libraries/LibWasm')
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp
index ed295dafd8..e6af12b21b 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp
+++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp
@@ -396,6 +396,13 @@ ALWAYS_INLINE static i32 ctz(T value)
VERIFY_NOT_REACHED();
}
+template<typename InputT, typename OutputT>
+ALWAYS_INLINE static OutputT extend_signed(InputT value)
+{
+ // Note: C++ will take care of sign extension.
+ return value;
+}
+
template<typename T>
ALWAYS_INLINE static T float_max(T lhs, T rhs)
{
@@ -970,6 +977,16 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
UNARY_MAP(i32, bit_cast<float>, float);
case Instructions::f64_reinterpret_i64.value():
UNARY_MAP(i64, bit_cast<double>, double);
+ case Instructions::i32_extend8_s.value():
+ UNARY_MAP(i32, (extend_signed<i8, i32>), i32);
+ case Instructions::i32_extend16_s.value():
+ UNARY_MAP(i32, (extend_signed<i16, i32>), i32);
+ case Instructions::i64_extend8_s.value():
+ UNARY_MAP(i64, (extend_signed<i8, i64>), i64);
+ case Instructions::i64_extend16_s.value():
+ UNARY_MAP(i64, (extend_signed<i16, i64>), i64);
+ case Instructions::i64_extend32_s.value():
+ UNARY_MAP(i64, (extend_signed<i32, i64>), i64);
case Instructions::i32_trunc_sat_f32_s.value():
case Instructions::i32_trunc_sat_f32_u.value():
case Instructions::i32_trunc_sat_f64_s.value():
@@ -988,11 +1005,6 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
case Instructions::table_grow.value():
case Instructions::table_size.value():
case Instructions::table_fill.value():
- case Instructions::i32_extend8_s.value():
- case Instructions::i32_extend16_s.value():
- case Instructions::i64_extend8_s.value():
- case Instructions::i64_extend16_s.value():
- case Instructions::i64_extend32_s.value():
default:
unimplemented:;
dbgln("Instruction '{}' not implemented", instruction_name(instruction.opcode()));