nvc0/ir: Handle OP_POPCNT when folding constant expressions
authorTobias Klausmann <tobias.johannes.klausmann@mni.thm.de>
Tue, 3 Jun 2014 22:35:50 +0000 (00:35 +0200)
committerIlia Mirkin <imirkin@alum.mit.edu>
Fri, 6 Jun 2014 04:05:11 +0000 (00:05 -0400)
Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann@mni.thm.de>
[imirkin: make sure to only fold 1-arg popcnt in opnd]
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp

index a91d698c5b256011051c05e5d978b5e2b92cacca..b89da43136e2c3553d76eb7a4c43c164b4b21500 100644 (file)
@@ -540,6 +540,9 @@ ConstantFolding::expr(Instruction *i,
       }
       break;
    }
+   case OP_POPCNT:
+      res.data.u32 = util_bitcount(a->data.u32 & b->data.u32);
+      break;
    default:
       return;
    }
@@ -957,6 +960,16 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s)
       i->subOp = 0;
       break;
    }
+   case OP_POPCNT: {
+      // Only deal with 1-arg POPCNT here
+      if (i->srcExists(1))
+         break;
+      uint32_t res = util_bitcount(imm0.reg.data.u32);
+      i->setSrc(0, new_ImmediateValue(i->bb->getProgram(), res));
+      i->setSrc(1, NULL);
+      i->op = OP_MOV;
+      break;
+   }
    default:
       return;
    }