-
Notifications
You must be signed in to change notification settings - Fork 1
/
interleave.h
49 lines (42 loc) · 1.49 KB
/
interleave.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright © 2023-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
* Matthias Kretz <[email protected]>
*/
#ifndef PROTOTYPE_INTERLEAVE_H_
#define PROTOTYPE_INTERLEAVE_H_
#include "simd.h"
#include "iota.h"
namespace std
{
template <size_t _Offset, typename _Tp>
constexpr const _Tp&
__pack_subscript(const _Tp& __x0) noexcept
{
static_assert(_Offset == 0);
return __x0;
}
template <size_t _Offset, typename _Tp, typename... _More>
constexpr const _Tp&
__pack_subscript(const _Tp& __x0, const _Tp& __x1, const _More&... __more) noexcept
{
if constexpr (_Offset == 0)
return __x0;
else if constexpr (_Offset == 1)
return __x1;
else
return __pack_subscript<_Offset - 2>(__more...);
}
template <__detail::__simd_type _Vp, std::same_as<_Vp>... _More>
_GLIBCXX_SIMD_ALWAYS_INLINE constexpr std::tuple<_Vp, _More...>
interleave(_Vp const& __a, _More const&... __more) noexcept
{
constexpr unsigned __n = 1 + sizeof...(_More);
return [&]<size_t... _Offsets>(std::index_sequence<_Offsets...>) {
return std::tuple{_Vp([&](auto __i) {
constexpr size_t __j = __i + _Offsets * _Vp::size();
return __pack_subscript<__j % __n>(__a, __more...)[__j / __n];
})...};
}(std::make_index_sequence<__n>());
}
}
#endif // PROTOTYPE_INTERLEAVE_H_