Skip to content

Commit

Permalink
Deprecate Vector::copySign in favor of Vc::copysign
Browse files Browse the repository at this point in the history
Fixes: gh-78
Signed-off-by: Matthias Kretz <kretz@kde.org>
  • Loading branch information
mattkretz committed Dec 15, 2015
1 parent f121987 commit da83c44
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 118 deletions.
13 changes: 10 additions & 3 deletions avx/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ Vc_ALWAYS_INLINE Vc_PURE AVX2::float_m isnan(const AVX2::float_v &x)
}

// copysign {{{1
template <typename T>
Vc_INTRINSIC AVX2::Vector<T> copysign(AVX2::Vector<T> a, AVX2::Vector<T> b)
Vc_INTRINSIC Vc_CONST AVX2::float_v copysign(AVX2::float_v mag, AVX2::float_v sign)
{
return _mm256_or_ps(_mm256_and_ps(sign.data(), AVX::setsignmask_ps()),
_mm256_and_ps(mag.data(), AVX::setabsmask_ps()));
}
Vc_INTRINSIC Vc_CONST AVX2::double_v copysign(AVX2::double_v::AsArg mag,
AVX2::double_v::AsArg sign)
{
return a.copySign(b);
return _mm256_or_pd(_mm256_and_pd(sign.data(), AVX::setsignmask_pd()),
_mm256_and_pd(mag.data(), AVX::setabsmask_pd()));
}

//}}}1
// frexp {{{1
/**
* splits \p v into exponent and mantissa, the sign is kept with the mantissa
Expand Down
7 changes: 6 additions & 1 deletion avx/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,12 @@ template <typename T> class Vector<T, VectorAbi::Avx>

template <typename G> static Vc_INTRINSIC_L Vector generate(G gen) Vc_INTRINSIC_R;

Vc_INTRINSIC_L Vector copySign(AsArg reference) const Vc_INTRINSIC_R;
Vc_INTRINSIC Vc_DEPRECATED("use copysign(x, y) instead") Vector
copySign(AsArg reference) const
{
return Vc::copysign(*this, reference);
}

Vc_INTRINSIC Vc_DEPRECATED("use exponent(x) instead") Vector exponent() const
{
Vc::exponent(*this);
Expand Down
15 changes: 0 additions & 15 deletions avx/vector.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -657,21 +657,6 @@ template<typename T> Vc_ALWAYS_INLINE typename Vector<T, VectorAbi::Avx>::EntryT
tmp(m) = *this;
return tmp.sum();
}//}}}
// copySign {{{1
template<> Vc_INTRINSIC AVX2::float_v AVX2::float_v::copySign(AVX2::float_v::AsArg reference) const
{
return _mm256_or_ps(
_mm256_and_ps(reference.d.v(), AVX::setsignmask_ps()),
_mm256_and_ps(d.v(), AVX::setabsmask_ps())
);
}
template<> Vc_INTRINSIC AVX2::double_v AVX2::double_v::copySign(AVX2::double_v::AsArg reference) const
{
return _mm256_or_pd(
_mm256_and_pd(reference.d.v(), AVX::setsignmask_pd()),
_mm256_and_pd(d.v(), AVX::setabsmask_pd())
);
}//}}}1
// exponent {{{1
namespace Detail
{
Expand Down
13 changes: 7 additions & 6 deletions common/simdarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ class alignas(
return {VectorType::generate(gen)};
}

Vc_INTRINSIC SimdArray copySign(const SimdArray &reference) const
Vc_INTRINSIC Vc_DEPRECATED("use copysign(x, y) instead") SimdArray
copySign(const SimdArray &reference) const
{
return {data.copySign(reference.data)};
return {Vc::copysign(data, reference.data)};
}

friend VectorType &internal_data<>(SimdArray &x);
Expand Down Expand Up @@ -1153,11 +1154,11 @@ class alignas(
storage_type1::generate([&](std::size_t i) { return gen(i + N0); })};
}

Vc_INTRINSIC SimdArray copySign(const SimdArray& reference) const
Vc_INTRINSIC Vc_DEPRECATED("use copysign(x, y) instead") SimdArray
copySign(const SimdArray &reference) const
{
auto lo = data0.copySign(reference.data0);
auto hi = data1.copySign(reference.data1);
return {std::move(lo), std::move(hi)};
return {Vc::copysign(data0, reference.data0),
Vc::copysign(data1, reference.data1)};
}

// internal_data0/1 {{{2
Expand Down
18 changes: 17 additions & 1 deletion common/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace Vc_VERSIONED_NAMESPACE
{
/**
* \ingroup Math
* Copies the sign(s) of \p sign to the value(s) in \p magnitude and returns the resulting
* vector.
*
* \param magnitude This vector's magnitude will be used in the return vector.
* \param sign This vector's sign bit will be used in the return vector.
*
* \return a value where the sign of the value equals the sign of \p sign. I.e.
* `sign(copysign(v, r)) == sign(r)`.
*/
template <typename T, typename Abi,
typename = enable_if<std::is_floating_point<T>::value>>
inline Vector<T, Abi> copysign(Vector<T, Abi> magnitude, Vector<T, Abi> sign);

/**
* \ingroup Math
* Extracts the exponent of each floating-point vector component.
Expand Down Expand Up @@ -761,7 +776,8 @@ template<typename T, typename Abi = VectorAbi::Best<T>> class Vector
*
* \deprecated Use Vc::copysign instead.
*/
inline Vector copySign(Vector reference) const;
inline Vc_DEPRECATED("use copysign(x, y) instead") Vector
copySign(Vector reference) const;
///@}
private:
VectorType d;
Expand Down
11 changes: 0 additions & 11 deletions doc/dox-real-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}}}*/


/**
* Copies the sign of \p reference.
*
* \param reference This values sign bit will be transferred.
*
* \return a value where the sign of the value equals the sign of \p reference. I.e.
* sign(v.copySign(r)) == sign(r).
*/
inline VECTOR_TYPE copySign(VECTOR_TYPE reference) const;

/**
* Check the sign bit of each vector entry.
*
Expand Down
13 changes: 9 additions & 4 deletions mic/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Vc_VERSIONED_NAMESPACE
{
// copysign {{{1
template <typename T>
Vc_ALWAYS_INLINE Vector<T, VectorAbi::Mic> copysign(Vector<T, VectorAbi::Mic> a,
Vector<T, VectorAbi::Mic> b)
Vc_INTRINSIC Vc_CONST MIC::float_v copysign(MIC::float_v mag, MIC::float_v sign)
{
return MIC::_or(MIC::_and(sign.d.v(), MIC::_mm512_setsignmask_ps()),
MIC::_and(mag.d.v(), MIC::_mm512_setabsmask_ps()));
}
Vc_INTRINSIC Vc_CONST MIC::double_v copysign(MIC::double_v mag, MIC::double_v sign)
{
return a.copySign(b);
return MIC::_or(MIC::_and(sign.d.v(), MIC::_mm512_setsignmask_pd()),
MIC::_and(mag.d.v(), MIC::_mm512_setabsmask_pd()));
}

// trunc {{{1
template <typename V> Vc_ALWAYS_INLINE V trunc(V v) { return _mm512_trunc_ps(v.data()); }
Vc_ALWAYS_INLINE MIC::double_v trunc(MIC::double_v v)
Expand Down
6 changes: 5 additions & 1 deletion mic/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ class Vector<T, VectorAbi::Mic> : public MIC::StoreMixin<MIC::Vector<T>, T>
return r;
}

Vc_INTRINSIC_L Vector copySign(AsArg reference) const Vc_INTRINSIC_R;
Vc_INTRINSIC Vc_DEPRECATED("use copysign(x, y) instead") Vector
copySign(AsArg reference) const
{
return Vc::copysign(*this, reference);
}
Vc_INTRINSIC Vc_DEPRECATED("use exponent(x) instead") Vector exponent() const
{
return Vc::exponent(*this);
Expand Down
11 changes: 0 additions & 11 deletions mic/vector.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,6 @@ template<> inline double Vector<double>::sum(MaskArgument m) const
return _mm512_mask_reduce_add_pd(m.data(), data());
}

// copySign {{{1
template<> Vc_INTRINSIC MIC::float_v MIC::float_v::copySign(MIC::float_v::AsArg reference) const
{
return MIC::_or(MIC::_and(reference.d.v(), MIC::_mm512_setsignmask_ps()),
MIC::_and(d.v(), MIC::_mm512_setabsmask_ps()));
}
template<> Vc_INTRINSIC MIC::double_v MIC::double_v::copySign(MIC::double_v::AsArg reference) const
{
return MIC::_or(MIC::_and(reference.d.v(), MIC::_mm512_setsignmask_pd()),
MIC::_and(d.v(), MIC::_mm512_setabsmask_pd()));
}//}}}1
// (u)short compares {{{1
// only unsigned integers have well-defined behavior on over-/underflow
template<> Vc_ALWAYS_INLINE MIC::ushort_m MIC::ushort_v::operator==(MIC::ushort_v::AsArg x) const {
Expand Down
26 changes: 24 additions & 2 deletions scalar/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,32 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace Vc_VERSIONED_NAMESPACE
{
template <typename T> Vc_ALWAYS_INLINE Scalar::Vector<T> copysign(Scalar::Vector<T> a, Scalar::Vector<T> b)
// copysign {{{1
Vc_INTRINSIC Scalar::float_v copysign(Scalar::float_v mag, Scalar::float_v sign)
{
return a.copySign(b);
union {
float f;
unsigned int i;
} value, s;
value.f = mag.data();
s.f = sign.data();
value.i = (s.i & 0x80000000u) | (value.i & 0x7fffffffu);
return Scalar::float_v{value.f};
}
Vc_INTRINSIC Vc_CONST Scalar::double_v copysign(Scalar::double_v mag,
Scalar::double_v sign)
{
union {
double f;
unsigned long long i;
} value, s;
value.f = mag.data();
s.f = sign.data();
value.i = (s.i & 0x8000000000000000ull) | (value.i & 0x7fffffffffffffffull);
return Scalar::double_v{value.f};
}

// }}}1

#define Vc_MINMAX(V) \
static Vc_ALWAYS_INLINE Scalar::V min(const Scalar::V &x, const Scalar::V &y) \
Expand Down
7 changes: 6 additions & 1 deletion scalar/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ template <typename T> class Vector<T, VectorAbi::Scalar>
return gen(0);
}

Vc_INTRINSIC_L Vector copySign(Vector reference) const Vc_INTRINSIC_R;
Vc_INTRINSIC Vc_DEPRECATED("use copysign(x, y) instead") Vector
copySign(Vector reference) const
{
return Vc::copysign(*this, reference);
}

Vc_INTRINSIC Vc_DEPRECATED("use exponent(x) instead") Vector exponent() const
{
return Vc::exponent(*this);
Expand Down
24 changes: 0 additions & 24 deletions scalar/vector.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,6 @@ Vc_ALWAYS_INLINE void Vector<T, VectorAbi::Scalar>::scatterImplementation(
}
}

// copySign {{{1
template <>
Vc_INTRINSIC Scalar::float_v Scalar::float_v::copySign(Scalar::float_v reference) const
{
union {
float f;
unsigned int i;
} value, sign;
value.f = data();
sign.f = reference.data();
value.i = (sign.i & 0x80000000u) | (value.i & 0x7fffffffu);
return Scalar::float_v{value.f};
}
template<> Vc_INTRINSIC Scalar::double_v Scalar::double_v::copySign(Scalar::double_v reference) const
{
union {
double f;
unsigned long long i;
} value, sign;
value.f = data();
sign.f = reference.data();
value.i = (sign.i & 0x8000000000000000ull) | (value.i & 0x7fffffffffffffffull);
return Scalar::double_v{value.f};
} // }}}1
// bitwise operators {{{1
#define Vc_CAST_OPERATOR_FORWARD(op, IntT, VecT) \
template<> Vc_ALWAYS_INLINE VecT &VecT::operator op##=(const VecT &x) { \
Expand Down
20 changes: 10 additions & 10 deletions src/trigonometric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,29 +393,29 @@ template<> template<typename V> V Trigonometric<Vc::Detail::TrigonometricImpleme
const M xInf = !isfinite(x);
const M yInf = !isfinite(y);

V a = C::_pi().copySign(y);
V a = copysign(C::_pi(), y);
a.setZero(x >= V::Zero());

// setting x to any finite value will have atan(y/x) return sign(y/x)*pi/2, just in case x is inf
V _x = x;
_x(yInf) = V::One().copySign(x);
_x(yInf) = copysign(V::One(), x);

a += atan(y / _x);

// if x is +0 and y is +/-0 the result is +0
a.setZero(xZero && yZero);

// for x = -0 we add/subtract pi to get the correct result
a(xMinusZero) += C::_pi().copySign(y);
a(xMinusZero) += copysign(C::_pi(), y);

// atan2(-Y, +/-0) = -pi/2
a(xZero && yNeg) = -C::_pi_2();

// if both inputs are inf the output is +/- (3)pi/4
a(xInf && yInf) += C::_pi_4().copySign(x ^ ~y);
a(xInf && yInf) += copysign(C::_pi_4(), x ^ ~y);

// correct the sign of y if the result is 0
a(a == V::Zero()) = a.copySign(y);
a(a == V::Zero()) = copysign(a, y);

// any NaN input will lead to NaN output
a.setQnan(isnan(y) || isnan(x));
Expand All @@ -434,29 +434,29 @@ template<> template<> Vc::double_v Trigonometric<Vc::Detail::TrigonometricImplem
const M xInf = !isfinite(x);
const M yInf = !isfinite(y);

V a = V(C::_pi()).copySign(y);
V a = copysign(V(C::_pi()), y);
a.setZero(x >= V::Zero());

// setting x to any finite value will have atan(y/x) return sign(y/x)*pi/2, just in case x is inf
V _x = x;
_x(yInf) = V::One().copySign(x);
_x(yInf) = copysign(V::One(), x);

a += atan(y / _x);

// if x is +0 and y is +/-0 the result is +0
a.setZero(xZero && yZero);

// for x = -0 we add/subtract pi to get the correct result
a(xMinusZero) += C::_pi().copySign(y);
a(xMinusZero) += copysign(C::_pi(), y);

// atan2(-Y, +/-0) = -pi/2
a(xZero && yNeg) = -C::_pi_2();

// if both inputs are inf the output is +/- (3)pi/4
a(xInf && yInf) += C::_pi_4().copySign(x ^ ~y);
a(xInf && yInf) += copysign(C::_pi_4(), x ^ ~y);

// correct the sign of y if the result is 0
a(a == V::Zero()) = a.copySign(y);
a(a == V::Zero()) = copysign(a, y);

// any NaN input will lead to NaN output
a.setQnan(isnan(y) || isnan(x));
Expand Down
14 changes: 12 additions & 2 deletions sse/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace Vc_VERSIONED_NAMESPACE
{
template <typename T> Vc_ALWAYS_INLINE SSE::Vector<T> copysign(SSE::Vector<T> a, SSE::Vector<T> b)
// copysign {{{1
Vc_INTRINSIC Vc_CONST SSE::float_v copysign(SSE::float_v mag, SSE::float_v sign)
{
return a.copySign(b);
return _mm_or_ps(_mm_and_ps(sign.data(), SSE::_mm_setsignmask_ps()),
_mm_and_ps(mag.data(), SSE::_mm_setabsmask_ps()));
}
Vc_INTRINSIC Vc_CONST SSE::double_v copysign(SSE::double_v mag, SSE::double_v sign)
{
return _mm_or_pd(_mm_and_pd(sign.data(), SSE::_mm_setsignmask_pd()),
_mm_and_pd(mag.data(), SSE::_mm_setabsmask_pd()));
}

//}}}1

/**
* splits \p v into exponent and mantissa, the sign is kept with the mantissa
*
Expand Down
7 changes: 6 additions & 1 deletion sse/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@ template <typename T> class Vector<T, VectorAbi::Sse>

template <typename G> static Vc_INTRINSIC_L Vector generate(G gen) Vc_INTRINSIC_R;

Vc_INTRINSIC_L Vector copySign(typename Vector::AsArg reference) const Vc_INTRINSIC_R;
Vc_INTRINSIC Vc_DEPRECATED("use copysign(x, y) instead") Vector
copySign(AsArg reference) const
{
return Vc::copysign(*this, reference);
}

Vc_INTRINSIC Vc_DEPRECATED("use exponent(x) instead") Vector exponent() const
{
return Vc::exponent(*this);
Expand Down
15 changes: 0 additions & 15 deletions sse/vector.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -551,21 +551,6 @@ template<typename T> Vc_ALWAYS_INLINE Vc_PURE typename Vector<T, VectorAbi::Sse>
}

///////////////////////////////////////////////////////////////////////////////////////////
// copySign {{{1
template<> Vc_INTRINSIC Vc_PURE SSE::float_v SSE::float_v::copySign(SSE::float_v::AsArg reference) const
{
return _mm_or_ps(
_mm_and_ps(reference.d.v(), SSE::_mm_setsignmask_ps()),
_mm_and_ps(d.v(), SSE::_mm_setabsmask_ps())
);
}
template<> Vc_INTRINSIC Vc_PURE SSE::double_v SSE::double_v::copySign(SSE::double_v::AsArg reference) const
{
return _mm_or_pd(
_mm_and_pd(reference.d.v(), SSE::_mm_setsignmask_pd()),
_mm_and_pd(d.v(), SSE::_mm_setabsmask_pd())
);
}//}}}1
// exponent {{{1
namespace Detail
{
Expand Down
Loading

0 comments on commit da83c44

Please sign in to comment.