util: move util_half_to_float code into _mesa_half_to_float_slow
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6774>
This commit is contained in:
@@ -110,29 +110,7 @@ util_float_to_half_rtz(float f)
|
|||||||
static inline float
|
static inline float
|
||||||
util_half_to_float(uint16_t f16)
|
util_half_to_float(uint16_t f16)
|
||||||
{
|
{
|
||||||
union fi infnan;
|
return _mesa_half_to_float(f16);
|
||||||
union fi magic;
|
|
||||||
union fi f32;
|
|
||||||
|
|
||||||
infnan.ui = 0x8f << 23;
|
|
||||||
infnan.f = 65536.0f;
|
|
||||||
magic.ui = 0xef << 23;
|
|
||||||
|
|
||||||
/* Exponent / Mantissa */
|
|
||||||
f32.ui = (f16 & 0x7fff) << 13;
|
|
||||||
|
|
||||||
/* Adjust */
|
|
||||||
f32.f *= magic.f;
|
|
||||||
/* XXX: The magic mul relies on denorms being available */
|
|
||||||
|
|
||||||
/* Inf / NaN */
|
|
||||||
if (f32.f >= infnan.f)
|
|
||||||
f32.ui |= 0xff << 23;
|
|
||||||
|
|
||||||
/* Sign */
|
|
||||||
f32.ui |= (uint32_t)(f16 & 0x8000) << 16;
|
|
||||||
|
|
||||||
return f32.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -142,7 +142,29 @@ _mesa_float_to_float16_rtz_slow(float val)
|
|||||||
float
|
float
|
||||||
_mesa_half_to_float_slow(uint16_t val)
|
_mesa_half_to_float_slow(uint16_t val)
|
||||||
{
|
{
|
||||||
return util_half_to_float(val);
|
union fi infnan;
|
||||||
|
union fi magic;
|
||||||
|
union fi f32;
|
||||||
|
|
||||||
|
infnan.ui = 0x8f << 23;
|
||||||
|
infnan.f = 65536.0f;
|
||||||
|
magic.ui = 0xef << 23;
|
||||||
|
|
||||||
|
/* Exponent / Mantissa */
|
||||||
|
f32.ui = (val & 0x7fff) << 13;
|
||||||
|
|
||||||
|
/* Adjust */
|
||||||
|
f32.f *= magic.f;
|
||||||
|
/* XXX: The magic mul relies on denorms being available */
|
||||||
|
|
||||||
|
/* Inf / NaN */
|
||||||
|
if (f32.f >= infnan.f)
|
||||||
|
f32.ui |= 0xff << 23;
|
||||||
|
|
||||||
|
/* Sign */
|
||||||
|
f32.ui |= (uint32_t)(val & 0x8000) << 16;
|
||||||
|
|
||||||
|
return f32.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user