Mesa (main): r600/sb: Avoid causing an exception when getting the reciprocal of 0u.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 20 21:57:30 UTC 2022


Module: Mesa
Branch: main
Commit: 0879c15666b5f3a9d53a8431c078ab8520bb6932
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0879c15666b5f3a9d53a8431c078ab8520bb6932

Author: Emma Anholt <emma at anholt.net>
Date:   Fri Feb 11 13:06:47 2022 -0800

r600/sb: Avoid causing an exception when getting the reciprocal of 0u.

I'm not sure what the hardware would return in this circumstance, so just
don't fold it.  Avoids regressions on transition to NIR.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14319>

---

 src/gallium/drivers/r600/sb/sb_expr.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/sb/sb_expr.cpp b/src/gallium/drivers/r600/sb/sb_expr.cpp
index 6d062b71b91..091037ce367 100644
--- a/src/gallium/drivers/r600/sb/sb_expr.cpp
+++ b/src/gallium/drivers/r600/sb/sb_expr.cpp
@@ -459,8 +459,13 @@ bool expr_handler::fold_alu_op1(alu_node& n) {
 	case ALU_OP1_RECIP_FF:
 	case ALU_OP1_RECIP_IEEE: dv = 1.0f / cv.f; break;
 //	case ALU_OP1_RECIP_INT:
-	case ALU_OP1_RECIP_UINT: dv.u = (1ull << 32) / cv.u; break;
-//	case ALU_OP1_RNDNE: dv = floor(cv.f + 0.5f); break;
+	case ALU_OP1_RECIP_UINT: {
+		if (!cv.u)
+			return false;
+		dv.u = (1ull << 32) / cv.u;
+		break;
+	}
+	//	case ALU_OP1_RNDNE: dv = floor(cv.f + 0.5f); break;
 	case ALU_OP1_SIN: dv = sin(cv.f * 2.0f * M_PI); break;
 	case ALU_OP1_SQRT_IEEE: dv = sqrtf(cv.f); break;
 	case ALU_OP1_TRUNC: dv = truncf(cv.f); break;



More information about the mesa-commit mailing list