[eigen] Comma-initializer is quite expensive with compile-time known constants

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

Hi, we're using fixed-size Eigen matrices (eigen 3.3.5), mostly 3-element-vectors, quaternions and 3x3 matrices but also larger ones. We've been initializing them with the comma initializer, but looking at the assembly produced the compiler (gcc 7) is not able to optimize everything away even for small code like

Eigen::Vector3f v;
v << 1,2,3;
example: https://godbolt..org/z/y5YUnJ
This is a bit expensive especially on embedded microcontrollers where we try to avoid function calls whenever possible. So we'll avoid the comma initializer completely there now.

This however is much more efficient:
v(0) = 1;
v(1) = 2;
v(2) = 3;
example: https://godbolt.org/z/zoLHJp

(Sure for these short vectors there is the equally efficient Eigen::Vector3f v(1,2,3)).

Would it be possible to add some C++11 (or 14) feature to help in this regard? Not sure if you want to keep Eigen completely free of C++11-features. I've tried some variadic template "make_matrix" functions that seem to do the trick, not having to do the error checks runtime. Ideally, it would be nice to be able to write stuff like

const Eigen::Matrix3f m{ 1,2,3, 4,5,6, 7,8,9 };

Best regards,

Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/