From 8085f983b16d2cd57609373d8a68b68b68b28b27 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 5 Jun 2026 16:40:29 -0400 Subject: [PATCH] jay: follow source order for mad/bfe otherwise s == 0 checks don't do the right thing. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/intel/compiler/jay/jay_assign_accumulators.c | 5 +++-- src/intel/compiler/jay/jay_from_nir.c | 4 ++-- src/intel/compiler/jay/jay_opcodes.py | 2 +- src/intel/compiler/jay/jay_to_binary.c | 4 ---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/intel/compiler/jay/jay_assign_accumulators.c b/src/intel/compiler/jay/jay_assign_accumulators.c index 04f8a0eb214..dff099edc91 100644 --- a/src/intel/compiler/jay/jay_assign_accumulators.c +++ b/src/intel/compiler/jay/jay_assign_accumulators.c @@ -326,11 +326,12 @@ pass(jay_function *func) * it works fine on Lunar Lake so ¯\_(ツ)_/¯ ... gate on !strict. */ if ((I->op == JAY_OPCODE_MAD && I->type == JAY_TYPE_F32) && - (I->src[2].file == ACCUM && I->src[2].reg == 0) && - !(I->src[2].negate || I->src[2].abs) && + (I->src[0].file == ACCUM && I->src[0].reg == 0) && + !(I->src[0].negate || I->src[0].abs) && !(jay_debug & JAY_DBG_STRICT)) { I->op = JAY_OPCODE_MAC; + SWAP(I->src[0], I->src[2]); } /* Sometimes this algorithm turns nontrivial GPR->GPR copies into diff --git a/src/intel/compiler/jay/jay_from_nir.c b/src/intel/compiler/jay/jay_from_nir.c index b6130c83e72..8284078c5f3 100644 --- a/src/intel/compiler/jay/jay_from_nir.c +++ b/src/intel/compiler/jay/jay_from_nir.c @@ -514,14 +514,14 @@ jay_emit_alu(struct nir_to_jay_state *nj, nir_alu_instr *alu) case nir_op_ubfe: case nir_op_ibfe: - jay_BFE(b, type, dst, src[0], src[1], src[2]); + jay_BFE(b, type, dst, src[2], src[1], src[0]); break; case nir_op_bfi: jay_BFI2(b, dst, src[0], src[1], src[2]); break; case nir_op_ffma: - jay_MAD(b, type, dst, src[0], src[1], src[2]); + jay_MAD(b, type, dst, src[2], src[1], src[0]); break; case nir_op_fcsel: diff --git a/src/intel/compiler/jay/jay_opcodes.py b/src/intel/compiler/jay/jay_opcodes.py index 4e4ac7055e6..3dbb78ee33f 100644 --- a/src/intel/compiler/jay/jay_opcodes.py +++ b/src/intel/compiler/jay/jay_opcodes.py @@ -98,7 +98,7 @@ op('fbl', 1, 'u32') op('lzd', 1, 'u32') op('frc', 1, 'f32 f64', Props.NEGATE | Props.CMOD) op('mad', 3, 'u32 s32 u16 s16 f32 f64 f16 bf16', - Props.NEGATE | Props.SAT | Props.CMOD | Props.COMMUTATIVE) + Props.NEGATE | Props.SAT | Props.CMOD) op('mac', 3, 'f32', Props.NEGATE | Props.SAT | Props.CMOD | Props.COMMUTATIVE) op('max', 2, 'u32 s32 u64 s64 u16 s16 f32 f64 f16 bf16', diff --git a/src/intel/compiler/jay/jay_to_binary.c b/src/intel/compiler/jay/jay_to_binary.c index c9cdf1fa81f..7edccf3b70e 100644 --- a/src/intel/compiler/jay/jay_to_binary.c +++ b/src/intel/compiler/jay/jay_to_binary.c @@ -367,10 +367,6 @@ emit(struct jay_codegen *jc, gen->src[i] = to_gen_operand(f, I, i, simd_offs, false); } - if (I->op == JAY_OPCODE_MAD || I->op == JAY_OPCODE_BFE) { - SWAP(gen->src[0], gen->src[2]); - } - switch (I->op) { case JAY_OPCODE_WHILE: { assert(util_dynarray_num_elements(&jc->loop_stack, int) > 0);