diff options
author | Iago Toral Quiroga <[email protected]> | 2016-01-04 16:10:11 +0100 |
---|---|---|
committer | Samuel Iglesias Gonsálvez <[email protected]> | 2016-04-28 12:01:36 +0200 |
commit | 126a1ac03f7c7d7cd01629c91725ffced06147a9 (patch) | |
tree | b5dacc0439d1f5bc3320aad993116ae0d8e5f1ad | |
parent | 29541ec53175120f916a0ab74e5d82308aa9ef47 (diff) |
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 <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
-rw-r--r-- | src/compiler/nir/nir.h | 1 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_double_ops.c | 23 |
2 files changed, 24 insertions, 0 deletions
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"); } |