Browse Source

Add operator[] to simd::Vector. Change implementation of movemaskInverse.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
d89034b01c
2 changed files with 11 additions and 2 deletions
  1. +6
    -2
      include/simd/functions.hpp
  2. +5
    -0
      include/simd/vector.hpp

+ 6
- 2
include/simd/functions.hpp View File

@@ -191,9 +191,13 @@ template <typename T>
inline T movemaskInverse(int a); inline T movemaskInverse(int a);


template <> template <>
inline float_4 movemaskInverse<float_4>(int a) {
return float_4(a & (1 << 0), a & (1 << 1), a & (1 << 2), a & (1 << 3)) != float_4::zero();
inline float_4 movemaskInverse<float_4>(int x) {
__m128i msk8421 = _mm_set_epi32(8, 4, 2, 1);
__m128i x_bc = _mm_set1_epi32(x);
__m128i t = _mm_and_si128(x_bc, msk8421);
return float_4(_mm_castsi128_ps(_mm_cmpeq_epi32(x_bc, t)));
} }



} // namespace simd } // namespace simd
} // namespace rack } // namespace rack

+ 5
- 0
include/simd/vector.hpp View File

@@ -85,6 +85,9 @@ struct Vector<float, 4> {
_mm_storeu_ps(x, v); _mm_storeu_ps(x, v);
} }


float &operator[](int i) {return s[i];}
const float &operator[](int i) const {return s[i];}

// Conversions // Conversions
Vector(Vector<int32_t, 4> a); Vector(Vector<int32_t, 4> a);
// Casts // Casts
@@ -126,6 +129,8 @@ struct Vector<int32_t, 4> {
// Use _mm_storeu_si128() because GCC doesn't support _mm_storeu_si32() // Use _mm_storeu_si128() because GCC doesn't support _mm_storeu_si32()
_mm_storeu_si128((__m128i*) x, v); _mm_storeu_si128((__m128i*) x, v);
} }
int32_t &operator[](int i) {return s[i];}
const int32_t &operator[](int i) const {return s[i];}
Vector(Vector<float, 4> a); Vector(Vector<float, 4> a);
static Vector cast(Vector<float, 4> a); static Vector cast(Vector<float, 4> a);
}; };


Loading…
Cancel
Save