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 "native/attributes.h"
6#include "native/targets.h"
7#include <bit>
8#include <cstdint>
9
10export module native.arm.jscvt;
11export import native.arm.features;
12
13namespace native::detail {
14 constexpr std::int32_t jcvt_constant(double value) noexcept {
15 auto bits = std::bit_cast<std::uint64_t>(value);
16 auto exponent = unsigned((bits >> 52) & 0x7ff);
17 // NaNs, infinities, zeros and magnitudes below one all convert to zero.
18 if (exponent == 0x7ff || exponent < 1023) return 0;
19 int shift = int(exponent) - 1023 - 52;
20 if (shift >= 32) return 0;
21 auto significand = (bits & 0x000fffffffffffffULL) | 0x0010000000000000ULL;
22 auto result = shift >= 0 ? std::uint32_t(significand) << shift
23 : std::uint32_t(significand >> -shift);
24 if (bits >> 63) result = std::uint32_t(0) - result;
25 return std::bit_cast<std::int32_t>(result);
26 }
27}
28
29#if NATIVE_HOST_NEON || defined(NATIVE_DOXYGEN)
30export namespace native {
37
39 template<isa<arm> Arch = NATIVE_BASELINE> requires(Arch.has(arm_feature::jsconv))
40 native_nodiscard native_inline native_target("jsconv") constexpr std::int32_t
41 jcvt(double value) noexcept {
42 if consteval {
43 return detail::jcvt_constant(value);
44 } else {
45 return __builtin_arm_jcvt(value);
46 }
47 }
48
50 template<isa<arm> Arch = NATIVE_BASELINE> requires(!Arch.has(arm_feature::jsconv))
51 native_nodiscard consteval std::int32_t jcvt(double value) noexcept {
52 return detail::jcvt_constant(value);
53 }
54
55}
56#endif
Compiler attributes for host code, with shader-safe shared modifiers.
constexpr std::int32_t jcvt(double value) noexcept
Convert a double using FJCVTZS; requires the jsconv feature and matching compiler target.
#define native_inline
inline [[always_inline]]
Definition attributes.h:212
#define native_nodiscard
C++17 [[nodiscard]].
Definition attributes.h:189
#define native_target(x)
this indicates a required feature set for the current multiversioned function.
Definition attributes.h:476
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...