Commit 386344e0 authored by Clemens Hammacher's avatar Clemens Hammacher

[ia32] Rename and move type conversions

Name type conversions from int to float and vice versa consistently,
and move them to the TurboAssembler, such that we can reuse them for
Liftoff.

R=jarin@chromium.org

Bug: v8:6600
Change-Id: Idced658a228eeb611dd4785aa277bd758c201eea
Reviewed-on: https://chromium-review.googlesource.com/1014037Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52620}
parent 38ebe528
......@@ -1351,28 +1351,15 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kSSEFloat32ToInt32:
__ cvttss2si(i.OutputRegister(), i.InputOperand(0));
break;
case kSSEFloat32ToUint32: {
Label success;
__ cvttss2si(i.OutputRegister(), i.InputOperand(0));
__ test(i.OutputRegister(), i.OutputRegister());
__ j(positive, &success);
__ Move(kScratchDoubleReg, static_cast<float>(INT32_MIN));
__ addss(kScratchDoubleReg, i.InputOperand(0));
__ cvttss2si(i.OutputRegister(), kScratchDoubleReg);
__ or_(i.OutputRegister(), Immediate(0x80000000));
__ bind(&success);
case kSSEFloat32ToUint32:
__ Cvttss2ui(i.OutputRegister(), i.InputOperand(0), kScratchDoubleReg);
break;
}
case kSSEFloat64ToInt32:
__ cvttsd2si(i.OutputRegister(), i.InputOperand(0));
break;
case kSSEFloat64ToUint32: {
__ Move(kScratchDoubleReg, -2147483648.0);
__ addsd(kScratchDoubleReg, i.InputOperand(0));
__ cvttsd2si(i.OutputRegister(), kScratchDoubleReg);
__ add(i.OutputRegister(), Immediate(0x80000000));
case kSSEFloat64ToUint32:
__ Cvttsd2ui(i.OutputRegister(), i.InputOperand(0), kScratchDoubleReg);
break;
}
case kSSEInt32ToFloat32:
__ cvtsi2ss(i.OutputDoubleRegister(), i.InputOperand(0));
break;
......@@ -1387,7 +1374,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
__ cvtsi2sd(i.OutputDoubleRegister(), i.InputOperand(0));
break;
case kSSEUint32ToFloat64:
__ LoadUint32(i.OutputDoubleRegister(), i.InputOperand(0));
__ Cvtui2sd(i.OutputDoubleRegister(), i.InputOperand(0));
break;
case kSSEFloat64ExtractLowWord32:
if (instr->InputAt(0)->IsFPStackSlot()) {
......
......@@ -188,17 +188,6 @@ void MacroAssembler::DoubleToI(Register result_reg, XMMRegister input_reg,
j(parity_even, is_nan, dst);
}
void TurboAssembler::LoadUint32(XMMRegister dst, Operand src) {
Label done;
cmp(src, Immediate(0));
ExternalReference uint32_bias =
ExternalReference::address_of_uint32_bias(isolate());
Cvtsi2sd(dst, src);
j(not_sign, &done, Label::kNear);
addsd(dst, Operand::StaticVariable(uint32_bias));
bind(&done);
}
void MacroAssembler::RecordWriteField(Register object, int offset,
Register value, Register dst,
SaveFPRegsMode save_fp,
......@@ -365,18 +354,23 @@ void MacroAssembler::MaybeDropFrames() {
RelocInfo::CODE_TARGET);
}
void TurboAssembler::Cvtsi2sd(XMMRegister dst, Operand src) {
void TurboAssembler::Cvtsi2ss(XMMRegister dst, Operand src) {
xorps(dst, dst);
cvtsi2ss(dst, src);
}
void TurboAssembler::Cvtsi2sd(XMMRegister dst, Operand src) {
xorpd(dst, dst);
cvtsi2sd(dst, src);
}
void TurboAssembler::Cvtui2ss(XMMRegister dst, Register src, Register tmp) {
Label msb_set_src;
Label jmp_return;
Label done;
test(src, src);
j(sign, &msb_set_src, Label::kNear);
cvtsi2ss(dst, src);
jmp(&jmp_return, Label::kNear);
jmp(&done, Label::kNear);
bind(&msb_set_src);
mov(tmp, src);
shr(src, 1);
......@@ -385,7 +379,37 @@ void TurboAssembler::Cvtui2ss(XMMRegister dst, Register src, Register tmp) {
or_(src, tmp);
cvtsi2ss(dst, src);
addss(dst, dst);
bind(&jmp_return);
bind(&done);
}
void TurboAssembler::Cvttss2ui(Register dst, Operand src, XMMRegister tmp) {
Label done;
cvttss2si(dst, src);
test(dst, dst);
j(positive, &done);
Move(tmp, static_cast<float>(INT32_MIN));
addss(tmp, src);
cvttss2si(dst, tmp);
or_(dst, Immediate(0x80000000));
bind(&done);
}
void TurboAssembler::Cvtui2sd(XMMRegister dst, Operand src) {
Label done;
cmp(src, Immediate(0));
ExternalReference uint32_bias =
ExternalReference::address_of_uint32_bias(isolate());
Cvtsi2sd(dst, src);
j(not_sign, &done, Label::kNear);
addsd(dst, Operand::StaticVariable(uint32_bias));
bind(&done);
}
void TurboAssembler::Cvttsd2ui(Register dst, Operand src, XMMRegister tmp) {
Move(tmp, -2147483648.0);
addsd(tmp, src);
cvttsd2si(dst, tmp);
add(dst, Immediate(0x80000000));
}
void TurboAssembler::ShlPair(Register high, Register low, uint8_t shift) {
......
......@@ -285,19 +285,26 @@ class TurboAssembler : public Assembler {
void Pinsrd(XMMRegister dst, Operand src, int8_t imm8,
bool is_64_bits = false);
void LoadUint32(XMMRegister dst, Register src) {
LoadUint32(dst, Operand(src));
}
void LoadUint32(XMMRegister dst, Operand src);
// Expression support
// cvtsi2sd instruction only writes to the low 64-bit of dst register, which
// hinders register renaming and makes dependence chains longer. So we use
// xorps to clear the dst register before cvtsi2sd to solve this issue.
void Cvtsi2ss(XMMRegister dst, Register src) { Cvtsi2ss(dst, Operand(src)); }
void Cvtsi2ss(XMMRegister dst, Operand src);
void Cvtsi2sd(XMMRegister dst, Register src) { Cvtsi2sd(dst, Operand(src)); }
void Cvtsi2sd(XMMRegister dst, Operand src);
void Cvtui2ss(XMMRegister dst, Register src, Register tmp);
void Cvttss2ui(Register dst, XMMRegister src, XMMRegister tmp) {
Cvttss2ui(dst, Operand(src), tmp);
}
void Cvttss2ui(Register dst, Operand src, XMMRegister tmp);
void Cvtui2sd(XMMRegister dst, Register src) { Cvtui2sd(dst, Operand(src)); }
void Cvtui2sd(XMMRegister dst, Operand src);
void Cvttsd2ui(Register dst, XMMRegister src, XMMRegister tmp) {
Cvttsd2ui(dst, Operand(src), tmp);
}
void Cvttsd2ui(Register dst, Operand src, XMMRegister tmp);
void Push(Register src) { push(src); }
void Push(Operand src) { push(src); }
......
......@@ -964,7 +964,7 @@ bool LiftoffAssembler::emit_type_conversion(WasmOpcode opcode,
Cvtsi2sd(dst.fp(), src.gp());
return true;
case kExprF64UConvertI32:
LoadUint32(dst.fp(), src.gp());
Cvtui2sd(dst.fp(), src.gp());
return true;
case kExprF64ConvertF32:
cvtss2sd(dst.fp(), src.fp());
......
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