agx: Fix packing of imsub instructions
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 28 Apr 2023 18:49:25 +0000 (14:49 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Thu, 11 May 2023 13:23:23 +0000 (09:23 -0400)
The negate for imad is on the third source (a * b - c), not the second source.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22695>

src/asahi/compiler/agx_pack.c

index 30d15ca..07a2a84 100644 (file)
@@ -395,7 +395,8 @@ agx_pack_alu(struct util_dynarray *emission, agx_instr *I)
 
          unsigned sxt = (extends && !zext) ? (1 << 10) : 0;
 
-         assert(!I->src[s].neg || s == 1);
+         unsigned negate_src = (I->op == AGX_OPCODE_IMAD) ? 2 : 1;
+         assert(!I->src[s].neg || s == negate_src);
          src_short |= sxt;
       }
 
@@ -408,7 +409,8 @@ agx_pack_alu(struct util_dynarray *emission, agx_instr *I)
       extend |= (src_extend << extend_offset);
    }
 
-   if ((I->op == AGX_OPCODE_IMAD || I->op == AGX_OPCODE_IADD) && I->src[1].neg)
+   if ((I->op == AGX_OPCODE_IMAD && I->src[2].neg) ||
+       (I->op == AGX_OPCODE_IADD && I->src[1].neg))
       raw |= (1 << 27);
 
    if (info.immediates & AGX_IMMEDIATE_TRUTH_TABLE) {