From 4311c636c2fde1f7a41239a0c55909816eb2d6ee Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 5 Jan 2023 20:52:09 -0500 Subject: [PATCH] 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 Part-of: --- src/asahi/compiler/agx_minifloat.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/asahi/compiler/agx_minifloat.h b/src/asahi/compiler/agx_minifloat.h index d0587a40c6a..aad80b559d9 100644 --- a/src/asahi/compiler/agx_minifloat.h +++ b/src/asahi/compiler/agx_minifloat.h @@ -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; }