Skip to content

Commit

Permalink
MSVC: fix isnan(fixed_size_simd) somehow returning bool
Browse files Browse the repository at this point in the history
For inexplicable reasons `isnan(fixed_size_simd<double, 19>())` returns
bool. None of the Vc functions could have been the chosen overload of
isnan for this too happen. Whatever crazy things Microsoft does to have
such an isnan function... now Vc tries harder to grab overloads of
fixed_size_simd.

In addition, the workaround for a MSVC miscompilation, now is ill-formed
when compiled for AVX, since SimdArray<double, 8, SSE::Vector<double>,
2> will use AVX::Vector<double> for its internal_data[01].

Signed-off-by: Matthias Kretz <kretz@kde.org>
  • Loading branch information
mattkretz committed Sep 18, 2018
1 parent 510396e commit b120d86
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Vc/common/simdarray.h
Expand Up @@ -1698,6 +1698,12 @@ Vc_ALL_COMPARES(Vc_BINARY_OPERATORS_);
return SimdArray<T, N, V, M>::fromOperation( \
Common::Operations::Forward_##name_(), x); \
} \
template <class T, int N> \
fixed_size_simd<T, N> name_(const fixed_size_simd<T, N> &x) \
{ \
return fixed_size_simd<T, N>::fromOperation( \
Common::Operations::Forward_##name_(), x); \
} \
Vc_NOTHING_EXPECTING_SEMICOLON

#define Vc_FORWARD_UNARY_BOOL_OPERATOR(name_) \
Expand All @@ -1708,6 +1714,12 @@ Vc_ALL_COMPARES(Vc_BINARY_OPERATORS_);
return SimdMaskArray<T, N, V, M>::fromOperation( \
Common::Operations::Forward_##name_(), x); \
} \
template <class T, int N> \
fixed_size_simd_mask<T, N> name_(const fixed_size_simd<T, N> &x) \
{ \
return fixed_size_simd_mask<T, N>::fromOperation( \
Common::Operations::Forward_##name_(), x); \
} \
Vc_NOTHING_EXPECTING_SEMICOLON

#define Vc_FORWARD_BINARY_OPERATOR(name_) \
Expand All @@ -1719,6 +1731,13 @@ Vc_ALL_COMPARES(Vc_BINARY_OPERATORS_);
return SimdArray<T, N, V, M>::fromOperation( \
Common::Operations::Forward_##name_(), x, y); \
} \
template <typename T, int N> \
inline fixed_size_simd<T, N> name_(const fixed_size_simd<T, N> &x, \
const fixed_size_simd<T, N> &y) \
{ \
return fixed_size_simd<T, N>::fromOperation( \
Common::Operations::Forward_##name_(), x, y); \
} \
Vc_NOTHING_EXPECTING_SEMICOLON

/**
Expand Down Expand Up @@ -1746,22 +1765,6 @@ inline SimdArray<T, N> fma(const SimdArray<T, N> &a, const SimdArray<T, N> &b,
Vc_FORWARD_UNARY_BOOL_OPERATOR(isfinite);
Vc_FORWARD_UNARY_BOOL_OPERATOR(isinf);
Vc_FORWARD_UNARY_BOOL_OPERATOR(isnan);
#if defined Vc_MSVC && defined Vc_IMPL_SSE
inline SimdMaskArray<double, 8, SSE::Vector<double>, 2> isnan(
const SimdArray<double, 8, SSE::Vector<double>, 2> &x)
{
using V = SSE::Vector<double>;
const SimdArray<double, 4, V, 2> &x0 = internal_data0(x);
const SimdArray<double, 4, V, 2> &x1 = internal_data1(x);
SimdMaskArray<double, 4, V, 2> r0;
SimdMaskArray<double, 4, V, 2> r1;
internal_data(internal_data0(r0)) = isnan(internal_data(internal_data0(x0)));
internal_data(internal_data1(r0)) = isnan(internal_data(internal_data1(x0)));
internal_data(internal_data0(r1)) = isnan(internal_data(internal_data0(x1)));
internal_data(internal_data1(r1)) = isnan(internal_data(internal_data1(x1)));
return {std::move(r0), std::move(r1)};
}
#endif
Vc_FORWARD_UNARY_BOOL_OPERATOR(isnegative);
/// Applies the std::frexp function component-wise and concurrently.
template <typename T, std::size_t N>
Expand Down
8 changes: 8 additions & 0 deletions Vc/common/simdmaskarray.h
Expand Up @@ -120,6 +120,10 @@ class SimdMaskArray<T, N, VectorType_, N>
{
return simd_cast<Vc::Mask<U, A>>(data);
}
operator fixed_size_simd_mask<T, N>() const
{
return static_cast<fixed_size_simd_mask<T, N>>(data);
}

// load/store (from/to bool arrays)
template <typename Flags = DefaultLoadTag>
Expand Down Expand Up @@ -394,6 +398,10 @@ class SimdMaskArray
{
return simd_cast<Vc::Mask<U, A>>(data0, data1);
}
Vc_INTRINSIC operator const fixed_size_simd_mask<T, N> &() const
{
return static_cast<const fixed_size_simd_mask<T, N> &>(*this);
}

///\copybrief Mask::Mask(VectorSpecialInitializerOne)
Vc_INTRINSIC explicit SimdMaskArray(VectorSpecialInitializerOne one)
Expand Down

0 comments on commit b120d86

Please sign in to comment.