From: Sagar Ghuge Date: Tue, 16 Apr 2019 06:06:23 +0000 (-0700) Subject: nir: Add lowering for nir_op_irem and nir_op_imod X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87cef718e17bce15f1730beab74e414326992332;p=mesa.git nir: Add lowering for nir_op_irem and nir_op_imod Tested on Gen > 9. v2: 1) Fix lowering 2) Keep a consistent i/u order (Matt Turner) Signed-off-by: Sagar Ghuge Reviewed-by: Matt Turner --- diff --git a/src/compiler/nir/nir_lower_idiv.c b/src/compiler/nir/nir_lower_idiv.c index 4e7e2408ae8..96e9412c80e 100644 --- a/src/compiler/nir/nir_lower_idiv.c +++ b/src/compiler/nir/nir_lower_idiv.c @@ -45,10 +45,14 @@ convert_instr(nir_builder *bld, nir_alu_instr *alu) if ((op != nir_op_idiv) && (op != nir_op_udiv) && - (op != nir_op_umod)) + (op != nir_op_imod) && + (op != nir_op_umod) && + (op != nir_op_irem)) return false; - is_signed = (op == nir_op_idiv); + is_signed = (op == nir_op_idiv || + op == nir_op_imod || + op == nir_op_irem); bld->cursor = nir_before_instr(&alu->instr); @@ -104,6 +108,16 @@ convert_instr(nir_builder *bld, nir_alu_instr *alu) r = nir_ilt(bld, r, nir_imm_int(bld, 0)); b = nir_ineg(bld, q); q = nir_bcsel(bld, r, b, q); + + if (op == nir_op_imod || op == nir_op_irem) { + q = nir_imul(bld, q, denom); + q = nir_isub(bld, numer, q); + if (op == nir_op_imod) { + q = nir_bcsel(bld, nir_ieq(bld, q, nir_imm_int(bld, 0)), + nir_imm_int(bld, 0), + nir_bcsel(bld, r, nir_iadd(bld, q, denom), q)); + } + } } if (op == nir_op_umod) {