This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

189
cppdraft/simd/bit.md Normal file
View File

@@ -0,0 +1,189 @@
[simd.bit]
# 29 Numerics library [[numerics]](./#numerics)
## 29.10 Data-parallel types [[simd]](simd#bit)
### 29.10.8 basic_vec non-member operations [[simd.nonmembers]](simd.nonmembers#simd.bit)
#### 29.10.8.14 basic_vec bit library [simd.bit]
[🔗](#lib:byteswap,simd)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr V byteswap(const V& v) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19756)
*Constraints*: The type V::value_type models [integral](concepts.arithmetic#concept:integral "18.4.7Arithmetic concepts[concepts.arithmetic]")[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19760)
*Returns*: A basic_vec object where the ith element is initialized to
the result of std::byteswap(v[i]) for all i in the range
[0, V::size())[.](#2.sentence-1)
[🔗](#lib:bit_ceil,simd)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr V bit_ceil(const V& v) noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19773)
*Constraints*: The type V::value_type is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19777)
*Preconditions*: For every i in the range [0, V::size()), the smallest power of 2
greater than or equal to v[i] is representable as a value of typeV::value_type[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19783)
*Returns*: A basic_vec object where the ith element is initialized to
the result of std::bit_ceil(v[i]) for all i in the range
[0, V::size())[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19789)
*Remarks*: A function call expression that violates the precondition in the *Preconditions*: element is not a core constant expression ([[expr.const]](expr.const "7.7Constant expressions"))[.](#6.sentence-1)
[🔗](#lib:bit_floor,simd)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr V bit_floor(const V& v) noexcept;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19801)
*Constraints*: The type V::value_type is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19805)
*Returns*: A basic_vec object where the ith element is initialized to
the result of std::bit_floor(v[i]) for all i in the range
[0, V::size())[.](#8.sentence-1)
[🔗](#lib:has_single_bit,simd)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr typename V::mask_type has_single_bit(const V& v) noexcept;
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19819)
*Constraints*: The type V::value_type is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19823)
*Returns*: A basic_mask object where the ith element is initialized
to the result of std::has_single_bit(v[i]) for all i in the range
[0, V::size())[.](#10.sentence-1)
[🔗](#lib:rotl,simd)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V0, [simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V1>
constexpr V0 rotl(const V0& v0, const V1& v1) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V0, [simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V1>
constexpr V0 rotr(const V0& v0, const V1& v1) noexcept;
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19840)
*Constraints*:
- [(11.1)](#11.1)
The type V0::value_type is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types")),
- [(11.2)](#11.2)
the type V1::value_type models [integral](concepts.arithmetic#concept:integral "18.4.7Arithmetic concepts[concepts.arithmetic]"),
- [(11.3)](#11.3)
V0::size() == V1::size() is true, and
- [(11.4)](#11.4)
sizeof(typename V0::value_type) == sizeof(typename V1::value_type) is true[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19853)
*Returns*: A basic_vec object where the ith element is initialized to
the result of *bit-func*(v0[i],static_cast<int>(v1[i])) for all i in the range [0, V0::size()),
where *bit-func* is the corresponding scalar function from [<bit>](bit.general#header:%3cbit%3e "22.11.1General[bit.general]")[.](#12.sentence-1)
[🔗](#lib:rotl,simd_)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr V rotl(const V& v, int s) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr V rotr(const V& v, int s) noexcept;
`
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19869)
*Constraints*: The type V::value_type is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19873)
*Returns*: A basic_vec object where the ith element is initialized to
the result of *bit-func*(v[i], s) for all i in the
range [0, V::size()), where *bit-func* is the corresponding
scalar function from [<bit>](bit.general#header:%3cbit%3e "22.11.1General[bit.general]")[.](#14.sentence-1)
[🔗](#lib:bit_width,simd)
`template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V> bit_width(const V& v) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V> countl_zero(const V& v) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V> countl_one(const V& v) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V> countr_zero(const V& v) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V> countr_one(const V& v) noexcept;
template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V> popcount(const V& v) noexcept;
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19903)
*Constraints*: The type V::value_type is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19907)
*Returns*: A basic_vec object where the ith element is initialized to
the result of *bit-func*(v[i]) for all i in the range
[0, V::size()), where *bit-func* is the corresponding scalar
function from [<bit>](bit.general#header:%3cbit%3e "22.11.1General[bit.general]")[.](#16.sentence-1)