2020-06-27 23:25:56 +02:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_SIMD_TRAITS_H
|
|
|
|
|
|
|
|
namespace ircd::simd
|
|
|
|
{
|
2020-09-20 13:35:44 +02:00
|
|
|
template<class T>
|
2021-02-27 21:50:32 +01:00
|
|
|
static constexpr size_t lanes();
|
2020-06-28 00:21:37 +02:00
|
|
|
|
2021-03-02 20:04:28 +01:00
|
|
|
template<class U,
|
|
|
|
class T>
|
|
|
|
static constexpr bool is_lane_same();
|
|
|
|
|
|
|
|
template<class U,
|
|
|
|
class T>
|
|
|
|
static constexpr bool is_lane_base_of();
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
static constexpr bool is_lane_integral();
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
static constexpr bool is_lane_floating();
|
|
|
|
|
2021-03-02 20:05:06 +01:00
|
|
|
template<class T>
|
|
|
|
T mask_full();
|
|
|
|
|
2020-11-13 05:59:00 +01:00
|
|
|
constexpr auto alignment
|
|
|
|
{
|
|
|
|
support::avx512f? 64:
|
|
|
|
support::avx? 32:
|
|
|
|
support::sse? 16:
|
|
|
|
8
|
|
|
|
};
|
2020-06-27 23:25:56 +02:00
|
|
|
}
|
2020-06-28 00:21:37 +02:00
|
|
|
|
2021-03-02 20:05:06 +01:00
|
|
|
template<class T>
|
2021-03-13 23:45:10 +01:00
|
|
|
[[gnu::const]]
|
2021-03-02 20:05:06 +01:00
|
|
|
inline T
|
|
|
|
ircd::simd::mask_full()
|
|
|
|
{
|
|
|
|
if constexpr(is_lane_floating<T>())
|
|
|
|
return T{};
|
|
|
|
else
|
|
|
|
return ~T{0};
|
|
|
|
}
|
|
|
|
|
2021-03-02 20:04:28 +01:00
|
|
|
template<class T>
|
|
|
|
constexpr bool
|
|
|
|
ircd::simd::is_lane_floating()
|
|
|
|
{
|
|
|
|
return std::is_floating_point<lane_type<T>>::value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
constexpr bool
|
|
|
|
ircd::simd::is_lane_integral()
|
|
|
|
{
|
|
|
|
return std::is_integral<lane_type<T>>::value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class U,
|
|
|
|
class T>
|
|
|
|
constexpr bool
|
|
|
|
ircd::simd::is_lane_same()
|
|
|
|
{
|
|
|
|
return std::is_same<U, lane_type<T>>::value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class U,
|
|
|
|
class T>
|
|
|
|
constexpr bool
|
|
|
|
ircd::simd::is_lane_base_of()
|
|
|
|
{
|
|
|
|
return std::is_base_of<U, lane_type<T>>::value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 00:21:37 +02:00
|
|
|
/// Get number of lanes for vector type (the number after the x in the
|
|
|
|
/// type name).
|
|
|
|
template<class T>
|
2021-02-27 21:50:32 +01:00
|
|
|
constexpr size_t
|
2020-07-10 03:00:27 +02:00
|
|
|
ircd::simd::lanes()
|
2020-06-28 00:21:37 +02:00
|
|
|
{
|
|
|
|
constexpr size_t ret
|
|
|
|
{
|
|
|
|
sizeof(T) / sizeof_lane<T>()
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert
|
|
|
|
(
|
|
|
|
sizeof(T) <= 64 && ret <= 64 && ret > 0
|
|
|
|
);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
constexpr size_t
|
2020-07-10 03:00:27 +02:00
|
|
|
ircd::simd::sizeof_lane<ircd::u128x1>()
|
2020-06-28 00:21:37 +02:00
|
|
|
{
|
|
|
|
return 16;
|
2021-02-27 21:50:32 +01:00
|
|
|
}
|
2020-06-28 00:21:37 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
constexpr size_t
|
2020-07-10 03:00:27 +02:00
|
|
|
ircd::simd::sizeof_lane<ircd::u256x1>()
|
2020-06-28 00:21:37 +02:00
|
|
|
{
|
|
|
|
return 32;
|
2021-02-27 21:50:32 +01:00
|
|
|
}
|
2020-06-28 00:21:37 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
constexpr size_t
|
2020-07-10 03:00:27 +02:00
|
|
|
ircd::simd::sizeof_lane<ircd::u512x1>()
|
2020-06-28 00:21:37 +02:00
|
|
|
{
|
|
|
|
return 64;
|
2021-02-27 21:50:32 +01:00
|
|
|
}
|