From ef8f09be3375231481373a5c49a5cef3db3d2141 Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Mon, 7 Jul 2014 02:32:45 -0400 Subject: [PATCH] nvc0/ir: handle zero and negative sqrt arguments Signed-off-by: Ilia Mirkin --- .../nouveau/codegen/nv50_ir_lowering_nvc0.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp index 8ac3b265893..18e8e67bc87 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp @@ -1567,10 +1567,22 @@ NVC0LoweringPass::handleMOD(Instruction *i) bool NVC0LoweringPass::handleSQRT(Instruction *i) { - Instruction *rsq = bld.mkOp1(OP_RSQ, i->dType, - bld.getSSA(typeSizeof(i->dType)), i->getSrc(0)); + Value *pred = bld.getSSA(1, FILE_PREDICATE); + Value *zero = bld.getSSA(); + Instruction *rsq; + + bld.mkOp1(OP_MOV, TYPE_U32, zero, bld.mkImm(0)); + if (i->dType == TYPE_F64) + zero = bld.mkOp2v(OP_MERGE, TYPE_U64, bld.getSSA(8), zero, zero); + bld.mkCmp(OP_SET, CC_LE, i->dType, pred, i->dType, i->getSrc(0), zero); + bld.mkOp1(OP_MOV, i->dType, i->getDef(0), zero)->setPredicate(CC_P, pred); + rsq = bld.mkOp1(OP_RSQ, i->dType, + bld.getSSA(typeSizeof(i->dType)), i->getSrc(0)); + rsq->setPredicate(CC_NOT_P, pred); i->op = OP_MUL; i->setSrc(1, rsq->getDef(0)); + i->setPredicate(CC_NOT_P, pred); + return true; } -- 2.30.2