agx: Don't crash trying to encoding minifloats
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 6 Jan 2023 01:52:09 +0000 (20:52 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 11 Jan 2023 21:14:21 +0000 (21:14 +0000)
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>

src/asahi/compiler/agx_minifloat.h

index d0587a4..aad80b5 100644 (file)
@@ -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;
    }