Commit 867e409c authored by Martin Reinecke's avatar Martin Reinecke
Browse files

prepare pseudoscalar vector types

parent 91cc5b6e
......@@ -171,12 +171,47 @@ template<typename Op, typename T, size_t len> T reduce(const vtp<T, len> &v, Op
res = op(res, v[i]);
return res;
}
template<typename T> class pseudoscalar
{
private:
T v;
public:
pseudoscalar() = default;
pseudoscalar(const pseudoscalar &other) = default;
pseudoscalar(T v_):v(v_) {}
pseudoscalar operator-() const { return pseudoscalar(-v); }
pseudoscalar operator+(pseudoscalar other) const { return pseudoscalar(v+other.v); }
pseudoscalar operator-(pseudoscalar other) const { return pseudoscalar(v-other.v); }
pseudoscalar operator*(pseudoscalar other) const { return pseudoscalar(v*other.v); }
pseudoscalar operator/(pseudoscalar other) const { return pseudoscalar(v/other.v); }
pseudoscalar &operator+=(pseudoscalar other) { v+=other.v; return *this; }
pseudoscalar &operator-=(pseudoscalar other) { v-=other.v; return *this; }
pseudoscalar &operator*=(pseudoscalar other) { v*=other.v; return *this; }
pseudoscalar &operator/=(pseudoscalar other) { v/=other.v; return *this; }
/*
pseudoscalar abs() const { return hlp::abs(v); }
inline pseudoscalar sqrt() const
{ return sqrt(v); }
pseudoscalar max(const pseudoscalar &other) const
{ return hlp::max(v, other.v); }
Tm operator>(const pseudoscalar &other) const
{ return hlp::gt(v, other.v); }
Tm operator>=(const pseudoscalar &other) const
{ return hlp::ge(v, other.v); }
Tm operator<(const vtp &other) const
{ return hlp::lt(v, other.v); }
Tm operator!=(const vtp &other) const
{ return hlp::ne(v, other.v); }
*/
const T &operator[] (size_t /*i*/) const { return v; }
T &operator[](size_t /*i*/) { return v; }
};
template<typename T> class helper_<T,1>
{
private:
static constexpr size_t len = 1;
public:
using Tv = T;
using Tv = pseudoscalar<T>;
using Tm = bool;
static Tv from_scalar(T v) { return v; }
......@@ -257,7 +292,7 @@ template<> class helper_<double,4>
static Tm lt (Tv v1, Tv v2) { return _mm256_cmp_pd(v1,v2,_CMP_LT_OQ); }
static Tm ne (Tv v1, Tv v2) { return _mm256_cmp_pd(v1,v2,_CMP_NEQ_OQ); }
static Tm mask_and (Tm v1, Tm v2) { return _mm256_and_pd(v1,v2); }
static size_t maskbits(Tm v) { return _mm256_movemask_pd(v); }
static size_t maskbits(Tm v) { return size_t(_mm256_movemask_pd(v)); }
};
template<> class helper_<float,8>
{
......@@ -278,7 +313,7 @@ template<> class helper_<float,8>
static Tm lt (Tv v1, Tv v2) { return _mm256_cmp_ps(v1,v2,_CMP_LT_OQ); }
static Tm ne (Tv v1, Tv v2) { return _mm256_cmp_ps(v1,v2,_CMP_NEQ_OQ); }
static Tm mask_and (Tm v1, Tm v2) { return _mm256_and_ps(v1,v2); }
static size_t maskbits(Tm v) { return _mm256_movemask_ps(v); }
static size_t maskbits(Tm v) { return size_t(_mm256_movemask_ps(v)); }
};
template<typename T> using native_simd = vtp<T,32/sizeof(T)>;
......@@ -309,7 +344,7 @@ template<> class helper_<double,2>
static Tm lt (Tv v1, Tv v2) { return _mm_cmplt_pd(v1,v2); }
static Tm ne (Tv v1, Tv v2) { return _mm_cmpneq_pd(v1,v2); }
static Tm mask_and (Tm v1, Tm v2) { return _mm_and_pd(v1,v2); }
static size_t maskbits(Tm v) { return _mm_movemask_pd(v); }
static size_t maskbits(Tm v) { return size_t(_mm_movemask_pd(v)); }
};
template<> class helper_<float,4>
{
......@@ -337,7 +372,7 @@ template<> class helper_<float,4>
static Tm lt (Tv v1, Tv v2) { return _mm_cmplt_ps(v1,v2); }
static Tm ne (Tv v1, Tv v2) { return _mm_cmpneq_ps(v1,v2); }
static Tm mask_and (Tm v1, Tm v2) { return _mm_and_ps(v1,v2); }
static size_t maskbits(Tm v) { return _mm_movemask_ps(v); }
static size_t maskbits(Tm v) { return size_t(_mm_movemask_ps(v)); }
};
template<typename T> using native_simd = vtp<T,16/sizeof(T)>;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment