mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +02:00
nir: Extract float_is_half tests in common code
Signed-off-by: Lorenzo Rossi <lorenzo.rossi@collabora.com> Reviewed-by: Eric R. Smith <eric.smith@collabora.com> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41096>
This commit is contained in:
parent
e092e945a7
commit
89436db611
2 changed files with 16 additions and 3 deletions
|
|
@ -476,9 +476,7 @@ static bool
|
|||
const_is_f16(nir_scalar scalar)
|
||||
{
|
||||
double value = nir_scalar_as_float(scalar);
|
||||
uint16_t fp16_val = _mesa_float_to_half(value);
|
||||
bool is_denorm = (fp16_val & 0x7fff) != 0 && (fp16_val & 0x7fff) <= 0x3ff;
|
||||
return value == _mesa_half_to_float(fp16_val) && !is_denorm;
|
||||
return _mesa_float_is_half(value);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
|||
|
|
@ -129,6 +129,21 @@ _mesa_half_is_negative(uint16_t h)
|
|||
return !!(h & 0x8000);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
_mesa_float_is_half(double val)
|
||||
{
|
||||
/* val parameter is double to prevent implicit double->float cast. We have
|
||||
* to cast to float because that's what _mesa_float_to_half expects and we
|
||||
* don't have any readily available _double_to_half function. This may
|
||||
* introduce double-rounding errors, however this is ok because the final
|
||||
* check is done at double precision, any rounding will fail to produce the
|
||||
* original value.
|
||||
*/
|
||||
uint16_t fp16_val = _mesa_float_to_half((float) val);
|
||||
bool is_denorm = (fp16_val & 0x7fff) != 0 && (fp16_val & 0x7fff) <= 0x3ff;
|
||||
return val == (double) _mesa_half_to_float(fp16_val) && !is_denorm;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue