libstdc++: simd_mask_reductions.h Source File

libstdc++

simd_mask_reductions.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_MASK_REDUCTIONS_H
26#define _GLIBCXX_SIMD_MASK_REDUCTIONS_H 1
27
28#ifdef _GLIBCXX_SYSHDR
29#pragma GCC system_header
30#endif
31
32#if __cplusplus >= 202400L
33
34#include "simd_mask.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.mask.reductions] -----------------------------------------------------
41namespace std _GLIBCXX_VISIBILITY(default)
42{
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
44namespace simd
45{
46 template <size_t _Bytes, typename _Ap>
47 [[__gnu__::__always_inline__]]
48 constexpr bool
49 all_of(const basic_mask<_Bytes, _Ap>& __k) noexcept
50 { return __k._M_all_of(); }
51
52 template <size_t _Bytes, typename _Ap>
53 [[__gnu__::__always_inline__]]
54 constexpr bool
55 any_of(const basic_mask<_Bytes, _Ap>& __k) noexcept
56 { return __k._M_any_of(); }
57
58 template <size_t _Bytes, typename _Ap>
59 [[__gnu__::__always_inline__]]
60 constexpr bool
61 none_of(const basic_mask<_Bytes, _Ap>& __k) noexcept
62 { return __k._M_none_of(); }
63
64 template <size_t _Bytes, typename _Ap>
65 [[__gnu__::__always_inline__]]
66 constexpr __simd_size_type
67 reduce_count(const basic_mask<_Bytes, _Ap>& __k) noexcept
68 {
69 if constexpr (_Ap::_S_size == 1)
70 return +__k[0];
71 else if constexpr (_Ap::_S_is_vecmask && _Bytes <= sizeof(0ll))
72 return -reduce(-__k);
73 else
74 return __k._M_reduce_count();
75 }
76
77 template <size_t _Bytes, typename _Ap>
78 [[__gnu__::__always_inline__]]
79 constexpr __simd_size_type
80 reduce_min_index(const basic_mask<_Bytes, _Ap>& __k)
81 { return __k._M_reduce_min_index(); }
82
83 template <size_t _Bytes, typename _Ap>
84 [[__gnu__::__always_inline__]]
85 constexpr __simd_size_type
86 reduce_max_index(const basic_mask<_Bytes, _Ap>& __k)
87 { return __k._M_reduce_max_index(); }
88
89 constexpr bool
90 all_of(same_as<bool> auto __x) noexcept
91 { return __x; }
92
93 constexpr bool
94 any_of(same_as<bool> auto __x) noexcept
95 { return __x; }
96
97 constexpr bool
98 none_of(same_as<bool> auto __x) noexcept
99 { return !__x; }
100
101 constexpr __simd_size_type
102 reduce_count(same_as<bool> auto __x) noexcept
103 { return __x; }
104
105 constexpr __simd_size_type
106 reduce_min_index(same_as<bool> auto __x)
107 { return 0; }
108
109 constexpr __simd_size_type
110 reduce_max_index(same_as<bool> auto __x)
111 { return 0; }
112} // namespace simd
113_GLIBCXX_END_NAMESPACE_VERSION
114} // namespace std
115
116#pragma GCC diagnostic pop
117#endif // C++26
118#endif // _GLIBCXX_SIMD_MASK_REDUCTIONS_H
std
ISO C++ entities toplevel namespace is std.