From 18e19882fa6117d83e146dfc180c2c74ebbb9dfe Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 25 Apr 2023 14:37:07 -0400 Subject: [PATCH] nir: Model AGX-specific multiply-shift-add Models `(a * b) + (c << d)` in general, as implemented in various forms on AGX. This will be fused with backend NIR opt algebraic rules, both for the literal pattern as well as to strength reduce certain multiplications, e.g. replacing a * 5 with `a + (a << 2)` expressed as imadshl_agx(a, 1, a, 2). Signed-off-by: Alyssa Rosenzweig Reviewed-by: Asahi Lina Part-of: --- src/compiler/nir/nir_opcodes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index c3c4ea2..3621ea2 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -1298,6 +1298,14 @@ opcode("extr_agx", 0, tuint32, } """); +# AGX multiply-shift-add. Corresponds to iadd/isub/imad/imsub instructions. +# The shift must be <= 4 (domain restriction). For performance, it should be +# constant. +opcode("imadshl_agx", 0, tint, [0, 0, 0, 0], [tint, tint, tint, tint], False, + "", f"(src0 * src1) + (src2 << src3)") +opcode("imsubshl_agx", 0, tint, [0, 0, 0, 0], [tint, tint, tint, tint], False, + "", f"(src0 * src1) - (src2 << src3)") + # 24b multiply into 32b result (with sign extension) binop("imul24", tint32, _2src_commutative + associative, "(((int32_t)src0 << 8) >> 8) * (((int32_t)src1 << 8) >> 8)") -- 2.7.4