Skip to content

Commit

Permalink
deps: V8: cherry-pick eadaef581c29
Browse files Browse the repository at this point in the history
Original commit message:

    Fix usage of MulHighS64 on <= z13

    mgrk is only available with MISC_INSTR_EXT2 installed.
    A runtime call needs to be made if it's unavailable.
    We also need to make sure caller saved registers are saved
    accordingly before making a call.

    Change-Id: If7ac06eef57cc3db059c2640b77c80de3b16fced
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4521297
    Reviewed-by: Junliang Yan <[email protected]>
    Commit-Queue: Milad Farazmand <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#87675}

Fixes: #47064
  • Loading branch information
AdamMajer committed Aug 29, 2023
1 parent 9cd70f4 commit d0d2c65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.14',
'v8_embedder_string': '-node.15',

##### V8 defaults for Node.js #####

Expand Down
19 changes: 17 additions & 2 deletions deps/v8/src/codegen/s390/macro-assembler-s390.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2906,8 +2906,23 @@ void MacroAssembler::MulS64(Register dst, const MemOperand& opnd) {
}

void MacroAssembler::MulHighS64(Register dst, Register src1, Register src2) {
mgrk(r0, src1, src2);
lgr(dst, r0);
if (CpuFeatures::IsSupported(MISC_INSTR_EXT2)) {
mgrk(r0, src1, src2);
lgr(dst, r0);
} else {
SaveFPRegsMode fp_mode = SaveFPRegsMode::kSave;
PushCallerSaved(fp_mode, ip);
Push(src1, src2);
Pop(r2, r3);
{
FrameScope scope(this, StackFrame::INTERNAL);
PrepareCallCFunction(2, 0, r0);
CallCFunction(ExternalReference::int64_mul_high_function(), 2, 0);
}
mov(r0, r2);
PopCallerSaved(fp_mode, ip);
mov(dst, r0);
}
}

void MacroAssembler::MulHighS64(Register dst, Register src1,
Expand Down
28 changes: 9 additions & 19 deletions deps/v8/src/compiler/backend/s390/code-generator-s390.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1699,15 +1699,18 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kS390_Mul64WithOverflow: {
Register dst = i.OutputRegister(), src1 = i.InputRegister(0),
src2 = i.InputRegister(1);
DCHECK(!AreAliased(dst, src1, src2));
CHECK(!AreAliased(dst, src1, src2));
if (CpuFeatures::IsSupported(MISC_INSTR_EXT2)) {
__ msgrkc(dst, src1, src2);
} else {
__ mgrk(r0, src1, src2); // r0 = high 64-bits, r1 = low 64-bits.
__ lgr(dst, r1);
__ ShiftRightS64(r1, r1, Operand(63));
// Mul high.
__ MulHighS64(r1, src1, src2);
// Mul low.
__ mov(dst, src1);
__ MulS64(dst, src2);
// Test whether {high} is a sign-extension of {result}.
__ CmpU64(r0, r1);
__ ShiftRightS64(r0, dst, Operand(63));
__ CmpU64(r1, r0);
}
break;
}
Expand All @@ -1725,20 +1728,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
ASSEMBLE_BIN_OP(RRRInstr(MulHighU64), nullInstr, nullInstr);
break;
case kS390_MulHighS64:
if (CpuFeatures::IsSupported(MISC_INSTR_EXT2)) {
ASSEMBLE_BIN_OP(RRRInstr(MulHighS64), nullInstr, nullInstr);
} else {
__ Push(r2, r3, i.InputRegister(0), i.InputRegister(1));
__ Pop(r2, r3);
{
FrameScope scope(masm(), StackFrame::INTERNAL);
__ PrepareCallCFunction(2, 0, kScratchReg);
__ CallCFunction(ExternalReference::int64_mul_high_function(), 2, 0);
}
__ mov(kScratchReg, r2);
__ Pop(r2, r3);
__ mov(i.OutputRegister(), kScratchReg);
}
ASSEMBLE_BIN_OP(RRRInstr(MulHighS64), nullInstr, nullInstr);
break;
case kS390_MulFloat:
ASSEMBLE_BIN_OP(DDInstr(meebr), DMTInstr(MulFloat32), nullInstr);
Expand Down

0 comments on commit d0d2c65

Please sign in to comment.