From ab5eaef5b81d2fa065cb86d745ed86bca2a3bad6 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 21 Apr 2022 18:15:56 +0800 Subject: [PATCH] Implement I64_EXTEND_I32 and I32_WRAP_I64 for Fast JIT (#1111) --- .../fast-jit/cg/x86-64/jit_codegen_x86_64.cpp | 55 +++++++------------ core/iwasm/fast-jit/fe/jit_emit_conversion.c | 27 ++++++++- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp b/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp index 47d9132f3..44f14ff8d 100644 --- a/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp +++ b/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp @@ -1144,9 +1144,9 @@ mov_r_to_r_f64(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) static bool convert_imm_i32_to_r_i8(x86::Assembler &a, int32 reg_no, int32 data) { - Imm imm((int8)data); - a.mov(regs_i32[reg_no], imm); - return true; + /* (int32)(int8)data will do sign-extension */ + /* (int32)(uint32)(int8)data is longer */ + return mov_imm_to_r_i32(a, reg_no, data & 0x000000FF); } /** @@ -1161,9 +1161,8 @@ convert_imm_i32_to_r_i8(x86::Assembler &a, int32 reg_no, int32 data) static bool convert_r_i32_to_r_i8(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) { - /* TODO */ - bh_assert(0); - return false; + a.and_(regs_i32[reg_no_src], 0x000000FF); + return mov_r_to_r_i32(a, reg_no_dst, reg_no_src); } /** @@ -1178,9 +1177,7 @@ convert_r_i32_to_r_i8(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) static bool convert_imm_i32_to_r_u8(x86::Assembler &a, int32 reg_no, int32 data) { - Imm imm((uint8)data); - a.mov(regs_i32[reg_no], imm); - return true; + return mov_imm_to_r_i32(a, reg_no, (uint8)data); } /** @@ -1195,9 +1192,7 @@ convert_imm_i32_to_r_u8(x86::Assembler &a, int32 reg_no, int32 data) static bool convert_r_i32_to_r_u8(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) { - /* TODO */ - bh_assert(0); - return false; + return convert_r_i32_to_r_i8(a, reg_no_dst, reg_no_src); } /** @@ -1212,9 +1207,9 @@ convert_r_i32_to_r_u8(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) static bool convert_imm_i32_to_r_i16(x86::Assembler &a, int32 reg_no, int32 data) { - Imm imm((int16)data); - a.mov(regs_i32[reg_no], imm); - return true; + /* (int32)(int16)data will do sign-extension */ + /* (int32)(uint32)(int16)data is longer */ + return mov_imm_to_r_i32(a, reg_no, data & 0x0000FFFF); } /** @@ -1229,9 +1224,8 @@ convert_imm_i32_to_r_i16(x86::Assembler &a, int32 reg_no, int32 data) static bool convert_r_i32_to_r_i16(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) { - /* TODO */ - bh_assert(0); - return false; + a.and_(regs_i32[reg_no_src], 0x0000FFFF); + return mov_r_to_r_i32(a, reg_no_dst, reg_no_src); } /** @@ -1246,9 +1240,7 @@ convert_r_i32_to_r_i16(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) static bool convert_imm_i32_to_r_u16(x86::Assembler &a, int32 reg_no, int32 data) { - Imm imm((uint16)data); - a.mov(regs_i32[reg_no], imm); - return true; + return mov_imm_to_r_i32(a, reg_no, (uint16)data); } /** @@ -1263,9 +1255,7 @@ convert_imm_i32_to_r_u16(x86::Assembler &a, int32 reg_no, int32 data) static bool convert_r_i32_to_r_u16(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) { - /* TODO */ - bh_assert(0); - return false; + return convert_r_i32_to_r_i16(a, reg_no_dst, reg_no_src); } /** @@ -1281,9 +1271,7 @@ static bool convert_imm_i32_to_r_i64(x86::Assembler &a, int32 reg_no, int32 data) { /* let compiler do sign-extending */ - Imm imm((int64)data); - a.mov(regs_i64[reg_no], imm); - return true; + return mov_imm_to_r_i64(a, reg_no, (int64)data); } /** @@ -1373,9 +1361,7 @@ convert_r_i32_to_r_f64(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) static bool convert_imm_u32_to_r_i64(x86::Assembler &a, int32 reg_no, uint32 data) { - Imm imm((uint64)data); - a.mov(regs_i64[reg_no], imm); - return true; + return mov_imm_to_r_i64(a, reg_no, (uint64)data); } /** @@ -1405,9 +1391,7 @@ convert_r_u32_to_r_i64(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) static bool convert_imm_i64_to_r_i32(x86::Assembler &a, int32 reg_no, int64 data) { - Imm imm((int32)data); - a.mov(regs_i32[reg_no], imm); - return true; + return mov_imm_to_r_i32(a, reg_no, (int32)data); } /** @@ -1422,9 +1406,8 @@ convert_imm_i64_to_r_i32(x86::Assembler &a, int32 reg_no, int64 data) static bool convert_r_i64_to_r_i32(x86::Assembler &a, int32 reg_no_dst, int32 reg_no_src) { - /* TODO */ - bh_assert(0); - return false; + a.and_(regs_i64[reg_no_src], 0x00000000FFFFFFFFLL); + return mov_r_to_r_i32(a, reg_no_dst, reg_no_src); } /** diff --git a/core/iwasm/fast-jit/fe/jit_emit_conversion.c b/core/iwasm/fast-jit/fe/jit_emit_conversion.c index cb6f2a748..28d1250ce 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_conversion.c +++ b/core/iwasm/fast-jit/fe/jit_emit_conversion.c @@ -9,6 +9,16 @@ bool jit_compile_op_i32_wrap_i64(JitCompContext *cc) { + JitReg num, res; + + POP_I64(num); + + res = jit_cc_new_reg_I32(cc); + GEN_INSN(I64TOI32, res, num); + PUSH_I32(res); + + return true; +fail: return false; } @@ -25,8 +35,23 @@ jit_compile_op_i32_trunc_f64(JitCompContext *cc, bool sign, bool saturating) } bool -jit_compile_op_i64_extend_i32(JitCompContext *comp_ctx, bool sign) +jit_compile_op_i64_extend_i32(JitCompContext *cc, bool sign) { + JitReg num, res; + + POP_I32(num); + + res = jit_cc_new_reg_I64(cc); + if (sign) { + GEN_INSN(I32TOI64, res, num); + } + else { + GEN_INSN(U32TOI64, res, num); + } + PUSH_I64(res); + + return true; +fail: return false; }