Hi, please review the following 4 patches: 1b1cfc6 nvc0/ir: Handle OP_BFIND when folding constant expressions d2d2727 nvc0/ir: Handle OP_POPCNT when folding constant expressions 86a1ee6 nvc0/ir: Handle reverse subop for OP_EXTBF when folding constant expressions 84563bf nvc0/ir: clear subop when folding constant expressions src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) Thanks, Tobias Klausmann
Tobias Klausmann
2014-May-29  19:43 UTC
[Nouveau] [PATCH 1/4] nvc0/ir: clear subop when folding constant expressions
Some operations (e.g. OP_MUL/OP_MAD/OP_EXTBF might have a subop set.
After folding, make sure that it is cleared
Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>
---
 src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp | 1 +
 1 file changed, 1 insertion(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 1a2c2e6..58092f4 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -563,6 +563,7 @@ ConstantFolding::expr(Instruction *i,
    } else {
       i->op = i->saturate ? OP_SAT : OP_MOV; /* SAT handled by unary() */
    }
+   i->subOp = 0;
 }
 
 void
-- 
1.8.4.5
Tobias Klausmann
2014-May-29  19:43 UTC
[Nouveau] [PATCH 2/4] nvc0/ir: Handle reverse subop for OP_EXTBF when folding constant expressions
Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>
---
 src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 58092f4..93f7c2a 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -529,8 +529,18 @@ ConstantFolding::expr(Instruction *i,
          lshift = 32 - width - offset;
       }
       switch (i->dType) {
-      case TYPE_S32: res.data.s32 = (a->data.s32 << lshift) >>
rshift; break;
-      case TYPE_U32: res.data.u32 = (a->data.u32 << lshift) >>
rshift; break;
+      case TYPE_S32: {
+         res.data.s32 = (res.data.s32 << lshift) >> rshift;
+         if (i->subOp == NV50_IR_SUBOP_EXTBF_REV)
+            res.data.s32 = util_bitreverse(res.data.s32);
+         break;
+      }
+      case TYPE_U32: {
+         res.data.u32 = (res.data.u32 << lshift) >> rshift;
+         if (i->subOp == NV50_IR_SUBOP_EXTBF_REV)
+            res.data.u32 = util_bitreverse(res.data.u32);
+         break;
+      }
       default:
          return;
       }
-- 
1.8.4.5
Tobias Klausmann
2014-May-29  19:43 UTC
[Nouveau] [PATCH 3/4] nvc0/ir: Handle OP_POPCNT when folding constant expressions
Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>
---
 src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 93f7c2a..68b9a6d 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -546,6 +546,16 @@ ConstantFolding::expr(Instruction *i,
       }
       break;
    }
+   case OP_POPCNT: {
+      switch (i->dType) {
+      case TYPE_S32:
+      case TYPE_U32:
+         res.data.u32 = util_bitcount(a->data.u32 & b->data.u32);
break;
+      default:
+        return;
+      }
+      break;
+   }
    default:
       return;
    }
-- 
1.8.4.5
Tobias Klausmann
2014-May-29  19:43 UTC
[Nouveau] [PATCH 4/4] nvc0/ir: Handle OP_BFIND when folding constant expressions
Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>
---
 src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 68b9a6d..a56756c 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -556,6 +556,20 @@ ConstantFolding::expr(Instruction *i,
       }
       break;
    }
+   case OP_BFIND: {
+      int shift = 0;
+      if (i->subOp == NV50_IR_SUBOP_BFIND_SAMT)
+         shift = 32 - (b->data.u32 & 0xff);
+      switch (i->dType) {
+      case TYPE_S32:
+         res.data.s32 = util_last_bit_signed(a->data.s32 >> shift)- 1;
break;
+      case TYPE_U32:
+         res.data.u32 = util_last_bit(a->data.u32 >> shift) -1; break;
+      default:
+         return;
+      }
+      break;
+   }
    default:
       return;
    }
-- 
1.8.4.5
Apparently Analagous Threads
- [PATCH v2 1/4] nvc0/ir: clear subop when folding constant expressions
- [PATCH v3 1/4] nvc0/ir: clear subop when folding constant expressions
- [Mesa-dev] [PATCH v3 1/4] nvc0/ir: clear subop when folding constant expressions
- [PATCH v3 0/4] Constant folding of new Instructions
- [Mesa-dev] [PATCH v3 1/4] nvc0/ir: clear subop when folding constant expressions