Re: [eigen] alignment question

[ Thread Index | Date Index | More Archives ]

This is indeed very surprising. I never observed such an issue. Regarding Vector3f vectorization better use a "structure-of-array" (SoA) approach and enable vectorization by working on 4 (or 8 with AVX) data at once. With Eigen, SoA is no more complicated than storing your collection of Vector3f as a Matrix<float,3,Dynamic,RowMajor>. With this approach you can really expect a x4 or x8 speedup. In general, I would not expect significant gain by moving to Vector4f especially if you do horizontal operations like norm(), dot(), etc. If you really want to go this way, you might also give a try to unsupported/Eigen/AlignedVector3.


On Tue, Jan 27, 2015 at 10:58 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
I'm surprised that Clang would have trouble aligning return values. Can you share a compilable testcase?

2015-01-27 16:56 GMT-05:00 Sylvain Pointeau <sylvain.pointeau@xxxxxxxxx>:

Hi again,

This was it, I created temp objects to hold the result of functions and the alignment issue is gone.
I still have a long road to replace all the Vector3 by Vector4... 

Do you do the same way? do you have as convention to always use temp variables to hold your function return?

Best regards,

On Tue, Jan 27, 2015 at 5:26 PM, Sylvain Pointeau <sylvain.pointeau@xxxxxxxxx> wrote:
On Tue, Jan 27, 2015 at 2:25 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
This code is fine by itself.
It does rely on a nontrivial assumption: that stack frames are 16-byte aligned. Indeed, the alignment for Vector4f is 16 bytes, and you are placing Vector4f's on the stack in two places: as the return value of ToPoint, and for the local variable v in the third snippet. However, that assumption --- that stack frames are 16-byte aligned --- should be true. What compiler and OS are we talking about?

I use clang from xcode on mac os x yosemite.
Can you share a compilable testcase?

I will prepare it tonight. I am not sure it is because of this, but I don't see other options.

2015-01-27 5:04 GMT-05:00 Sylvain Pointeau <sylvain.pointeau@xxxxxxxxx>:

Dear all,

I currently migrate my application to use Vector4f instead of Vector3f to benefit the vectorisation.
However I face an alignment error at runtime. (I use the latest clang from xcode on mac os x)

Vector4f toPoint(const Vector4f &v) {
  return Vector4f( v.x(), v.y(), v.z(), 1 );

void process( const Vector4f &v ) {
  // do process my vector

is there an issue with the alignment doing the following?

Vector4f v (1,3,4,0);
process( toPoint(v) );

Please let me know, I have the suspicion that the error comes from there, I wonder if I am right.

Best regards,

Mail converted by MHonArc 2.6.19+