Bug 89640 - dEQP-GLES3: tanh produces incorrect results for some limit cases
Summary: dEQP-GLES3: tanh produces incorrect results for some limit cases
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/DRI/i965 (show other bugs)
Version: git
Hardware: Other All
: medium normal
Assignee: Intel 3D Bugs Mailing List
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-18 07:25 UTC by Iago Toral
Modified: 2017-02-13 23:44 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Iago Toral 2015-03-18 07:25:23 UTC
List of affected tests:

dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.scalar
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.vec2
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.vec3
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.vec4
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.scalar
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.vec2
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.vec3
dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.vec4

tanh is implemented as:

   body.emit(ret(div(sub(exp(x), exp(neg(x))),
                     add(exp(x), exp(neg(x))))));

For some values of x this leads to a infinity values in the denominator and numerator. The division of such values leads to a NaN instead of 1.0 (the result expected by dEQP and the result of tanh from libc too).

I suppose we can add as-hoc code to handle these cases and produce a result of 1.0 directly in software when we detect them, but I wonder if it is worth the cost.
Comment 1 Kenneth Graunke 2015-03-19 01:42:09 UTC
I have not seen a single (non-test) shader that uses tanh(), so I'm not worried about any performance impact.  Emitting extra instructions to compute the correct value sounds sensible.
Comment 2 Matt Turner 2015-03-19 03:43:40 UTC
glibc's tanh() returns 1.0f if x > 22.0.
Comment 3 Kenneth Graunke 2016-03-26 09:41:23 UTC
I believe these tests were stricken from the Android must-pass list, but I think they still may exist in the Vulkan CTS.
Comment 4 Matt Turner 2017-02-13 23:44:02 UTC
I think these were fixed by

commit d4983390a869c3051929858a8b783be53d46b722
Author: Haixia Shi <hshi@chromium.org>
Date:   Thu Dec 8 17:41:02 2016 -0800

    compiler/glsl: fix precision problem of tanh

(they at least pass for me as of commit d49d275c41)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.