@@ -1928,6 +1928,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
19281928
19291929 void cvtVOP3Interp (MCInst &Inst, const OperandVector &Operands);
19301930 void cvtVINTERP (MCInst &Inst, const OperandVector &Operands);
1931+ void cvtOpSelHelper (MCInst &Inst, unsigned OpSel);
19311932
19321933 bool parseDimId (unsigned &Encoding);
19331934 ParseStatus parseDim (OperandVector &Operands);
@@ -9177,6 +9178,32 @@ static bool isRegOrImmWithInputMods(const MCInstrDesc &Desc, unsigned OpNum) {
91779178 MCOI::OperandConstraint::TIED_TO) == -1 ;
91789179}
91799180
9181+ void AMDGPUAsmParser::cvtOpSelHelper (MCInst &Inst, unsigned OpSel) {
9182+ unsigned Opc = Inst.getOpcode ();
9183+ const AMDGPU::OpName Ops[] = {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
9184+ AMDGPU::OpName::src2};
9185+ const AMDGPU::OpName ModOps[] = {AMDGPU::OpName::src0_modifiers,
9186+ AMDGPU::OpName::src1_modifiers,
9187+ AMDGPU::OpName::src2_modifiers};
9188+ // Some v_interp instructions in GFX9 have src0, src2, but no src1.
9189+ for (int J = 0 ; J < 3 ; ++J) {
9190+ int OpIdx = AMDGPU::getNamedOperandIdx (Opc, Ops[J]);
9191+ if (OpIdx == -1 )
9192+ continue ;
9193+
9194+ int ModIdx = AMDGPU::getNamedOperandIdx (Opc, ModOps[J]);
9195+ uint32_t ModVal = Inst.getOperand (ModIdx).getImm ();
9196+
9197+ if ((OpSel & (1 << J)) != 0 )
9198+ ModVal |= SISrcMods::OP_SEL_0;
9199+ // op_sel[3] is encoded in src0_modifiers.
9200+ if (ModOps[J] == AMDGPU::OpName::src0_modifiers && (OpSel & (1 << 3 )) != 0 )
9201+ ModVal |= SISrcMods::DST_OP_SEL;
9202+
9203+ Inst.getOperand (ModIdx).setImm (ModVal);
9204+ }
9205+ }
9206+
91809207void AMDGPUAsmParser::cvtVOP3Interp (MCInst &Inst, const OperandVector &Operands)
91819208{
91829209 OptionalImmIndexMap OptionalIdx;
@@ -9214,36 +9241,14 @@ void AMDGPUAsmParser::cvtVOP3Interp(MCInst &Inst, const OperandVector &Operands)
92149241 addOptionalImmOperand (Inst, Operands, OptionalIdx,
92159242 AMDGPUOperand::ImmTyOModSI);
92169243
9217- // Some v_interp instrutions use op_sel[3] for dst.
9244+ // Some v_interp instructions use op_sel[3] for dst.
92189245 if (AMDGPU::hasNamedOperand (Opc, AMDGPU::OpName::op_sel)) {
92199246 addOptionalImmOperand (Inst, Operands, OptionalIdx,
92209247 AMDGPUOperand::ImmTyOpSel);
92219248 int OpSelIdx = AMDGPU::getNamedOperandIdx (Opc, AMDGPU::OpName::op_sel);
92229249 unsigned OpSel = Inst.getOperand (OpSelIdx).getImm ();
92239250
9224- const AMDGPU::OpName Ops[] = {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
9225- AMDGPU::OpName::src2};
9226- const AMDGPU::OpName ModOps[] = {AMDGPU::OpName::src0_modifiers,
9227- AMDGPU::OpName::src1_modifiers,
9228- AMDGPU::OpName::src2_modifiers};
9229- // Some v_interp instructions in GFX9 have src0, src2, but no src1.
9230- for (int J = 0 ; J < 3 ; ++J) {
9231- int OpIdx = AMDGPU::getNamedOperandIdx (Opc, Ops[J]);
9232- if (OpIdx == -1 )
9233- continue ;
9234-
9235- int ModIdx = AMDGPU::getNamedOperandIdx (Opc, ModOps[J]);
9236- uint32_t ModVal = Inst.getOperand (ModIdx).getImm ();
9237-
9238- if ((OpSel & (1 << J)) != 0 )
9239- ModVal |= SISrcMods::OP_SEL_0;
9240- // op_sel[3] is encoded in src0_modifiers.
9241- if (ModOps[J] == AMDGPU::OpName::src0_modifiers &&
9242- (OpSel & (1 << 3 )) != 0 )
9243- ModVal |= SISrcMods::DST_OP_SEL;
9244-
9245- Inst.getOperand (ModIdx).setImm (ModVal);
9246- }
9251+ cvtOpSelHelper (Inst, OpSel);
92479252 }
92489253}
92499254
@@ -9280,31 +9285,10 @@ void AMDGPUAsmParser::cvtVINTERP(MCInst &Inst, const OperandVector &Operands)
92809285 if (OpSelIdx == -1 )
92819286 return ;
92829287
9283- const AMDGPU::OpName Ops[] = {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
9284- AMDGPU::OpName::src2};
9285- const AMDGPU::OpName ModOps[] = {AMDGPU::OpName::src0_modifiers,
9286- AMDGPU::OpName::src1_modifiers,
9287- AMDGPU::OpName::src2_modifiers};
9288-
92899288 unsigned OpSel = Inst.getOperand (OpSelIdx).getImm ();
9290-
9291- for (int J = 0 ; J < 3 ; ++J) {
9292- int OpIdx = AMDGPU::getNamedOperandIdx (Opc, Ops[J]);
9293- if (OpIdx == -1 )
9294- break ;
9295-
9296- int ModIdx = AMDGPU::getNamedOperandIdx (Opc, ModOps[J]);
9297- uint32_t ModVal = Inst.getOperand (ModIdx).getImm ();
9298-
9299- if ((OpSel & (1 << J)) != 0 )
9300- ModVal |= SISrcMods::OP_SEL_0;
9301- if (ModOps[J] == AMDGPU::OpName::src0_modifiers &&
9302- (OpSel & (1 << 3 )) != 0 )
9303- ModVal |= SISrcMods::DST_OP_SEL;
9304-
9305- Inst.getOperand (ModIdx).setImm (ModVal);
9306- }
9289+ cvtOpSelHelper (Inst, OpSel);
93079290}
9291+
93089292void AMDGPUAsmParser::cvtScaledMFMA (MCInst &Inst,
93099293 const OperandVector &Operands) {
93109294 OptionalImmIndexMap OptionalIdx;
0 commit comments