- Fixed strict aliaing warnings #473

This commit is contained in:
Christophe Riccio 2016-06-04 22:57:21 +02:00
parent 4155e5b820
commit b54a256499
2 changed files with 88 additions and 83 deletions

View File

@ -122,13 +122,8 @@ namespace detail
else if(glm::isinf(x)) else if(glm::isinf(x))
return 0x1Fu << 6u; return 0x1Fu << 6u;
# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_LLVM)
uint Pack = 0u; uint Pack = 0u;
memcpy(&Pack, &x, sizeof(Pack)); memcpy(&Pack, &x, sizeof(Pack));
# else
uint Pack = reinterpret_cast<uint&>(x);
# endif
return float2packed11(Pack); return float2packed11(Pack);
} }
@ -143,13 +138,9 @@ namespace detail
uint Result = packed11ToFloat(x); uint Result = packed11ToFloat(x);
# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_LLVM)
float Temp = 0; float Temp = 0;
memcpy(&Temp, &Result, sizeof(Temp)); memcpy(&Temp, &Result, sizeof(Temp));
return Temp; return Temp;
# else
return reinterpret_cast<float&>(Result);
# endif
} }
GLM_FUNC_QUALIFIER glm::uint floatTo10bit(float x) GLM_FUNC_QUALIFIER glm::uint floatTo10bit(float x)
@ -161,13 +152,8 @@ namespace detail
else if(glm::isinf(x)) else if(glm::isinf(x))
return 0x1Fu << 5u; return 0x1Fu << 5u;
# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_LLVM)
uint Pack = 0; uint Pack = 0;
memcpy(&Pack, &x, sizeof(Pack)); memcpy(&Pack, &x, sizeof(Pack));
# else
uint Pack = reinterpret_cast<uint&>(x);
# endif
return float2packed10(Pack); return float2packed10(Pack);
} }
@ -182,13 +168,9 @@ namespace detail
uint Result = packed10ToFloat(x); uint Result = packed10ToFloat(x);
# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_LLVM)
float Temp = 0; float Temp = 0;
memcpy(&Temp, &Result, sizeof(Temp)); memcpy(&Temp, &Result, sizeof(Temp));
return Temp; return Temp;
# else
return reinterpret_cast<float&>(Result);
# endif
} }
// GLM_FUNC_QUALIFIER glm::uint f11_f11_f10(float x, float y, float z) // GLM_FUNC_QUALIFIER glm::uint f11_f11_f10(float x, float y, float z)
@ -297,13 +279,17 @@ namespace detail
{ {
GLM_FUNC_QUALIFIER static tvec1<uint16, P> pack(tvec1<float, P> const & v) GLM_FUNC_QUALIFIER static tvec1<uint16, P> pack(tvec1<float, P> const & v)
{ {
int16 const Unpacked(detail::toFloat16(v.x)); int16 const Unpack(detail::toFloat16(v.x));
return tvec1<uint16, P>(reinterpret_cast<uint16 const &>(Unpacked)); u16vec1 Packed(uninitialize);
memcpy(&Packed, &Unpack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER static tvec1<float, P> unpack(tvec1<uint16, P> const & v) GLM_FUNC_QUALIFIER static tvec1<float, P> unpack(tvec1<uint16, P> const & v)
{ {
return tvec1<float, P>(detail::toFloat32(reinterpret_cast<int16 const &>(v.x))); i16vec1 Unpack(uninitialize);
memcpy(&Unpack, &v, sizeof(Unpack));
return tvec1<float, P>(detail::toFloat32(v.x));
} }
}; };
@ -312,17 +298,17 @@ namespace detail
{ {
GLM_FUNC_QUALIFIER static tvec2<uint16, P> pack(tvec2<float, P> const & v) GLM_FUNC_QUALIFIER static tvec2<uint16, P> pack(tvec2<float, P> const & v)
{ {
tvec2<int16, P> const Unpacked(detail::toFloat16(v.x), detail::toFloat16(v.y)); tvec2<int16, P> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y));
return tvec2<uint16, P>( u16vec2 Packed(uninitialize);
reinterpret_cast<uint16 const &>(Unpacked.x), memcpy(&Packed, &Unpack, sizeof(Packed));
reinterpret_cast<uint16 const &>(Unpacked.y)); return Packed;
} }
GLM_FUNC_QUALIFIER static tvec2<float, P> unpack(tvec2<uint16, P> const & v) GLM_FUNC_QUALIFIER static tvec2<float, P> unpack(tvec2<uint16, P> const & v)
{ {
return tvec2<float, P>( i16vec2 Unpack(uninitialize);
detail::toFloat32(reinterpret_cast<int16 const &>(v.x)), memcpy(&Unpack, &v, sizeof(Unpack));
detail::toFloat32(reinterpret_cast<int16 const &>(v.y))); return tvec2<float, P>(detail::toFloat32(v.x), detail::toFloat32(v.y));
} }
}; };
@ -331,19 +317,17 @@ namespace detail
{ {
GLM_FUNC_QUALIFIER static tvec3<uint16, P> pack(tvec3<float, P> const & v) GLM_FUNC_QUALIFIER static tvec3<uint16, P> pack(tvec3<float, P> const & v)
{ {
tvec3<int16, P> const Unpacked(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z)); tvec3<int16, P> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z));
return tvec3<uint16, P>( u16vec3 Packed(uninitialize);
reinterpret_cast<uint16 const &>(Unpacked.x), memcpy(&Packed, &Unpack, sizeof(Packed));
reinterpret_cast<uint16 const &>(Unpacked.y), return Packed;
reinterpret_cast<uint16 const &>(Unpacked.z));
} }
GLM_FUNC_QUALIFIER static tvec3<float, P> unpack(tvec3<uint16, P> const & v) GLM_FUNC_QUALIFIER static tvec3<float, P> unpack(tvec3<uint16, P> const & v)
{ {
return tvec3<float, P>( i16vec3 Unpack(uninitialize);
detail::toFloat32(reinterpret_cast<int16 const &>(v.x)), memcpy(&Unpack, &v, sizeof(Unpack));
detail::toFloat32(reinterpret_cast<int16 const &>(v.y)), return tvec3<float, P>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z));
detail::toFloat32(reinterpret_cast<int16 const &>(v.z)));
} }
}; };
@ -352,21 +336,17 @@ namespace detail
{ {
GLM_FUNC_QUALIFIER static tvec4<uint16, P> pack(tvec4<float, P> const & v) GLM_FUNC_QUALIFIER static tvec4<uint16, P> pack(tvec4<float, P> const & v)
{ {
tvec4<int16, P> const Unpacked(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w)); tvec4<int16, P> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w));
return tvec4<uint16, P>( u16vec4 Packed(uninitialize);
reinterpret_cast<uint16 const &>(Unpacked.x), memcpy(&Packed, &Unpack, sizeof(Packed));
reinterpret_cast<uint16 const &>(Unpacked.y), return Packed;
reinterpret_cast<uint16 const &>(Unpacked.z),
reinterpret_cast<uint16 const &>(Unpacked.w));
} }
GLM_FUNC_QUALIFIER static tvec4<float, P> unpack(tvec4<uint16, P> const & v) GLM_FUNC_QUALIFIER static tvec4<float, P> unpack(tvec4<uint16, P> const & v)
{ {
return tvec4<float, P>( i16vec4 Unpack(uninitialize);
detail::toFloat32(reinterpret_cast<int16 const &>(v.x)), memcpy(&Unpack, &v, sizeof(Unpack));
detail::toFloat32(reinterpret_cast<int16 const &>(v.y)), return tvec4<float, P>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z), detail::toFloat32(v.w));
detail::toFloat32(reinterpret_cast<int16 const &>(v.z)),
detail::toFloat32(reinterpret_cast<int16 const &>(v.w)));
} }
}; };
}//namespace detail }//namespace detail
@ -385,40 +365,50 @@ namespace detail
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v) GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
{ {
u8vec2 const Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f)); u8vec2 const Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
return reinterpret_cast<uint16 const &>(Topack);
uint16 Unpack = 0;
memcpy(&Unpack, &Topack, sizeof(Unpack));
return Unpack;
} }
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
{ {
vec2 const Unpack(reinterpret_cast<u8vec2 const &>(p)); u8vec2 Unpack(uninitialize);
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255 memcpy(&Unpack, &p, sizeof(Unpack));
return vec2(Unpack) * float(0.0039215686274509803921568627451); // 1 / 255
} }
GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v) GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v)
{ {
int8 const Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f))); int8 const Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f)));
return reinterpret_cast<uint8 const &>(Topack); uint8 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p) GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p)
{ {
float const Unpack(reinterpret_cast<int8 const &>(p)); int8 Unpack = 0;
memcpy(&Unpack, &p, sizeof(Unpack));
return clamp( return clamp(
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f static_cast<float>(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
-1.0f, 1.0f); -1.0f, 1.0f);
} }
GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v) GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v)
{ {
i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f)); i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f));
return reinterpret_cast<uint16 const &>(Topack); uint16 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
{ {
vec2 const Unpack(reinterpret_cast<i8vec2 const &>(p)); i8vec2 Unpack(uninitialize);
memcpy(&Unpack, &p, sizeof(Unpack));
return clamp( return clamp(
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f vec2(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
-1.0f, 1.0f); -1.0f, 1.0f);
} }
@ -436,69 +426,83 @@ namespace detail
GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v) GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v)
{ {
u16vec4 const Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f)); u16vec4 const Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f));
return reinterpret_cast<uint64 const &>(Topack); uint64 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p) GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
{ {
vec4 const Unpack(reinterpret_cast<u16vec4 const &>(p)); u16vec4 Unpack(uninitialize);
return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 memcpy(&Unpack, &p, sizeof(Unpack));
return vec4(Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
} }
GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v) GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v)
{ {
int16 const Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); int16 const Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
return reinterpret_cast<uint16 const &>(Topack); uint16 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p) GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p)
{ {
float const Unpack(reinterpret_cast<int16 const &>(p)); int16 Unpack = 0;
memcpy(&Unpack, &p, sizeof(Unpack));
return clamp( return clamp(
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, static_cast<float>(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
-1.0f, 1.0f); -1.0f, 1.0f);
} }
GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v) GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v)
{ {
i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
return reinterpret_cast<uint64 const &>(Topack); uint64 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p) GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p)
{ {
vec4 const Unpack(reinterpret_cast<i16vec4 const &>(p)); i16vec4 Unpack(uninitialize);
memcpy(&Unpack, &p, sizeof(Unpack));
return clamp( return clamp(
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, vec4(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
-1.0f, 1.0f); -1.0f, 1.0f);
} }
GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v) GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v)
{ {
int16 const Topack(detail::toFloat16(v)); int16 const Topack(detail::toFloat16(v));
return reinterpret_cast<uint16 const &>(Topack); uint16 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v) GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v)
{ {
return detail::toFloat32(reinterpret_cast<int16 const &>(v)); int16 Unpack = 0;
memcpy(&Unpack, &v, sizeof(Unpack));
return detail::toFloat32(Unpack);
} }
GLM_FUNC_QUALIFIER uint64 packHalf4x16(glm::vec4 const & v) GLM_FUNC_QUALIFIER uint64 packHalf4x16(glm::vec4 const & v)
{ {
i16vec4 Unpack( i16vec4 const Unpack(
detail::toFloat16(v.x), detail::toFloat16(v.x),
detail::toFloat16(v.y), detail::toFloat16(v.y),
detail::toFloat16(v.z), detail::toFloat16(v.z),
detail::toFloat16(v.w)); detail::toFloat16(v.w));
uint64 Packed = 0;
return reinterpret_cast<uint64 const &>(Unpack); memcpy(&Packed, &Unpack, sizeof(Packed));
return Packed;
} }
GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v) GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
{ {
i16vec4 Unpack(reinterpret_cast<i16vec4 const &>(v)); i16vec4 Unpack(uninitialize);
memcpy(&Unpack, &v, sizeof(Unpack));
return vec4( return vec4(
detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.x),
detail::toFloat32(Unpack.y), detail::toFloat32(Unpack.y),

View File

@ -83,6 +83,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Fixed intersectRayTriangle to not do any unintentional backface culling - Fixed intersectRayTriangle to not do any unintentional backface culling
- Fixed long long warnings when using C++98 on GCC and Clang #482 - Fixed long long warnings when using C++98 on GCC and Clang #482
- Fixed sign with signed integer function on non-x86 architecture - Fixed sign with signed integer function on non-x86 architecture
- Fixed strict aliaing warnings #473
##### Deprecation: ##### Deprecation:
- Removed GLM_FORCE_SIZE_FUNC define - Removed GLM_FORCE_SIZE_FUNC define