Commit 68105996 authored by Milad Fa's avatar Milad Fa Committed by Commit Bot

[wasm-simd] Retrieve the value of SupportsWasmSimd128() in builtin

WasmCompileLazy needs to save the content of vector
parameter registers. If Simd is not enabled or the hardware
does not support Simd operations then we need to saves the value of
Double registers instead, therefore we need a way to retrieve the
value of "CpuFeatures::SupportsWasmSimd128()" in builtins
during runtime.

Bug: v8:11377
Change-Id: I74a5f870d7077166548472adb25c3fb06d0ebdb9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2679682Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Reviewed-by: 's avatarZhi An Ng <zhin@chromium.org>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/master@{#72584}
parent 5e568739
......@@ -2461,7 +2461,24 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
NumRegs(fp_regs),
"frame size mismatch");
__ MultiPush(gp_regs);
// Check if machine has simd enabled, if so push vector registers. If not
// then only push double registers.
Label push_doubles, simd_pushed;
__ Move(r1, ExternalReference::supports_wasm_simd_128_address());
__ LoadU8(r1, MemOperand(r1));
__ LoadAndTestP(r1, r1); // If > 0 then simd is available.
__ ble(&push_doubles, Label::kNear);
// Save vector registers, don't save double registers anymore.
__ MultiPushV128(fp_regs);
__ b(&simd_pushed);
__ bind(&push_doubles);
// Simd not supported, only save double registers.
__ MultiPushDoubles(fp_regs);
// kFixedFrameSizeFromFp is hard coded to include space for Simd
// registers, so we still need to allocate extra (unused) space on the stack
// as if they were saved.
__ lay(sp, MemOperand(sp, -(NumRegs(fp_regs) * kDoubleSize)));
__ bind(&simd_pushed);
// Pass instance and function index as explicit arguments to the runtime
// function.
......@@ -2474,7 +2491,19 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ mov(ip, r2);
// Restore registers.
__ Move(r1, ExternalReference::supports_wasm_simd_128_address());
__ LoadU8(r1, MemOperand(r1));
Label pop_doubles, simd_popped;
__ LoadAndTestP(r1, r1); // If > 0 then simd is available.
__ ble(&pop_doubles, Label::kNear);
// Pop vector registers, don't pop double registers anymore.
__ MultiPopV128(fp_regs);
__ b(&simd_popped);
__ bind(&pop_doubles);
// Simd not supported, only pop double registers.
__ lay(sp, MemOperand(sp, NumRegs(fp_regs) * kDoubleSize));
__ MultiPopDoubles(fp_regs);
__ bind(&simd_popped);
__ MultiPop(gp_regs);
}
// Finally, jump to the entrypoint.
......
......@@ -248,6 +248,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
DCHECK_IMPLIES(IsSupported(ARMv7_SUDIV), IsSupported(ARMv7));
DCHECK_IMPLIES(IsSupported(ARMv8), IsSupported(ARMv7_SUDIV));
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {
......
......@@ -110,6 +110,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
supported_ |= CpuFeaturesFromCompiler();
supported_ |= runtime;
#endif // USE_SIMULATOR
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {}
......
......@@ -181,6 +181,7 @@ CpuFeatureScope::~CpuFeatureScope() {
#endif
bool CpuFeatures::initialized_ = false;
bool CpuFeatures::supports_wasm_simd_128_ = false;
unsigned CpuFeatures::supported_ = 0;
unsigned CpuFeatures::icache_line_size_ = 0;
unsigned CpuFeatures::dcache_line_size_ = 0;
......
......@@ -133,6 +133,10 @@ class V8_EXPORT_PRIVATE CpuFeatures : public AllStatic {
static unsigned icache_line_size_;
static unsigned dcache_line_size_;
static bool initialized_;
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
static bool supports_wasm_simd_128_;
};
} // namespace internal
......
......@@ -612,6 +612,11 @@ ExternalReference::address_of_wasm_f64x2_convert_low_i32x4_u_int_mask() {
reinterpret_cast<Address>(&wasm_f64x2_convert_low_i32x4_u_int_mask));
}
ExternalReference ExternalReference::supports_wasm_simd_128_address() {
return ExternalReference(
reinterpret_cast<Address>(&CpuFeatures::supports_wasm_simd_128_));
}
ExternalReference ExternalReference::address_of_wasm_double_2_power_52() {
return ExternalReference(reinterpret_cast<Address>(&wasm_double_2_power_52));
}
......
......@@ -245,6 +245,7 @@ class StatsCounter;
V(wasm_memory_fill, "wasm::memory_fill") \
V(address_of_wasm_f64x2_convert_low_i32x4_u_int_mask, \
"wasm_f64x2_convert_low_i32x4_u_int_mask") \
V(supports_wasm_simd_128_address, "wasm::supports_wasm_simd_128_address") \
V(address_of_wasm_double_2_power_52, "wasm_double_2_power_52") \
V(address_of_wasm_int32_max_as_double, "wasm_int32_max_as_double") \
V(address_of_wasm_uint32_max_as_double, "wasm_uint32_max_as_double") \
......
......@@ -153,6 +153,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
} else if (strcmp(FLAG_mcpu, "atom") == 0) {
supported_ |= 1u << ATOM;
}
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {}
......
......@@ -115,6 +115,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
}
#endif
#endif
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {}
......
......@@ -91,6 +91,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
if (cpu.has_msa()) supported_ |= 1u << MIPS_SIMD;
#endif
#endif
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {}
......
......@@ -110,6 +110,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
supported_ |= (1u << FPR_GPR_MOV);
#endif
#endif
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {
......
......@@ -241,6 +241,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
supported_ |= (1u << VECTOR_ENHANCE_FACILITY_1);
#endif
supported_ |= (1u << FPU);
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {
......
......@@ -108,6 +108,12 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
} else if (strcmp(FLAG_mcpu, "atom") == 0) {
supported_ |= 1u << ATOM;
}
// Set a static value on whether Simd is supported.
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
}
void CpuFeatures::PrintTarget() {}
......
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