[Mesa-dev] [PATCH 3/3] i965/fs: Optimize sqrt+inv into rsq.

Matt Turner mattst88 at gmail.com
Sat Sep 27 12:12:37 PDT 2014


Transform

   sqrt a, b
   rcp  c, a

into

   sqrt a, b
   rsq  c, b

The improvement here is that we've broken a dependency between these
instructions. Leads to 330 fewer INV instructions and 330 more RSQ.
---
 src/mesa/drivers/dri/i965/brw_fs.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index ffe8ba8..8241f67 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2091,6 +2091,17 @@ fs_visitor::opt_algebraic()
             }
          }
          break;
+      case SHADER_OPCODE_RCP: {
+         fs_inst *prev = (fs_inst *)inst->prev;
+         if (prev->opcode == SHADER_OPCODE_SQRT) {
+            if (inst->src[0].equals(prev->dst)) {
+               inst->opcode = SHADER_OPCODE_RSQ;
+               inst->src[0] = prev->src[0];
+               progress = true;
+            }
+         }
+         break;
+      }
       default:
 	 break;
       }
-- 
1.8.5.5



More information about the mesa-dev mailing list