Intel xvec
Experimental C++ simd class library
Loading...
Searching...
No Matches
intrin.hpp
1//===----------------------------------------------------------------------===//
2//
3// Copyright (C) 2021 Intel Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include <immintrin.h>
12
13#include <cstdint> // std::uint8_t
14
15#include <xvec/detail/config.hpp>
16#include <xvec/detail/utilities.hpp>
17#include <xvec/detail/core.hpp>
18
19namespace _XVEC_NAMESPACE::simd::x86 {
20
26
30template<typename _Vec, typename _Tp = typename _Vec::value_type>
31concept xmm_register = (sizeof(_Vec) <= 16) && (std::same_as<_Tp, typename _Vec::value_type>);
32
36template<typename _Vec, typename _Tp = typename _Vec::value_type>
37concept ymm_register = (sizeof(_Vec) > 16 && sizeof(_Vec) <= 32) && (std::same_as<_Tp, typename _Vec::value_type>);
38
42template<typename _Vec, typename _Tp = typename _Vec::value_type>
43concept zmm_register = (sizeof(_Vec) > 32 && sizeof(_Vec) <= 64) && (std::same_as<_Tp, typename _Vec::value_type>);
44
45#if defined(__GFNI__)
62template<std::uint8_t imm_byte = 0, vec_type _Bytes, vec_type _Matrix>
63requires ((sizeof(typename _Bytes::value_type) == 1) &&
64 (sizeof(typename _Matrix::value_type) == 8) &&
65 ((_Matrix::size() * 8) == _Bytes::size()))
66inline _Bytes gf2p8affine(const _Bytes& b, const _Matrix& m)
67{
68 using namespace detail;
69
70 target_overloads impl {
71 [=]<xmm_register<std::uint8_t> _Vec>(_Vec x, _Vec y)
72 { return _mm_gf2p8affine_epi64_epi8 (x.to_register(), y.to_register(), imm_byte); },
73 [=]<ymm_register<std::uint8_t> _Vec>(_Vec x, _Vec y)
74 { return _mm256_gf2p8affine_epi64_epi8 (x.to_register(), y.to_register(), imm_byte); },
75 [=]<zmm_register<std::uint8_t> _Vec>(_Vec x, _Vec y)
76 { return _mm512_gf2p8affine_epi64_epi8 (x.to_register(), y.to_register(), imm_byte); },
77
78 [=](auto unhandled, auto) { static_assert(dependent_false<decltype(unhandled)>, "No target intrinsics"); return unhandled; }
79 };
80
81 return std::bit_cast<_Bytes>(chunked_invoke([=](auto x, auto y) { return decltype(x)(impl(x, y)); },
83}
84
93template<std::uint8_t imm_byte = 0, vec_type _Bytes>
94requires (sizeof(typename _Bytes::value_type) == 1) // Allow any type of single byte element to be transformed.
95inline _Bytes gf2p8affine(const _Bytes& b, std::uint64_t m)
96{
97 constexpr int roundedTo8 = ((_Bytes::size() + 7) / 8) * 8;
98 auto resizeTo8 = permute<roundedTo8>(b, detail::perm_uninitResize);
99 auto r = gf2p8affine<imm_byte>(resizeTo8, vec<std::uint64_t, roundedTo8 / 8>(m));
101}
102
103#else
104inline auto gf2p8affine(auto unhandled, auto); // Does nothing for other platforms to allow link-time detection.
105#endif
106
108
109} // End of simd::x86 namespace
110
111namespace _XVEC_NAMESPACE::simd::detail {
112 using x86::xmm_register;
113 using x86::ymm_register;
114 using x86::zmm_register;
115}
Detect a vector occupying at most an xmm-sized register.
Definition intrin.hpp:31
Detect a vector larger than xmm and no larger than ymm.
Definition intrin.hpp:37
Detect a vector larger than ymm and no larger than zmm.
Definition intrin.hpp:43
basic_vec< _Tp, simd_fixed_size_abi< _Np > > vec
Definition core.hpp:379
constexpr auto permute(const _Vp &v, detail::index_generator_function auto &&fn)
Permute the elements in a vec value using a generator function to compute the indexing.
Definition permute.hpp:94
constexpr auto chunked_invoke(_Fn fn, const _Arg0 &arg0, const _Args &... args)
Invoke a callable on corresponding vector or mask chunks.
Definition invoke.hpp:61
constexpr auto take(const vec_or_mask_type auto &in)
Definition named_permute.hpp:237
constexpr auto simd_bit_cast(const _From &v) noexcept
A simd-generic version of simd_bit_cast which directly invokes std::bit_cast.
Definition core.hpp:585
Detect a scoped enum. This will be provided in C++23 onwards.
Definition compat.hpp:27