[Mesa-dev] [PATCH 46/50] glsl: Add a lowering pass for 64-bit float rsq()

Dave Airlie airlied at gmail.com
Tue Mar 13 04:25:11 UTC 2018


From: Elie Tournier <elie.tournier at collabora.com>

---
 src/compiler/glsl/ir_optimization.h      |  1 +
 src/compiler/glsl/lower_instructions.cpp | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index ba0c101..e6f9ad3 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -56,6 +56,7 @@
 #define SQRT_TO_ABS_SQRT          0x200000
 #define DMIN_DMAX_TO_LESS         0x400000
 #define DOPS_TO_DTRUNC            0x800000
+#define DRSQ_TO_DRCP              0x1000000
 
 /* Opertaions for lower_64bit_integer_instructions() */
 #define MUL64                     (1U << 0)
diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp
index 94b262d..d13a99b 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -45,6 +45,7 @@
  * - DOPS_TO_DFRAC
  * - DMIN_DMAX_TO_LESS
  * - DOPS_TO_DTRUNC
+ * - DRSQ_TO_DRCP
  *
  * SUB_TO_ADD_NEG:
  * ---------------
@@ -182,6 +183,7 @@ private:
    void dfloor_to_dtrunc(ir_expression *ir);
    void dceil_to_dtrunc(ir_expression *ir);
    void dfrac_to_dtrunc(ir_expression *ir);
+   void drsq_to_drcp(ir_expression *ir);
 
    ir_expression *_carry(operand a, operand b);
 };
@@ -1780,6 +1782,22 @@ lower_instructions_visitor::dfrac_to_dtrunc(ir_expression *ir)
    this->progress = true;
 }
 
+void
+lower_instructions_visitor::drsq_to_drcp(ir_expression *ir)
+{
+   ir_expression *const sqrt_expr =
+      new(ir) ir_expression(ir_unop_sqrt,
+                            ir->operands[0]->type, ir->operands[0]);
+   if (lowering(SQRT_TO_ABS_SQRT))
+      sqrt_to_abs_sqrt(sqrt_expr);
+
+   ir->operation = ir_unop_rcp;
+   ir->init_num_operands();
+   ir->operands[0] = sqrt_expr;
+
+   this->progress = true;
+}
+
 ir_visitor_status
 lower_instructions_visitor::visit_leave(ir_expression *ir)
 {
@@ -1928,6 +1946,13 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
       break;
 
    case ir_unop_rsq:
+      if (lowering(DRSQ_TO_DRCP) &&
+          ir->type->is_double())
+         drsq_to_drcp(ir);
+      else if (lowering(SQRT_TO_ABS_SQRT))
+         sqrt_to_abs_sqrt(ir);
+      break;
+
    case ir_unop_sqrt:
       if (lowering(SQRT_TO_ABS_SQRT))
          sqrt_to_abs_sqrt(ir);
-- 
2.9.5



More information about the mesa-dev mailing list