[Mesa-dev] [PATCH] nir: mark dsqrt/drsqrt/drcp implementation as exact

Connor Abbott cwabbott0 at gmail.com
Thu Apr 28 15:21:42 UTC 2016


On Thu, Apr 28, 2016 at 11:20 AM, Ilia Mirkin <imirkin at alum.mit.edu> 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.

>
> On Thu, Apr 28, 2016 at 11:17 AM, Connor Abbott <cwabbott0 at gmail.com> 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 <cwabbott0 at gmail.com>
>> ---
>>  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 at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list