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 <alyssa@rosenzweig.io>
Reviewed-by: Asahi Lina <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22695>
This commit is contained in:
Alyssa Rosenzweig 2023-04-25 14:37:07 -04:00
parent 3df4ae3334
commit 18e19882fa

View file

@ -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)")