libstdc++: simd_math.h Source File

libstdc++

bits/simd_math.h
1// Implementation of <simd> -*- C++ -*-
2
3// Copyright The GNU Toolchain Authors.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25#ifndef _GLIBCXX_SIMD_MATH_H
26#define _GLIBCXX_SIMD_MATH_H 1
27
28#ifdef _GLIBCXX_SYSHDR
29#pragma GCC system_header
30#endif
31
32#if __cplusplus >= 202400L
33
34#include "simd_vec.h"
35
36// psabi warnings are bogus because the ABI of the internal types never leaks into user code
37#pragma GCC diagnostic push
38#pragma GCC diagnostic ignored "-Wpsabi"
39
40// [simd.math] ----------------------------------------------------------------
41namespace std _GLIBCXX_VISIBILITY(default)
42{
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
44namespace simd
45{
46 template <signed_integral T, typename Abi>
47 [[__gnu__::__always_inline__]]
48 constexpr basic_vec<T, Abi>
49 abs(const basic_vec<T, Abi>& __x)
50 { return __x._M_abs(); }
51
52 template <__math_floating_point _Vp>
53 [[__gnu__::__always_inline__]]
54 constexpr typename __deduced_vec_t<_Vp>::mask_type
55 isinf(const _Vp& __x)
56 { return static_cast<const __deduced_vec_t<_Vp>&>(__x)._M_isinf(); }
57
58 template <__math_floating_point _Vp>
59 [[__gnu__::__always_inline__]]
60 constexpr typename __deduced_vec_t<_Vp>::mask_type
61 isnan(const _Vp& __x)
62 { return static_cast<const __deduced_vec_t<_Vp>&>(__x)._M_isnan(); }
63} // namespace simd
64
65
66// [simd.complex.math] --------------------------------------------------------
67namespace simd
68{
69 template <__simd_complex _Vp>
70 [[__gnu__::__always_inline__]]
71 constexpr rebind_t<__simd_complex_value_type<_Vp>, _Vp>
72 real(const _Vp& __x) noexcept
73 { return __x.real(); }
74
75 template <__simd_complex _Vp>
76 [[__gnu__::__always_inline__]]
77 constexpr rebind_t<__simd_complex_value_type<_Vp>, _Vp>
78 imag(const _Vp& __x) noexcept
79 { return __x.imag(); }
80
81 template <__simd_complex _Vp>
82 [[__gnu__::__always_inline__]]
83 constexpr rebind_t<__simd_complex_value_type<_Vp>, _Vp>
84 abs(const _Vp& __x) noexcept
85 { return __x._M_abs(); }
86
87 template <__simd_complex _Vp>
88 [[__gnu__::__always_inline__]]
89 constexpr rebind_t<__simd_complex_value_type<_Vp>, _Vp>
90 arg(const _Vp& __x) noexcept
91 { return __x._M_arg(); }
92
93 template <__simd_complex _Vp>
94 [[__gnu__::__always_inline__]]
95 constexpr rebind_t<__simd_complex_value_type<_Vp>, _Vp>
96 norm(const _Vp& __x) noexcept
97 { return __x._M_norm(); }
98
99 template <__simd_complex _Vp>
100 [[__gnu__::__always_inline__]]
101 constexpr _Vp
102 conj(const _Vp& __x) noexcept
103 { return __x._M_conj(); }
104
105 template <__simd_complex _Vp>
106 [[__gnu__::__always_inline__]]
107 constexpr _Vp
108 proj(const _Vp& __x) noexcept
109 { return __x._M_proj(); }
110} // namespace simd
111
112 using simd::real;
113 using simd::imag;
114 using simd::abs;
115 using simd::arg;
116 using simd::norm;
117 using simd::conj;
118 using simd::proj;
119
120_GLIBCXX_END_NAMESPACE_VERSION
121} // namespace std
122
123#pragma GCC diagnostic pop
124#endif // C++26
125#endif // _GLIBCXX_SIMD_MATH_H
std
ISO C++ entities toplevel namespace is std.