Skip to content

Commit

Permalink
ImplTraits_SupportSIMD, val don't support SIMD
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed May 28, 2020
1 parent be917a3 commit c4e9735
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 61 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(UGM VERSION 0.6.2)
project(UGM VERSION 0.6.3)
message(STATUS "[Project] ${PROJECT_NAME}")

include(FetchContent)
Expand Down
10 changes: 0 additions & 10 deletions config/natvis.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,6 @@
</ArrayItems>
</Expand>
</Type>
<!-- SIMD -->
<Type Name="Ubpa::val&lt;*,4&gt;>">
<DisplayString>{{{m.m128_f32[0]}, {m.m128_f32[1]}, {m.m128_f32[2]}, {m.m128_f32[3]}}}</DisplayString>
<Expand>
<ArrayItems>
<Size>4</Size>
<ValuePointer>m.m128_f32</ValuePointer>
</ArrayItems>
</Expand>
</Type>

<Type Name="Ubpa::scale&lt;*,1&gt;>">
<DisplayString>{{{_Elems[0]}}}</DisplayString>
Expand Down
4 changes: 2 additions & 2 deletions include/UGM/Interfaces/IArray/IArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Ubpa {
struct IArray_Impl;

template<typename Base, typename Impl>
struct IArray : IArray_Impl<SupportSIMD_v<Impl>, Base, Impl> {
using IArray_Impl<SupportSIMD_v<Impl>, Base, Impl>::IArray_Impl;
struct IArray : IArray_Impl<ImplTraits_SupportSIMD<Impl>, Base, Impl> {
using IArray_Impl<ImplTraits_SupportSIMD<Impl>, Base, Impl>::IArray_Impl;
};

template<typename IArray_Base, typename Impl>
Expand Down
10 changes: 5 additions & 5 deletions include/UGM/Interfaces/IArray/IArray1D_Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Ubpa {
inline const Impl abs() const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_abs_ps(x);
#endif // UBPA_USE_SIMD
{
Expand All @@ -33,7 +33,7 @@ namespace Ubpa {

inline T min_component() const noexcept {
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>) {
if constexpr (ImplTraits_SupportSIMD<Impl>) {
// 5 instructions
const auto& s0 = *this;
auto s1 = VecSwizzle(s0, 1, 0, 3, 2);
Expand All @@ -55,7 +55,7 @@ namespace Ubpa {

inline T max_component() const noexcept {
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>) {
if constexpr (ImplTraits_SupportSIMD<Impl>) {
// 5 instructions
const auto& s0 = *this;
auto s1 = VecSwizzle(s0, 1, 0, 3, 2);
Expand Down Expand Up @@ -97,7 +97,7 @@ namespace Ubpa {

static const Impl min(const Impl& x, const Impl& y) noexcept {
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_min_ps(x, y);
#endif // UBPA_USE_SIMD
{
Expand All @@ -111,7 +111,7 @@ namespace Ubpa {

static const Impl max(const Impl& x, const Impl& y) noexcept {
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_max_ps(x, y);
#endif // UBPA_USE_SIMD
{
Expand Down
14 changes: 7 additions & 7 deletions include/UGM/Interfaces/IArray/IArrayAdd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Ubpa {
inline const Impl impl_add(const Impl& y) const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_add_ps(x, y);
else
#endif // UBPA_USE_SIMD
Expand All @@ -34,7 +34,7 @@ namespace Ubpa {
inline Impl& impl_add_to_self(const Impl& y) noexcept {
auto& x = static_cast<Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return x = x + y;
else
#endif // UBPA_USE_SIMD
Expand All @@ -48,7 +48,7 @@ namespace Ubpa {
inline const Impl impl_add_inverse() const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
// ref: https://stackoverflow.com/questions/20083997/how-to-negate-change-sign-of-the-floating-point-elements-in-a-m128-type-vari
return _mm_sub_ps(Impl{ 0.f }, x);
else
Expand All @@ -68,7 +68,7 @@ namespace Ubpa {
inline const Impl impl_minus(const Impl& y) const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>) {
if constexpr (ImplTraits_SupportSIMD<Impl>) {
return _mm_sub_ps(x, y);
}
else
Expand All @@ -84,7 +84,7 @@ namespace Ubpa {
inline Impl& impl_minus_to_self(const Impl& y) noexcept {
auto& x = static_cast<Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>) {
if constexpr (ImplTraits_SupportSIMD<Impl>) {
return x = x - y;
}
else
Expand All @@ -100,7 +100,7 @@ namespace Ubpa {
inline Impl impl_add_mul(U v) const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_mul_ps(x, Impl{ v });
else
#endif // UBPA_USE_SIMD
Expand All @@ -116,7 +116,7 @@ namespace Ubpa {
inline Impl& impl_add_mul_to_self(U v) noexcept {
auto& x = static_cast<Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return x = x * v;
else
#endif // UBPA_USE_SIMD
Expand Down
10 changes: 5 additions & 5 deletions include/UGM/Interfaces/IArray/IArrayHadamardProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Ubpa {
Impl& operator*=(const Impl& y) noexcept {
auto& x = static_cast<Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
x = x * y;
else
#endif // UBPA_USE_SIMD
Expand All @@ -31,7 +31,7 @@ namespace Ubpa {
const Impl operator/(const Impl& y) const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_div_ps(x, y);
else
#endif // UBPA_USE_SIMD
Expand All @@ -46,7 +46,7 @@ namespace Ubpa {
Impl& operator/=(const Impl& y) noexcept {
auto& x = static_cast<Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return x = x / y;
else
#endif // UBPA_USE_SIMD
Expand All @@ -59,7 +59,7 @@ namespace Ubpa {
const auto& x = static_cast<const Impl&>(*this);

#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_div_ps(Impl{ 1.f }, x);
else
#endif // UBPA_USE_SIMD
Expand All @@ -79,7 +79,7 @@ namespace Ubpa {
const auto& x = static_cast<const Impl&>(*this);

#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_mul_ps(x, y);
else
#endif // UBPA_USE_SIMD
Expand Down
10 changes: 5 additions & 5 deletions include/UGM/Interfaces/IArray/IArrayScalarMul.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ namespace Ubpa {
using Base::operator/=;

inline bool is_scalar() const noexcept {
static_assert(SupportSIMD_v<Impl>);
static_assert(ImplTraits_SupportSIMD<Impl>);
const auto& x = static_cast<const Impl&>(*this);
return x == x.replicate<0>();
}

inline Impl operator*(const __m128& k) const noexcept {
static_assert(SupportSIMD_v<Impl>);
static_assert(ImplTraits_SupportSIMD<Impl>);
const auto& x = static_cast<const Impl&>(*this);
assert(Impl{ k }.is_scalar() || x.is_scalar());
return _mm_mul_ps(x, k);
Expand All @@ -37,7 +37,7 @@ namespace Ubpa {
}

inline Impl operator/(const __m128& k) const noexcept {
static_assert(SupportSIMD_v<Impl>);
static_assert(ImplTraits_SupportSIMD<Impl>);
const auto& x = static_cast<const Impl&>(*this);
assert(Impl{ k }.is_scalar());
return _mm_div_ps(x, k);
Expand All @@ -56,7 +56,7 @@ namespace Ubpa {
inline Impl impl_scalar_mul(F k) const noexcept {
const auto& x = static_cast<const Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_mul_ps(x, Impl{ k });
else
#endif // UBPA_USE_SIMD
Expand All @@ -71,7 +71,7 @@ namespace Ubpa {
inline Impl& impl_scalar_mul_to_self(F k) noexcept {
auto& x = static_cast<Impl&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return x = x * k;
else
#endif // UBPA_USE_SIMD
Expand Down
4 changes: 2 additions & 2 deletions include/UGM/Interfaces/IArray/IArrayUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Ubpa {
static const Impl lerp(const Impl& x, const Impl& y, F t) noexcept {
F one_minus_t = static_cast<F>(1) - t;
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>)
if constexpr (ImplTraits_SupportSIMD<Impl>)
return _mm_add_ps(_mm_mul_ps(x, _mm_set1_ps(one_minus_t)), _mm_mul_ps(y, _mm_set1_ps(t)));
else
#endif // UBPA_USE_SIMD
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace Ubpa {
auto weight_iter = weights.begin();

#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>) {
if constexpr (ImplTraits_SupportSIMD<Impl>) {
__m128 rst = _mm_mul_ps(*val_iter, *weight_iter);
++val_iter;
++weight_iter;
Expand Down
10 changes: 5 additions & 5 deletions include/UGM/Interfaces/IArray/IEuclideanA.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Ubpa {
inline const Point impl_affine_subspace_add(const Vector& v) const noexcept {
auto& p = static_cast<const Point&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Point>)
if constexpr (ImplTraits_SupportSIMD<Point>)
return _mm_add_ps(p, v);
else
#endif // UBPA_USE_SIMD
Expand All @@ -50,7 +50,7 @@ namespace Ubpa {
inline Point& impl_affine_subspace_add_to_self(const Vector& v) noexcept {
auto& p = static_cast<Point&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Point>)
if constexpr (ImplTraits_SupportSIMD<Point>)
return p = p + v;
else
#endif // UBPA_USE_SIMD
Expand All @@ -62,7 +62,7 @@ namespace Ubpa {
inline const Point impl_affine_subspace_minus(const Vector& v) const noexcept {
auto& p = static_cast<const Point&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Point>)
if constexpr (ImplTraits_SupportSIMD<Point>)
return _mm_sub_ps(p, v);
else
#endif // UBPA_USE_SIMD
Expand All @@ -77,7 +77,7 @@ namespace Ubpa {
inline Point& impl_affine_subspace_minus_to_self(const Vector& v) noexcept {
auto& p = static_cast<Point&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Point>)
if constexpr (ImplTraits_SupportSIMD<Point>)
return p = p - v;
else
#endif // UBPA_USE_SIMD
Expand All @@ -92,7 +92,7 @@ namespace Ubpa {
inline const Vector impl_affine_minus(const Point& y) const noexcept {
auto& x = static_cast<const Point&>(*this);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Point>)
if constexpr (ImplTraits_SupportSIMD<Point>)
return _mm_sub_ps(x, y);
/* // no benefits
else if constexpr (std::is_same_v<T, float> && N == 3) {
Expand Down
6 changes: 3 additions & 3 deletions include/UGM/Interfaces/IArray/IEuclideanV.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Ubpa {
#ifdef UBPA_USE_SIMD
// w == 0
inline static const Impl v3_cross(const Impl& x, const Impl& y) noexcept {
static_assert(SupportSIMD_v<Impl>);
static_assert(ImplTraits_SupportSIMD<Impl>);
/*
|a.x| |b.x| | a.y * b.z - a.z * b.y |
|a.y| X |b.y| = | a.z * b.x - a.x * b.z |
Expand All @@ -36,7 +36,7 @@ namespace Ubpa {

// x = y = z = w
inline static Impl v3_dot(const Impl& x, const Impl& y) noexcept {
static_assert(SupportSIMD_v<Impl>);
static_assert(ImplTraits_SupportSIMD<Impl>);
// 0x7f : 011111111
return _mm_dp_ps(x, y, 0x7f);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace Ubpa {

inline static F impl_dot(const Impl& x, const Impl& y) noexcept {
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<Impl>) {
if constexpr (ImplTraits_SupportSIMD<Impl>) {
// ref
// https://stackoverflow.com/questions/4120681/how-to-calculate-single-vector-dot-product-using-sse-intrinsic-functions-in-c
#ifdef UBPA_USE_SSE_4_1
Expand Down
4 changes: 2 additions & 2 deletions include/UGM/Interfaces/IMatrix/IMatrixMul_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace Ubpa::detail::IMatrixMul {
using F = typename M::F;

#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<ImplTraits_T<M>>) {
if constexpr (ImplTraits_SupportSIMD<ImplTraits_T<M>>) {
#if 1 // Eric: https://lxjk.github.io/2017/09/03/Fast-4x4-Matrix-Inverse-with-SSE-SIMD-Explained.html
return Eric::GetInverse(m);
#else // intel: https://software.intel.com/en-us/articles/optimized-matrix-library-for-use-with-the-intel-pentiumr-4-processors-sse2-instructions/
Expand Down Expand Up @@ -488,7 +488,7 @@ namespace Ubpa::detail::IMatrixMul {
using F = typename M::F;

#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<ImplTraits_T<M>>)
if constexpr (ImplTraits_SupportSIMD<ImplTraits_T<M>>)
return m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3] * v[3];
else
#endif // UBPA_USE_SIMD
Expand Down
8 changes: 4 additions & 4 deletions include/UGM/Interfaces/IMatrix/IMatrix_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Ubpa::detail::IMatrix_ {
inline static const M run(const M& m) noexcept {
static_assert(M::N == 4);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<ImplTraits_T<M>>) {
if constexpr (ImplTraits_SupportSIMD<ImplTraits_T<M>>) {
M rst{ m };
_MM_TRANSPOSE4_PS(rst[0], rst[1], rst[2], rst[3]);
return rst;
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace Ubpa::detail::IMatrix_ {
inline static ImplTraits_F<M> run(const M& m) noexcept {
static_assert(M::N == 4);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<ImplTraits_T<M>>)
if constexpr (ImplTraits_SupportSIMD<ImplTraits_T<M>>)
return m[0].get<0>() + m[1].get<1>() + m[2].get<2>() + m[3].get<3>();
else
#endif // UBPA_USE_SIMD
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace Ubpa::detail::IMatrix_ {
inline static void run(M& m, const std::array<ImplTraits_F<M>, 4 * 4>& data) noexcept {
static_assert(M::N == 4);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<ImplTraits_T<M>>) {
if constexpr (ImplTraits_SupportSIMD<ImplTraits_T<M>>) {
m[0] = _mm_loadu_ps(&(data[0]));
m[1] = _mm_loadu_ps(&(data[4]));
m[2] = _mm_loadu_ps(&(data[8]));
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace Ubpa::detail::IMatrix_ {
inline static M run() noexcept {
static_assert(M::N == 4);
#ifdef UBPA_USE_SIMD
if constexpr (SupportSIMD_v<ImplTraits_T<M>>) {
if constexpr (ImplTraits_SupportSIMD<ImplTraits_T<M>>) {
using V = ImplTraits_T<M>;
const __m128 z = _mm_set1_ps(0.f);
return { V{z}, V{z}, V{z}, V{z} };
Expand Down
Loading

0 comments on commit c4e9735

Please sign in to comment.