From 8ccba4ea5c46b4e408779b7d2c3d55df8dcef7de Mon Sep 17 00:00:00 2001 From: Danilo Krummrich Date: Tue, 16 Aug 2022 02:03:02 +0200 Subject: [PATCH] nv50/ir: add intermediate conversion for f2{i,u}{8,16} Directly converting from a float to an 8 bit integer and from a 64 bit float to an integer smaller than 32 bit is not supported, therefore add an intermediate conversion to an 32 bit integer. Reviewed-by: Karol Herbst Signed-off-by: Danilo Krummrich Part-of: --- src/nouveau/codegen/nv50_ir_lowering_helper.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/nouveau/codegen/nv50_ir_lowering_helper.cpp b/src/nouveau/codegen/nv50_ir_lowering_helper.cpp index ed5a804..58c288e 100644 --- a/src/nouveau/codegen/nv50_ir_lowering_helper.cpp +++ b/src/nouveau/codegen/nv50_ir_lowering_helper.cpp @@ -85,8 +85,23 @@ LoweringHelper::handleCVT(Instruction *insn) DataType dTy = insn->dType; DataType sTy = insn->sType; - if (typeSizeof(dTy) <= 4 && typeSizeof(sTy) <= 4) + bld.setPosition(insn, true); + + /* We can't convert from 32bit floating point to 8bit integer and from 64bit + * floating point to any integer smaller than 32bit, hence add an instruction + * to convert to a 32bit integer first. + */ + if (((typeSizeof(dTy) == 1) && isFloatType(sTy)) || + ((typeSizeof(dTy) <= 2) && sTy == TYPE_F64)) { + Value *tmp = insn->getDef(0); + DataType tmpTy = (isSignedIntType(dTy)) ? TYPE_S32 : TYPE_U32; + + insn->setType(tmpTy, sTy); + insn->setDef(0, bld.getSSA()); + bld.mkCvt(OP_CVT, dTy, tmp, tmpTy, insn->getDef(0))->saturate = 1; + return true; + } bld.setPosition(insn, false); -- 2.7.4