native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
constant_lanes.h
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2#pragma once
3#include <array>
4#include <bit>
5#include <cstdint>
6#include <type_traits>
7
8namespace native::detail::arm_constant {
9 // Work with logical lanes, including the padded two-word integer shape.
10 template<class V> constexpr auto lanes(V value) noexcept {
11 using T = typename V::value_type;
12 auto physical = __builtin_bit_cast(std::array<T, sizeof(typename V::native_type) / sizeof(T)>, value.to_native());
13 std::array<T, V::lanes> result{};
14 for (unsigned i = 0; i < V::lanes; ++i) result[i] = physical[i];
15 return result;
16 }
17
18 template<class V, class T, std::size_t N>
19 constexpr V pack(std::array<T, N> const &values) noexcept {
20 static_assert(N == V::lanes);
21 std::array<T, sizeof(typename V::native_type) / sizeof(T)> physical{};
22 for (unsigned i = 0; i < N; ++i) physical[i] = values[i];
23 return V::from_native(__builtin_bit_cast(typename V::native_type, physical));
24 }
25}