mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-24 14:45:14 +08:00
Remove aligned-on-scalar assert and fallback to non vectorized path at runtime (first_aligned already had this runtime guard)
This commit is contained in:
parent
2361ec9c0e
commit
1c6b224fb3
@ -439,19 +439,26 @@ struct assign_impl<Derived1, Derived2, SliceVectorizedTraversal, NoUnrolling, Ve
|
||||
typedef typename Derived1::Index Index;
|
||||
static inline void run(Derived1 &dst, const Derived2 &src)
|
||||
{
|
||||
typedef packet_traits<typename Derived1::Scalar> PacketTraits;
|
||||
typedef typename Derived1::Scalar Scalar;
|
||||
typedef packet_traits<Scalar> PacketTraits;
|
||||
enum {
|
||||
packetSize = PacketTraits::size,
|
||||
alignable = PacketTraits::AlignedOnScalar,
|
||||
dstAlignment = alignable ? Aligned : int(assign_traits<Derived1,Derived2>::DstIsAligned) ,
|
||||
dstIsAligned = assign_traits<Derived1,Derived2>::DstIsAligned,
|
||||
dstAlignment = alignable ? Aligned : int(dstIsAligned),
|
||||
srcAlignment = assign_traits<Derived1,Derived2>::JointAlignment
|
||||
};
|
||||
const Scalar *dst_ptr = &dst.coeffRef(0,0);
|
||||
if((!bool(dstIsAligned)) && (Index(dst_ptr) % sizeof(Scalar))>0)
|
||||
{
|
||||
// the pointer is not aligend-on scalar, so alignment is not possible
|
||||
return assign_impl<Derived1,Derived2,DefaultTraversal,NoUnrolling>::run(dst, src);
|
||||
}
|
||||
const Index packetAlignedMask = packetSize - 1;
|
||||
const Index innerSize = dst.innerSize();
|
||||
const Index outerSize = dst.outerSize();
|
||||
const Index alignedStep = alignable ? (packetSize - dst.outerStride() % packetSize) & packetAlignedMask : 0;
|
||||
Index alignedStart = ((!alignable) || assign_traits<Derived1,Derived2>::DstIsAligned) ? 0
|
||||
: internal::first_aligned(&dst.coeffRef(0,0), innerSize);
|
||||
Index alignedStart = ((!alignable) || bool(dstIsAligned)) ? 0 : internal::first_aligned(dst_ptr, innerSize);
|
||||
|
||||
for(Index outer = 0; outer < outerSize; ++outer)
|
||||
{
|
||||
|
@ -140,7 +140,6 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma
|
||||
: Base(cast_to_pointer_type(dataPtr)), m_stride(a_stride)
|
||||
{
|
||||
PlainObjectType::Base::_check_template_params();
|
||||
checkPointer(dataPtr);
|
||||
}
|
||||
|
||||
/** Constructor in the dynamic-size vector case.
|
||||
@ -153,7 +152,6 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma
|
||||
: Base(cast_to_pointer_type(dataPtr), a_size), m_stride(a_stride)
|
||||
{
|
||||
PlainObjectType::Base::_check_template_params();
|
||||
checkPointer(dataPtr);
|
||||
}
|
||||
|
||||
/** Constructor in the dynamic-size matrix case.
|
||||
@ -167,26 +165,11 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma
|
||||
: Base(cast_to_pointer_type(dataPtr), nbRows, nbCols), m_stride(a_stride)
|
||||
{
|
||||
PlainObjectType::Base::_check_template_params();
|
||||
checkPointer(dataPtr);
|
||||
}
|
||||
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
|
||||
|
||||
protected:
|
||||
|
||||
void checkPointer(const Scalar* dataPtr)
|
||||
{
|
||||
enum {
|
||||
MightTryToAlignOnScalar = internal::packet_traits<Scalar>::AlignedOnScalar
|
||||
&& bool(internal::traits<Map>::Flags&PacketAccessBit)
|
||||
&& internal::is_lvalue<Map>::value,
|
||||
PacketSize = internal::packet_traits<Scalar>::size
|
||||
};
|
||||
Index linear_size = bool(internal::traits<Map>::Flags&LinearAccessBit) ? this->size() : this->innerSize();
|
||||
eigen_assert(EIGEN_IMPLIES(bool(MightTryToAlignOnScalar) && (linear_size>=PacketSize), (size_t(dataPtr) % sizeof(Scalar)) == 0)
|
||||
&& "input pointer is not aligned on scalar boundary, e.g., use \"EIGEN_ALIGN8 T ptr[N];\" for double or complex<float>");
|
||||
}
|
||||
|
||||
StrideType m_stride;
|
||||
};
|
||||
|
||||
|
@ -114,6 +114,28 @@ template<typename PlainObjectType> void check_const_correctness(const PlainObjec
|
||||
VERIFY( !(Map<ConstPlainObjectType, Aligned>::Flags & LvalueBit) );
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
void map_not_aligned_on_scalar()
|
||||
{
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> MatrixType;
|
||||
typedef typename MatrixType::Index Index;
|
||||
Index size = 11;
|
||||
Scalar* array1 = internal::aligned_new<Scalar>((size+1)*(size+1)+1);
|
||||
Scalar* array2 = reinterpret_cast<Scalar*>(sizeof(Scalar)/2+std::size_t(array1));
|
||||
Map<MatrixType,0,OuterStride<> > map2(array2, size, size, OuterStride<>(size+1));
|
||||
MatrixType m2 = MatrixType::Random(size,size);
|
||||
map2 = m2;
|
||||
VERIFY_IS_EQUAL(m2, map2);
|
||||
|
||||
typedef Matrix<Scalar,Dynamic,1> VectorType;
|
||||
Map<VectorType> map3(array2, size);
|
||||
MatrixType v3 = VectorType::Random(size);
|
||||
map3 = v3;
|
||||
VERIFY_IS_EQUAL(v3, map3);
|
||||
|
||||
internal::aligned_delete(array1, (size+1)*(size+1)+1);
|
||||
}
|
||||
|
||||
void test_mapped_matrix()
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
@ -137,5 +159,7 @@ void test_mapped_matrix()
|
||||
CALL_SUBTEST_8( map_static_methods(RowVector3d()) );
|
||||
CALL_SUBTEST_9( map_static_methods(VectorXcd(8)) );
|
||||
CALL_SUBTEST_10( map_static_methods(VectorXf(12)) );
|
||||
|
||||
CALL_SUBTEST_11( map_not_aligned_on_scalar<double>() );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user