From c0fc71803c41cbd3e7d373eb7312eb239bae0d1f Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 01:54:55 +0200 Subject: [PATCH] Integer SSE code generation --- glm/detail/type_vec4.inl | 202 +++++++++++++++------------------- glm/detail/type_vec4_simd.inl | 56 ++++++++++ 2 files changed, 142 insertions(+), 116 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index ea11c7df..5f282ea5 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -68,6 +68,60 @@ namespace detail return tvec4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); } }; + + template + struct compute_vec4_mod + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x % b.x, a.y % b.y, a.z % b.z, a.w % b.w); + } + }; + + template + struct compute_vec4_and + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x & b.x, a.y & b.y, a.z & b.z, a.w & b.w); + } + }; + + template + struct compute_vec4_or + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w); + } + }; + + template + struct compute_vec4_xor + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); + } + }; + + template + struct compute_vec4_shift_left + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x << b.x, a.y << b.y, a.z << b.z, a.w << b.w); + } + }; + + template + struct compute_vec4_shift_right + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x >> b.x, a.y >> b.y, a.z >> b.z, a.w >> b.w); + } + }; }//namespace detail // -- Implicit basic constructors -- @@ -291,96 +345,84 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(U scalar) { - *this = detail::compute_vec4_add::call(*this, tvec4(scalar)); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(tvec1 const & v) { - *this = detail::compute_vec4_add::call(*this, tvec4(v.x)); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(tvec4 const & v) { - *this = detail::compute_vec4_add::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(U scalar) { - *this = detail::compute_vec4_sub::call(*this, tvec4(scalar)); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(tvec1 const & v) { - *this = detail::compute_vec4_sub::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(tvec4 const & v) { - *this = detail::compute_vec4_sub::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(U scalar) { - *this = detail::compute_vec4_mul::call(*this, tvec4(scalar)); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(tvec1 const & v) { - *this = detail::compute_vec4_mul::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(tvec4 const & v) { - *this = detail::compute_vec4_mul::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(U scalar) { - *this = detail::compute_vec4_div::call(*this, tvec4(scalar)); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(tvec1 const & v) { - *this = detail::compute_vec4_div::call(*this, tvec4(v)); - return *this; + return (*this = (detail::compute_vec4_div::call(*this, tvec4(v)))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(tvec4 const & v) { - *this = detail::compute_vec4_div::call(*this, tvec4(v)); - return *this; + return (*this = (detail::compute_vec4_div::call(*this, tvec4(v)))); } // -- Increment and decrement operators -- @@ -427,198 +469,126 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator%=(U scalar) { - this->x %= static_cast(scalar); - this->y %= static_cast(scalar); - this->z %= static_cast(scalar); - this->w %= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_mod::call(*this, tvec4(scalar))); } template template - GLM_FUNC_QUALIFIER tvec4 & tvec4::operator%=(tvec1 const & v) + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator%=(tvec1 const& v) { - this->x %= static_cast(v.x); - this->y %= static_cast(v.x); - this->z %= static_cast(v.x); - this->w %= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_mod::call(*this, tvec4(v))); } template template - GLM_FUNC_QUALIFIER tvec4 & tvec4::operator%=(tvec4 const & v) + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator%=(tvec4 const& v) { - this->x %= static_cast(v.x); - this->y %= static_cast(v.y); - this->z %= static_cast(v.z); - this->w %= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_mod::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator&=(U scalar) { - this->x &= static_cast(scalar); - this->y &= static_cast(scalar); - this->z &= static_cast(scalar); - this->w &= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_and::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator&=(tvec1 const & v) { - this->x &= static_cast(v.x); - this->y &= static_cast(v.x); - this->z &= static_cast(v.x); - this->w &= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_and::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator&=(tvec4 const & v) { - this->x &= static_cast(v.x); - this->y &= static_cast(v.y); - this->z &= static_cast(v.z); - this->w &= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_and::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator|=(U scalar) { - this->x |= static_cast(scalar); - this->y |= static_cast(scalar); - this->z |= static_cast(scalar); - this->w |= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_or::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator|=(tvec1 const & v) { - this->x |= static_cast(v.x); - this->y |= static_cast(v.x); - this->z |= static_cast(v.x); - this->w |= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_or::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator|=(tvec4 const & v) { - this->x |= static_cast(v.x); - this->y |= static_cast(v.y); - this->z |= static_cast(v.z); - this->w |= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_or::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator^=(U scalar) { - this->x ^= static_cast(scalar); - this->y ^= static_cast(scalar); - this->z ^= static_cast(scalar); - this->w ^= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_xor::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator^=(tvec1 const & v) { - this->x ^= static_cast(v.x); - this->y ^= static_cast(v.x); - this->z ^= static_cast(v.x); - this->w ^= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_xor::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator^=(tvec4 const & v) { - this->x ^= static_cast(v.x); - this->y ^= static_cast(v.y); - this->z ^= static_cast(v.z); - this->w ^= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_xor::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator<<=(U scalar) { - this->x <<= static_cast(scalar); - this->y <<= static_cast(scalar); - this->z <<= static_cast(scalar); - this->w <<= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_shift_left::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator<<=(tvec1 const & v) { - this->x <<= static_cast(v.x); - this->y <<= static_cast(v.x); - this->z <<= static_cast(v.x); - this->w <<= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_shift_left::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator<<=(tvec4 const & v) { - this->x <<= static_cast(v.x); - this->y <<= static_cast(v.y); - this->z <<= static_cast(v.z); - this->w <<= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_shift_left::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator>>=(U scalar) { - this->x >>= static_cast(scalar); - this->y >>= static_cast(scalar); - this->z >>= static_cast(scalar); - this->w >>= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_shift_right::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator>>=(tvec1 const & v) { - this->x >>= static_cast(v.x); - this->y >>= static_cast(v.y); - this->z >>= static_cast(v.z); - this->w >>= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_shift_right::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator>>=(tvec4 const & v) { - this->x >>= static_cast(v.x); - this->y >>= static_cast(v.y); - this->z >>= static_cast(v.z); - this->w >>= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_shift_right::call(*this, tvec4(v))); } // -- Unary constant operators -- diff --git a/glm/detail/type_vec4_simd.inl b/glm/detail/type_vec4_simd.inl index c2ed2f97..072e386c 100644 --- a/glm/detail/type_vec4_simd.inl +++ b/glm/detail/type_vec4_simd.inl @@ -60,6 +60,62 @@ namespace detail return Result; } }; + + template + struct compute_vec4_and + { + static tvec4 call(tvec4 const& a, tvec4 const& b) + { + tvec4 Result(uninitialize); + Result.data = _mm_and_si128(a.data, b.data); + return Result; + } + }; + + template + struct compute_vec4_or + { + static tvec4 call(tvec4 const& a, tvec4 const& b) + { + tvec4 Result(uninitialize); + Result.data = _mm_or_si128(a.data, b.data); + return Result; + } + }; + + template + struct compute_vec4_xor + { + static tvec4 call(tvec4 const& a, tvec4 const& b) + { + tvec4 Result(uninitialize); + Result.data = _mm_xor_si128(a.data, b.data); + return Result; + } + }; +/* + template + struct compute_vec4_shift_left + { + static tvec4 call(tvec4 const& a, tvec4 const& b) + { + tvec4 Result(uninitialize); + Result.data = _mm_sll_epi32(a.data, b.data); + return Result; + } + }; + + template + struct compute_vec4_shift_right + { + static tvec4 call(tvec4 const& a, tvec4 const& b) + { + tvec4 Result(uninitialize); + Result.data = _mm_srl_epi32(a.data, b.data); + return Result; + } + }; +*/ }//namespace detail # if !GLM_HAS_DEFAULTED_FUNCTIONS