feat(tulip): introduce basic SIMD abstraction
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#ifndef TULIP_SIMD_TRAITS_HPP
|
||||
#define TULIP_SIMD_TRAITS_HPP
|
||||
|
||||
#include "./config.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace tulip {
|
||||
namespace simd {
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename Isa>
|
||||
struct traits {};
|
||||
|
||||
template <typename T>
|
||||
struct traits<T, scalar_isa> {
|
||||
using pack_type = T;
|
||||
|
||||
static constexpr std::size_t width = 1;
|
||||
|
||||
static pack_type load(const T* ptr) noexcept { return *ptr; }
|
||||
static void store(T* ptr, pack_type value) noexcept { *ptr = value; }
|
||||
|
||||
static pack_type add(pack_type lhs, pack_type rhs) noexcept { return lhs + rhs; }
|
||||
};
|
||||
|
||||
template <typename T, typename Isa>
|
||||
using pack_t = typename traits<T, Isa>::pack_type;
|
||||
|
||||
template <typename T, typename Isa>
|
||||
inline constexpr auto width_v = traits<T, Isa>::width;
|
||||
|
||||
template <typename T, typename Isa>
|
||||
static auto load(const T* ptr) noexcept {
|
||||
return traits<T, Isa>::load(ptr);
|
||||
}
|
||||
|
||||
template <typename T, typename Isa>
|
||||
static void store(const T* ptr, pack_t<T, Isa> value) noexcept {
|
||||
traits<T, Isa>::store(ptr, value);
|
||||
}
|
||||
|
||||
template <typename T, typename Isa>
|
||||
static auto add(pack_t<T, Isa> lhs, pack_t<T, Isa> rhs) noexcept {
|
||||
return traits<T, Isa>::add(lhs, rhs);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace simd
|
||||
} // namespace tulip
|
||||
|
||||
#endif // TULIP_SIMD_TRAITS_HPP
|
||||
Reference in New Issue
Block a user