xref: /aosp_15_r20/external/eigen/doc/FixedSizeVectorizable.dox (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Linamespace Eigen {
2*bf2c3715SXin Li
3*bf2c3715SXin Li/** \eigenManualPage TopicFixedSizeVectorizable Fixed-size vectorizable %Eigen objects
4*bf2c3715SXin Li
5*bf2c3715SXin LiThe goal of this page is to explain what we mean by "fixed-size vectorizable".
6*bf2c3715SXin Li
7*bf2c3715SXin Li\section FixedSizeVectorizable_summary Executive Summary
8*bf2c3715SXin Li
9*bf2c3715SXin LiAn Eigen object is called "fixed-size vectorizable" if it has fixed size and that size is a multiple of 16 bytes.
10*bf2c3715SXin Li
11*bf2c3715SXin LiExamples include:
12*bf2c3715SXin Li\li Eigen::Vector2d
13*bf2c3715SXin Li\li Eigen::Vector4d
14*bf2c3715SXin Li\li Eigen::Vector4f
15*bf2c3715SXin Li\li Eigen::Matrix2d
16*bf2c3715SXin Li\li Eigen::Matrix2f
17*bf2c3715SXin Li\li Eigen::Matrix4d
18*bf2c3715SXin Li\li Eigen::Matrix4f
19*bf2c3715SXin Li\li Eigen::Affine3d
20*bf2c3715SXin Li\li Eigen::Affine3f
21*bf2c3715SXin Li\li Eigen::Quaterniond
22*bf2c3715SXin Li\li Eigen::Quaternionf
23*bf2c3715SXin Li
24*bf2c3715SXin Li\section FixedSizeVectorizable_explanation Explanation
25*bf2c3715SXin Li
26*bf2c3715SXin LiFirst, "fixed-size" should be clear: an %Eigen object has fixed size if its number of rows and its number of columns are fixed at compile-time. So for example \ref Matrix3f has fixed size, but \ref MatrixXf doesn't (the opposite of fixed-size is dynamic-size).
27*bf2c3715SXin Li
28*bf2c3715SXin LiThe array of coefficients of a fixed-size %Eigen object is a plain "static array", it is not dynamically allocated. For example, the data behind a \ref Matrix4f is just a "float array[16]".
29*bf2c3715SXin Li
30*bf2c3715SXin LiFixed-size objects are typically very small, which means that we want to handle them with zero runtime overhead -- both in terms of memory usage and of speed.
31*bf2c3715SXin Li
32*bf2c3715SXin LiNow, vectorization works with 128-bit packets (e.g., SSE, AltiVec, NEON), 256-bit packets (e.g., AVX), or 512-bit packets (e.g., AVX512). Moreover, for performance reasons, these packets are most efficiently read and written if they have the same alignment as the packet size, that is 16 bytes, 32 bytes, and 64 bytes respectively.
33*bf2c3715SXin Li
34*bf2c3715SXin LiSo it turns out that the best way that fixed-size %Eigen objects can be vectorized, is if their size is a multiple of 16 bytes (or more). %Eigen will then request 16-byte alignment (or more) for these objects, and henceforth rely on these objects being aligned to achieve maximal efficiency.
35*bf2c3715SXin Li
36*bf2c3715SXin Li*/
37*bf2c3715SXin Li
38*bf2c3715SXin Li}
39