nir/lower_int64: do not try to clamp floats to int-range

The clamping isn't correct, because the exact values ended up getting
rounded off a bit when converting back to floats.

But, converting floats to integers have undefined results when the
float value doesn't fit in the integer. So let's not try to clamp the
value here.

This was caught by digging at a Clang warning, see this thread for
details:

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15547#note_1329769

Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16022>
This commit is contained in:
Erik Faye-Lund 2022-04-19 08:21:08 +02:00 committed by Marge Bot
parent 25acf1d869
commit 30aab0af07
1 changed files with 1 additions and 6 deletions

View File

@ -759,16 +759,11 @@ lower_f2(nir_builder *b, nir_ssa_def *x, bool dst_is_signed)
if (dst_is_signed)
x_sign = nir_fsign(b, x);
else
x = nir_fmin(b, x, nir_imm_floatN_t(b, UINT64_MAX, x->bit_size));
x = nir_ftrunc(b, x);
if (dst_is_signed) {
x = nir_fmin(b, x, nir_imm_floatN_t(b, INT64_MAX, x->bit_size));
x = nir_fmax(b, x, nir_imm_floatN_t(b, INT64_MIN, x->bit_size));
if (dst_is_signed)
x = nir_fabs(b, x);
}
nir_ssa_def *div = nir_imm_floatN_t(b, 1ULL << 32, x->bit_size);
nir_ssa_def *res_hi = nir_f2u32(b, nir_fdiv(b, x, div));