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

Author: Alyssa Rosenzweig <[email protected]>
Date:   Tue Jan  5 14:06:07 2021 -0500

nir/lower_idiv: Factor out numer/denom load

No need to duplicate across paths.

Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8339>

---

 src/compiler/nir/nir_lower_idiv.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/compiler/nir/nir_lower_idiv.c 
b/src/compiler/nir/nir_lower_idiv.c
index 22aab5ab95b..b30500190ea 100644
--- a/src/compiler/nir/nir_lower_idiv.c
+++ b/src/compiler/nir/nir_lower_idiv.c
@@ -41,19 +41,16 @@
  */
 
 static nir_ssa_def *
-convert_instr(nir_builder *bld, nir_alu_instr *alu)
+convert_instr(nir_builder *bld, nir_op op,
+      nir_ssa_def *numer, nir_ssa_def *denom)
 {
-   nir_ssa_def *numer, *denom, *af, *bf, *a, *b, *q, *r, *rt;
-   nir_op op = alu->op;
+   nir_ssa_def *af, *bf, *a, *b, *q, *r, *rt;
    bool is_signed;
 
    is_signed = (op == nir_op_idiv ||
                 op == nir_op_imod ||
                 op == nir_op_irem);
 
-   numer = nir_ssa_for_alu_src(bld, alu, 0);
-   denom = nir_ssa_for_alu_src(bld, alu, 1);
-
    if (is_signed) {
       af = nir_i2f32(bld, numer);
       bf = nir_i2f32(bld, denom);
@@ -192,12 +189,9 @@ emit_idiv(nir_builder *bld, nir_ssa_def *numer, 
nir_ssa_def *denom, nir_op op)
 }
 
 static nir_ssa_def *
-convert_instr_precise(nir_builder *bld, nir_alu_instr *alu)
+convert_instr_precise(nir_builder *bld, nir_op op,
+      nir_ssa_def *numer, nir_ssa_def *denom)
 {
-   nir_op op = alu->op;
-   nir_ssa_def *numer = nir_ssa_for_alu_src(bld, alu, 0);
-   nir_ssa_def *denom = nir_ssa_for_alu_src(bld, alu, 1);
-
    if (op == nir_op_udiv || op == nir_op_umod)
       return emit_udiv(bld, numer, denom, op == nir_op_umod);
    else
@@ -208,11 +202,15 @@ static nir_ssa_def *
 lower_idiv(nir_builder *b, nir_instr *instr, void *_data)
 {
    enum nir_lower_idiv_path *path = _data;
+   nir_alu_instr *alu = nir_instr_as_alu(instr);
+
+   nir_ssa_def *numer = nir_ssa_for_alu_src(b, alu, 0);
+   nir_ssa_def *denom = nir_ssa_for_alu_src(b, alu, 1);
 
    if (*path == nir_lower_idiv_precise)
-      return convert_instr_precise(b, nir_instr_as_alu(instr));
+      return convert_instr_precise(b, alu->op, numer, denom);
    else
-      return convert_instr(b, nir_instr_as_alu(instr));
+      return convert_instr(b, alu->op, numer, denom);
 }
 
 static bool

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to