agx: Don't crash trying to encoding minifloats
Fixes assertion fails in piglit isinf-and-isnan, which uses a constant infinity, which has an out-of-bounds mantissa (but the function contract says that's fine and we just return something undefined.) Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20563>
This commit is contained in:

committed by
Marge Bot

parent
7859b531c2
commit
4311c636c2
@@ -45,9 +45,11 @@ agx_minifloat_decode(uint8_t imm)
|
||||
}
|
||||
|
||||
/* Encodes a float. Results are only valid if the float can be represented
|
||||
* exactly, if not the result of this function is UNDEFINED. signbit() is used
|
||||
* to ensure -0.0 is handled correctly. */
|
||||
|
||||
* exactly, if not the result of this function is UNDEFINED. However, it is
|
||||
* guaranteed that this function will not crash on out-of-spec inputs, so it is
|
||||
* safe to call on any input. signbit() is used to ensure -0.0 is handled
|
||||
* correctly.
|
||||
*/
|
||||
static inline uint8_t
|
||||
agx_minifloat_encode(float f)
|
||||
{
|
||||
@@ -63,13 +65,9 @@ agx_minifloat_encode(float f)
|
||||
exp -= 5; /* 2^5 = 32 */
|
||||
exp = CLAMP(exp + 7, 0, 7);
|
||||
|
||||
assert(mantissa >= 0x10 && mantissa < 0x20);
|
||||
assert(exp >= 1);
|
||||
|
||||
return sign | (exp << 4) | (mantissa & 0xF);
|
||||
} else {
|
||||
unsigned mantissa = (f * 64.0f);
|
||||
assert(mantissa < 0x10);
|
||||
|
||||
return sign | mantissa;
|
||||
}
|
||||
|
Reference in New Issue
Block a user