<html>
<head>
<base href="https://bugs.freedesktop.org/">
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - fp64 division gives imprecise results"
href="https://bugs.freedesktop.org/show_bug.cgi?id=110435#c3">Comment # 3</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - fp64 division gives imprecise results"
href="https://bugs.freedesktop.org/show_bug.cgi?id=110435">bug 110435</a>
from <span class="vcard"><a class="email" href="mailto:b7.10110111@gmail.com" title="Ruslan Kabatsayev <b7.10110111@gmail.com>"> <span class="fn">Ruslan Kabatsayev</span></a>
</span></b>
<pre>The problem appears to be with lower_rcp from nir_lower_double_ops.c. Namely,
it's supposed to use two Newton-Raphson steps to improve precision of initial
single-precision rcp. But instead of actually doing the steps, it employs FMA
operation, with a mistake.
Namely, the correct expression should be (as noted in the comment, thanks to it
being present):
x_new = x + x * (1 - x*src).
But actual implementation is
ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra),
which is equivalent to
x_new = x - x * (1 - x*src).
Notice the minus sign before the outermost multiplication.
I'm not sure how to change sign of `ra` to check whether this would completely
fix the problem, but at least in an equivalent-code test in C++ I've reproduced
the problem, and the change
ra=std::fma(ra, std::fma(ra, src, -1.), ra);
to
ra=std::fma(-ra, std::fma(ra, src, -1.), ra);
made the difference between 1./src and the rcp-via-float in the C++ test go
away (for src=5.44786569377455 I used in the test).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the QA Contact for the bug.</li>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>