Mesa (master): nir/algebraic: add lowering for fsign

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 19 15:43:11 UTC 2019


Module: Mesa
Branch: master
Commit: 4577eb7b7cddb0a5dd2ee77682eab01a4d55676b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4577eb7b7cddb0a5dd2ee77682eab01a4d55676b

Author: Erico Nunes <nunes.erico at gmail.com>
Date:   Tue Apr 16 22:49:41 2019 +0200

nir/algebraic: add lowering for fsign

The mali utgard pp doesn't support a sign instruction.
In the ARM offline shader compiler, the sign function is implemented
using sub(gt(0.0, a), lt(0.0, a)).
This is a generic optimization, so implement it in the nir level when
lower_fsign is set, alongside the lowering for isign.

Signed-off-by: Erico Nunes <nunes.erico at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/compiler/nir/nir.h                | 3 +++
 src/compiler/nir/nir_opt_algebraic.py | 1 +
 2 files changed, 4 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 2a381d28d7c..c79dcecafc4 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2242,6 +2242,9 @@ typedef struct nir_shader_compiler_options {
    /** enables rules to lower isign to imin+imax */
    bool lower_isign;
 
+   /** enables rules to lower fsign to fsub and flt */
+   bool lower_fsign;
+
    /* Does the native fdot instruction replicate its result for four
     * components?  If so, then opt_algebraic_late will turn all fdotN
     * instructions into fdot_replicatedN instructions.
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index b0914aca395..dad0545594f 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -840,6 +840,7 @@ optimizations.extend([
      'options->lower_unpack_snorm_4x8'),
 
    (('isign', a), ('imin', ('imax', a, -1), 1), 'options->lower_isign'),
+   (('fsign', a), ('fsub', ('b2f', ('flt', 0.0, a)), ('b2f', ('flt', a, 0.0))), 'options->lower_fsign'),
 ])
 
 # bit_size dependent lowerings




More information about the mesa-commit mailing list