HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
raw_numeric_array.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../architecture.hpp"
8#include <array>
9#include <cstdint>
10#include <type_traits>
11#include <concepts>
12
13#if defined(TT_X86_64_V2)
14#include <emmintrin.h>
15#include <smmintrin.h>
16#include <xmmintrin.h>
17#endif
18
19namespace tt {
20
21using ri8x16 = std::array<int8_t, 16>;
22using ru8x16 = std::array<uint8_t, 16>;
23using ri16x8 = std::array<int16_t, 8>;
24using ru16x8 = std::array<uint16_t, 8>;
25using ri32x4 = std::array<int32_t, 4>;
26using ru32x4 = std::array<uint32_t, 4>;
27using rf32x4 = std::array<float, 4>;
28using ri64x2 = std::array<int64_t, 2>;
29using ru64x2 = std::array<uint64_t, 2>;
30using rf64x2 = std::array<double, 2>;
31
32#if defined(TT_X86_64_V2)
33
34template<std::integral T, size_t N>
35requires(sizeof(T) * N == 16) [[nodiscard]] inline __m128i to_m128i(std::array<T, N> const &rhs) noexcept
36{
37 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(rhs.data()));
38}
39
40[[nodiscard]] inline __m128 to_m128(rf32x4 const &rhs) noexcept
41{
42 return _mm_loadu_ps(rhs.data());
43}
44
45[[nodiscard]] inline __m128d to_m128d(rf64x2 const &rhs) noexcept
46{
47 return _mm_loadu_pd(rhs.data());
48}
49
50#define X(x) \
51 [[nodiscard]] inline x to_##x(__m128i rhs) noexcept \
52 { \
53 x r; \
54 _mm_storeu_si128(reinterpret_cast<__m128i *>(r.data()), rhs); \
55 return r; \
56 }
57
58X(ri8x16)
59X(ru8x16)
60X(ri16x8)
61X(ru16x8)
62X(ri32x4)
63X(ru32x4)
64X(ri64x2)
65X(ru64x2)
66#undef X
67
68[[nodiscard]] inline rf32x4 to_rf32x4(__m128 rhs) noexcept
69{
70 rf32x4 r;
71 _mm_storeu_ps(r.data(), rhs);
72 return r;
73}
74
75[[nodiscard]] inline rf64x2 to_rf64x2(__m128d rhs) noexcept
76{
77 rf64x2 r;
78 _mm_storeu_pd(r.data(), rhs);
79 return r;
80}
81
82#endif
83
84} // namespace tt