From 6320e37d4be16407cd237c2049a46360405599d5 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 26 Sep 2019 10:32:00 -0700 Subject: 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 Reviewed-by: Kristian H. Kristensen Reviewed-by: Eduardo Lima Mitev --- src/compiler/nir/nir_builder.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/compiler/nir/nir_builder.h') 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,11 +658,25 @@ 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) { -- cgit v1.2.3