[Mesa-dev] [PATCH 3/3] nv50/ir: convert slct with boolean result to set
Ilia Mirkin
imirkin at alum.mit.edu
Sat Dec 15 19:08:46 UTC 2018
On Fri, Dec 14, 2018 at 6:12 PM Karol Herbst <kherbst at redhat.com> wrote:
>
> From: Karol Herbst <karolherbst at gmail.com>
>
> helps mainly feral ported games
>
> changes in shader-db:
> total instructions in shared programs : 7565661 -> 7545812 (-0.26%)
> total gprs used in shared programs : 797213 -> 797088 (-0.02%)
> total shared used in shared programs : 639636 -> 639636 (0.00%)
> total local used in shared programs : 24648 -> 24648 (0.00%)
> total bytes used in shared programs : 80806160 -> 80594056 (-0.26%)
>
> local shared gpr inst bytes
> helped 0 0 103 5049 5049
> hurt 0 0 29 0 0
>
> Signed-off-by: Karol Herbst <kherbst at redhat.com>
> ---
> .../nouveau/codegen/nv50_ir_peephole.cpp | 50 +++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
> index 37e9edc49f4..b62dee675ce 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
> @@ -372,6 +372,8 @@ private:
> void expr(Instruction *, ImmediateValue&, ImmediateValue&, ImmediateValue&);
> /* true if i was deleted */
> bool opnd(Instruction *i, ImmediateValue&, int s);
> + /* 3 srcs where 1st and 2nd are immediates */
> + void opnd(Instruction *, ImmediateValue&, ImmediateValue&);
> void opnd3(Instruction *, ImmediateValue&);
>
> void unary(Instruction *, const ImmediateValue&);
> @@ -432,6 +434,10 @@ ConstantFolding::visit(BasicBlock *bb)
> }
> if (i->srcExists(2) && i->src(2).getImmediate(src2))
> opnd3(i, src2);
> + else
> + if (i->srcExists(2) &&
> + i->src(0).getImmediate(src0) && i->src(1).getImmediate(src1))
> + opnd(i, src0, src1);
> }
> return true;
> }
> @@ -935,6 +941,50 @@ ConstantFolding::tryCollapseChainedMULs(Instruction *mul2,
> }
> }
>
> +void
> +ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, ImmediateValue &imm1)
> +{
> + const Storage &a = imm0.reg;
> + const Storage &b = imm1.reg;
> +
> + switch (i->op) {
> + case OP_SLCT: {
> + CmpInstruction *slct = i->asCmp();
> + if (a.data.u32 == 0xffffffff && b.data.u32 == 0x0) {
> + slct->setSrc(0, slct->getSrc(2));
> + slct->setSrc(2, NULL);
> + slct->dType = TYPE_U32;
> + slct->op = OP_SET;
> + }
> + else if (a.data.u32 == 0x3f800000 && b.data.u32 == 0x0) {
> + slct->setSrc(0, slct->getSrc(2));
> + slct->setSrc(2, NULL);
> + slct->dType = TYPE_F32;
> + slct->op = OP_SET;
> + }
> + else if (a.data.u32 == 0x0 && b.data.u32 == 0xffffffff) {
> + slct->swapSources(0, 1);
> + slct->setSrc(0, slct->getSrc(2));
> + slct->setSrc(2, NULL);
> + slct->dType = TYPE_U32;
> + slct->setCondition(inverseCondCode(slct->getCondition()));
> + slct->op = OP_SET;
> + }
> + else if (a.data.u32 == 0x0 && b.data.u32 == 0x3f800000) {
> + slct->swapSources(0, 1);
> + slct->setSrc(0, slct->getSrc(2));
> + slct->setSrc(2, NULL);
> + slct->dType = TYPE_F32;
> + slct->setCondition(inverseCondCode(slct->getCondition()));
> + slct->op = OP_SET;
> + }
You could make the code a little less repetitive by doing something like:
bool swap = false;
if (a.data.u32 == 0x0) {
std::swap(a, b);
swap = true;
}
if (b.data.u32 != 0x0)
break;
if (a.data.f32 == 1.0)
slct->dType = TYPE_F32
else if (a.data.u32 == 0xffffffff)
slct->dType = TYPE_U32;
else
break;
if (swap)
slct->swapSources(0, 1);
slct->setSrc(0, ...);
slct->setSrc(2, NULL);
if (swap)
slct->setCondition(...);
slct->op = OP_SET;
Your call.
> + break;
> + }
> + default:
> + break;
> + }
> +}
> +
> void
> ConstantFolding::opnd3(Instruction *i, ImmediateValue &imm2)
> {
> --
> 2.19.2
>
More information about the mesa-dev
mailing list