27template <
typename TYPE,
int SIZE>
36 constexpr static int size = 4;
57 Vector(
float x1,
float x2,
float x3,
float x4) {
58 v = _mm_setr_ps(x1, x2, x3, x4);
63 return Vector(_mm_setzero_ps());
68 return Vector(_mm_castsi128_ps(_mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128())));
80 return Vector(_mm_loadu_ps(x));
110 constexpr static int size = 4;
120 v = _mm_set1_epi32(x);
122 Vector(int32_t x1, int32_t x2, int32_t x3, int32_t x4) {
123 v = _mm_setr_epi32(x1, x2, x3, x4);
126 return Vector(_mm_setzero_si128());
129 return Vector(_mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128()));
134 return Vector(_mm_loadu_si128((
const __m128i*) x));
139 _mm_storeu_si128((__m128i*) x, v);
156 v = _mm_cvtepi32_ps(a.v);
160 v = _mm_cvttps_epi32(a.v);
164 return Vector(_mm_castsi128_ps(a.v));
168 return Vector(_mm_castps_si128(a.v));
176#define DECLARE_VECTOR_OPERATOR_INFIX(t, s, operator, func) \
177 inline Vector<t, s> operator(const Vector<t, s>& a, const Vector<t, s>& b) { \
178 return Vector<t, s>(func(a.v, b.v)); \
182#define DECLARE_VECTOR_OPERATOR_INCREMENT(t, s, operator, opfunc) \
183 inline Vector<t, s>& operator(Vector<t, s>& a, const Vector<t, s>& b) { \
184 return a = opfunc(a, b); \
250inline Vector<int32_t, 4>
operator<=(
const Vector<int32_t, 4>& a,
const Vector<int32_t, 4>& b) {
327inline Vector<int32_t, 4>
operator<<(
const Vector<int32_t, 4>& a,
const int& b) {
328 return Vector<int32_t, 4>(_mm_sll_epi32(a.v, _mm_cvtsi32_si128(b)));
#define DECLARE_VECTOR_OPERATOR_INFIX(t, s, operator,func)
a @ b
Definition Vector.hpp:176
#define DECLARE_VECTOR_OPERATOR_INCREMENT(t, s, operator,opfunc)
a @= b
Definition Vector.hpp:182
Vector< int32_t, 4 > operator<=(const Vector< int32_t, 4 > &a, const Vector< int32_t, 4 > &b)
Definition Vector.hpp:250
Vector< int32_t, 4 > operator>>(const Vector< int32_t, 4 > &a, const int &b)
a >> b
Definition Vector.hpp:332
Vector< int32_t, 4 > operator<<(const Vector< int32_t, 4 > &a, const int &b)
a << b
Definition Vector.hpp:327
Vector< float, 4 > operator-(const Vector< float, 4 > &a)
-a
Definition Vector.hpp:271
Vector< float, 4 > & operator++(Vector< float, 4 > &a)
++a
Definition Vector.hpp:279
Vector< float, 4 > & operator--(Vector< float, 4 > &a)
--a
Definition Vector.hpp:287
Vector< float, 4 > operator~(const Vector< float, 4 > &a)
~a
Definition Vector.hpp:319
Vector< float, 4 > operator+(const Vector< float, 4 > &a)
+a
Definition Vector.hpp:263
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Wrapper for __m128 representing an aligned vector of 4 single-precision float values.
Definition Vector.hpp:34
static Vector mask()
Returns a vector with all 1 bits.
Definition Vector.hpp:67
void store(float *x)
Writes an array of 4 values.
Definition Vector.hpp:86
Vector(float x1, float x2, float x3, float x4)
Constructs a vector from four scalars.
Definition Vector.hpp:57
float & operator[](int i)
Accessing vector elements individually is slow and defeats the purpose of vectorizing.
Definition Vector.hpp:93
Vector(__m128 v)
Constructs a vector from a native __m128 type.
Definition Vector.hpp:49
Vector(float x)
Constructs a vector with all elements set to x.
Definition Vector.hpp:52
Vector()=default
Constructs an uninitialized vector.
static Vector load(const float *x)
Reads an array of 4 values.
Definition Vector.hpp:74
const float & operator[](int i) const
Definition Vector.hpp:96
float type
Definition Vector.hpp:35
static Vector zero()
Returns a vector with all 0 bits.
Definition Vector.hpp:62
__m128 v
Definition Vector.hpp:39
Definition Vector.hpp:108
Vector(int32_t x1, int32_t x2, int32_t x3, int32_t x4)
Definition Vector.hpp:122
static Vector zero()
Definition Vector.hpp:125
Vector(__m128i v)
Definition Vector.hpp:118
__m128i v
Definition Vector.hpp:113
Vector(int32_t x)
Definition Vector.hpp:119
const int32_t & operator[](int i) const
Definition Vector.hpp:144
int32_t type
Definition Vector.hpp:109
static Vector mask()
Definition Vector.hpp:128
static Vector load(const int32_t *x)
Definition Vector.hpp:131
int32_t & operator[](int i)
Definition Vector.hpp:141
void store(int32_t *x)
Definition Vector.hpp:136
Generic class for vector types.
Definition Vector.hpp:28