Re: [Mesa-dev] [PATCH] nir: mark dsqrt/drsqrt/drcp implementation as exact
On Thu, Apr 28, 2016 at 11:26 AM, Ilia Mirkinwrote: > On Thu, Apr 28, 2016 at 11:21 AM, Connor Abbott wrote: >> On Thu, Apr 28, 2016 at 11:20 AM, Ilia Mirkin wrote: >>> What if the existing operations were already exact? >> >> They aren't -- the builder makes them non-exact by default, and we >> initialize the builder ourselves in this pass. > > Hmm... OK. I'm just thinking of the case > > precise c = op(a, b) > > And op gets lowered. The resulting operations should also be exact. If > that's what's happening, then all's well. The resulting operations should be exact regardless of whether the original one was exact -- they're relying on the extra precision that fma() gives us in order to get the right precision in the result, and like in GLSL, there's no guarantee that a non-exact fma won't be split into multiply + add. Once we lower the operation, the compiler can't really apply any optimizations to the operation as a whole (except maybe constant folding) so it basically becomes exact anyways. > > -ilia ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] nir: mark dsqrt/drsqrt/drcp implementation as exact
On Thu, Apr 28, 2016 at 11:21 AM, Connor Abbottwrote: > On Thu, Apr 28, 2016 at 11:20 AM, Ilia Mirkin wrote: >> What if the existing operations were already exact? > > They aren't -- the builder makes them non-exact by default, and we > initialize the builder ourselves in this pass. Hmm... OK. I'm just thinking of the case precise c = op(a, b) And op gets lowered. The resulting operations should also be exact. If that's what's happening, then all's well. -ilia ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] nir: mark dsqrt/drsqrt/drcp implementation as exact
On Thu, Apr 28, 2016 at 11:20 AM, Ilia Mirkinwrote: > What if the existing operations were already exact? They aren't -- the builder makes them non-exact by default, and we initialize the builder ourselves in this pass. > > On Thu, Apr 28, 2016 at 11:17 AM, Connor Abbott wrote: >> The floating-point operations used to implement these have been >> carefully chosen to minimize rounding error while still getting decent >> performance. We don't want any optimizations to mess with them. While >> this shouldn't affect anything now, it seems like a good idea. >> >> Signed-off-by: Connor Abbott >> --- >> src/compiler/nir/nir_lower_double_ops.c | 4 >> 1 file changed, 4 insertions(+) >> >> diff --git a/src/compiler/nir/nir_lower_double_ops.c >> b/src/compiler/nir/nir_lower_double_ops.c >> index 7505fa3..42b94bb 100644 >> --- a/src/compiler/nir/nir_lower_double_ops.c >> +++ b/src/compiler/nir/nir_lower_double_ops.c >> @@ -142,8 +142,10 @@ lower_rcp(nir_builder *b, nir_ssa_def *src) >> * See https://en.wikipedia.org/wiki/Division_algorithm for more details. >> */ >> >> + b->exact = true; >> ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); >> ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); >> + b->exact = false; >> >> return fix_inv_result(b, ra, src, new_exp); >> } >> @@ -267,6 +269,7 @@ lower_sqrt_rsq(nir_builder *b, nir_ssa_def *src, bool >> sqrt) >> * (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots). >> */ >> >> +b->exact = true; >> nir_ssa_def *one_half = nir_imm_double(b, 0.5); >> nir_ssa_def *h_0 = nir_fmul(b, one_half, ra); >> nir_ssa_def *g_0 = nir_fmul(b, src, ra); >> @@ -283,6 +286,7 @@ lower_sqrt_rsq(nir_builder *b, nir_ssa_def *src, bool >> sqrt) >> one_half); >> res = nir_ffma(b, y_1, r_1, y_1); >> } >> +b->exact = false; >> >> if (sqrt) { >> /* Here, the special cases we need to handle are >> -- >> 2.5.0 >> >> ___ >> mesa-dev mailing list >> mesa-dev@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/mesa-dev ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] nir: mark dsqrt/drsqrt/drcp implementation as exact
What if the existing operations were already exact? On Thu, Apr 28, 2016 at 11:17 AM, Connor Abbottwrote: > The floating-point operations used to implement these have been > carefully chosen to minimize rounding error while still getting decent > performance. We don't want any optimizations to mess with them. While > this shouldn't affect anything now, it seems like a good idea. > > Signed-off-by: Connor Abbott > --- > src/compiler/nir/nir_lower_double_ops.c | 4 > 1 file changed, 4 insertions(+) > > diff --git a/src/compiler/nir/nir_lower_double_ops.c > b/src/compiler/nir/nir_lower_double_ops.c > index 7505fa3..42b94bb 100644 > --- a/src/compiler/nir/nir_lower_double_ops.c > +++ b/src/compiler/nir/nir_lower_double_ops.c > @@ -142,8 +142,10 @@ lower_rcp(nir_builder *b, nir_ssa_def *src) > * See https://en.wikipedia.org/wiki/Division_algorithm for more details. > */ > > + b->exact = true; > ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); > ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); > + b->exact = false; > > return fix_inv_result(b, ra, src, new_exp); > } > @@ -267,6 +269,7 @@ lower_sqrt_rsq(nir_builder *b, nir_ssa_def *src, bool > sqrt) > * (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots). > */ > > +b->exact = true; > nir_ssa_def *one_half = nir_imm_double(b, 0.5); > nir_ssa_def *h_0 = nir_fmul(b, one_half, ra); > nir_ssa_def *g_0 = nir_fmul(b, src, ra); > @@ -283,6 +286,7 @@ lower_sqrt_rsq(nir_builder *b, nir_ssa_def *src, bool > sqrt) > one_half); > res = nir_ffma(b, y_1, r_1, y_1); > } > +b->exact = false; > > if (sqrt) { > /* Here, the special cases we need to handle are > -- > 2.5.0 > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] nir: mark dsqrt/drsqrt/drcp implementation as exact
The floating-point operations used to implement these have been carefully chosen to minimize rounding error while still getting decent performance. We don't want any optimizations to mess with them. While this shouldn't affect anything now, it seems like a good idea. Signed-off-by: Connor Abbott--- src/compiler/nir/nir_lower_double_ops.c | 4 1 file changed, 4 insertions(+) diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c index 7505fa3..42b94bb 100644 --- a/src/compiler/nir/nir_lower_double_ops.c +++ b/src/compiler/nir/nir_lower_double_ops.c @@ -142,8 +142,10 @@ lower_rcp(nir_builder *b, nir_ssa_def *src) * See https://en.wikipedia.org/wiki/Division_algorithm for more details. */ + b->exact = true; ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); + b->exact = false; return fix_inv_result(b, ra, src, new_exp); } @@ -267,6 +269,7 @@ lower_sqrt_rsq(nir_builder *b, nir_ssa_def *src, bool sqrt) * (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots). */ +b->exact = true; nir_ssa_def *one_half = nir_imm_double(b, 0.5); nir_ssa_def *h_0 = nir_fmul(b, one_half, ra); nir_ssa_def *g_0 = nir_fmul(b, src, ra); @@ -283,6 +286,7 @@ lower_sqrt_rsq(nir_builder *b, nir_ssa_def *src, bool sqrt) one_half); res = nir_ffma(b, y_1, r_1, y_1); } +b->exact = false; if (sqrt) { /* Here, the special cases we need to handle are -- 2.5.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev