Commit 9282c907 authored by Richard Stotz's avatar Richard Stotz Committed by Commit Bot

[wasm][liftoff][x64] Add saturated conversion float->int32

Bug: v8:10520
Change-Id: I0b4867d9b705058536b0f4640a9a87059db3aca7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2201576
Commit-Queue: Richard Stotz <rstz@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67858}
parent dfabc70a
...@@ -1914,6 +1914,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, ...@@ -1914,6 +1914,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
case kExprI32SConvertSatF32: case kExprI32SConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32"); bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32");
return true; return true;
case kExprI32UConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF32");
return true;
case kExprI32SConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF64");
return true;
case kExprI32UConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF64");
return true;
case kExprI32ReinterpretF32: case kExprI32ReinterpretF32:
vmov(dst.gp(), liftoff::GetFloatRegister(src.fp())); vmov(dst.gp(), liftoff::GetFloatRegister(src.fp()));
return true; return true;
......
...@@ -961,6 +961,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, ...@@ -961,6 +961,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
case kExprI32SConvertSatF32: case kExprI32SConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32"); bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32");
return true; return true;
case kExprI32UConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF32");
return true;
case kExprI32SConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF64");
return true;
case kExprI32UConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF64");
return true;
case kExprI32ReinterpretF32: case kExprI32ReinterpretF32:
Fmov(dst.gp().W(), src.fp().S()); Fmov(dst.gp().W(), src.fp().S());
return true; return true;
......
...@@ -1694,6 +1694,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, ...@@ -1694,6 +1694,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
case kExprI32SConvertSatF32: case kExprI32SConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32"); bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32");
return true; return true;
case kExprI32UConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF32");
return true;
case kExprI32SConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF64");
return true;
case kExprI32UConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF64");
return true;
case kExprI32ReinterpretF32: case kExprI32ReinterpretF32:
Movd(dst.gp(), src.fp()); Movd(dst.gp(), src.fp());
return true; return true;
......
...@@ -1090,9 +1090,9 @@ class LiftoffCompiler { ...@@ -1090,9 +1090,9 @@ class LiftoffCompiler {
nullptr); nullptr);
}); });
CASE_TYPE_CONVERSION(I32SConvertSatF32, I32, F32, nullptr, kNoTrap) CASE_TYPE_CONVERSION(I32SConvertSatF32, I32, F32, nullptr, kNoTrap)
case kExprI32UConvertSatF32: CASE_TYPE_CONVERSION(I32UConvertSatF32, I32, F32, nullptr, kNoTrap)
case kExprI32SConvertSatF64: CASE_TYPE_CONVERSION(I32SConvertSatF64, I32, F64, nullptr, kNoTrap)
case kExprI32UConvertSatF64: CASE_TYPE_CONVERSION(I32UConvertSatF64, I32, F64, nullptr, kNoTrap)
case kExprI64SConvertSatF32: case kExprI64SConvertSatF32:
case kExprI64UConvertSatF32: case kExprI64UConvertSatF32:
case kExprI64SConvertSatF64: case kExprI64SConvertSatF64:
......
...@@ -1272,6 +1272,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, ...@@ -1272,6 +1272,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
case kExprI32SConvertSatF32: case kExprI32SConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32"); bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32");
return true; return true;
case kExprI32UConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF32");
return true;
case kExprI32SConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF64");
return true;
case kExprI32UConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF64");
return true;
case kExprI32ReinterpretF32: case kExprI32ReinterpretF32:
mfc1(dst.gp(), src.fp()); mfc1(dst.gp(), src.fp());
return true; return true;
......
...@@ -1182,6 +1182,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, ...@@ -1182,6 +1182,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
case kExprI32SConvertSatF32: case kExprI32SConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32"); bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF32");
return true; return true;
case kExprI32UConvertSatF32:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF32");
return true;
case kExprI32SConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32SConvertSatF64");
return true;
case kExprI32UConvertSatF64:
bailout(kNonTrappingFloatToInt, "kExprI32UConvertSatF64");
return true;
} }
} }
......
...@@ -1703,11 +1703,19 @@ inline bool EmitSatTruncateFloatToInt(LiftoffAssembler* assm, Register dst, ...@@ -1703,11 +1703,19 @@ inline bool EmitSatTruncateFloatToInt(LiftoffAssembler* assm, Register dst,
DoubleRegister converted_back = kScratchDoubleReg2; DoubleRegister converted_back = kScratchDoubleReg2;
DoubleRegister zero_reg = kScratchDoubleReg; DoubleRegister zero_reg = kScratchDoubleReg;
__ Roundss(rounded, src, kRoundToZero); if (std::is_same<double, src_type>::value) { // f64
__ Roundsd(rounded, src, kRoundToZero);
} else { // f32
__ Roundss(rounded, src, kRoundToZero);
}
ConvertFloatToIntAndBack<dst_type, src_type>(assm, dst, rounded, ConvertFloatToIntAndBack<dst_type, src_type>(assm, dst, rounded,
converted_back); converted_back);
__ Ucomiss(converted_back, rounded); if (std::is_same<double, src_type>::value) { // f64
__ Ucomisd(converted_back, rounded);
} else { // f32
__ Ucomiss(converted_back, rounded);
}
// Return 0 if PF is 0 (one of the operands was NaN) // Return 0 if PF is 0 (one of the operands was NaN)
__ j(parity_odd, &not_nan); __ j(parity_odd, &not_nan);
...@@ -1720,14 +1728,18 @@ inline bool EmitSatTruncateFloatToInt(LiftoffAssembler* assm, Register dst, ...@@ -1720,14 +1728,18 @@ inline bool EmitSatTruncateFloatToInt(LiftoffAssembler* assm, Register dst,
__ xorpd(zero_reg, zero_reg); __ xorpd(zero_reg, zero_reg);
__ Ucomiss(src, kScratchDoubleReg); if (std::is_same<double, src_type>::value) { // f64
__ Ucomisd(src, kScratchDoubleReg);
} else { // f32
__ Ucomiss(src, kScratchDoubleReg);
}
__ j(above, &src_pos); __ j(above, &src_pos);
__ movl(dst, Immediate(kMinInt)); __ movl(dst, Immediate(std::numeric_limits<dst_type>::min()));
__ jmp(&done); __ jmp(&done);
__ bind(&src_pos); __ bind(&src_pos);
__ movl(dst, Immediate(kMaxInt)); __ movl(dst, Immediate(std::numeric_limits<dst_type>::max()));
__ bind(&done); __ bind(&done);
return true; return true;
...@@ -1757,6 +1769,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode, ...@@ -1757,6 +1769,15 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
case kExprI32SConvertSatF32: case kExprI32SConvertSatF32:
return liftoff::EmitSatTruncateFloatToInt<int32_t, float>(this, dst.gp(), return liftoff::EmitSatTruncateFloatToInt<int32_t, float>(this, dst.gp(),
src.fp()); src.fp());
case kExprI32UConvertSatF32:
return liftoff::EmitSatTruncateFloatToInt<uint32_t, float>(this, dst.gp(),
src.fp());
case kExprI32SConvertSatF64:
return liftoff::EmitSatTruncateFloatToInt<int32_t, double>(this, dst.gp(),
src.fp());
case kExprI32UConvertSatF64:
return liftoff::EmitSatTruncateFloatToInt<uint32_t, double>(
this, dst.gp(), src.fp());
case kExprI32ReinterpretF32: case kExprI32ReinterpretF32:
Movd(dst.gp(), src.fp()); Movd(dst.gp(), src.fp());
return true; return true;
......
...@@ -787,6 +787,9 @@ void WasmGenerator::Generate<ValueType::kI32>(DataRange* data) { ...@@ -787,6 +787,9 @@ void WasmGenerator::Generate<ValueType::kI32>(DataRange* data) {
&WasmGenerator::op<kExprI32ReinterpretF32, ValueType::kF32>, &WasmGenerator::op<kExprI32ReinterpretF32, ValueType::kF32>,
&WasmGenerator::op<kExprI32SConvertSatF32, ValueType::kF32>, &WasmGenerator::op<kExprI32SConvertSatF32, ValueType::kF32>,
&WasmGenerator::op<kExprI32UConvertSatF32, ValueType::kF32>,
&WasmGenerator::op<kExprI32SConvertSatF64, ValueType::kF64>,
&WasmGenerator::op<kExprI32UConvertSatF64, ValueType::kF64>,
&WasmGenerator::block<ValueType::kI32>, &WasmGenerator::block<ValueType::kI32>,
&WasmGenerator::loop<ValueType::kI32>, &WasmGenerator::loop<ValueType::kI32>,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment