LibJS: Make use of arm64 FJCVTZS instruction if available
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

FJCVTZS (Floating-point Javascript Convert to Signed fixed-point,
rounding toward Zero) does exactly what we need for ToInt32 in the
JavaScript specification.

This isn't world-changing, but it does give a ~2% boost on compute-
heavy benchmarks like JetStream, so we should obviously use it.
This commit is contained in:
Andreas Kling 2025-04-09 12:33:38 +02:00 committed by Andreas Kling
parent 938b1e91fe
commit 8c8023465b
Notes: github-actions[bot] 2025-04-09 20:07:43 +00:00
2 changed files with 9 additions and 0 deletions

View file

@ -934,6 +934,9 @@ ThrowCompletionOr<i32> Value::to_i32_slow_case(VM& vm) const
// 1. Let number be ? ToNumber(argument).
double number = TRY(to_number(vm)).as_double();
#if __has_builtin(__builtin_arm_jcvt)
return __builtin_arm_jcvt(number);
#else
// 2. If number is not finite or number is either +0𝔽 or -0𝔽, return +0𝔽.
if (!isfinite(number) || number == 0)
return 0;
@ -951,6 +954,7 @@ ThrowCompletionOr<i32> Value::to_i32_slow_case(VM& vm) const
if (int32bit >= 2147483648.0)
int32bit -= 4294967296.0;
return static_cast<i32>(int32bit);
#endif
}
// 7.1.8 ToInt16 ( argument ), https://tc39.es/ecma262/#sec-toint16

View file

@ -54,6 +54,11 @@ inline ThrowCompletionOr<i32> Value::to_i32(VM& vm) const
if (is_int32())
return as_i32();
#if __has_builtin(__builtin_arm_jcvt)
if (is_double())
return __builtin_arm_jcvt(m_value.as_double);
#endif
return to_i32_slow_case(vm);
}