3#include "native/isa_import.h"
4#include "native/config.h"
6#include "native/targets.h"
10namespace native::detail {
12 hint_inline hint_target(
"jsconv") std::int32_t jcvt_runtime(
double value) noexcept {
16 asm volatile(
"fjcvtzs %w0, %d1" :
"=r"(result) :
"w"(value));
25namespace native::detail {
26 constexpr std::int32_t jcvt_constant(
double value)
noexcept {
27 auto bits = std::bit_cast<std::uint64_t>(value);
28 auto exponent = unsigned((bits >> 52) & 0x7ff);
30 if (exponent == 0x7ff || exponent < 1023)
return 0;
31 int shift = int(exponent) - 1023 - 52;
32 if (shift >= 32)
return 0;
33 auto significand = (bits & 0x000fffffffffffffULL) | 0x0010000000000000ULL;
34 auto result = shift >= 0 ? std::uint32_t(significand) << shift
35 : std::uint32_t(significand >> -shift);
36 if (bits >> 63) result = std::uint32_t(0) - result;
37 return std::bit_cast<std::int32_t>(result);
41#if NATIVE_HOST_NEON || defined(NATIVE_DOXYGEN)
51 template<isa<arm> Arch = NATIVE_BA
SELINE>
requires(Arch.has(arm_feature::jsconv))
52 [[nodiscard]] hint_inline hint_target(
"jsconv") constexpr std::int32_t
53 jcvt(
double value) noexcept {
55 return detail::jcvt_constant(value);
57 return detail::jcvt_runtime(value);
62 template<isa<arm> Arch = NATIVE_BA
SELINE>
requires(!Arch.has(polyfill) && !Arch.has(arm_feature::jsconv))
63 [[nodiscard]]
consteval std::int32_t
jcvt(
double value)
noexcept {
64 return detail::jcvt_constant(value);
68 template<isa<arm> Arch = NATIVE_BA
SELINE>
requires(Arch.has(polyfill) && !Arch.has(arm_feature::jsconv))
69 [[nodiscard]]
constexpr std::int32_t
jcvt(
double value)
noexcept {
70 return detail::jcvt_constant(value);
constexpr std::int32_t jcvt(double value) noexcept
Convert a double using FJCVTZS; requires the jsconv feature and matching compiler target.
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...