summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_lower_double_ops.c
diff options
context:
space:
mode:
authorIago Toral Quiroga <itoral@igalia.com>2016-01-04 16:10:11 +0100
committerSamuel Iglesias Gonsálvez <siglesias@igalia.com>2016-04-28 12:01:36 +0200
commit126a1ac03f7c7d7cd01629c91725ffced06147a9 (patch)
treeb5dacc0439d1f5bc3320aad993116ae0d8e5f1ad /src/compiler/nir/nir_lower_double_ops.c
parent29541ec53175120f916a0ab74e5d82308aa9ef47 (diff)
downloadexternal_mesa3d-126a1ac03f7c7d7cd01629c91725ffced06147a9.zip
external_mesa3d-126a1ac03f7c7d7cd01629c91725ffced06147a9.tar.gz
external_mesa3d-126a1ac03f7c7d7cd01629c91725ffced06147a9.tar.bz2
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 <siglesias@igalia.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'src/compiler/nir/nir_lower_double_ops.c')
-rw-r--r--src/compiler/nir/nir_lower_double_ops.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c
index 1370ddf..2d94f78 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");
}