#include <FXMaths.h>
This is a generic vector of size A of type components. Specialisations have been provided for SIMD quantities on platforms which support those, so for example on Intel SSE platforms four floats will map to a __m128
SSE register. Where the size is a power of two up to 1Kb, the compiler is asked to memory align the vector and an assert is added to ensure instantiation will not succeed without correct alignment.
__m128
SSE operations on current processor technology. This means that you can write now for upcoming vector processors eg; Intel's upcoming Advanced Vector Extensions (AVX) which use a GPU-like parallel processing engine (Larrabee) to process blocks of 256-1024 bit vectors (8 to 32 floats) at once. For this same reason, operands available for this class have been kept minimal - sin()
probably is too big for a simple math processor.
isZero(), min(), max(), sum(), dot()
; for floating-point only: sqrt(), rcp(), rsqrt()
; for integer only: lshiftvec(), rshiftvec()
. These can be invoked via Koenig lookup so you can use them as though they were in the C library.FOX provides hardwired versions of this class in the forms of FX::FXVec2f, FX::FXVec2d, FX::FXVec3f, FX::FXVec3d, FX::FXVec4f, FX::FXVec4d. These are nothing like as fast, and also they are designed in a highly SIMD unfriendly way - FX::Maths::Vector was deliberately designed with an inconvenient API to force high performance programming.
The following combinations have been optimised:
__m128
__m128d
. Vector<FXushort|FXshort,8>, Vector<FXuint|FXint,4> both use __m128i
(SSE2 does not have a full set of instructions for 16 chars nor 2 long long's). For integers on SSE2 only, multiplication, division, modulus, min(), max() are emulated (slowly) as they don't have corresponding SSE instructions available. For SSE4 only, multiplication, min(), max() is SSE optimised.
Note that the SSE2 optimised bit shift ignores all but the lowest member - for future compatibility you should set all members of the shift quantity to be identical. lshiftvec() and rshiftvec() treat the entire vector as higher indexed members being higher bits. On little endian machines, this leads to shifts occurring within their member types going "the wrong way" and then leaping to the next member. Usually, you want this. Only bit shifts which are multiples of eight are accelerated on SSE2.
See FX::Maths::VectorArray for an array of vectors letting you easily implement a matrix. See also the FXVECTOROFVECTORS macro for how to declare to the compiler when a vector should be implemented as a sequence of other vectors (this is how the SSE specialisations overload specialisations for two power increments) - if you want a non-two power size, you'll need to declare the VectorOfVectors specialisation manually.
Public Types | |
typedef type | TYPE |
Public Member Functions | |
Vector (const type *d) | |
Vector (const type &d) | |
operator const supertype & () const | |
type | operator[] (unsigned int i) const |
VectorBase & | set (unsigned int i, const type &d) |
Static Public Attributes | |
static const unsigned int | DIMENSION |
static const bool | isArithmetic |
static const bool | isInteger |
Protected Attributes | |
union { | |
type data [A] | |
SIMDType v | |
}; |
typedef type FX::Maths::Impl::VectorBase< type, A, supertype, _isArithmetic, _isInteger, SIMDType >::TYPE [inherited] |
The container type.
FX::Maths::Vector< type, A >::Vector | ( | const type * | d | ) | [inline, explicit] |
Use d =0 to initialise to zero.
FX::Maths::Vector< type, A >::Vector | ( | const type & | d | ) | [inline, explicit] |
Initialises all members to a certain value.
type FX::Maths::Impl::VectorBase< type, A, supertype, _isArithmetic, _isInteger, SIMDType >::operator[] | ( | unsigned int | i | ) | const [inline, inherited] |
Retrieves a component.
VectorBase& FX::Maths::Impl::VectorBase< type, A, supertype, _isArithmetic, _isInteger, SIMDType >::set | ( | unsigned int | i, | |
const type & | d | |||
) | [inline, inherited] |
Sets a component.
const unsigned int FX::Maths::Impl::VectorBase< type, A, supertype, _isArithmetic, _isInteger, SIMDType >::DIMENSION [static, inherited] |
The dimension.
const bool FX::Maths::Impl::VectorBase< type, A, supertype, _isArithmetic, _isInteger, SIMDType >::isArithmetic [static, inherited] |
True if arithmetric.
const bool FX::Maths::Impl::VectorBase< type, A, supertype, _isArithmetic, _isInteger, SIMDType >::isInteger [static, inherited] |
True if integer.