1 /* { dg-do compile } */ 2 /* { dg-additional-options "-w" } */ 3 /* { dg-additional-options "-mavx2" { target { x86_64-*-* i?86-*-* } } } */ 4 5 namespace std { 6 template < typename _Default > struct __detector { using type = _Default; }; 7 template < typename _Default, template < typename > class > 8 using __detected_or = __detector< _Default >; 9 template < typename _Default, template < typename > class _Op > 10 using __detected_or_t = typename __detected_or< _Default, _Op >::type; 11 template < typename > struct iterator_traits; 12 template < typename _Tp > struct iterator_traits< _Tp * > { 13 typedef _Tp reference; 14 }; 15 } // std 16 using std::iterator_traits; 17 template < typename _Iterator, typename > struct __normal_iterator { 18 typename iterator_traits< _Iterator >::reference operator*(); 19 void operator++(); 20 }; 21 template < typename _IteratorL, typename _IteratorR, typename _Container > 22 int operator!=(__normal_iterator< _IteratorL, _Container >, 23 __normal_iterator< _IteratorR, _Container >); 24 namespace std { 25 template < typename _Tp > struct allocator { typedef _Tp value_type; }; 26 struct __allocator_traits_base { 27 template < typename _Tp > using __pointer = typename _Tp::pointer; 28 }; 29 template < typename _Alloc > struct allocator_traits : __allocator_traits_base { 30 using pointer = __detected_or_t< typename _Alloc::value_type *, __pointer >; 31 }; 32 } // std 33 typedef double __m128d __attribute__((__vector_size__(16))); 34 typedef double __m256d __attribute__((__vector_size__(32))); 35 enum { InnerVectorizedTraversal, LinearVectorizedTraversal }; 36 enum { ReadOnlyAccessors }; 37 template < int, typename Then, typename > struct conditional { 38 typedef Then type; 39 }; 40 template < typename Then, typename Else > struct conditional< 0, Then, Else > { 41 typedef Else type; 42 }; 43 template < typename, typename > struct is_same { 44 enum { value }; 45 }; 46 template < typename T > struct is_same< T, T > { 47 enum { value = 1 }; 48 }; 49 template < typename > struct traits; 50 struct accessors_level { 51 enum { has_direct_access, has_write_access, value }; 52 }; 53 template < typename > struct EigenBase; 54 template < typename > struct PlainObjectBase; 55 template < typename, int = accessors_level::value > struct DenseCoeffsBase; 56 template < typename, int, int, int = 0, int = 0, int = 0 > struct Matrix; 57 template < typename > struct MatrixBase; 58 template < typename, int, int, bool = 0 > struct Block; 59 struct VectorBlock; 60 template < typename, typename > struct CwiseNullaryOp; 61 template < typename, typename, typename > struct CwiseBinaryOp; 62 template < typename, int = accessors_level::has_write_access > struct MapBase; 63 template < typename > struct packet_traits; 64 template < typename > struct unpacket_traits; 65 template < int Size, typename PacketType, 66 int = Size == is_same< PacketType, typename unpacket_traits< 67 PacketType >::half >::value > 68 struct find_best_packet_helper; 69 template < int Size, typename PacketType > 70 struct find_best_packet_helper< Size, PacketType, 1 > { 71 typedef PacketType type; 72 }; 73 template < int Size, typename PacketType > 74 struct find_best_packet_helper< Size, PacketType, 0 > { 75 typedef typename find_best_packet_helper< 76 1, typename unpacket_traits< PacketType >::half >::type type; 77 }; 78 template < typename T, int Size > struct find_best_packet { 79 typedef typename find_best_packet_helper< 80 Size, typename packet_traits< T >::type >::type type; 81 }; 82 struct compute_matrix_flags { 83 enum { ret = 1 }; 84 }; 85 struct ref_selector { 86 typedef Matrix< double, 10, 1 > &type; 87 }; 88 template < typename Derived > struct dense_xpr_base { 89 typedef MatrixBase< Derived > type; 90 }; 91 template < typename ExpressionType > struct is_lvalue { 92 enum { value = traits< ExpressionType >::Flags }; 93 }; 94 template < typename Packet > void pmul(Packet); 95 template < typename Packet > 96 Packet pload(const typename unpacket_traits< Packet >::type *); 97 template < typename Packet > 98 Packet pset1(const typename unpacket_traits< Packet >::type &); 99 template < typename Scalar, typename Packet > void pstoreu(Scalar, Packet &); 100 template < typename Packet, int > 101 Packet ploadt(const typename unpacket_traits< Packet >::type *from) { 102 return pload< Packet >(from); 103 } 104 template < typename Scalar, typename Packet, int > 105 void pstoret(Scalar *to, const Packet from) { 106 pstoreu(to, from); 107 } 108 typedef __m128d Packet2d; 109 template <> struct unpacket_traits< Packet2d > { 110 typedef double type; 111 typedef Packet2d half; 112 }; 113 template <> Packet2d pload(const double *from) { return *(__m128d *)from; } 114 typedef __m256d Packet4d; 115 template <> struct packet_traits< double > { typedef Packet4d type; }; 116 template <> struct unpacket_traits< Packet4d > { 117 typedef double type; 118 typedef Packet2d half; 119 }; 120 __m256d pset1___trans_tmp_1; 121 template <> Packet4d pset1(const double &) { 122 int __A; 123 pset1___trans_tmp_1 = __m256d{__A}; 124 return pset1___trans_tmp_1; 125 } 126 template <> void pstoreu(double *to, const Packet4d &from) { 127 *(__attribute__((__vector_size__(4 * sizeof(double)))) double *)to = from; 128 } 129 struct scalar_product_op { 130 template < typename Packet > void packetOp(Packet a, Packet) { pmul(a); } 131 }; 132 struct scalar_constant_op { 133 template < typename PacketType > PacketType packetOp() { 134 return pset1< PacketType >(0); 135 } 136 }; 137 struct assign_op { 138 template < int, typename Packet > void assignPacket(double *a, Packet b) { 139 pstoret< double, Packet, 0 >(a, b); 140 } 141 }; 142 template < typename Derived > 143 struct DenseCoeffsBase< Derived, 0 > : EigenBase< Derived > {}; 144 template < typename Derived > 145 struct DenseCoeffsBase< Derived > : DenseCoeffsBase< Derived, 0 > {}; 146 template < typename Derived > struct DenseBase : DenseCoeffsBase< Derived > { 147 using DenseCoeffsBase< Derived >::derived; 148 enum { SizeAtCompileTime, MaxSizeAtCompileTime }; 149 static CwiseNullaryOp< scalar_constant_op, Derived > Constant(); 150 Derived &setConstant(); 151 struct FixedSegmentReturnType { 152 typedef VectorBlock Type; 153 }; 154 template < int > typename FixedSegmentReturnType::Type segment() { 155 return typename FixedSegmentReturnType::Type(derived(), 0, 0); 156 } 157 }; 158 template < typename Derived > struct MatrixBase : DenseBase< Derived > { 159 using DenseBase< Derived >::derived; 160 template < typename OtherDerived > 161 CwiseBinaryOp< scalar_product_op, const Derived, const OtherDerived > 162 cwiseProduct(OtherDerived) { 163 return CwiseBinaryOp< scalar_product_op, const Derived, 164 const OtherDerived >(derived(), derived()); 165 } 166 template < typename OtherDerived > 167 Derived &operator=(const DenseBase< OtherDerived > &); 168 }; 169 template < typename Derived > struct EigenBase { 170 Derived &derived() { return *static_cast< Derived * >(this); } 171 Derived derived() const; 172 }; 173 template < typename > struct binary_evaluator; 174 template < typename Derived > struct evaluator { 175 typedef Derived PlainObjectType; 176 typedef typename PlainObjectType::Scalar Scalar; 177 enum { IsVectorAtCompileTime, Flags }; 178 evaluator(PlainObjectType m) : m_data(m.data()) {} 179 Scalar &coeffRef(int, int); 180 template < int, typename PacketType > PacketType packet(int, int) { 181 return ploadt< PacketType, 0 >(m_data); 182 } 183 const Scalar *m_data; 184 }; 185 template < typename Scalar, int Rows, int Cols, int Options, int MaxRows, 186 int MaxCols > 187 struct evaluator< Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > > 188 : evaluator< PlainObjectBase< Matrix< Scalar, Rows, Cols > > > { 189 typedef Matrix< Scalar, Rows, Cols > XprType; 190 evaluator(XprType m) : evaluator< PlainObjectBase< XprType > >(m) {} 191 }; 192 struct nullary_wrapper { 193 template < typename T, typename IndexType > 194 T packetOp(scalar_constant_op op, IndexType, IndexType) { 195 return op.packetOp< T >(); 196 } 197 }; 198 template < typename NullaryOp, typename PlainObjectType > 199 struct evaluator< CwiseNullaryOp< NullaryOp, PlainObjectType > > { 200 evaluator(CwiseNullaryOp< NullaryOp, PlainObjectType >); 201 template < int, typename PacketType, typename IndexType > 202 PacketType packet(IndexType row, IndexType col) { 203 return m_wrapper.packetOp< PacketType >(m_functor, row, col); 204 } 205 NullaryOp m_functor; 206 nullary_wrapper m_wrapper; 207 }; 208 template < typename BinaryOp, typename Lhs, typename Rhs > 209 struct evaluator< CwiseBinaryOp< BinaryOp, Lhs, Rhs > > 210 : binary_evaluator< CwiseBinaryOp< BinaryOp, Lhs, Rhs > > { 211 evaluator(CwiseBinaryOp< BinaryOp, Lhs, Rhs > xpr) 212 : binary_evaluator< CwiseBinaryOp< BinaryOp, Lhs, Rhs > >(xpr) {} 213 }; 214 template < typename BinaryOp, typename Lhs, typename Rhs > 215 struct binary_evaluator< CwiseBinaryOp< BinaryOp, Lhs, Rhs > > { 216 binary_evaluator(CwiseBinaryOp< BinaryOp, Lhs, Rhs > xpr) 217 : m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) {} 218 template < int, typename PacketType > PacketType packet(int, int) { 219 PacketType __trans_tmp_1 = m_lhsImpl.template packet< 0, PacketType >(0, 0); 220 PacketType __trans_tmp_2; 221 m_functor.packetOp(__trans_tmp_1, __trans_tmp_2); 222 } 223 BinaryOp m_functor; 224 evaluator< Lhs > m_lhsImpl; 225 evaluator< Rhs > m_rhsImpl; 226 }; 227 template < typename Derived > struct mapbase_evaluator { 228 typedef Derived XprType; 229 mapbase_evaluator(XprType map) : m_data(map.data()) {} 230 typename XprType::Scalar &coeffRef(int, int) { return m_data[0]; } 231 typename XprType::PointerType m_data; 232 }; 233 template < int > struct block_evaluator; 234 template < typename ArgType, int BlockRows, int BlockCols, bool InnerPanel > 235 struct evaluator< Block< ArgType, BlockRows, BlockCols, InnerPanel > > 236 : block_evaluator< BlockCols > { 237 enum { Flags }; 238 evaluator(Block< ArgType, 1, 1 > block) : block_evaluator< 1 >(block) {} 239 }; 240 template < int BlockCols > 241 struct block_evaluator 242 : mapbase_evaluator< Block< Matrix< double, 10, 1 >, 1, BlockCols > > { 243 typedef Block< Matrix< double, 10, 1 >, 1, BlockCols > XprType; 244 block_evaluator(XprType block) : mapbase_evaluator< XprType >(block) {} 245 }; 246 template < typename DstEvaluator > struct copy_using_evaluator_traits { 247 typedef typename DstEvaluator::XprType Dst; 248 typedef typename Dst::Scalar DstScalar; 249 enum { DstFlags = DstEvaluator::Flags }; 250 enum { InnerSize = DstFlags }; 251 typedef typename conditional< 252 int() == LinearVectorizedTraversal, 253 typename find_best_packet< DstScalar, Dst::SizeAtCompileTime >::type, 254 typename find_best_packet< DstScalar, InnerSize >::type >::type 255 PacketType; 256 }; 257 template < typename Kernel > 258 struct copy_using_evaluator_innervec_CompleteUnrolling { 259 enum { outer, inner, SrcAlignment, DstAlignment }; 260 static void run(Kernel kernel) { 261 kernel.template assignPacketByOuterInner< DstAlignment, SrcAlignment, 262 typename Kernel::PacketType >( 263 outer, inner); 264 } 265 }; 266 template < typename Kernel > struct dense_assignment_loop { 267 static void run(Kernel kernel) { 268 copy_using_evaluator_innervec_CompleteUnrolling< Kernel >::run(kernel); 269 } 270 }; 271 template < typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, 272 typename Functor > 273 struct generic_dense_assignment_kernel { 274 typedef DstEvaluatorTypeT DstXprType; 275 typedef DstEvaluatorTypeT DstEvaluatorType; 276 typedef SrcEvaluatorTypeT SrcEvaluatorType; 277 typedef typename copy_using_evaluator_traits< DstEvaluatorTypeT >::PacketType 278 PacketType; 279 generic_dense_assignment_kernel(DstEvaluatorType dst, SrcEvaluatorType src, 280 Functor, DstXprType dstExpr) 281 : m_dst(dst), m_src(src), m_dstExpr(dstExpr) {} 282 template < int StoreMode, int LoadMode, typename > 283 void assignPacketByOuterInner(long, long) { 284 long row; 285 long col; 286 m_functor.template assignPacket< StoreMode >( 287 &m_dst.coeffRef(row, col), 288 m_src.template packet< LoadMode, PacketType >(row, col)); 289 } 290 DstEvaluatorType &m_dst; 291 SrcEvaluatorType m_src; 292 Functor m_functor; 293 DstXprType m_dstExpr; 294 }; 295 template < typename DstXprType, typename SrcXprType, typename Functor > 296 void call_dense_assignment_loop(DstXprType dst, SrcXprType src, Functor func) { 297 typedef evaluator< DstXprType > DstEvaluatorType; 298 typedef evaluator< SrcXprType > SrcEvaluatorType; 299 SrcEvaluatorType srcEvaluator(src); 300 DstEvaluatorType dstEvaluator(dst); 301 typedef generic_dense_assignment_kernel< DstEvaluatorType, SrcEvaluatorType, 302 Functor > 303 Kernel; 304 Kernel kernel(dstEvaluator, srcEvaluator, func, dst); 305 dense_assignment_loop< Kernel >::run(kernel); 306 } 307 template < typename, typename, typename > struct Assignment; 308 template < typename Dst, typename Src > void call_assignment(Dst dst, Src src) { 309 call_assignment(dst, src, assign_op()); 310 } 311 template < typename Dst, typename Src, typename Func > 312 void call_assignment(Dst dst, Src src, Func func) { 313 call_assignment_no_alias(dst, src, func); 314 } 315 template < typename Dst, typename Src, typename Func > 316 void call_assignment_no_alias(Dst dst, Src src, Func func) { 317 enum { NeedToTranspose }; 318 Assignment< typename conditional< NeedToTranspose, int, Dst >::type, Src, 319 Func >::run(dst, src, func); 320 } 321 template < typename DstXprType, typename SrcXprType, typename Functor > 322 struct Assignment { 323 static void run(DstXprType dst, SrcXprType src, Functor func) { 324 call_dense_assignment_loop(dst, src, func); 325 } 326 }; 327 template < typename Derived > 328 template < typename OtherDerived > 329 Derived &MatrixBase< Derived >:: 330 operator=(const DenseBase< OtherDerived > &other) { 331 call_assignment(derived(), other.derived()); 332 } 333 template < int Size > struct plain_array { double array[Size]; }; 334 template < int Size > class DenseStorage { 335 plain_array< Size > m_data; 336 337 public: 338 const double *data() const { return m_data.array; } 339 double *data() { return m_data.array; } 340 }; 341 template < typename Derived > 342 struct PlainObjectBase : dense_xpr_base< Derived >::type { 343 typedef typename dense_xpr_base< Derived >::type Base; 344 typedef typename traits< Derived >::Scalar Scalar; 345 DenseStorage< Base::MaxSizeAtCompileTime > m_storage; 346 const Scalar *data() const { return m_storage.data(); } 347 Scalar *data() { return m_storage.data(); } 348 PlainObjectBase() {} 349 template < typename OtherDerived > PlainObjectBase(OtherDerived other) { 350 call_assignment_no_alias(this->derived(), other, assign_op()); 351 } 352 }; 353 template < typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, 354 int _MaxCols > 355 struct traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > > { 356 typedef _Scalar Scalar; 357 enum { Flags = compute_matrix_flags::ret }; 358 }; 359 template < typename, int _Rows, int _Cols, int, int, int > 360 struct Matrix : PlainObjectBase< Matrix< double, _Rows, _Cols > > { 361 PlainObjectBase< Matrix > Base; 362 Matrix() {} 363 template < typename OtherDerived > Matrix(OtherDerived other) : Base(other) {} 364 }; 365 template < typename, typename, typename > struct CwiseBinaryOp { 366 typedef ref_selector::type LhsNested; 367 CwiseBinaryOp(Matrix< double, 10, 1 > &aLhs, Matrix< double, 0, 0 >) 368 : m_lhs(aLhs) {} 369 LhsNested lhs() { return m_lhs; } 370 Matrix< double, 8, 1 > rhs() {} 371 LhsNested m_lhs; 372 }; 373 template < typename NullaryOp, typename > 374 struct CwiseNullaryOp 375 : dense_xpr_base< CwiseNullaryOp< NullaryOp, int > >::type {}; 376 template < typename Derived > Derived &DenseBase< Derived >::setConstant() { 377 derived() = Constant(); 378 } 379 template < typename Derived > 380 struct MapBase< Derived, ReadOnlyAccessors > : dense_xpr_base< Derived >::type { 381 typedef typename dense_xpr_base< Derived >::type Base; 382 typedef typename traits< Derived >::Scalar Scalar; 383 typedef typename conditional< is_lvalue< Derived >::value, Scalar *, 384 Scalar >::type PointerType; 385 Scalar *data() { return m_data; } 386 MapBase(PointerType dataPtr, long, long) : m_data(dataPtr) {} 387 PointerType m_data; 388 }; 389 template < typename Derived > 390 struct MapBase< Derived > : MapBase< Derived, ReadOnlyAccessors > { 391 typedef MapBase< Derived, ReadOnlyAccessors > Base; 392 MapBase(typename Base::PointerType dataPtr, long rows, long cols) 393 : Base(dataPtr, rows, cols) {} 394 using MapBase< Derived, ReadOnlyAccessors >::Base::operator=; 395 }; 396 template < typename XprType, int BlockRows, int BlockCols, bool InnerPanel > 397 struct traits< Block< XprType, BlockRows, BlockCols, InnerPanel > > 398 : traits< XprType > {}; 399 template < int, int > struct BlockImpl_dense; 400 template < typename, int, int, typename > class BlockImpl; 401 template < typename, int BlockRows, int BlockCols, bool > 402 struct Block : BlockImpl< Matrix< double, 10, 1 >, BlockRows, BlockCols, int > { 403 typedef BlockImpl< Matrix< double, 10, 1 >, BlockRows, BlockCols, int > Impl; 404 using Impl::operator=; 405 Block(Matrix< double, 10, 1 > &xpr, long startRow, long startCol, 406 long blockRows, long blockCols) 407 : Impl(xpr, startRow, startCol, blockRows, blockCols) {} 408 }; 409 template < typename XprType, int BlockRows, int BlockCols > 410 struct BlockImpl< XprType, BlockRows, BlockCols, int > 411 : BlockImpl_dense< BlockRows, BlockCols > { 412 typedef BlockImpl_dense< BlockRows, BlockCols > Impl; 413 typedef Impl Base; 414 using Base::operator=; 415 BlockImpl(XprType &xpr, long startRow, long startCol, long blockRows, 416 long blockCols) 417 : Impl(xpr, startRow, startCol, blockRows, blockCols) {} 418 }; 419 template < int BlockRows, int BlockCols > 420 struct BlockImpl_dense 421 : MapBase< Block< Matrix< double, 10, 1 >, BlockRows, BlockCols > > { 422 typedef MapBase< Block< Matrix< double, 10, 1 >, BlockRows, BlockCols > > 423 Base; 424 using Base::operator=; 425 BlockImpl_dense(Matrix< double, 10, 1 > &xpr, long, long, long blockRows, 426 long blockCols) 427 : Base(xpr.data(), blockRows, blockCols) {} 428 }; 429 struct VectorBlock : Block< int, traits< Matrix< double, 0, 1 > >::Flags, 1 > { 430 VectorBlock(Matrix< double, 10, 1 > &vector, long start, long size) 431 : Block(vector, 0, start, 1, size) {} 432 }; 433 namespace std { 434 template < typename _Alloc > struct _Vector_base { 435 typedef typename allocator_traits< _Alloc >::pointer pointer; 436 }; 437 template < typename _Tp, typename _Alloc = allocator< _Tp > > class vector { 438 public: 439 typedef __normal_iterator< typename _Vector_base< _Alloc >::pointer, int > 440 iterator; 441 iterator begin(); 442 iterator end(); 443 }; 444 struct FrameHessian { 445 Matrix< double, 0, 1 > step; 446 void setState(Matrix< double, 0, 1 >); 447 }; 448 struct FullSystem { 449 bool doStepFromBackup(); 450 vector< FrameHessian * > frameHessians; 451 }; 452 bool FullSystem::doStepFromBackup() { 453 Matrix< double, 10, 1 > pstepfac; 454 pstepfac.segment< 4 >().setConstant(); 455 for (FrameHessian *fh : frameHessians) 456 fh->setState(pstepfac.cwiseProduct(fh->step)); 457 } 458 } // namespace std 459