native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.math.ccm
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2module;
3#include "native/isa_import.h"
4import native.simd;
5#include <native/simd/math/exp.h>
6#include <native/simd/math/bits.h>
7#if NATIVE_HOST_X86
8#include "native/exp_policies.h"
9#endif
10export module native.math;
11export import native.simd;
12// SPDX-FileCopyrightText: 2026 Edward Kmett <ekmett@gmail.com>
13// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
14// Included in the hub purview after the separately owned wide module is imported.
15#if NATIVE_HOST_X86
16export namespace native {
20#define NATIVE_EMIT_WIDE_EXP(i,name) \
21 NATIVE_TARGET_PUSH(name) \
22 template<bool Flush=false,unsigned Degree=6,std::size_t L,std::size_t N,isa<> Arch> \
23 requires (Degree >= 1 && Degree <= 7) && (detail::exp_target<Arch> == i) && \
24 requires(std::array<simd<float,L,Arch>,N> const & x) { ::native::exp<Flush,Degree>(x); } \
25 native_nodiscard native_inline constexpr wide<simd<float,L,Arch>,N> \
26 exp(wide<simd<float,L,Arch>,N> const & input) \
27 noexcept(noexcept(wide<simd<float,L,Arch>,N>{::native::exp<Flush,Degree>(input.registers)})) { \
28 return wide<simd<float,L,Arch>,N>{::native::exp<Flush,Degree>(input.registers)}; \
29 } \
30 NATIVE_TARGET_POP()
31 NATIVE_EXP_TARGETS(NATIVE_EMIT_WIDE_EXP)
32#undef NATIVE_EMIT_WIDE_EXP
33}
34#endif
35// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
36export namespace math {
37 using ::native::exp_width;
38 using ::native::exp2_width;
39 using ::native::expm1_width;
41 using ::native::log_width;
42 using ::native::log2_width;
43 using ::native::log1p_width;
44 using ::native::tanh_width;
45 using ::native::atan2_width;
47 using ::native::sin_width;
48 using ::native::cos_width;
49 using ::math::horner;
50 using ::math::exp;
51 using ::math::exp2;
52 using ::math::expm1;
53 using ::math::damping_gain;
54 using ::math::log;
55 using ::math::log2;
56 using ::math::log1p;
57 using ::math::tanh;
58 using ::math::atan2;
59 using ::math::sin;
60 using ::math::cos;
61 using ::math::sincos;
62 using ::math::flush_to_zero;
63 using ::math::abs;
64 using ::math::sqrt;
65 using ::math::floor;
66 using ::math::ceil;
67 using ::math::trunc;
68 using ::math::round_even;
69}
70export namespace wide {
71 using ::wide::horner;
72 using ::wide::constant_like;
73 using ::wide::add;
74 using ::wide::sub;
75 using ::wide::negate;
76 using ::wide::mul;
77 using ::wide::div;
78 using ::wide::bit_and;
79 using ::wide::bit_or;
80 using ::wide::bit_xor;
81 using ::wide::bit_not;
82 using ::wide::cmp_eq;
83 using ::wide::cmp_ne;
84 using ::wide::cmp_lt;
85 using ::wide::cmp_le;
86 using ::wide::cmp_gt;
87 using ::wide::cmp_ge;
88 using ::wide::mask_not;
89 using ::wide::min;
90 using ::wide::max;
91 using ::wide::abs;
92 using ::wide::sqrt;
93 using ::wide::floor;
94 using ::wide::ceil;
95 using ::wide::trunc;
96 using ::wide::round_even;
98 using ::wide::fma;
100 using ::wide::select;
101 using ::wide::scaleb;
103 using ::wide::masked_scaleb;
105 using ::wide::masked_scaleb_zero;
106 using ::wide::bits;
107 using ::wide::from_bits;
109 using ::wide::mask_bits;
111 using ::wide::left;
112 using ::wide::right;
113 using ::wide::exp;
114 using ::wide::exp2;
115 using ::wide::expm1;
116 using ::wide::damping_gain;
117 using ::wide::log;
118 using ::wide::log2;
119 using ::wide::log1p;
120 using ::wide::tanh;
121 using ::wide::atan2;
122 using ::wide::sin;
123 using ::wide::cos;
124 using ::wide::sincos;
125 using ::wide::flush_to_zero;
126}
127
128export namespace native {
129 using ::native::exp_width;
130 using ::native::exp2_width;
131 using ::native::expm1_width;
133 using ::native::log_width;
134 using ::native::log2_width;
135 using ::native::log1p_width;
136 using ::native::tanh_width;
137 using ::native::atan2_width;
138 using ::native::sincos_width;
139 using ::native::sin_width;
140 using ::native::cos_width;
141 using ::native::sin;
142 using ::native::cos;
143 using ::native::sincos;
144 using ::native::exp;
145 using ::native::exp2;
146 using ::native::expm1;
147 using ::native::damping_gain;
148 using ::native::log;
149 using ::native::log2;
150 using ::native::log1p;
151 using ::native::tanh;
152 using ::native::atan2;
153 namespace math {
154 using ::native::exp_width;
155 using ::native::exp2_width;
156 using ::native::expm1_width;
158 using ::native::log_width;
159 using ::native::log2_width;
160 using ::native::log1p_width;
161 using ::native::tanh_width;
162 using ::native::atan2_width;
163 using ::native::sincos_width;
164 using ::native::sin_width;
165 using ::native::cos_width;
166 using ::native::abs;
167 using ::native::cos;
168 using ::native::exp;
169 using ::native::exp2;
170 using ::native::expm1;
171 using ::native::damping_gain;
172 using ::native::fma;
173 using ::native::log;
174 using ::native::log2;
175 using ::native::log1p;
176 using ::native::sin;
177 using ::native::sincos;
178 using ::native::sqrt;
179 using ::native::floor;
180 using ::native::ceil;
181 using ::native::trunc;
182 using ::native::tanh;
183 using ::native::atan2;
184 }
185}
constexpr simd< float, L, Arch > atan2(simd< float, L, Arch > y, simd< float, L, Arch > x) noexcept
Definition exp_body.h:91
constexpr simd< float, N, Arch > ceil(simd< float, N, Arch > x) noexcept
constexpr simd< float, L, Arch > exp2(simd< float, L, Arch > input) noexcept
Definition exp_body.h:65
constexpr auto abs(simd< float, N, Arch > a) noexcept
constexpr simd< float, N, Arch > trunc(simd< float, N, Arch > x) noexcept
constexpr simd< float, L, Arch > exp(simd< float, L, Arch > input) noexcept
Evaluate the binary32 range-reduced exponential approximation. Degree selects a polynomial from one t...
Definition exp_body.h:109
constexpr simd< float, N, Arch > floor(simd< float, N, Arch > x) noexcept
constexpr auto sincos(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &x) { detail::wide_generic_detail::adl_sincos(x);}) return noexcept(detail::wide_generic_detail::adl_sincos(std::declval< std::array< R, N > const & >())) &&std::is_nothrow_move_constructible_v< std::array< R, N > >;else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||(noexcept(detail::wide_generic_detail::adl_sincos(std::declval< R const & >())) &&noexcept(std::declval< R & >()=std::declval< decltype(detail::wide_generic_detail::adl_sincos(std::declval< R const & >())) & >().first) &&noexcept(std::declval< R & >()=std::declval< decltype(detail::wide_generic_detail::adl_sincos(std::declval< R const & >())) & >().second)));}())
Definition wide.h:1263
constexpr wide< R, N > cos(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_cos(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_cos(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_cos(std::declval< R const & >())));}())
Definition wide.h:1024
constexpr wide< R, N > tanh(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_tanh(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_tanh(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_tanh(std::declval< R const & >())));}())
Definition wide.h:1193
constexpr wide< R, N > sin(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_sin(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_sin(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_sin(std::declval< R const & >())));}())
Definition wide.h:1003
constexpr wide< R, N > log(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_log(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_log(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_log(std::declval< R const & >())));}())
Definition wide.h:1130
constexpr wide< R, N > log2(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_log2(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_log2(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_log2(std::declval< R const & >())));}())
Definition wide.h:1151
constexpr wide< R, N > damping_gain(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_damping_gain(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_damping_gain(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_damping_gain(std::declval< R const & >())));}())
Definition wide.h:1109
constexpr wide< R, N > expm1(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_expm1(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_expm1(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_expm1(std::declval< R const & >())));}())
Definition wide.h:1088
constexpr wide< R, N > log1p(wide< R, N > const &input) noexcept([] { if constexpr(requires(std::array< R, N > const &a) { detail::wide_generic_detail::adl_log1p(a);}) return noexcept(wide< R, N >{detail::wide_generic_detail::adl_log1p(std::declval< std::array< R, N > const & >())});else return noexcept(wide< R, N >()) &&std::is_nothrow_move_constructible_v< wide< R, N > > &&(N==0||noexcept(std::declval< R & >()=detail::wide_generic_detail::adl_log1p(std::declval< R const & >())));}())
Definition wide.h:1172
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
constexpr std::size_t sin_width
Suggested sine register count, matching the paired trigonometric kernel.
Definition wide_math.h:86
constexpr simd< T, N, A > sqrt(simd< T, N, A > v) noexcept
Compute correctly rounded square roots; negative finite lanes produce NaN.
constexpr std::size_t log_width
Conservative independent register count for the logarithm kernel.
Definition wide_math.h:59
constexpr std::size_t cos_width
Suggested cosine register count, matching the paired trigonometric kernel.
Definition wide_math.h:90
constexpr simd< fp16, 32, Arch > fma(simd< fp16, 32, Arch > a, simd< fp16, 32, Arch > b, simd< fp16, 32, Arch > c) noexcept
constexpr std::size_t log1p_width
Conservative independent register count for cancellation-safe log1p.
Definition wide_math.h:67
constexpr std::size_t damping_gain_width
Suggested damping_gain register count, matching its expm1 graph.
Definition wide_math.h:55
constexpr std::size_t atan2_width
Definition wide_math.h:76
constexpr std::size_t log2_width
Suggested log2 register count, matching the logarithm recommendation.
Definition wide_math.h:63
constexpr std::size_t exp2_width
Recommended exp2 register count; its shorter reduction favors small batches.
Definition wide_math.h:47
constexpr std::size_t expm1_width
Conservative independent register count for cancellation-safe expm1.
Definition wide_math.h:51
constexpr std::size_t tanh_width
Conservative independent register count for tanh's table and polynomial.
Definition wide_math.h:71
constexpr std::size_t exp_width
Definition wide_math.h:38
constexpr std::size_t sincos_width
Recommended independent register count for paired sine and cosine.
Definition wide_math.h:80