Commit 669e9f05 authored by Zhao Jiazhong's avatar Zhao Jiazhong Committed by Commit Bot

[mips][wasm-simd][liftoff] Implement floating-point roundings

Port 7f654693
https://chromium-review.googlesource.com/c/v8/v8/+/2411691

Change-Id: I8b06288b003d99d1ee76415aee3fafd5cd963ae7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2415852
Commit-Queue: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarZhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69979}
parent 69951fa7
......@@ -2613,6 +2613,38 @@ void TurboAssembler::Round_s_s(FPURegister dst, FPURegister src) {
});
}
void TurboAssembler::MSARoundW(MSARegister dst, MSARegister src,
FPURoundingMode mode) {
BlockTrampolinePoolScope block_trampoline_pool(this);
Register scratch = t8;
Register scratch2 = at;
cfcmsa(scratch, MSACSR);
if (mode == kRoundToNearest) {
scratch2 = zero_reg;
} else {
li(scratch2, Operand(mode));
}
ctcmsa(MSACSR, scratch2);
frint_w(dst, src);
ctcmsa(MSACSR, scratch);
}
void TurboAssembler::MSARoundD(MSARegister dst, MSARegister src,
FPURoundingMode mode) {
BlockTrampolinePoolScope block_trampoline_pool(this);
Register scratch = t8;
Register scratch2 = at;
cfcmsa(scratch, MSACSR);
if (mode == kRoundToNearest) {
scratch2 = zero_reg;
} else {
li(scratch2, Operand(mode));
}
ctcmsa(MSACSR, scratch2);
frint_d(dst, src);
ctcmsa(MSACSR, scratch);
}
void MacroAssembler::Madd_s(FPURegister fd, FPURegister fr, FPURegister fs,
FPURegister ft, FPURegister scratch) {
DCHECK(fr != scratch && fs != scratch && ft != scratch);
......
......@@ -791,6 +791,9 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
void Floor_s_s(FPURegister fd, FPURegister fs);
void Ceil_s_s(FPURegister fd, FPURegister fs);
void MSARoundW(MSARegister dst, MSARegister src, FPURoundingMode mode);
void MSARoundD(MSARegister dst, MSARegister src, FPURoundingMode mode);
// Jump the register contains a smi.
void JumpIfSmi(Register value, Label* smi_label, Register scratch = at,
BranchDelaySlot bd = PROTECT);
......
......@@ -2305,38 +2305,26 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
}
case kMips64F64x2Ceil: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
__ li(kScratchReg2, kRoundToPlusInf);
__ ctcmsa(MSACSR, kScratchReg2);
__ frint_d(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundD(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToPlusInf);
break;
}
case kMips64F64x2Floor: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
__ li(kScratchReg2, kRoundToMinusInf);
__ ctcmsa(MSACSR, kScratchReg2);
__ frint_d(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundD(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToMinusInf);
break;
}
case kMips64F64x2Trunc: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
__ li(kScratchReg2, kRoundToZero);
__ ctcmsa(MSACSR, kScratchReg2);
__ frint_d(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundD(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToZero);
break;
}
case kMips64F64x2NearestInt: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
// kRoundToNearest == 0
__ ctcmsa(MSACSR, zero_reg);
__ frint_d(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundD(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToNearest);
break;
}
case kMips64I64x2ReplaceLane: {
......@@ -2677,38 +2665,26 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
}
case kMips64F32x4Ceil: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
__ li(kScratchReg2, kRoundToPlusInf);
__ ctcmsa(MSACSR, kScratchReg2);
__ frint_w(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundW(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToPlusInf);
break;
}
case kMips64F32x4Floor: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
__ li(kScratchReg2, kRoundToMinusInf);
__ ctcmsa(MSACSR, kScratchReg2);
__ frint_w(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundW(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToMinusInf);
break;
}
case kMips64F32x4Trunc: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
__ li(kScratchReg2, kRoundToZero);
__ ctcmsa(MSACSR, kScratchReg2);
__ frint_w(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundW(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToZero);
break;
}
case kMips64F32x4NearestInt: {
CpuFeatureScope msa_scope(tasm(), MIPS_SIMD);
__ cfcmsa(kScratchReg, MSACSR);
// kRoundToNearest == 0
__ ctcmsa(MSACSR, zero_reg);
__ frint_w(i.OutputSimd128Register(), i.InputSimd128Register(0));
__ ctcmsa(MSACSR, kScratchReg);
__ MSARoundW(i.OutputSimd128Register(), i.InputSimd128Register(0),
kRoundToNearest);
break;
}
case kMips64I32x4SConvertF32x4: {
......
......@@ -2214,6 +2214,26 @@ void LiftoffAssembler::emit_f32x4_sqrt(LiftoffRegister dst,
bailout(kSimd, "emit_f32x4_sqrt");
}
bool LiftoffAssembler::emit_f32x4_ceil(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
bool LiftoffAssembler::emit_f32x4_floor(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
bool LiftoffAssembler::emit_f32x4_trunc(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
bool LiftoffAssembler::emit_f32x4_nearest_int(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
void LiftoffAssembler::emit_f32x4_add(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs) {
bailout(kSimd, "emit_f32x4_add");
......@@ -2269,6 +2289,26 @@ void LiftoffAssembler::emit_f64x2_sqrt(LiftoffRegister dst,
bailout(kSimd, "emit_f64x2_sqrt");
}
bool LiftoffAssembler::emit_f64x2_ceil(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
bool LiftoffAssembler::emit_f64x2_floor(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
bool LiftoffAssembler::emit_f64x2_trunc(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
bool LiftoffAssembler::emit_f64x2_nearest_int(LiftoffRegister dst,
LiftoffRegister src) {
return false;
}
void LiftoffAssembler::emit_f64x2_add(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs) {
bailout(kSimd, "emit_f64x2_add");
......
......@@ -2202,6 +2202,30 @@ void LiftoffAssembler::emit_f32x4_sqrt(LiftoffRegister dst,
fsqrt_w(dst.fp().toW(), src.fp().toW());
}
bool LiftoffAssembler::emit_f32x4_ceil(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundW(dst.fp().toW(), src.fp().toW(), kRoundToPlusInf);
return true;
}
bool LiftoffAssembler::emit_f32x4_floor(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundW(dst.fp().toW(), src.fp().toW(), kRoundToMinusInf);
return true;
}
bool LiftoffAssembler::emit_f32x4_trunc(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundW(dst.fp().toW(), src.fp().toW(), kRoundToZero);
return true;
}
bool LiftoffAssembler::emit_f32x4_nearest_int(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundW(dst.fp().toW(), src.fp().toW(), kRoundToNearest);
return true;
}
void LiftoffAssembler::emit_f32x4_add(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs) {
fadd_w(dst.fp().toW(), lhs.fp().toW(), rhs.fp().toW());
......@@ -2297,6 +2321,30 @@ void LiftoffAssembler::emit_f64x2_sqrt(LiftoffRegister dst,
fsqrt_d(dst.fp().toW(), src.fp().toW());
}
bool LiftoffAssembler::emit_f64x2_ceil(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundD(dst.fp().toW(), src.fp().toW(), kRoundToPlusInf);
return true;
}
bool LiftoffAssembler::emit_f64x2_floor(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundD(dst.fp().toW(), src.fp().toW(), kRoundToMinusInf);
return true;
}
bool LiftoffAssembler::emit_f64x2_trunc(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundD(dst.fp().toW(), src.fp().toW(), kRoundToZero);
return true;
}
bool LiftoffAssembler::emit_f64x2_nearest_int(LiftoffRegister dst,
LiftoffRegister src) {
MSARoundD(dst.fp().toW(), src.fp().toW(), kRoundToNearest);
return true;
}
void LiftoffAssembler::emit_f64x2_add(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs) {
fadd_d(dst.fp().toW(), lhs.fp().toW(), rhs.fp().toW());
......
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