From: Iago Toral Quiroga Date: Mon, 4 Jan 2016 15:10:11 +0000 (+0100) Subject: nir/lower_double_ops: lower ceil() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=126a1ac03f7c7d7cd01629c91725ffced06147a9;p=mesa.git nir/lower_double_ops: lower ceil() At least i965 hardware does not have native support for ceil on doubles. v2 (Sam): - Improve the lowering pass to remove one bcsel (Jason). Signed-off-by: Samuel Iglesias Gonsálvez Reviewed-by: Jason Ekstrand --- diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 809e83b7d12..252567ceae5 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2419,6 +2419,7 @@ typedef enum { nir_lower_drsq = (1 << 2), nir_lower_dtrunc = (1 << 3), nir_lower_dfloor = (1 << 4), + nir_lower_dceil = (1 << 5), } nir_lower_doubles_options; void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options); diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c index 1370ddf9266..2d94f78ec4e 100644 --- a/src/compiler/nir/nir_lower_double_ops.c +++ b/src/compiler/nir/nir_lower_double_ops.c @@ -368,6 +368,21 @@ lower_floor(nir_builder *b, nir_ssa_def *src) nir_fsub(b, tr, nir_imm_double(b, 1.0))); } +static nir_ssa_def * +lower_ceil(nir_builder *b, nir_ssa_def *src) +{ + /* if x < 0, ceil(x) = trunc(x) + * else if (x - trunc(x) == 0), ceil(x) = x + * else, ceil(x) = trunc(x) + 1 + */ + nir_ssa_def *tr = nir_ftrunc(b, src); + nir_ssa_def *negative = nir_flt(b, src, nir_imm_double(b, 0.0)); + return nir_bcsel(b, + nir_ior(b, negative, nir_feq(b, src, tr)), + tr, + nir_fadd(b, tr, nir_imm_double(b, 1.0))); +} + static void lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options) { @@ -401,6 +416,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options) return; break; + case nir_op_fceil: + if (!(options & nir_lower_dceil)) + return; + break; + default: return; } @@ -430,6 +450,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options) case nir_op_ffloor: result = lower_floor(&bld, src); break; + case nir_op_fceil: + result = lower_ceil(&bld, src); + break; default: unreachable("unhandled opcode"); }