[Mesa-dev] [RFC 09/10] nir/lower_double_ops: lower sub()

Elie Tournier tournier.elie at gmail.com
Wed Apr 12 22:43:18 UTC 2017


Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
 src/compiler/nir/nir.h                  |  3 ++-
 src/compiler/nir/nir_lower_double_ops.c | 24 ++++++++++++++++++++++++
 src/intel/compiler/brw_nir.c            |  3 ++-
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index d161380b1b..c5c955c92e 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2576,7 +2576,8 @@ typedef enum {
    nir_lower_dlt = (1 << 13),
    nir_lower_dmul = (1 << 14),
    nir_lower_ddiv = (1 << 15),
-   nir_lower_dadd = (1 << 16)
+   nir_lower_dadd = (1 << 16),
+   nir_lower_dsub = (1 << 17)
 } nir_lower_doubles_options;
 
 bool nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);
diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c
index db1a3c0b72..f7fb7dccd4 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -2057,6 +2057,18 @@ lower_fadd64(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
                     sub_frac_fp64(b, x_si, x, y));
 }
 
+static nir_ssa_def *
+lower_fsub64(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
+{
+   nir_ssa_def *x_si = get_sign(b, x);
+   nir_ssa_def *y_si = get_sign(b, y);
+
+   return nir_bcsel(b,
+                    nir_ieq(b, x_si, y_si),
+                    sub_frac_fp64(b, x_si, x, y),
+                    add_frac_fp64(b, x_si, x, y));
+}
+
 static bool
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
 {
@@ -2150,6 +2162,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
          return false;
       break;
 
+   case nir_op_fsub:
+      if (!(options & nir_lower_dsub))
+         return false;
+      break;
+
    default:
       return false;
    }
@@ -2243,6 +2260,13 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
    }
       break;
 
+   case nir_op_fsub: {
+      nir_ssa_def *src1 = nir_fmov_alu(&bld, instr->src[1],
+                                      instr->dest.dest.ssa.num_components);
+      result = lower_fsub64(&bld, src, src1);
+   }
+      break;
+
    default:
       unreachable("unhandled opcode");
    }
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index 67e8cea2b6..8ef56813b6 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -517,7 +517,8 @@ nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
                              nir_lower_dlt |
                              nir_lower_dmul |
                              nir_lower_ddiv |
-                             nir_lower_dadd);
+                             nir_lower_dadd |
+                             nir_lower_dsub);
       OPT(nir_lower_64bit_pack);
    } while (progress);
 
-- 
2.11.0



More information about the mesa-dev mailing list