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

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

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: [eigen] Comma-initializer is quite expensive with compile-time known constants*From*: Ola Røer Thorsen <ola@xxxxxxxxxxxxxx>*Date*: Mon, 5 Nov 2018 15:34:15 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silentwings-no.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=oaAazg9EpczoJR77Y28NFXnLQc6w7XucPk2ZFbBoOzU=; b=qOlM6aYuWQ730OhCv6XdHswSlCsTMdDpuoPxqi6E1B7PrJB4pG1HvFyZXi6FBifXr/ 5MTXXso8PEW3p62buKOkfJfrGpBbO+rocD8rNNt1fbS140XIbbZGiHS0w8DU/o3bOBsz ZDOxoGswKTpz2u5I1eip3OA686/l/jKlSiHBSBmevX1iwBZDjO3SlEG5AK+cV51NHnxF zfZvsyxuguIC9/VpWw8fGVD1JlepasEWnwgzCMZ7OKJiqbRSAYbxGC8WpiZuID2UJE7i 09qKYzMirgJPoScU6AsNOTCfN83UtmgmyHbwKCGcYWvZtTr6r8x3AeucZiaMLTOhOR1z wwIg==

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,

Ola

**Follow-Ups**:**Re: [eigen] Comma-initializer is quite expensive with compile-time known constants***From:*Christoph Hertzberg

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Eigen3 features request** - Next by Date:
**Re: [eigen] Comma-initializer is quite expensive with compile-time known constants** - Previous by thread:
**Re: [eigen] Hyperplane::signedDistance incorrect** - Next by thread:
**Re: [eigen] Comma-initializer is quite expensive with compile-time known constants**

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