<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 8, 2016 at 5:50 PM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thursday, December 8, 2016 5:41:02 PM PST Haixia Shi wrote:<br>
> Clamp input scalar value to range [-10, +10] to avoid precision problems<br>
> when the absolute value of input is too large.<br>
><br>
> Fixes dEQP-GLES3.functional.shaders.<wbr>builtin_functions.precision.<wbr>tanh.* test<br>
> failures.<br>
><br>
> v2: added more explanation in the comment.<br>
> v3: fixed a typo in the comment.<br>
><br>
> Signed-off-by: Haixia Shi <<a href="mailto:hshi@chromium.org">hshi@chromium.org</a>><br>
> Cc: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>>,<br>
> Cc: Stéphane Marchesin <<a href="mailto:marcheu@chromium.org">marcheu@chromium.org</a>>,<br>
> Cc: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
><br>
> Change-Id: I324c948b3323ff8107127c42934f1<wbr>4459e124b95<br>
> ---<br>
> src/compiler/glsl/builtin_<wbr>functions.cpp | 13 +++++++++++--<br>
> 1 file changed, 11 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/src/compiler/glsl/builtin_<wbr>functions.cpp b/src/compiler/glsl/builtin_<wbr>functions.cpp<br>
> index 3e4bcbb..0bacffb 100644<br>
> --- a/src/compiler/glsl/builtin_<wbr>functions.cpp<br>
> +++ b/src/compiler/glsl/builtin_<wbr>functions.cpp<br>
> @@ -3563,9 +3563,18 @@ builtin_builder::_tanh(const glsl_type *type)<br>
> ir_variable *x = in_var(type, "x");<br>
> MAKE_SIG(type, v130, 1, x);<br>
><br>
> + /*<br>
<br>
</span>For future reference, /* doesn't go on its own line in Mesa.<br>
(We can fix that when pushing, no big deal.)<br>
<br>
Thanks for fixing this. The explanation makes sense.<br>
<br>
Reviewed-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br></blockquote><div><br></div><div>I just pushed this with my and ken's reviews and the comment change Ken suggested.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
> + * Clamp x to [-10, +10] to avoid precision problems.<br>
> + * When x > 10, e^(-x) is so small relative to e^x that it gets flushed to<br>
> + * zero in the computation e^x + e^(-x). The same happens in the other<br>
> + * direction when x < -10.<br>
> + */<br>
> + ir_variable *t = body.make_temp(type, "tmp");<br>
> + body.emit(assign(t, min2(max2(x, imm(-10.0f)), imm(10.0f))));<br>
> +<br>
> /* (e^x - e^(-x)) / (e^x + e^(-x)) */<br>
> - body.emit(ret(div(sub(exp(x), exp(neg(x))),<br>
> - add(exp(x), exp(neg(x))))));<br>
> + body.emit(ret(div(sub(exp(t), exp(neg(t))),<br>
> + add(exp(t), exp(neg(t))))));<br>
><br>
> return sig;<br>
> }<br>
><br>
<br>
</div></div><br>______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
<br></blockquote></div><br></div></div>