Created
April 24, 2015 12:51
-
-
Save syoyo/d9fb3092860614861efb to your computer and use it in GitHub Desktop.
SIMD class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PRE_ALIGN(128) struct __vec8_d { | |
__vec8_d() { } | |
FORCEINLINE __vec8_d(const double v0) { | |
u.v0 = _mm_set_pd(v0, v0); | |
u.v1 = _mm_set_pd(v0, v0); | |
u.v2 = _mm_set_pd(v0, v0); | |
u.v3 = _mm_set_pd(v0, v0); | |
} | |
FORCEINLINE __vec8_d(const double v0, const double v1, const double v2, const double v3, | |
const double v4, const double v5, const double v6, const double v7) { | |
u.v0 = _mm_set_pd(v0, v1); | |
u.v1 = _mm_set_pd(v2, v3); | |
u.v2 = _mm_set_pd(v4, v5); | |
u.v3 = _mm_set_pd(v6, v7); | |
} | |
FORCEINLINE __vec8_d(const __m128d w0, const __m128d w1, const __m128d w2, const __m128d w3) { | |
u.v0 = w0; | |
u.v1 = w1; | |
u.v2 = w2; | |
u.v3 = w3; | |
} | |
FORCEINLINE __vec8_d(const __vec8_d& rhs) { | |
u.v0 = rhs.u.v0; | |
u.v1 = rhs.u.v1; | |
u.v2 = rhs.u.v2; | |
u.v3 = rhs.u.v3; | |
} | |
FORCEINLINE __vec8_d operator=(const __vec8_d& rhs){ | |
u.v0 = rhs.u.v0; | |
u.v1 = rhs.u.v1; | |
u.v2 = rhs.u.v2; | |
u.v3 = rhs.u.v3; | |
return (*this); | |
} | |
FORCEINLINE __vec8_d operator+(const __vec8_d& rhs) const { | |
return __vec8_d(_mm_add_pd(u.v0, rhs.u.v0), | |
_mm_add_pd(u.v1, rhs.u.v1), | |
_mm_add_pd(u.v2, rhs.u.v2), | |
_mm_add_pd(u.v3, rhs.u.v3)); | |
} | |
FORCEINLINE __vec8_d operator-(const __vec8_d& rhs) const { | |
return __vec8_d(_mm_sub_pd(u.v0, rhs.u.v0), | |
_mm_sub_pd(u.v1, rhs.u.v1), | |
_mm_sub_pd(u.v2, rhs.u.v2), | |
_mm_sub_pd(u.v3, rhs.u.v3)); | |
} | |
FORCEINLINE __vec8_d operator*(const __vec8_d& rhs) const { | |
return __vec8_d(_mm_mul_pd(u.v0, rhs.u.v0), | |
_mm_mul_pd(u.v1, rhs.u.v1), | |
_mm_mul_pd(u.v2, rhs.u.v2), | |
_mm_mul_pd(u.v3, rhs.u.v3)); | |
} | |
union { | |
double v[8]; | |
struct { __m128d v0, v1, v2, v3; }; | |
} u; | |
} POST_ALIGN(128); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment