[Nouveau] [PATCH v4] nv50/ir: Handle OP_CVT when folding constant expressions
Tobias Klausmann
tobias.johannes.klausmann at mni.thm.de
Sat Jan 24 10:18:50 PST 2015
Folding for conversions:
F32->(U{16/32}, S{16/32})
(U{16/32}, {S16/32})->F32
U32 -> U16
Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>
---
V2: Split out F64 parts
V3: remove handling of saturate for (U/S)32
V4: handle U32->U16 for OP_TXF
.../drivers/nouveau/codegen/nv50_ir_peephole.cpp | 79 ++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
index 21d20ca..235aed9 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
@@ -997,6 +997,85 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s)
i->op = OP_MOV;
break;
}
+ case OP_CVT: {
+ Storage res;
+ bld.setPosition(i, true); /* make sure bld is init'ed */
+ switch(i->dType) {
+ case TYPE_U16:
+ switch (i->sType) {
+ case TYPE_F32:
+ if (i->saturate)
+ res.data.u16 = util_iround(CLAMP(imm0.reg.data.f32, 0,
+ UINT16_MAX));
+ else
+ res.data.u16 = util_iround(imm0.reg.data.f32);
+ break;
+ case TYPE_U32:
+ if (i->saturate)
+ res.data.u16 = CLAMP(imm0.reg.data.u32, 0, UINT16_MAX);
+ else
+ res.data.u16 = imm0.reg.data.u32;
+ break;
+ default:
+ return;
+ }
+ i->setSrc(0, bld.mkImm(res.data.u16));
+ break;
+ case TYPE_U32:
+ assert(!i->saturate);
+ switch (i->sType) {
+ case TYPE_F32:
+ res.data.u32 = util_iround(imm0.reg.data.f32);
+ break;
+ default:
+ return;
+ }
+ i->setSrc(0, bld.mkImm(res.data.u32));
+ break;
+ case TYPE_S16:
+ switch (i->sType) {
+ case TYPE_F32:
+ if (i->saturate)
+ res.data.s16 = util_iround(CLAMP(imm0.reg.data.f32, INT16_MIN,
+ INT16_MAX));
+ else
+ res.data.s16 = util_iround(imm0.reg.data.f32);
+ break;
+ default:
+ return;
+ }
+ i->setSrc(0, bld.mkImm(res.data.s16));
+ break;
+ case TYPE_S32:
+ assert(!i->saturate);
+ switch (i->sType) {
+ case TYPE_F32:
+ res.data.s32 = util_iround(imm0.reg.data.f32);
+ break;
+ default:
+ return;
+ }
+ i->setSrc(0, bld.mkImm(res.data.s32));
+ break;
+ case TYPE_F32:
+ switch (i->sType) {
+ case TYPE_U16: res.data.f32 = (float) imm0.reg.data.u16; break;
+ case TYPE_U32: res.data.f32 = (float) imm0.reg.data.u32; break;
+ case TYPE_S16: res.data.f32 = (float) imm0.reg.data.s16; break;
+ case TYPE_S32: res.data.f32 = (float) imm0.reg.data.s32; break;
+ default:
+ return;
+ }
+ i->setSrc(0, bld.mkImm(res.data.f32));
+ break;
+ default:
+ return;
+ }
+ i->setType(i->dType); /* Remove i->sType, which we don't need anymore */
+ i->op = OP_MOV;
+ i->src(0).mod = Modifier(0); /* Clear the already applied modifier */
+ break;
+ }
default:
return;
}
--
2.2.2
More information about the Nouveau
mailing list