Add simd_none implementation

This commit is contained in:
Luke Street 2022-08-03 18:15:45 -04:00
parent ac7d83009d
commit e9ec10a382
4 changed files with 236 additions and 8 deletions

View File

@ -1477,6 +1477,9 @@ private:
friend class simd_mask; friend class simd_mask;
public: public:
constexpr __simd_storage(_Tp __rv) : __storage_{__rv, __rv, __rv, __rv} {}
constexpr __simd_storage(_Tp a, _Tp b, _Tp c, _Tp d) : __storage_{a, b, c, d} {}
constexpr _Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; constexpr _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
constexpr void __set(size_t __index, _Tp __val) noexcept { __storage_[__index] = __val; } constexpr void __set(size_t __index, _Tp __val) noexcept { __storage_[__index] = __val; }
constexpr std::enable_if_t<__num_element >= 4> __set4(float a, float b, float c, float d) noexcept { constexpr std::enable_if_t<__num_element >= 4> __set4(float a, float b, float c, float d) noexcept {

View File

@ -18,7 +18,7 @@ using namespace std;
#elif __ARM_NEON #elif __ARM_NEON
#include "simd_neon.hpp" #include "simd_neon.hpp"
#else #else
namespace simd_abi { namespace zeus::_simd::simd_abi {
template <typename T> template <typename T>
struct zeus_native {}; struct zeus_native {};
template <> template <>
@ -29,7 +29,8 @@ template <>
struct zeus_native<double> { struct zeus_native<double> {
using type = fixed_size<4>; using type = fixed_size<4>;
}; };
} // namespace simd_abi } // namespace zeus::_simd::simd_abi
#include "simd_none.hpp"
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View File

@ -0,0 +1,224 @@
#pragma once
#ifndef _ZEUS_SIMD_INCLUDED
#error simd_none.hpp must not be included directly. Include simd.hpp instead.
#endif
namespace zeus::_simd {
using m128_abi = __simd_abi<_StorageKind::_Array, 4>;
using m128d_abi = __simd_abi<_StorageKind::_Array, 4>;
// m128 ABI
template <>
inline simd<float, m128_abi> simd<float, m128_abi>::operator-() const {
return {-__s_.__storage_[0], -__s_.__storage_[1], -__s_.__storage_[2], -__s_.__storage_[3]};
}
inline simd<float, m128_abi> operator+(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
return {a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]};
}
inline simd<float, m128_abi> operator-(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
return {a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]};
}
inline simd<float, m128_abi> operator*(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
return {a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]};
}
inline simd<float, m128_abi> operator/(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
return {a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3]};
}
inline simd<float, m128_abi>& operator+=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a[0] += b[0];
a[1] += b[1];
a[2] += b[2];
a[3] += b[3];
return a;
}
inline simd<float, m128_abi>& operator-=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a[0] -= b[0];
a[1] -= b[1];
a[2] -= b[2];
a[3] -= b[3];
return a;
}
inline simd<float, m128_abi>& operator*=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a[0] *= b[0];
a[1] *= b[1];
a[2] *= b[2];
a[3] *= b[3];
return a;
}
inline simd<float, m128_abi>& operator/=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a[0] /= b[0];
a[1] /= b[1];
a[2] /= b[2];
a[3] /= b[3];
return a;
}
inline simd<float, m128_abi>::mask_type operator==(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret;
ret[0] = a[0] == b[0];
ret[1] = a[1] == b[1];
ret[2] = a[2] == b[2];
ret[3] = a[3] == b[3];
return ret;
}
inline simd<float, m128_abi>::mask_type operator!=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret;
ret[0] = a[0] != b[0];
ret[1] = a[1] != b[1];
ret[2] = a[2] != b[2];
ret[3] = a[3] != b[3];
return ret;
}
inline simd<float, m128_abi>::mask_type operator>=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret;
ret[0] = a[0] >= b[0];
ret[1] = a[1] >= b[1];
ret[2] = a[2] >= b[2];
ret[3] = a[3] >= b[3];
return ret;
}
inline simd<float, m128_abi>::mask_type operator<=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret;
ret[0] = a[0] <= b[0];
ret[1] = a[1] <= b[1];
ret[2] = a[2] <= b[2];
ret[3] = a[3] <= b[3];
return ret;
}
inline simd<float, m128_abi>::mask_type operator>(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret;
ret[0] = a[0] > b[0];
ret[1] = a[1] > b[1];
ret[2] = a[2] > b[2];
ret[3] = a[3] > b[3];
return ret;
}
inline simd<float, m128_abi>::mask_type operator<(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret;
ret[0] = a[0] < b[0];
ret[1] = a[1] < b[1];
ret[2] = a[2] < b[2];
ret[3] = a[3] < b[3];
return ret;
}
// m128d ABI
template <>
inline simd<double, m128d_abi> simd<double, m128d_abi>::operator-() const {
return {-__s_.__storage_[0], -__s_.__storage_[1], -__s_.__storage_[2], -__s_.__storage_[3]};
}
inline simd<double, m128d_abi> operator+(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
return {a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]};
}
inline simd<double, m128d_abi> operator-(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
return {a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]};
}
inline simd<double, m128d_abi> operator*(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
return {a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]};
}
inline simd<double, m128d_abi> operator/(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
return {a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3]};
}
inline simd<double, m128d_abi>& operator+=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
a[0] += b[0];
a[1] += b[1];
a[2] += b[2];
a[3] += b[3];
return a;
}
inline simd<double, m128d_abi>& operator-=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
a[0] -= b[0];
a[1] -= b[1];
a[2] -= b[2];
a[3] -= b[3];
return a;
}
inline simd<double, m128d_abi>& operator*=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
a[0] *= b[0];
a[1] *= b[1];
a[2] *= b[2];
a[3] *= b[3];
return a;
}
inline simd<double, m128d_abi>& operator/=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
a[0] /= b[0];
a[1] /= b[1];
a[2] /= b[2];
a[3] /= b[3];
return a;
}
inline simd<double, m128d_abi>::mask_type operator==(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret;
ret[0] = a[0] == b[0];
ret[1] = a[1] == b[1];
ret[2] = a[2] == b[2];
ret[3] = a[3] == b[3];
return ret;
}
inline simd<double, m128d_abi>::mask_type operator!=(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret;
ret[0] = a[0] != b[0];
ret[1] = a[1] != b[1];
ret[2] = a[2] != b[2];
ret[3] = a[3] != b[3];
return ret;
}
inline simd<double, m128d_abi>::mask_type operator>=(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret;
ret[0] = a[0] >= b[0];
ret[1] = a[1] >= b[1];
ret[2] = a[2] >= b[2];
ret[3] = a[3] >= b[3];
return ret;
}
inline simd<double, m128d_abi>::mask_type operator<=(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret;
ret[0] = a[0] <= b[0];
ret[1] = a[1] <= b[1];
ret[2] = a[2] <= b[2];
ret[3] = a[3] <= b[3];
return ret;
}
inline simd<double, m128d_abi>::mask_type operator>(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret;
ret[0] = a[0] > b[0];
ret[1] = a[1] > b[1];
ret[2] = a[2] > b[2];
ret[3] = a[3] > b[3];
return ret;
}
inline simd<double, m128d_abi>::mask_type operator<(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret;
ret[0] = a[0] < b[0];
ret[1] = a[1] < b[1];
ret[2] = a[2] < b[2];
ret[3] = a[3] < b[3];
return ret;
}
} // namespace zeus::_simd

View File

@ -46,15 +46,15 @@ void CMatrix3f::transpose() {
float tmp; float tmp;
tmp = m[0][1]; tmp = m[0][1];
m[0][1] = m[1][0]; m[0][1] = m[1][0].operator float();
m[1][0] = tmp; m[1][0] = tmp;
tmp = m[0][2]; tmp = m[0][2];
m[0][2] = m[2][0]; m[0][2] = m[2][0].operator float();
m[2][0] = tmp; m[2][0] = tmp;
tmp = m[1][2]; tmp = m[1][2];
m[1][2] = m[2][1]; m[1][2] = m[2][1].operator float();
m[2][1] = tmp; m[2][1] = tmp;
#endif #endif
} }
@ -80,15 +80,15 @@ CMatrix3f CMatrix3f::transposed() const {
float tmp; float tmp;
tmp = ret.m[0][1]; tmp = ret.m[0][1];
ret.m[0][1] = ret.m[1][0]; ret.m[0][1] = ret.m[1][0].operator float();
ret.m[1][0] = tmp; ret.m[1][0] = tmp;
tmp = m[0][2]; tmp = m[0][2];
ret.m[0][2] = ret.m[2][0]; ret.m[0][2] = ret.m[2][0].operator float();
ret.m[2][0] = tmp; ret.m[2][0] = tmp;
tmp = m[1][2]; tmp = m[1][2];
ret.m[1][2] = ret.m[2][1]; ret.m[1][2] = ret.m[2][1].operator float();
ret.m[2][1] = tmp; ret.m[2][1] = tmp;
return ret; return ret;