native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.arm.jscvt.ccm
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2module;
3#include "native/isa_import.h"
4#include "native/config.h"
5#include <hint.h>
6#include "native/targets.h"
7#include <bit>
8#include <cstdint>
9
10namespace native::detail {
11#if NATIVE_HOST_NEON
12 hint_inline hint_target("jsconv") std::int32_t jcvt_runtime(double value) noexcept {
13 // Clang gates its builtin on all of v8.3a, not jsconv alone. Keep assembly
14 // outside the exported template so importing it needs no asm substitution.
15 std::int32_t result;
16 asm volatile("fjcvtzs %w0, %d1" : "=r"(result) : "w"(value));
17 return result;
18 }
19#endif
20}
21
22export module native.arm.jscvt;
23export import native.arm.features;
24
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);
29 // NaNs, infinities, zeros and magnitudes below one all convert to zero.
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);
38 }
39}
40
41#if NATIVE_HOST_NEON || defined(NATIVE_DOXYGEN)
42export namespace native {
49
51 template<isa<arm> Arch = NATIVE_BASELINE> requires(Arch.has(arm_feature::jsconv))
52 [[nodiscard]] hint_inline hint_target("jsconv") constexpr std::int32_t
53 jcvt(double value) noexcept {
54 if consteval {
55 return detail::jcvt_constant(value);
56 } else {
57 return detail::jcvt_runtime(value);
58 }
59 }
60
62 template<isa<arm> Arch = NATIVE_BASELINE> 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);
65 }
66
68 template<isa<arm> Arch = NATIVE_BASELINE> 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);
71 }
72
73}
74#endif
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...