anv/grl: Use union for reinterpreting integer as float

Fixes strict aliasing violations flagged by GCC 12:

../src/intel/vulkan/grl/include/GRLOCLCompatibility.h: In function ‘float as_float(uint32_t)’:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:182:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  182 |     return *reinterpret_cast<float*>(&i);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h: In function ‘float3 as_float3(int3)’:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:187:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  187 |     return *reinterpret_cast<float3*>(&i3);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:187:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h: In function ‘float4 as_float4(int4)’:
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:192:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  192 |     return *reinterpret_cast<float4*>(&i4);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/intel/vulkan/grl/include/GRLOCLCompatibility.h:192:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

Fixes: 5f948503e4 ("anv: Import GRL")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21236>
This commit is contained in:
Michel Dänzer 2023-02-09 18:27:23 +01:00 committed by Marge Bot
parent a10529080b
commit 53ce756eeb

View file

@ -179,17 +179,22 @@ inline float dot(const float3& a, const float3& b) {
inline float as_float(uint32_t i)
{
return *reinterpret_cast<float*>(&i);
union { float f; uint32_t i; } fi;
fi.i = i;
return fi.f;
}
inline float3 as_float3(int3 i3)
{
return *reinterpret_cast<float3*>(&i3);
float3 o = { as_float(i3.x), as_float(i3.y), as_float(i3.z) };
return o;
}
inline float4 as_float4(int4 i4)
{
return *reinterpret_cast<float4*>(&i4);
float4 o = { as_float(i4.x), as_float(i4.y), as_float(i4.z), as_float(i4.w) };
return o;
}
inline float4 convert_float4_rtn(int4 i4)