summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_builder.h
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2019-09-26 10:32:00 -0700
committerRob Clark <[email protected]>2019-10-18 15:08:54 -0700
commit6320e37d4be16407cd237c2049a46360405599d5 (patch)
tree7ab211ba6ac99da320f6586f19ed068adb11637f /src/compiler/nir/nir_builder.h
parent0568761f8e7b9249ec8cffbd7826c24e38bf16d6 (diff)
nir: add amul instruction
Used for address/offset calculation (ie. array derefs), where we can potentially use less than 32b for the multiply of array idx by element size. For backends that support `imul24`, this gives a lowering pass an easy way to find multiplies that potentially can be converted to `imul24`. Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Kristian H. Kristensen <[email protected]> Reviewed-by: Eduardo Lima Mitev <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_builder.h')
-rw-r--r--src/compiler/nir/nir_builder.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index cad0e133cbf..5714ea08ed2 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -646,7 +646,7 @@ nir_iadd_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
}
static inline nir_ssa_def *
-nir_imul_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
+_nir_mul_imm(nir_builder *build, nir_ssa_def *x, uint64_t y, bool amul)
{
assert(x->bit_size <= 64);
if (x->bit_size < 64)
@@ -658,12 +658,26 @@ nir_imul_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
return x;
} else if (util_is_power_of_two_or_zero64(y)) {
return nir_ishl(build, x, nir_imm_int(build, ffsll(y) - 1));
+ } else if (amul) {
+ return nir_amul(build, x, nir_imm_intN_t(build, y, x->bit_size));
} else {
return nir_imul(build, x, nir_imm_intN_t(build, y, x->bit_size));
}
}
static inline nir_ssa_def *
+nir_imul_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
+{
+ return _nir_mul_imm(build, x, y, false);
+}
+
+static inline nir_ssa_def *
+nir_amul_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
+{
+ return _nir_mul_imm(build, x, y, true);
+}
+
+static inline nir_ssa_def *
nir_fadd_imm(nir_builder *build, nir_ssa_def *x, double y)
{
return nir_fadd(build, x, nir_imm_floatN_t(build, y, x->bit_size));