[Mesa-dev] [PATCH 45/47] glsl: Add a lowering pass for 64-bit float ceil()

Elie Tournier tournier.elie at gmail.com
Wed Aug 23 11:08:15 UTC 2017


Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
 src/compiler/glsl/lower_instructions.cpp | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp
index 50c35124fb..3ef13d1166 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -180,6 +180,7 @@ private:
    void min_to_less(ir_expression *ir);
    void max_to_less(ir_expression *ir);
    void dfloor_to_dtrunc(ir_expression *ir);
+   void dceil_to_dtrunc(ir_expression *ir);
 
    ir_expression *_carry(operand a, operand b);
 };
@@ -1685,6 +1686,27 @@ lower_instructions_visitor::dfloor_to_dtrunc(ir_expression *ir)
    this->progress = true;
 }
 
+void
+lower_instructions_visitor::dceil_to_dtrunc(ir_expression *ir)
+{
+   /* if x < 0,                    ceil(x) = trunc(x)
+    * else if (x - trunc(x) == 0), ceil(x) = x
+    * else,                        ceil(x) = trunc(x) + 1
+    */
+
+   ir_rvalue *src = ir->operands[0]->clone(ir, NULL);
+   ir_rvalue *tr = trunc(src);
+
+   ir->operation = ir_triop_csel;
+   ir->init_num_operands();
+   ir->operands[0] = logic_or(less(src, new(ir) ir_constant(0.0, 1)),
+                              equal(src, tr));
+   ir->operands[1] = tr;
+   ir->operands[2] = add(tr, new(ir) ir_constant(1.0, 1));
+
+   this->progress = true;
+}
+
 ir_visitor_status
 lower_instructions_visitor::visit_leave(ir_expression *ir)
 {
@@ -1768,8 +1790,13 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
       break;
 
    case ir_unop_ceil:
-      if (lowering(DOPS_TO_DFRAC) && ir->type->is_double())
-         dceil_to_dfrac(ir);
+      if (ir->type->is_double()) {
+         if (lowering(DOPS_TO_DFRAC)) {
+            dceil_to_dfrac(ir);
+         } else if (lowering(DOPS_TO_DTRUNC) && ir->type->is_scalar()) {
+            dceil_to_dtrunc(ir);
+         }
+      }
       break;
 
    case ir_unop_floor:
-- 
2.14.1



More information about the mesa-dev mailing list