From 7cd438c6d39a058096d6adb59940bbdfeebc3f47 Mon Sep 17 00:00:00 2001 From: Lu Yahan Date: Fri, 8 Oct 2021 10:46:08 +0800 Subject: [PATCH] [riscv64] Port [fastcall] Enable float support on arm64 Change-Id: Iba439f2de9da359baeebd23482880013939b3066 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3212059 Auto-Submit: Yahan Lu Reviewed-by: ji qiu Commit-Queue: Yahan Lu Commit-Queue: ji qiu Cr-Commit-Position: refs/heads/main@{#77294} --- .../backend/riscv64/code-generator-riscv64.cc | 7 ++++--- src/execution/riscv64/simulator-riscv64.cc | 16 ++++++++++++++-- .../baseline/riscv64/liftoff-assembler-riscv64.h | 8 +++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/compiler/backend/riscv64/code-generator-riscv64.cc b/src/compiler/backend/riscv64/code-generator-riscv64.cc index c95299ee1d..147541bee7 100644 --- a/src/compiler/backend/riscv64/code-generator-riscv64.cc +++ b/src/compiler/backend/riscv64/code-generator-riscv64.cc @@ -693,7 +693,8 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( AssemblePrepareTailCall(); break; case kArchCallCFunction: { - int const num_parameters = MiscField::decode(instr->opcode()); + int const num_gp_parameters = ParamField::decode(instr->opcode()); + int const num_fp_parameters = FPParamField::decode(instr->opcode()); Label after_call; bool isWasmCapiFunction = linkage()->GetIncomingDescriptor()->IsWasmCapiFunction(); @@ -705,10 +706,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( } if (instr->InputAt(0)->IsImmediate()) { ExternalReference ref = i.InputExternalReference(0); - __ CallCFunction(ref, num_parameters); + __ CallCFunction(ref, num_gp_parameters, num_fp_parameters); } else { Register func = i.InputOrZeroRegister(0); - __ CallCFunction(func, num_parameters); + __ CallCFunction(func, num_gp_parameters, num_fp_parameters); } __ bind(&after_call); if (isWasmCapiFunction) { diff --git a/src/execution/riscv64/simulator-riscv64.cc b/src/execution/riscv64/simulator-riscv64.cc index 4d289c4d20..8def955334 100644 --- a/src/execution/riscv64/simulator-riscv64.cc +++ b/src/execution/riscv64/simulator-riscv64.cc @@ -2218,8 +2218,20 @@ void Simulator::SoftwareInterrupt() { reinterpret_cast(external); target(arg0, arg1, Redirection::ReverseRedirection(arg2)); } else { - DCHECK(redirection->type() == ExternalReference::BUILTIN_CALL || - redirection->type() == ExternalReference::BUILTIN_CALL_PAIR); + DCHECK( + redirection->type() == ExternalReference::BUILTIN_CALL || + redirection->type() == ExternalReference::BUILTIN_CALL_PAIR || + // FAST_C_CALL is temporarily handled here as well, because we lack + // proper support for direct C calls with FP params in the simulator. + // The generic BUILTIN_CALL path assumes all parameters are passed in + // the GP registers, thus supporting calling the slow callback without + // crashing. The reason for that is that in the mjsunit tests we check + // the `fast_c_api.supports_fp_params` (which is false on + // non-simulator builds for arm/arm64), thus we expect that the slow + // path will be called. And since the slow path passes the arguments + // as a `const FunctionCallbackInfo&` (which is a GP argument), + // the call is made correctly. + redirection->type() == ExternalReference::FAST_C_CALL); SimulatorRuntimeCall target = reinterpret_cast(external); if (::v8::internal::FLAG_trace_sim) { diff --git a/src/wasm/baseline/riscv64/liftoff-assembler-riscv64.h b/src/wasm/baseline/riscv64/liftoff-assembler-riscv64.h index 616f10fa8f..6ac87a1f32 100644 --- a/src/wasm/baseline/riscv64/liftoff-assembler-riscv64.h +++ b/src/wasm/baseline/riscv64/liftoff-assembler-riscv64.h @@ -57,9 +57,10 @@ inline constexpr Condition ToCondition(LiftoffCondition liftoff_cond) { // -----+--------------------+ <-- frame ptr (fp) // -1 | 0xa: WASM | // -2 | instance | +// -3 | feedback vector| // -----+--------------------+--------------------------- -// -3 | slot 0 | ^ -// -4 | slot 1 | | +// -4 | slot 0 | ^ +// -5 | slot 1 | | // | | Frame slots // | | | // | | v @@ -68,7 +69,8 @@ inline constexpr Condition ToCondition(LiftoffCondition liftoff_cond) { // // fp-8 holds the stack marker, fp-16 is the instance parameter. -constexpr int kInstanceOffset = 16; +constexpr int kInstanceOffset = 2 * kSystemPointerSize; +constexpr int kFeedbackVectorOffset = 3 * kSystemPointerSize; inline MemOperand GetStackSlot(int offset) { return MemOperand(fp, -offset); }