[Mesa-dev] [RFC 01/10] nir/lower_double_ops: lower abs()
Elie Tournier
tournier.elie at gmail.com
Wed Apr 12 22:43:10 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 | 20 ++++++++++++++++++++
src/intel/compiler/brw_nir.c | 3 ++-
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ce5b434d56..0ec09f54e2 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2568,7 +2568,8 @@ typedef enum {
nir_lower_dceil = (1 << 5),
nir_lower_dfract = (1 << 6),
nir_lower_dround_even = (1 << 7),
- nir_lower_dmod = (1 << 8)
+ nir_lower_dmod = (1 << 8),
+ nir_lower_dabs = (1 << 9)
} 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 b3543bc696..4ea8d339cc 100644
--- a/src/compiler/nir/nir_lower_double_ops.c
+++ b/src/compiler/nir/nir_lower_double_ops.c
@@ -456,6 +456,16 @@ lower_mod(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1)
nir_imm_double(b, 0.0));
}
+static nir_ssa_def *
+lower_fabs64(nir_builder *b, nir_ssa_def *src)
+{
+ nir_ssa_def *src_lo = nir_unpack_64_2x32_split_x(b, src);
+ nir_ssa_def *src_hi = nir_unpack_64_2x32_split_y(b, src);
+ /* Clear the sign bit */
+ nir_ssa_def *new_src_hi = nir_iand(b, src_hi, nir_imm_int(b, 0x7FFFFFFF));
+ return nir_pack_64_2x32_split(b, src_lo, new_src_hi);
+}
+
static bool
lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
{
@@ -509,6 +519,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
return false;
break;
+ case nir_op_fabs:
+ if (!(options & nir_lower_dabs))
+ return false;
+ break;
+
default:
return false;
}
@@ -554,6 +569,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
result = lower_mod(&bld, src, src1);
}
break;
+
+ case nir_op_fabs:
+ result = lower_fabs64(&bld, src);
+ break;
+
default:
unreachable("unhandled opcode");
}
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index 36ccdf3cb1..8e41a6eaea 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -509,7 +509,8 @@ nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
nir_lower_dceil |
nir_lower_dfract |
nir_lower_dround_even |
- nir_lower_dmod);
+ nir_lower_dmod |
+ nir_lower_dabs);
OPT(nir_lower_64bit_pack);
} while (progress);
--
2.11.0
More information about the mesa-dev
mailing list