Skip to content

Commit

Permalink
[fastapi] Add flag to disable float support in arm64 simulator
Browse files Browse the repository at this point in the history
As described in the referenced design doc, supporting fast API calls
with FP parameters in simulator builds is hard. The current
implementation in d8 is to provide a helper function for each API
function that takes all parameters as GP parameters and then converts
parameters to FP parameters where necessary.

This solution works nicely for testing fast API calls in d8, but it does
not work in blink where the helper functions don't exist. There were no
correctness tests with FP parameters in blink, though, so this problem
was not noticed until the revert of https://crrev.com/c/5721393.

With this CL we introduce a V8 flag that allows to enable FP parameters
in simulator builds. This flag is enabled in d8 tests explicitly.
However, by default the flag is disabled, and therefore also for blink
tests.

[email protected]

Doc: https://docs.google.com/document/d/1ZxOF3GSyNmtU0C0YJvrsydPJj35W_tTJZymeXwfDxoI
Bug: 41492790
Change-Id: If7354db172039081931c4ba8eccd33ea1e68127a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/ /5756568
Commit-Queue: Andreas Haas <[email protected]>
Reviewed-by: Nico Hartmann <[email protected]>
Cr-Commit-Position: refs/heads/main@{#95507}
  • Loading branch information
gahaas authored and V8 LUCI CQ committed Aug 6, 2024
1 parent 4184a3d commit 6c1f796
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/compiler/fast-api-calls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 123,14 @@ bool CanOptimizeFastSignature(const CFunctionInfo* c_signature) {
}
#endif

#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
if (!v8_flags.fast_api_allow_float_in_sim &&
(c_signature->ReturnInfo().GetType() == CTypeInfo::Type::kFloat32 ||
c_signature->ReturnInfo().GetType() == CTypeInfo::Type::kFloat64)) {
return false;
}
#endif

#ifndef V8_TARGET_ARCH_64_BIT
if (c_signature->ReturnInfo().GetType() == CTypeInfo::Type::kInt64 ||
c_signature->ReturnInfo().GetType() == CTypeInfo::Type::kUint64) {
Expand All @@ -148,6 156,14 @@ bool CanOptimizeFastSignature(const CFunctionInfo* c_signature) {
}
#endif

#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
if (!v8_flags.fast_api_allow_float_in_sim &&
(c_signature->ArgumentInfo(i).GetType() == CTypeInfo::Type::kFloat32 ||
c_signature->ArgumentInfo(i).GetType() == CTypeInfo::Type::kFloat64)) {
return false;
}
#endif

#ifndef V8_TARGET_ARCH_64_BIT
if (c_signature->ArgumentInfo(i).GetType() == CTypeInfo::Type::kInt64 ||
c_signature->ArgumentInfo(i).GetType() == CTypeInfo::Type::kUint64) {
Expand Down
4 changes: 4 additions & 0 deletions src/flags/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 1358,10 @@ DEFINE_BOOL(
stress_gc_during_compilation, false,
"simulate GC/compiler thread race related to https://crbug.com/v8/8520")
DEFINE_BOOL(turbo_fast_api_calls, true, "enable fast API calls from TurboFan")

DEFINE_BOOL(fast_api_allow_float_in_sim, false,
"allow float parameters to be passed in simulator mode")

#ifdef V8_USE_ZLIB
DEFINE_BOOL(turbo_compress_frame_translations, false,
"compress deoptimization frame translations (experimental)")
Expand Down
2 changes: 2 additions & 0 deletions test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28983,6 28983,7 @@ TEST(FastApiCalls) {
i::v8_flags.turbofan = true;
i::v8_flags.turbo_fast_api_calls = true;
i::v8_flags.allow_natives_syntax = true;
i::v8_flags.fast_api_allow_float_in_sim = true;
// Disable --always_turbofan, otherwise we haven't generated the necessary
// feedback to go down the "best optimization" path for the fast call.
i::v8_flags.always_turbofan = false;
Expand Down Expand Up @@ -29448,6 29449,7 @@ TEST(FastApiCallsFromWasm) {
i::v8_flags.wasm_fast_api = true;
i::v8_flags.turbo_fast_api_calls = true;
i::v8_flags.wasm_lazy_compilation = true;
i::v8_flags.fast_api_allow_float_in_sim = true;
i::FlagList::EnforceFlagImplications();

CcTest::InitializeVM();
Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

const fast_c_api = new d8.test.FastCAPI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

const fast_c_api = new d8.test.FastCAPI();

Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-calls-8args.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 13,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

const add_all_32bit_int_arg1 = -42;
const add_all_32bit_int_arg2 = 45;
Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-calls-pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

assertThrows(() => d8.test.FastCAPI());
const fast_c_api = new d8.test.FastCAPI();
Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-calls-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

assertThrows(() => d8.test.FastCAPI());
const fast_c_api = new d8.test.FastCAPI();
Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-calls-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,7 @@
// --wasm-lazy-compilation is needed so that wellknown imports work in the
// absence of dynamic tiering.
// Flags: --wasm-lazy-compilation
// Flags: --fast-api-allow-float-in-sim

load('test/mjsunit/wasm/wasm-module-builder.js');

Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-calls-wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@
// found in the LICENSE file.

// Flags: --turbo-fast-api-calls --expose-fast-api
// Flags: --fast-api-allow-float-in-sim

d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');

Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

assertThrows(() => d8.test.FastCAPI());
const fast_c_api = new d8.test.FastCAPI();
Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-clamp-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --enable-sse4-1 --enable-sse4-2
// Flags: --fast-api-allow-float-in-sim

const fast_c_api = new d8.test.FastCAPI();

Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-interface-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 7,7 @@
// Flags: --turbo-fast-api-calls --expose-fast-api --allow-natives-syntax --turbofan
// Flags: --no-always-turbofan
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

const fast_c_api = new d8.test.FastCAPI();
// We create another API object to avoid migrating the map of fast_c_api
Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-sequences-x64.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

d8.file.execute('test/mjsunit/compiler/fast-api-helpers.js');

Expand Down
1 change: 1 addition & 0 deletions test/mjsunit/compiler/fast-api-sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0
// Flags: --fast-api-allow-float-in-sim

d8.file.execute('test/mjsunit/compiler/fast-api-helpers.js');

Expand Down
2 changes: 1 addition & 1 deletion test/mjsunit/regress/regress-335548148.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,7 @@
// The test relies on optimizing/deoptimizing at predictable moments, so
// it's not suitable for deoptimization fuzzing.
// Flags: --deopt-every-n-times=0

// Flags: --fast-api-allow-float-in-sim

const __v_0 = new d8.test.FastCAPI();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@
// Flags: --turbo-fast-api-calls --expose-fast-api --no-liftoff --wasm-fast-api
// Flags: --turboshaft-wasm --wasm-lazy-compilation
// Flags: --no-wasm-native-module-cache-enabled
// Flags: --fast-api-allow-float-in-sim

d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,7 @@

// Flags: --turbo-fast-api-calls --expose-fast-api --no-liftoff --wasm-fast-api
// Flags: --turboshaft-wasm --wasm-lazy-compilation
// Flags: --fast-api-allow-float-in-sim

d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@
// Flags: --turbo-fast-api-calls --expose-fast-api --no-liftoff --wasm-fast-api
// Flags: --turboshaft-wasm --wasm-lazy-compilation
// Flags: --no-wasm-native-module-cache-enabled
// Flags: --fast-api-allow-float-in-sim

d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');

Expand Down

0 comments on commit 6c1f796

Please sign in to comment.