From d89034b01c0dc13ecc2a374d82610334d557f8cc Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 16 Jun 2019 23:02:28 -0400 Subject: [PATCH] Add operator[] to simd::Vector. Change implementation of movemaskInverse. --- include/simd/functions.hpp | 8 ++++++-- include/simd/vector.hpp | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/simd/functions.hpp b/include/simd/functions.hpp index 36b5a828..c68830d0 100644 --- a/include/simd/functions.hpp +++ b/include/simd/functions.hpp @@ -191,9 +191,13 @@ template inline T movemaskInverse(int a); template <> -inline float_4 movemaskInverse(int a) { - return float_4(a & (1 << 0), a & (1 << 1), a & (1 << 2), a & (1 << 3)) != float_4::zero(); +inline float_4 movemaskInverse(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 rack diff --git a/include/simd/vector.hpp b/include/simd/vector.hpp index 9a12d33f..a42e8317 100644 --- a/include/simd/vector.hpp +++ b/include/simd/vector.hpp @@ -85,6 +85,9 @@ struct Vector { _mm_storeu_ps(x, v); } + float &operator[](int i) {return s[i];} + const float &operator[](int i) const {return s[i];} + // Conversions Vector(Vector a); // Casts @@ -126,6 +129,8 @@ struct Vector { // Use _mm_storeu_si128() because GCC doesn't support _mm_storeu_si32() _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 a); static Vector cast(Vector a); };