native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.math.ccm
1// SPDX-FileCopyrightText: 2026 Edward Kmett <ekmett@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
3module;
4#include "native/isa_import.h"
5import native.simd;
6#include <native/simd/math/exp.h>
7#include <native/simd/math/bits.h>
8#if NATIVE_HOST_X86
9#include "native/exp_policies.h"
10#endif
11export module native.math;
12export import native.simd;
13#if NATIVE_HOST_X86
14export namespace native {
18 // Pattern: [callback lists](README.md#callback-lists).
19#define NATIVE_EMIT_WIDE_EXP(i, name) \
20 NATIVE_TARGET_PUSH(name) \
21 template<bool Flush=false, unsigned Degree=6, std::size_t L, std::size_t N, isa<> Arch> \
22 requires (Degree >= 1 && Degree <= 7) && (detail::exp_target<Arch> == i) && \
23 requires(std::array<simd<float, L, Arch>, N> const & x) { ::native::exp<Flush, Degree>(x); } \
24 [[nodiscard]] hint_inline constexpr wide<simd<float, L, Arch>, N> \
25 exp(wide<simd<float, L, Arch>, N> const & input) \
26 noexcept(noexcept(wide<simd<float, L, Arch>, N>{::native::exp<Flush, Degree>(input.registers)})) { \
27 return wide<simd<float, L, Arch>, N>{::native::exp<Flush, Degree>(input.registers)}; \
28 } \
29 NATIVE_TARGET_POP()
30
31 NATIVE_EXP_TARGETS(NATIVE_EMIT_WIDE_EXP)
32#undef NATIVE_EMIT_WIDE_EXP
33}
34#endif
35export namespace math {
36 using ::native::exp_width;
37 using ::native::exp2_width;
38 using ::native::expm1_width;
40 using ::native::log_width;
41 using ::native::log2_width;
42 using ::native::log1p_width;
43 using ::native::tanh_width;
44 using ::native::atan2_width;
46 using ::native::sin_width;
47 using ::native::cos_width;
48 using ::math::horner;
49 using ::math::exp;
50 using ::math::exp2;
51 using ::math::expm1;
52 using ::math::damping_gain;
53 using ::math::log;
54 using ::math::log2;
55 using ::math::log1p;
56 using ::math::tanh;
57 using ::math::atan2;
58 using ::math::sin;
59 using ::math::cos;
60 using ::math::sincos;
61 using ::math::flush_to_zero;
62 using ::math::abs;
63 using ::math::sqrt;
64 using ::math::floor;
65 using ::math::ceil;
66 using ::math::trunc;
67 using ::math::round_even;
68}
69export namespace wide {
70 using ::wide::horner;
71 using ::wide::constant_like;
72 using ::wide::add;
73 using ::wide::sub;
74 using ::wide::negate;
75 using ::wide::mul;
76 using ::wide::div;
77 using ::wide::bit_and;
78 using ::wide::bit_or;
79 using ::wide::bit_xor;
80 using ::wide::bit_not;
81 using ::wide::cmp_eq;
82 using ::wide::cmp_ne;
83 using ::wide::cmp_lt;
84 using ::wide::cmp_le;
85 using ::wide::cmp_gt;
86 using ::wide::cmp_ge;
87 using ::wide::mask_not;
88 using ::wide::min;
89 using ::wide::max;
90 using ::wide::abs;
91 using ::wide::sqrt;
92 using ::wide::floor;
93 using ::wide::ceil;
94 using ::wide::trunc;
95 using ::wide::round_even;
97 using ::wide::fma;
99 using ::wide::select;
100 using ::wide::scaleb;
102 using ::wide::masked_scaleb;
104 using ::wide::masked_scaleb_zero;
105 using ::wide::bits;
106 using ::wide::from_bits;
108 using ::wide::mask_bits;
110 using ::wide::left;
111 using ::wide::right;
112 using ::wide::exp;
113 using ::wide::exp2;
114 using ::wide::expm1;
115 using ::wide::damping_gain;
116 using ::wide::log;
117 using ::wide::log2;
118 using ::wide::log1p;
119 using ::wide::tanh;
120 using ::wide::atan2;
121 using ::wide::sin;
122 using ::wide::cos;
123 using ::wide::sincos;
124 using ::wide::flush_to_zero;
125}
126
127export namespace native {
128 using ::native::exp_width;
129 using ::native::exp2_width;
130 using ::native::expm1_width;
132 using ::native::log_width;
133 using ::native::log2_width;
134 using ::native::log1p_width;
135 using ::native::tanh_width;
136 using ::native::atan2_width;
137 using ::native::sincos_width;
138 using ::native::sin_width;
139 using ::native::cos_width;
140 using ::native::sin;
141 using ::native::cos;
142 using ::native::sincos;
143 using ::native::exp;
144 using ::native::exp2;
145 using ::native::expm1;
146 using ::native::damping_gain;
147 using ::native::log;
148 using ::native::log2;
149 using ::native::log1p;
150 using ::native::tanh;
151 using ::native::atan2;
152 namespace math {
153 using ::native::exp_width;
154 using ::native::exp2_width;
155 using ::native::expm1_width;
157 using ::native::log_width;
158 using ::native::log2_width;
159 using ::native::log1p_width;
160 using ::native::tanh_width;
161 using ::native::atan2_width;
162 using ::native::sincos_width;
163 using ::native::sin_width;
164 using ::native::cos_width;
165 using ::native::abs;
166 using ::native::cos;
167 using ::native::exp;
168 using ::native::exp2;
169 using ::native::expm1;
170 using ::native::damping_gain;
171 using ::native::fma;
172 using ::native::log;
173 using ::native::log2;
174 using ::native::log1p;
175 using ::native::sin;
176 using ::native::sincos;
177 using ::native::sqrt;
178 using ::native::floor;
179 using ::native::ceil;
180 using ::native::trunc;
181 using ::native::tanh;
182 using ::native::atan2;
183 }
184}
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 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:1027
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:1196
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:1006
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:1133
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:1154
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:1112
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:1091
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:1175
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
constexpr auto sincos(simd< float, L, A > input) noexcept
Paired sine/cosine preserving the permitted logical lane shape.
Definition exp_body.h:165
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