Vector
Module of libSIMDx86
The Vector module of libSIMDx86 gives
functions to accelerate 3D vectors, commonly used for 3D games and
simulations. A 3D vector usually represents a position, a force
vector, or an array of scalars for three axes. SIMDx86 pads the 3D
Vector to have 4 components so that it can be loaded more efficiently
in memory and in registers. Applications should not store data of any
kind in the padded area as it is considered volatile –
different code paths for different versions of the library may alter
it without warning. Even if the function has a constant structure, it
too may be modified.
typedef
struct SIMDx86Vector
{
float x, y, z;
float __SIMD_pad__; /* Padding to 16th byte for SIMD operations (3DNow!/SSE) */
} SIMDx86Vector;
void
SIMDx86Vector_Sum(SIMDx86Vector* pOut, const
SIMDx86Vector* pIn);
Adds pOut to pIn and stores the result in pOut.
void SIMDx86Vector_SumOf(SIMDx86Vector* pOut, const SIMDx86Vector* pIn1, const SIMDx86Vector* pIn2);
Adds pIn1 to pIn2 and stores the result in pOut.
void SIMDx86Vector_Diff(SIMDx86Vector* pLeft, SIMDx86Vector* pRight);
Subtracts pRight from pLeft and stores the result in pLeft.
void SIMDx86Vector_DiffOf(SIMDx86Vector* pOut, const SIMDx86Vector* pLeft, const SIMDx86Vector* pRight);
Subtracts pRight from pLeft and stores the result in pOut.
void SIMDx86Vector_Scale(SIMDx86Vector* pVec, float scalar);
Scales the components of pVec by scalar and stores the result in pVec.
void SIMDx86Vector_ScaleOf(SIMDx86Vector* pOut, const SIMDx86Vector* pIn, float scalar);
Scales the components of pIn by scalar and stores the result in pOut.
float SIMDx86Vector_Dot(const SIMDx86Vector* pSrc1, const SIMDx86Vector* pSrc2);
Calculates the dot product (known as the inner product) of pSrc1 and pSrc2, that represents the cosine of the angle between them, if both are normalized.
float SIMDx86Vector_Dot4(const float* pSrc1, const float* pSrc2);
Calculates the dot 4D product (known as the inner product) of pSrc1 and pSrc2.
float SIMDx86Vector_LengthSq(const SIMDx86Vector* pVec);
Returns the squared length of pVec. This can be useful when doing sphere-sphere collision tests where the exact distance is not needed and a squared one can be used, for example. It is signifigantly faster than using the square root version SIMDx86Vector_Length().
float SIMDx86Vector_Length(const SIMDx86Vector* pVec);
Returns the length (magnitude) of pVec. Normalized vectors (e.g. the output of SIMDx86Vector_Normalize() ) are of unit length, or 1.0)
void SIMDx86Vector_Cross(SIMDx86Vector* pLeft, const SIMDx86Vector* pRight);
Finds the cross product of pLeft and pRight and stores the resulting vector in pLeft.
void SIMDx86Vector_CrossOf(SIMDx86Vector* pOut, const SIMDx86Vector* pLeft, const SIMDx86Vector* pRight);
Finds the cross product of pLeft and pRight and stores the resulting vector in pOut.
void SIMDx86Vector_Normalize(SIMDx86Vector* pVec);
Normalizes pVec and stores the result in pVec.
void SIMDx86Vector_NormalizeOf(SIMDx86Vector* pOut, const SIMDx86Vector* pVec);
Normalizes pVec and stores the result in pOut.
float SIMDx86Vector_Distance(const SIMDx86Vector* pVec1, const SIMDx86Vector* pVec2);
Returns the distance between pVec1 and pVec2.
Aligned Vector Functions
The following functions perform the same task as their above counterparts, however, their name is prefixed with “Aligned”. All pointer arguments to these functions must have their addresses aligned to the 16th byte, or undefined results may occur, such as program crashes, exceptions, or incorrect results. These functions usually have much higher performance than their unaligned versions. The prototypes are listed below, but the documentation is not duplicated. For the description of the below functions, see their above counterparts.
void
SIMDx86Vector_AlignedSum(SIMDx86Vector* pOut, const
SIMDx86Vector* pIn);
void SIMDx86Vector_AlignedSumOf(SIMDx86Vector* pOut, const SIMDx86Vector* pIn1, const SIMDx86Vector* pIn2);
void
SIMDx86Vector_AlignedDiff(SIMDx86Vector* pLeft, SIMDx86Vector*
pRight);
void
SIMDx86Vector_AlignedDiffOf(SIMDx86Vector* pOut, const
SIMDx86Vector* pLeft, const SIMDx86Vector*
pRight);
void
SIMDx86Vector_AlignedScale(SIMDx86Vector* pOut, float
scalar);
void
SIMDx86Vector_AlignedScaleOf(SIMDx86Vector* pOut, const
SIMDx86Vector* pIn, float scalar);
float
SIMDx86Vector_AlignedDot(const
SIMDx86Vector* pSrc1, const
SIMDx86Vector* pSrc2);
float
SIMDx86Vector_AlignedDot4(const float*
pSrc4D1, const float*
pSrc4D2);
float
SIMDx86Vector_AlignedLengthSq(const
SIMDx86Vector* pVec);
float
SIMDx86Vector_AlignedLength(const
SIMDx86Vector* pVec);
void
SIMDx86Vector_AlignedCross(SIMDx86Vector* pLeft, const
SIMDx86Vector* pRight);
void
SIMDx86Vector_AlignedCrossOf(SIMDx86Vector* pOut, const
SIMDx86Vector* pLeft, const
SIMDx86Vector* pRight);
void
SIMDx86Vector_AlignedNormalize(SIMDx86Vector* pVec);
void
SIMDx86Vector_AlignedNormalizeOf(SIMDx86Vector* pOut, const
SIMDx86Vector* pVec);
float
SIMDx86Vector_AlignedDistance(const
SIMDx86Vector* pVec1, const
SIMDx86Vector* pVec2);