Refactoring of swizzle operators, preparing for vec4 swizzle SIMD optimizations

This commit is contained in:
Christophe Riccio 2016-05-30 01:39:16 +02:00
parent 89f6da9552
commit b9199a2c1a
8 changed files with 601 additions and 580 deletions

File diff suppressed because it is too large Load Diff

View File

@ -92,15 +92,15 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec1(tvec1<U, Q> const & v); GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec1(tvec1<U, Q> const & v);
// -- Swizzle constructors -- // -- Swizzle constructors --
/*
# if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)) # if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE))
template <int E0> template <int E0>
GLM_FUNC_DECL tvec1(detail::_swizzle<1, T, P, tvec1<T, P>, E0, -1,-2,-3> const & that) GLM_FUNC_DECL tvec1(detail::_swizzle<1, T, P, tvec1, E0, -1,-2,-3> const & that)
{ {
*this = that(); *this = that();
} }
# endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)) # endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE))
*/
// -- Unary arithmetic operators -- // -- Unary arithmetic operators --
GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v) GLM_DEFAULT; GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v) GLM_DEFAULT;

View File

@ -34,16 +34,17 @@ namespace glm
struct{ T s, t; }; struct{ T s, t; };
# ifdef GLM_SWIZZLE # ifdef GLM_SWIZZLE
_GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, x, y) _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, x, y)
_GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, r, g) _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, r, g)
_GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, s, t) _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, s, t)
_GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, x, y) _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, x, y)
_GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, r, g) _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, r, g)
_GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, s, t) _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, s, t)
_GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, x, y) _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, x, y)
_GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, r, g) _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, r, g)
_GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, s, t) _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, s, t)
# endif//GLM_SWIZZLE # endif//GLM_SWIZZLE
}; };
# else # else
union {T x, r, s;}; union {T x, r, s;};
@ -98,10 +99,9 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec2(tvec2<U, Q> const & v); GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec2(tvec2<U, Q> const & v);
// -- Swizzle constructors -- // -- Swizzle constructors --
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) # if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
template <int E0, int E1> template <int E0, int E1>
GLM_FUNC_DECL tvec2(detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1,-1,-2> const & that) GLM_FUNC_DECL tvec2(detail::_swizzle<2, T, P, glm::tvec2, E0, E1,-1,-2> const& that)
{ {
*this = that(); *this = that();
} }

View File

@ -34,15 +34,15 @@ namespace glm
struct{ T s, t, p; }; struct{ T s, t, p; };
# ifdef GLM_SWIZZLE # ifdef GLM_SWIZZLE
_GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, x, y, z) _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, x, y, z)
_GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, r, g, b) _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, r, g, b)
_GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, s, t, p) _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, s, t, p)
_GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, x, y, z) _GLM_SWIZZLE3_3_MEMBERS(T, P, glm::tvec3, x, y, z)
_GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, r, g, b) _GLM_SWIZZLE3_3_MEMBERS(T, P, glm::tvec3, r, g, b)
_GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, s, t, p) _GLM_SWIZZLE3_3_MEMBERS(T, P, glm::tvec3, s, t, p)
_GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, x, y, z) _GLM_SWIZZLE3_4_MEMBERS(T, P, glm::tvec4, x, y, z)
_GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, r, g, b) _GLM_SWIZZLE3_4_MEMBERS(T, P, glm::tvec4, r, g, b)
_GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, s, t, p) _GLM_SWIZZLE3_4_MEMBERS(T, P, glm::tvec4, s, t, p)
# endif//GLM_SWIZZLE # endif//GLM_SWIZZLE
}; };
# else # else
@ -108,22 +108,21 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec3(tvec3<U, Q> const & v); GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec3(tvec3<U, Q> const & v);
// -- Swizzle constructors -- // -- Swizzle constructors --
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) # if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
template <int E0, int E1, int E2> template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec3(detail::_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & that) GLM_FUNC_DECL tvec3(detail::_swizzle<3, T, P, glm::tvec3, E0, E1, E2, -1> const & that)
{ {
*this = that(); *this = that();
} }
template <int E0, int E1> template <int E0, int E1>
GLM_FUNC_DECL tvec3(detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & scalar) GLM_FUNC_DECL tvec3(detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v, T const & scalar)
{ {
*this = tvec3<T, P>(v(), scalar); *this = tvec3<T, P>(v(), scalar);
} }
template <int E0, int E1> template <int E0, int E1>
GLM_FUNC_DECL tvec3(T const & scalar, detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v) GLM_FUNC_DECL tvec3(T const & scalar, detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v)
{ {
*this = tvec3<T, P>(scalar, v()); *this = tvec3<T, P>(scalar, v());
} }

View File

@ -93,15 +93,15 @@ namespace detail
typename detail::simd_data<T>::type data; typename detail::simd_data<T>::type data;
# ifdef GLM_SWIZZLE # ifdef GLM_SWIZZLE
_GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, x, y, z, w) _GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, x, y, z, w)
_GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, r, g, b, a) _GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, r, g, b, a)
_GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, s, t, p, q) _GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, s, t, p, q)
_GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, x, y, z, w) _GLM_SWIZZLE4_3_MEMBERS(T, P, glm::tvec3, x, y, z, w)
_GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, r, g, b, a) _GLM_SWIZZLE4_3_MEMBERS(T, P, glm::tvec3, r, g, b, a)
_GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, s, t, p, q) _GLM_SWIZZLE4_3_MEMBERS(T, P, glm::tvec3, s, t, p, q)
_GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, x, y, z, w) _GLM_SWIZZLE4_4_MEMBERS(T, P, glm::tvec4, x, y, z, w)
_GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, r, g, b, a) _GLM_SWIZZLE4_4_MEMBERS(T, P, glm::tvec4, r, g, b, a)
_GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, s, t, p, q) _GLM_SWIZZLE4_4_MEMBERS(T, P, glm::tvec4, s, t, p, q)
# endif//GLM_SWIZZLE # endif//GLM_SWIZZLE
}; };
# else # else
@ -186,46 +186,45 @@ namespace detail
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec4(tvec4<U, Q> const& v); GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec4(tvec4<U, Q> const& v);
// -- Swizzle constructors -- // -- Swizzle constructors --
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) # if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
template <int E0, int E1, int E2, int E3> template <int E0, int E1, int E2, int E3>
GLM_FUNC_DECL tvec4(detail::_swizzle<4, T, P, tvec4<T, P>, E0, E1, E2, E3> const & that) GLM_FUNC_DECL tvec4(detail::_swizzle<4, T, P, glm::tvec4, E0, E1, E2, E3> const & that)
{ {
*this = that(); *this = that();
} }
template <int E0, int E1, int F0, int F1> template <int E0, int E1, int F0, int F1>
GLM_FUNC_DECL tvec4(detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, detail::_swizzle<2, T, P, tvec2<T, P>, F0, F1, -1, -2> const & u) GLM_FUNC_DECL tvec4(detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v, detail::_swizzle<2, T, P, glm::tvec2, F0, F1, -1, -2> const & u)
{ {
*this = tvec4<T, P>(v(), u()); *this = tvec4<T, P>(v(), u());
} }
template <int E0, int E1> template <int E0, int E1>
GLM_FUNC_DECL tvec4(T const & x, T const & y, detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v) GLM_FUNC_DECL tvec4(T const & x, T const & y, detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v)
{ {
*this = tvec4<T, P>(x, y, v()); *this = tvec4<T, P>(x, y, v());
} }
template <int E0, int E1> template <int E0, int E1>
GLM_FUNC_DECL tvec4(T const & x, detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & w) GLM_FUNC_DECL tvec4(T const & x, detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v, T const & w)
{ {
*this = tvec4<T, P>(x, v(), w); *this = tvec4<T, P>(x, v(), w);
} }
template <int E0, int E1> template <int E0, int E1>
GLM_FUNC_DECL tvec4(detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & z, T const & w) GLM_FUNC_DECL tvec4(detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v, T const & z, T const & w)
{ {
*this = tvec4<T, P>(v(), z, w); *this = tvec4<T, P>(v(), z, w);
} }
template <int E0, int E1, int E2> template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec4(detail::_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & v, T const & w) GLM_FUNC_DECL tvec4(detail::_swizzle<3, T, P, glm::tvec3, E0, E1, E2, -1> const & v, T const & w)
{ {
*this = tvec4<T, P>(v(), w); *this = tvec4<T, P>(v(), w);
} }
template <int E0, int E1, int E2> template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec4(T const & x, detail::_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & v) GLM_FUNC_DECL tvec4(T const & x, detail::_swizzle<3, T, P, glm::tvec3, E0, E1, E2, -1> const & v)
{ {
*this = tvec4<T, P>(x, v()); *this = tvec4<T, P>(x, v());
} }
@ -485,6 +484,20 @@ namespace detail
template <precision P> template <precision P>
GLM_FUNC_DECL tvec4<bool, P> operator||(tvec4<bool, P> const & v1, tvec4<bool, P> const & v2); GLM_FUNC_DECL tvec4<bool, P> operator||(tvec4<bool, P> const & v1, tvec4<bool, P> const & v2);
/*
namespace detail
{
template <precision P, int E0, int E1, int E2, int E3>
struct _swizzle_base1<4, float, P, glm::tvec4, E0,E1,E2,E3> : public _swizzle_base0<float, 4>
{
GLM_FUNC_QUALIFIER tvec4<float, P> operator ()() const
{
return tvec4<float, P>(this->elem(E0), this->elem(E1), this->elem(E2), this->elem(E3));
}
};
}//namespace detail
*/
}//namespace glm }//namespace glm
#ifndef GLM_EXTERNAL_TEMPLATE #ifndef GLM_EXTERNAL_TEMPLATE

View File

@ -52,6 +52,15 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_div_lowp(glm_vec4 a, glm_vec4 b)
return glm_vec4_mul(a, _mm_rcp_ps(b)); return glm_vec4_mul(a, _mm_rcp_ps(b));
} }
GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_swizzle_xyzw(glm_vec4 a)
{
# if GLM_ARCH & GLM_ARCH_AVX2_BIT
return _mm_permute_ps(a, _MM_SHUFFLE(3, 2, 1, 0));
# else
return _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 2, 1, 0));
# endif
}
GLM_FUNC_QUALIFIER glm_vec4 glm_vec1_fma(glm_vec4 a, glm_vec4 b, glm_vec4 c) GLM_FUNC_QUALIFIER glm_vec4 glm_vec1_fma(glm_vec4 a, glm_vec4 b, glm_vec4 c)
{ {
# if GLM_ARCH & GLM_ARCH_AVX2_BIT # if GLM_ARCH & GLM_ARCH_AVX2_BIT

View File

@ -1243,6 +1243,12 @@ int main()
glm::int32 const c(1); glm::int32 const c(1);
glm::int32 const d = ~c; glm::int32 const d = ~c;
glm_vec4 const A = _mm_set_ps(4, 3, 2, 1);
glm_vec4 const B = glm_vec4_swizzle_xyzw(A);
glm_vec4 const C = _mm_permute_ps(A, _MM_SHUFFLE(3, 2, 1, 0));
glm_vec4 const D = _mm_permute_ps(A, _MM_SHUFFLE(0, 1, 2, 3));
glm_vec4 const E = _mm_shuffle_ps(A, A, _MM_SHUFFLE(0, 1, 2, 3));
Error += sign::test(); Error += sign::test();
Error += floor_::test(); Error += floor_::test();
Error += mod_::test(); Error += mod_::test();

View File

@ -502,6 +502,7 @@ int test_vec4_simd()
int main() int main()
{ {
int Error(0); int Error(0);
/* /*
{ {
glm::ivec4 const a1(2); glm::ivec4 const a1(2);