summaryrefslogtreecommitdiff
path: root/src/compiler/nir/nir_opt_algebraic.py
diff options
context:
space:
mode:
authorJonathan Marek <jonathan@marek.ca>2019-05-08 10:26:49 -0400
committerJonathan Marek <jonathan@marek.ca>2019-07-24 17:36:21 -0400
commitbc3b6168bac39a16326c730a9d0ae97b45c7df23 (patch)
tree58816c0efaa72880f75d457c725ff8b417ecf188 /src/compiler/nir/nir_opt_algebraic.py
parent5a4e71c082886810504ecfa329fb57050acc623f (diff)
downloadmesa-bc3b6168bac39a16326c730a9d0ae97b45c7df23.tar.gz
nir: replace lower_sincos with algebraic opt
This version has less ops for the same precision. Signed-off-by: Jonathan Marek <jonathan@marek.ca> Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com> Acked-by: Matt Turner <mattst88@gmail.com>
Diffstat (limited to 'src/compiler/nir/nir_opt_algebraic.py')
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 00145fc80f5..951771fa37a 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -29,6 +29,7 @@ from collections import OrderedDict
import nir_algebraic
from nir_opcodes import type_sizes
import itertools
+from math import pi
# Convenience variables
a = 'a'
@@ -74,6 +75,12 @@ e = 'e'
# another condition, the two can be separated by a comma (e.g.,
# "(many-comm-expr,is_used_once)").
+# based on https://web.archive.org/web/20180105155939/http://forum.devmaster.net/t/fast-and-accurate-sine-cosine/9648
+def lowered_sincos(c):
+ x = ('fsub', ('fmul', 2.0, ('ffract', ('fadd', ('fmul', 0.5 / pi, a), c))), 1.0)
+ x = ('fmul', ('fsub', x, ('fmul', x, ('fabs', x))), 4.0)
+ return ('ffma', ('ffma', x, ('fabs', x), ('fneg', x)), 0.225, x)
+
optimizations = [
(('imul', a, '#b@32(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b)), '!options->lower_bitshift'),
@@ -645,6 +652,9 @@ optimizations = [
(('~frcp', ('fsqrt', a)), ('frsq', a)),
(('fsqrt', a), ('frcp', ('frsq', a)), 'options->lower_fsqrt'),
(('~frcp', ('frsq', a)), ('fsqrt', a), '!options->lower_fsqrt'),
+ # Trig
+ (('fsin', a), lowered_sincos(0.5), 'options->lower_sincos'),
+ (('fcos', a), lowered_sincos(0.75), 'options->lower_sincos'),
# Boolean simplifications
(('i2b32(is_used_by_if)', a), ('ine32', a, 0)),
(('i2b1(is_used_by_if)', a), ('ine', a, 0)),