[Mesa-dev] [RFC 04/10] nir/lower_double_ops: lower eq()
Elie Tournier
tournier.elie at gmail.com
Wed Apr 12 22:43:13 UTC 2017
Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
src/compiler/nir/nir.h | 3 ++-
src/compiler/nir/nir_lower_double_ops.c | 43 +++++++++++++++++++++++++++++++++
src/intel/compiler/brw_nir.c | 3 ++-
3 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 10dd6b1056..7b1a4655ca 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2571,7 +2571,8 @@ typedef enum {
nir_lower_dmod = (1 << 8),
nir_lower_dabs = (1 << 9),
nir_lower_dneg = (1 << 10),
- nir_lower_dsign = (1 << 11)
+ nir_lower_dsign = (1 << 11),
+ nir_lower_deq = (1 << 12)
} nir_lower_doubles_options;
bool 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 5c0d62b554..d3e05bf519 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -526,6 +526,37 @@ lower_fsign64(nir_builder *b, nir_ssa_def *src)
nir_ior(b, sign, one)));
}
+static nir_ssa_def *
+lower_feq64(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
+{
+ nir_ssa_def *x_lo = nir_unpack_64_2x32_split_x(b, x);
+ nir_ssa_def *x_hi = nir_unpack_64_2x32_split_y(b, x);
+ nir_ssa_def *y_lo = nir_unpack_64_2x32_split_x(b, y);
+ nir_ssa_def *y_hi = nir_unpack_64_2x32_split_y(b, y);
+
+ nir_ssa_def *eq_lo = nir_ieq(b, x_lo, y_lo);
+ nir_ssa_def *eq_hi = nir_ieq(b, x_hi, y_hi);
+ nir_ssa_def *eq_x_lo = nir_ieq(b, x_lo, nir_imm_int(b, 0));
+ nir_ssa_def *eq_xy_hi = nir_ieq(b,
+ nir_ishl(b,
+ nir_ior(b, x_hi, y_hi),
+ nir_imm_int(b, 1)),
+ nir_imm_int(b, 0));
+ /* if x or y is a nan
+ * return false;
+ * else
+ * return (x_lo == y_lo) &&
+ * ((x_hi == y_hi) ||
+ * ((x_lo == 0) && (((x_hi | y_hi)<<1) == 0)));
+ */
+ return nir_bcsel(b, nir_ior(b, is_nan(b, x), is_nan(b, y)),
+ nir_imm_int(b, NIR_FALSE),
+ nir_iand(b, eq_lo,
+ nir_ior(b,
+ eq_hi,
+ nir_iand(b, eq_x_lo, eq_xy_hi))));
+}
+
static bool
lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
{
@@ -594,6 +625,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
return false;
break;
+ case nir_op_feq:
+ if (!(options & nir_lower_deq))
+ return false;
+ break;
+
default:
return false;
}
@@ -652,6 +688,13 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
result = lower_fsign64(&bld, src);
break;
+ case nir_op_feq: {
+ nir_ssa_def *src1 = nir_fmov_alu(&bld, instr->src[1],
+ instr->dest.dest.ssa.num_components);
+ result = lower_feq64(&bld, src, src1);
+ }
+ break;
+
default:
unreachable("unhandled opcode");
}
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index 405d756e6c..7b8b34b4ba 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -512,7 +512,8 @@ nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
nir_lower_dmod |
nir_lower_dabs |
nir_lower_dneg |
- nir_lower_dsign);
+ nir_lower_dsign |
+ nir_lower_deq);
OPT(nir_lower_64bit_pack);
} while (progress);
--
2.11.0
More information about the mesa-dev
mailing list