38 lines
902 B
C++
38 lines
902 B
C++
#ifndef TULIP_KERNELS_ELEMENTWISE_HPP
|
|
#define TULIP_KERNELS_ELEMENTWISE_HPP
|
|
|
|
#include "../simd/simd.hpp"
|
|
|
|
#include <cstddef>
|
|
|
|
namespace tulip {
|
|
namespace kernels {
|
|
|
|
template <typename T, typename Expr>
|
|
void elementwise_scalar(T* dst, const Expr& expr, std::size_t size) {
|
|
for (std::size_t idx = 0; idx < size; ++idx) {
|
|
dst[idx] = expr.coeff(idx);
|
|
}
|
|
}
|
|
|
|
template <typename Isa, typename T, typename Expr>
|
|
void elementwise(T* dst, const Expr& expr, std::size_t size) {
|
|
std::size_t idx = 0;
|
|
|
|
constexpr std::size_t width = simd::detail::width_v<T, Isa>;
|
|
|
|
for (; idx + width <= size; idx += width) {
|
|
auto value = expr.template eval_pack<Isa>(idx);
|
|
simd::detail::store<T, Isa>(dst + idx, value);
|
|
}
|
|
|
|
for (; idx < size; ++idx) {
|
|
dst[idx] = expr.coeff(idx);
|
|
}
|
|
}
|
|
|
|
} // namespace kernels
|
|
} // namespace tulip
|
|
|
|
#endif // TULIP_KERNELS_ELEMENTWISE_HPP
|