diff --git a/src/wasm/baseline/mips/liftoff-assembler-mips.h b/src/wasm/baseline/mips/liftoff-assembler-mips.h index 4509005891..3763c96b80 100644 --- a/src/wasm/baseline/mips/liftoff-assembler-mips.h +++ b/src/wasm/baseline/mips/liftoff-assembler-mips.h @@ -864,6 +864,40 @@ void LiftoffAssembler::emit_i64_shr(LiftoffRegister dst, LiftoffRegister src, kScratchReg); } +void LiftoffAssembler::emit_i64_clz(LiftoffRegister dst, LiftoffRegister src) { + // return high == 0 ? 32 + CLZ32(low) : CLZ32(high); + Label done; + Label high_is_zero; + Branch(&high_is_zero, eq, src.high_gp(), Operand(zero_reg)); + + clz(dst.low_gp(), src.high_gp()); + jmp(&done); + + bind(&high_is_zero); + clz(dst.low_gp(), src.low_gp()); + Addu(dst.low_gp(), dst.low_gp(), Operand(32)); + + bind(&done); + mov(dst.high_gp(), zero_reg); // High word of result is always 0. +} + +void LiftoffAssembler::emit_i64_ctz(LiftoffRegister dst, LiftoffRegister src) { + // return low == 0 ? 32 + CTZ32(high) : CTZ32(low); + Label done; + Label low_is_zero; + Branch(&low_is_zero, eq, src.low_gp(), Operand(zero_reg)); + + Ctz(dst.low_gp(), src.low_gp()); + jmp(&done); + + bind(&low_is_zero); + Ctz(dst.low_gp(), src.high_gp()); + Addu(dst.low_gp(), dst.low_gp(), Operand(32)); + + bind(&done); + mov(dst.high_gp(), zero_reg); // High word of result is always 0. +} + void LiftoffAssembler::emit_i32_to_intptr(Register dst, Register src) { // This is a nop on mips32. } diff --git a/src/wasm/baseline/mips64/liftoff-assembler-mips64.h b/src/wasm/baseline/mips64/liftoff-assembler-mips64.h index b20cd69a36..6a85e5d24d 100644 --- a/src/wasm/baseline/mips64/liftoff-assembler-mips64.h +++ b/src/wasm/baseline/mips64/liftoff-assembler-mips64.h @@ -556,6 +556,14 @@ void LiftoffAssembler::FillStackSlotsWithZero(uint32_t index, uint32_t count) { } } +void LiftoffAssembler::emit_i64_clz(LiftoffRegister dst, LiftoffRegister src) { + Clz(dst.gp(), src.gp()); +} + +void LiftoffAssembler::emit_i64_ctz(LiftoffRegister dst, LiftoffRegister src) { + Ctz(dst.gp(), src.gp()); +} + void LiftoffAssembler::emit_i32_mul(Register dst, Register lhs, Register rhs) { TurboAssembler::Mul(dst, lhs, rhs); }