Commit baae7a03 authored by akos.palfi's avatar akos.palfi Committed by Commit bot

MIPS64: [turbofan] Implemented the TruncateFloat32ToUint64 TurboFan operator.

Port 68cc0be2

Original commit message:
The TruncateFloat32ToUint64 operator converts a float32 to an uint64 using
round-to-zero rounding mode. If the input value is outside uint64 range, then
the result depends on the architecture. I provide an implementation for x64 and
arm64.

BUG=

Review URL: https://codereview.chromium.org/1481093003

Cr-Commit-Position: refs/heads/master@{#32383}
parent 970a7ad7
......@@ -1035,6 +1035,12 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
__ Trunc_uw_d(i.InputDoubleRegister(0), i.OutputRegister(), scratch);
break;
}
case kMips64TruncUlS: {
FPURegister scratch = kScratchDoubleReg;
// TODO(plind): Fix wrong param order of Trunc_ul_s() macro-asm function.
__ Trunc_ul_s(i.InputDoubleRegister(0), i.OutputRegister(), scratch);
break;
}
case kMips64TruncUlD: {
FPURegister scratch = kScratchDoubleReg;
// TODO(plind): Fix wrong param order of Trunc_ul_d() macro-asm function.
......
......@@ -82,6 +82,7 @@ namespace compiler {
V(Mips64TruncLS) \
V(Mips64TruncLD) \
V(Mips64TruncUwD) \
V(Mips64TruncUlS) \
V(Mips64TruncUlD) \
V(Mips64CvtDW) \
V(Mips64CvtSL) \
......
......@@ -742,7 +742,7 @@ void InstructionSelector::VisitTruncateFloat64ToInt64(Node* node) {
void InstructionSelector::VisitTruncateFloat32ToUint64(Node* node) {
UNIMPLEMENTED();
VisitRR(this, kMips64TruncUlS, node);
}
......
......@@ -1628,6 +1628,13 @@ void MacroAssembler::Trunc_ul_d(FPURegister fd, FPURegister fs,
}
void MacroAssembler::Trunc_ul_s(FPURegister fd, FPURegister fs,
FPURegister scratch) {
Trunc_ul_s(fs, t8, scratch);
dmtc1(t8, fd);
}
void MacroAssembler::Trunc_w_d(FPURegister fd, FPURegister fs) {
trunc_w_d(fd, fs);
}
......@@ -1686,7 +1693,7 @@ void MacroAssembler::Trunc_ul_d(FPURegister fd, Register rs,
DCHECK(!fd.is(scratch));
DCHECK(!rs.is(at));
// Load 2^63 into scratch as its float representation.
// Load 2^63 into scratch as its double representation.
li(at, 0x43e0000000000000);
dmtc1(at, scratch);
......@@ -1712,6 +1719,37 @@ void MacroAssembler::Trunc_ul_d(FPURegister fd, Register rs,
}
void MacroAssembler::Trunc_ul_s(FPURegister fd, Register rs,
FPURegister scratch) {
DCHECK(!fd.is(scratch));
DCHECK(!rs.is(at));
// Load 2^63 into scratch as its float representation.
li(at, 0x5f000000);
dmtc1(at, scratch);
// Test if scratch > fd.
// If fd < 2^63 we can convert it normally.
Label simple_convert, done;
BranchF32(&simple_convert, NULL, lt, fd, scratch);
// First we subtract 2^63 from fd, then trunc it to rs
// and add 2^63 to rs.
sub_s(scratch, fd, scratch);
trunc_l_s(scratch, scratch);
dmfc1(rs, scratch);
Or(rs, rs, Operand(1UL << 63));
Branch(&done);
// Simple conversion.
bind(&simple_convert);
trunc_l_s(scratch, fd);
dmfc1(rs, scratch);
bind(&done);
}
void MacroAssembler::Madd_d(FPURegister fd, FPURegister fr, FPURegister fs,
FPURegister ft, FPURegister scratch) {
if (0) { // TODO(plind): find reasonable arch-variant symbol names.
......
......@@ -839,6 +839,10 @@ class MacroAssembler: public Assembler {
void Trunc_ul_d(FPURegister fd, FPURegister fs, FPURegister scratch);
void Trunc_ul_d(FPURegister fd, Register rs, FPURegister scratch);
// Convert single to unsigned long.
void Trunc_ul_s(FPURegister fd, FPURegister fs, FPURegister scratch);
void Trunc_ul_s(FPURegister fd, Register rs, FPURegister scratch);
void Trunc_w_d(FPURegister fd, FPURegister fs);
void Round_w_d(FPURegister fd, FPURegister fs);
void Floor_w_d(FPURegister fd, FPURegister fs);
......
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