[ODE] Why is dVector3 defined as dReal[4] ???

Henri Hakl henri at cs.sun.ac.za
Thu Feb 13 03:23:02 2003


dVector3 is a dReal[4] to allow for future SIMD extension (the dMatrix3 is
similarily defined).

However, there may already be a speed difference by defining it as a
dReal[4]; the reason is that properly alligned memory data can be accessed
more efficiently by the CPU. You should go to great lengths to ensure that
every instance of dVector3 in your projects are atleast 4-byte aligned
(virtually default), 16-byte alignments are better still and usually need to
be enforced.

This ensures that memory access (read/write) can be performed just a little
bit faster.

For example:
You'll notice that if you used dReal[3] for an array of dVector3, then not
every vector would fall onto a 16-byte boundary (provided that the first
vector was properly alligned). Whereas it is guaranteed with dReal[4]
(provided that the first vector was properly alligned).