[go: nahoru, domu]

Skip to content

Commit

Permalink
Fixes a serious bug that caused math functions on vectors greater tha…
Browse files Browse the repository at this point in the history
…n 256 to not compile
  • Loading branch information
romeric committed May 3, 2019
1 parent f707070 commit ca2c74d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 16 deletions.
96 changes: 84 additions & 12 deletions simd_vector/SIMDVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@
// Generic overloads
namespace Fastor {

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> exp(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_exp(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> exp(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::exp(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> log(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_log(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> log(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::log(i);}
return out;
}

template<typename T, typename U>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> pow(const SIMDVector<T,DEFAULT_ABI> &a, const SIMDVector<U,DEFAULT_ABI> &b) {
Expand All @@ -32,76 +44,136 @@ FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> pow(const SIMDVector<T,DEFAULT_ABI> &a,
return out;
}

template<typename T, typename U>
template<typename T, typename U, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> pow(const SIMDVector<T,DEFAULT_ABI> &a, U bb) {
SIMDVector<T,DEFAULT_ABI> out;
SIMDVector<T,DEFAULT_ABI> b = static_cast<T>(bb);
out.value = internal_pow(a.value, b.value);
return out;
}
template<typename T, typename U, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> pow(const SIMDVector<T,DEFAULT_ABI> &a, U bb) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::pow(i, bb);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> sin(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_sin(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> sin(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::sin(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> cos(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_cos(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> cos(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::cos(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> tan(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_tan(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> tan(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::tan(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> asin(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_asin(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> asin(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::asin(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> acos(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_acos(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> acos(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::acos(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> atan(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_atan(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> atan(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::atan(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> sinh(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_sinh(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> sinh(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::sinh(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> cosh(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_cosh(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> cosh(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::cosh(i);}
return out;
}

template<typename T>
template<typename T, typename std::enable_if<!std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> tanh(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
out.value = internal_tanh(a.value);
return out;
}
template<typename T, typename std::enable_if<std::is_array<typename SIMDVector<T,DEFAULT_ABI>::value_type>::value,bool>::type=0>
FASTOR_INLINE SIMDVector<T,DEFAULT_ABI> tanh(const SIMDVector<T,DEFAULT_ABI> &a) {
SIMDVector<T,DEFAULT_ABI> out;
for (FASTOR_INDEX i=0; i<SIMDVector<T,DEFAULT_ABI>::Size; i++) { out.value[i] = std::tanh(i);}
return out;
}



Expand Down
1 change: 1 addition & 0 deletions simd_vector/simd_vector_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct SIMDVector {
static constexpr FASTOR_INDEX Size = get_vector_size<T,ABI>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<T,ABI>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
using value_type = T[Size];

FASTOR_INLINE SIMDVector() {
std::fill(value, value+Size, 0.);
Expand Down
3 changes: 3 additions & 0 deletions simd_vector/simd_vector_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Fastor {

template <>
struct SIMDVector<double, 256> {
using value_type = __m256d;
static constexpr FASTOR_INDEX Size = get_vector_size<double>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<double>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -262,6 +263,7 @@ FASTOR_INLINE SIMDVector<double> abs(const SIMDVector<double> &a) {

template <>
struct SIMDVector<double, 128> {
using value_type = __m128d;
static constexpr FASTOR_INDEX Size = get_vector_size<double,128>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<double,128>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -508,6 +510,7 @@ FASTOR_INLINE SIMDVector<double,128> abs(const SIMDVector<double,128> &a) {
//------------------------------------------------------------------------------------------------------------
template <>
struct SIMDVector<double, 64> {
using value_type = double;
static constexpr FASTOR_INDEX Size = 1;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return 1;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - 1);}
Expand Down
3 changes: 3 additions & 0 deletions simd_vector/simd_vector_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Fastor {

template <>
struct SIMDVector<float,256> {
using value_type = __m256;
static constexpr FASTOR_INDEX Size = get_vector_size<float>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<float>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -268,6 +269,7 @@ FASTOR_INLINE SIMDVector<float> abs(const SIMDVector<float> &a) {

template <>
struct SIMDVector<float,128> {
using value_type = __m128;
static constexpr FASTOR_INDEX Size = get_vector_size<float,128>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<float,128>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -510,6 +512,7 @@ FASTOR_INLINE SIMDVector<float,128> abs(const SIMDVector<float,128> &a) {
//------------------------------------------------------------------------------------------------------------
template <>
struct SIMDVector<float, 32> {
using value_type = float;
static constexpr FASTOR_INDEX Size = 1;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return 1;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - 1);}
Expand Down
5 changes: 3 additions & 2 deletions simd_vector/simd_vector_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Fastor {

template<>
struct SIMDVector<int,256> {

using value_type = __m256i;
static constexpr FASTOR_INDEX Size = get_vector_size<int,256>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<int,256>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -231,7 +231,7 @@ FASTOR_INLINE SIMDVector<int> abs(const SIMDVector<int> &a) {

template<>
struct SIMDVector<int,128> {

using value_type = __m128i;
static constexpr FASTOR_INDEX Size = get_vector_size<int,128>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<int,128>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -433,6 +433,7 @@ FASTOR_INLINE SIMDVector<int,128> abs(const SIMDVector<int,128> &a) {
//------------------------------------------------------------------------------------------------------------
template <>
struct SIMDVector<int, 32> {
using value_type = int;
static constexpr FASTOR_INDEX Size = 1;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return 1;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - 1);}
Expand Down
5 changes: 3 additions & 2 deletions simd_vector/simd_vector_int64.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Fastor {

template<>
struct SIMDVector<Int64,256> {

using value_type = __m256i;
static constexpr FASTOR_INDEX Size = get_vector_size<Int64,256>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<Int64,256>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -218,7 +218,7 @@ FASTOR_INLINE SIMDVector<Int64> operator*(Int64 a, const SIMDVector<Int64> &b) {
template<>
struct SIMDVector<Int64,128> {
// CAREFUL WHILE USING THIS AS THIS CONVERTS Int64 TO int IN MOST CASES

using value_type = __m128i;
static constexpr FASTOR_INDEX Size = get_vector_size<Int64,128>::size;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return get_vector_size<Int64,128>::size;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - static_cast<int>(Size));}
Expand Down Expand Up @@ -425,6 +425,7 @@ FASTOR_INLINE SIMDVector<Int64,128> operator*(Int64 a, const SIMDVector<Int64,12
//------------------------------------------------------------------------------------------------------------
template <>
struct SIMDVector<Int64, 64> {
using value_type = Int64;
static constexpr FASTOR_INDEX Size = 1;
static constexpr FASTOR_INLINE FASTOR_INDEX size() {return 1;}
static constexpr int unroll_size(FASTOR_INDEX size) {return (static_cast<int>(size) - 1);}
Expand Down

0 comments on commit ca2c74d

Please sign in to comment.