summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian H. Kristensen <hoegsberg@google.com>2020-02-26 16:52:45 -0800
committerEric Engestrom <eric@engestrom.ch>2020-03-06 22:59:42 +0100
commitfa1d2996f70929f962f0a0498ceb088b0a2fcdf2 (patch)
tree8644100c22b1288e7085846a62c7a3be14b49c52
parentdba2d46d8c059d29d65b0fc43b0ce777620e5929 (diff)
downloadmesa-fa1d2996f70929f962f0a0498ceb088b0a2fcdf2.tar.gz
Revert "glsl: Use a simpler formula for tanh"
This reverts commit 9807f502eb7a023be619a14119388b2a43271b0e. The simplified formula doesn't pass the tanh dEQP tests when we lower to fp16 math. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4054> (cherry picked from commit 986e92f0ea803caf014adc40e900bc774af71da3)
-rw-r--r--.pick_status.json2
-rw-r--r--src/compiler/glsl/builtin_functions.cpp18
2 files changed, 9 insertions, 11 deletions
diff --git a/.pick_status.json b/.pick_status.json
index 0a80b02cbf6..ee733be8156 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -697,7 +697,7 @@
"description": "Revert \"glsl: Use a simpler formula for tanh\"",
"nominated": true,
"nomination_type": 2,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "9807f502eb7a023be619a14119388b2a43271b0e"
},
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index e262a1ec780..cfb9607698a 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -4928,19 +4928,17 @@ builtin_builder::_tanh(const glsl_type *type)
ir_variable *x = in_var(type, "x");
MAKE_SIG(type, v130, 1, x);
- /* tanh(x) := (0.5 * (e^x - e^(-x))) / (0.5 * (e^x + e^(-x)))
- *
- * With a little algebra this reduces to (e^2x - 1) / (e^2x + 1)
- *
- * Clamp x to (-inf, +10] to avoid precision problems. When x > 10, e^2x
- * is so much larger than 1.0 that 1.0 gets flushed to zero in the
- * computation e^2x +/- 1 so it can be ignored.
+ /* Clamp x to [-10, +10] to avoid precision problems.
+ * When x > 10, e^(-x) is so small relative to e^x that it gets flushed to
+ * zero in the computation e^x + e^(-x). The same happens in the other
+ * direction when x < -10.
*/
ir_variable *t = body.make_temp(type, "tmp");
- body.emit(assign(t, min2(x, imm(10.0f))));
+ body.emit(assign(t, min2(max2(x, imm(-10.0f)), imm(10.0f))));
- body.emit(ret(div(sub(exp(mul(t, imm(2.0f))), imm(1.0f)),
- add(exp(mul(t, imm(2.0f))), imm(1.0f)))));
+ /* (e^x - e^(-x)) / (e^x + e^(-x)) */
+ body.emit(ret(div(sub(exp(t), exp(neg(t))),
+ add(exp(t), exp(neg(t))))));
return sig;
}