Mesa (master): nir/lower_double_ops: lower ceil()

Samuel Iglesias Gonsálvez samuelig at kemper.freedesktop.org
Thu Apr 28 10:02:38 UTC 2016


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

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Mon Jan  4 16:10:11 2016 +0100

nir/lower_double_ops: lower ceil()

At least i965 hardware does not have native support for ceil on doubles.

v2 (Sam):
   - Improve the lowering pass to remove one bcsel (Jason).

Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/compiler/nir/nir.h                  |  1 +
 src/compiler/nir/nir_lower_double_ops.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 809e83b..252567c 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2419,6 +2419,7 @@ typedef enum {
    nir_lower_drsq = (1 << 2),
    nir_lower_dtrunc = (1 << 3),
    nir_lower_dfloor = (1 << 4),
+   nir_lower_dceil = (1 << 5),
 } nir_lower_doubles_options;
 
 void 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 1370ddf..2d94f78 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -368,6 +368,21 @@ lower_floor(nir_builder *b, nir_ssa_def *src)
                     nir_fsub(b, tr, nir_imm_double(b, 1.0)));
 }
 
+static nir_ssa_def *
+lower_ceil(nir_builder *b, nir_ssa_def *src)
+{
+   /* if x < 0,                    ceil(x) = trunc(x)
+    * else if (x - trunc(x) == 0), ceil(x) = x
+    * else,                        ceil(x) = trunc(x) + 1
+    */
+   nir_ssa_def *tr = nir_ftrunc(b, src);
+   nir_ssa_def *negative = nir_flt(b, src, nir_imm_double(b, 0.0));
+   return nir_bcsel(b,
+                    nir_ior(b, negative, nir_feq(b, src, tr)),
+                    tr,
+                    nir_fadd(b, tr, nir_imm_double(b, 1.0)));
+}
+
 static void
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
 {
@@ -401,6 +416,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
          return;
       break;
 
+   case nir_op_fceil:
+      if (!(options & nir_lower_dceil))
+         return;
+      break;
+
    default:
       return;
    }
@@ -430,6 +450,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
    case nir_op_ffloor:
       result = lower_floor(&bld, src);
       break;
+   case nir_op_fceil:
+      result = lower_ceil(&bld, src);
+      break;
    default:
       unreachable("unhandled opcode");
    }




More information about the mesa-commit mailing list