Support aligned *vec* even when SIMD isn't enabled

This commit is contained in:
Christophe Riccio
2016-06-02 00:33:55 +02:00
parent 416632ea37
commit fd4ada5843
5 changed files with 124 additions and 67 deletions

View File

@@ -57,7 +57,7 @@ namespace detail
template <>
GLM_FUNC_QUALIFIER int bitCount(uint64 x)
{
return _mm_popcnt_u64(x);
return static_cast<int>(_mm_popcnt_u64(x));
}
# endif

View File

@@ -6,8 +6,68 @@
#include "precision.hpp"
#include "type_int.hpp"
namespace glm
namespace glm{
namespace detail
{
template <typename T, std::size_t size, bool aligned>
struct simd_data
{
typedef struct type {
uint8 data[size];
} type;
};
template <typename T, std::size_t size>
struct simd_data<T, size, true>
{
typedef GLM_ALIGNED_STRUCT(size) type {
uint8 data[size];
} type;
};
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
template <>
struct simd_data<float, 16, true>
{
typedef glm_vec4 type;
};
template <>
struct simd_data<int, 16, true>
{
typedef glm_ivec4 type;
};
template <>
struct simd_data<unsigned int, 16, true>
{
typedef glm_uvec4 type;
};
# endif
# if (GLM_ARCH & GLM_ARCH_AVX_BIT)
template <>
struct simd_data<double, 32, true>
{
typedef glm_dvec4 type;
};
# endif
# if (GLM_ARCH & GLM_ARCH_AVX2_BIT)
template <>
struct simd_data<int64, 32, true>
{
typedef glm_i64vec4 type;
};
template <>
struct simd_data<uint64, 32, true>
{
typedef glm_u64vec4 type;
};
# endif
}//namespace detail
template <typename T, precision P> struct tvec1;
template <typename T, precision P> struct tvec2;
template <typename T, precision P> struct tvec3;

View File

@@ -14,64 +14,8 @@
#endif //GLM_SWIZZLE
#include <cstddef>
namespace glm{
namespace detail
namespace glm
{
template <typename T, bool aligned>
struct simd_data
{
typedef T type[4];
};
/*
template <typename T>
GLM_ALIGNED_STRUCT(16) struct simd_data<T, true>
{
typedef T type[4];
};
*/
# if (GLM_ARCH & GLM_ARCH_SSE2_BIT)
template <>
struct simd_data<float, true>
{
typedef glm_vec4 type;
};
template <>
struct simd_data<int, true>
{
typedef glm_ivec4 type;
};
template <>
struct simd_data<unsigned int, true>
{
typedef glm_uvec4 type;
};
# endif
# if (GLM_ARCH & GLM_ARCH_AVX_BIT)
template <>
struct simd_data<double, true>
{
typedef glm_dvec4 type;
};
# endif
# if (GLM_ARCH & GLM_ARCH_AVX2_BIT)
template <>
struct simd_data<int64, true>
{
typedef glm_i64vec4 type;
};
template <>
struct simd_data<uint64, true>
{
typedef glm_u64vec4 type;
};
# endif
}//namespace detail
template <typename T, precision P = defaultp>
struct tvec4
{
@@ -90,7 +34,7 @@ namespace detail
struct { T r, g, b, a; };
struct { T s, t, p, q; };
typename detail::simd_data<T, detail::is_aligned<P>::value>::type data;
typename detail::simd_data<T, sizeof(T) * 4, detail::is_aligned<P>::value>::type data;
# ifdef GLM_SWIZZLE
_GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, x, y, z, w)