[Mesa-dev] [PATCH] nir: fix divide by zero crash during constant folding

Roland Scheidegger sroland at vmware.com
Wed Feb 28 03:45:37 UTC 2018


I think you just have to rely on the default of them being disabled.
It is a bug of an app calling into mesa with non-default float state.

Roland

Am 28.02.2018 um 04:35 schrieb Jason Ekstrand:
> On Tue, Feb 27, 2018 at 7:28 PM, Connor Abbott <cwabbott0 at gmail.com
> <mailto:cwabbott0 at gmail.com>> wrote:
> 
>     Floating point division shouldn't signal on division by zero, it
>     should just return an appropriately-signed infinity, which seems like
>     a sane thing to do, and way better than just returning 0.
> 
> 
> I think that depends on whether or not floating-point exceptions are
> enabled.  Unfortunately, I don't really know how to enable/disable them. :-(
>  
> 
>     So we
>     shouldn't do this with fdiv. I guess 0 is as good a result as any for
>     the integer division, though -- there aren't really any great choices.
> 
> 
> Yeah, 0 is as good as anything.  Honestly, I'm a bit tempted to say that
> integer division by 0 is always 42. :-)
>  
> 
>     On Tue, Feb 27, 2018 at 10:07 PM, Timothy Arceri
>     <tarceri at itsqueeze.com <mailto:tarceri at itsqueeze.com>> wrote:
>     > From the GLSL 4.60 spec Section 5.9 (Expressions):
>     >
>     >    "Dividing by zero does not cause an exception but does result in
>     >     an unspecified value."
>     >
>     > Fixes: 89285e4d47a6 "nir: add new constant folding infrastructure"
>     >
>     > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105271
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.freedesktop.org_show-5Fbug.cgi-3Fid-3D105271&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0&m=xwOqfDj5YhD5I8CsA5gm7Z1MM2EDarjrQZgMbJ3X3Ns&s=mruWkGkxVy4KNN5wzRckPaDyiulf3EtMZwaF7IrBvdU&e=>
>     > ---
>     >  src/compiler/nir/nir_opcodes.py | 6 +++---
>     >  1 file changed, 3 insertions(+), 3 deletions(-)
>     >
>     > diff --git a/src/compiler/nir/nir_opcodes.py
>     b/src/compiler/nir/nir_opcodes.py
>     > index 278562b2bd..dcc5b07d05 100644
>     > --- a/src/compiler/nir/nir_opcodes.py
>     > +++ b/src/compiler/nir/nir_opcodes.py
>     > @@ -403,9 +403,9 @@ binop("imul_high", tint32, commutative,
>     >  binop("umul_high", tuint32, commutative,
>     >        "(uint32_t)(((uint64_t) src0 * (uint64_t) src1) >> 32)")
>     >
>     > -binop("fdiv", tfloat, "", "src0 / src1")
>     > -binop("idiv", tint, "", "src0 / src1")
>     > -binop("udiv", tuint, "", "src0 / src1")
>     > +binop("fdiv", tfloat, "", "src1 == 0 ? 0 : (src0 / src1)")
>     > +binop("idiv", tint, "", "src1 == 0 ? 0 : (src0 / src1)")
>     > +binop("udiv", tuint, "", "src1 == 0 ? 0 : (src0 / src1)")
>     >
>     >  # returns a boolean representing the carry resulting from the
>     addition of
>     >  # the two unsigned arguments.
>     > --
>     > 2.14.3
>     >
>     > _______________________________________________
>     > mesa-dev mailing list
>     > mesa-dev at lists.freedesktop.org <mailto:mesa-dev at lists.freedesktop.org>
>     > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0&m=xwOqfDj5YhD5I8CsA5gm7Z1MM2EDarjrQZgMbJ3X3Ns&s=nDfjLHo9SqOf-KSvRJrDZOi93VfiBnnV-NN8hx4NyvE&e=>
>     _______________________________________________
>     mesa-dev mailing list
>     mesa-dev at lists.freedesktop.org <mailto:mesa-dev at lists.freedesktop.org>
>     https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0&m=xwOqfDj5YhD5I8CsA5gm7Z1MM2EDarjrQZgMbJ3X3Ns&s=nDfjLHo9SqOf-KSvRJrDZOi93VfiBnnV-NN8hx4NyvE&e=>
> 
> 
> 
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev&d=DwIGaQ&c=uilaK90D4TOVoH58JNXRgQ&r=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0&m=xwOqfDj5YhD5I8CsA5gm7Z1MM2EDarjrQZgMbJ3X3Ns&s=nDfjLHo9SqOf-KSvRJrDZOi93VfiBnnV-NN8hx4NyvE&e=
> 



More information about the mesa-dev mailing list