Skip to content

Commit 7abb500

Browse files
DianaChensys_zuul
authored andcommitted
Add iga::OpSpec::hasImplicitFlagModifier to check if instructions
have implicit flag modifier. In the case the instructions have, we should set the flag registers. Also refactor BinaryEncodingIGA. Change-Id: I23cef5a3ad4f5497a4de2306d91a09cfea3d292e
1 parent 19010e7 commit 7abb500

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

visa/BinaryEncodingIGA.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,35 @@ void BinaryEncodingIGA::SetSWSB(G4_INST *inst, iga::SWSB &sw)
592592
return;
593593
}
594594

595+
void BinaryEncodingIGA::getIGAFlagInfo(
596+
G4_INST* inst, const OpSpec* opSpec, Predication& pred, FlagModifier& condMod, RegRef& flagReg)
597+
{
598+
G4_Predicate* predG4 = inst->getPredicate();
599+
G4_CondMod* condModG4 = inst->getCondMod();
600+
iga::RegRef predFlag;
601+
bool hasPredFlag = false;
602+
603+
if (opSpec->supportsPredication() && predG4 != nullptr)
604+
{
605+
pred = getIGAPredication(predG4);
606+
predFlag = getIGAFlagReg(predG4->getBase());
607+
flagReg = predFlag;
608+
hasPredFlag = true;
609+
}
610+
611+
if ((opSpec->supportsFlagModifier() || opSpec->hasImplicitFlagModifier()) &&
612+
condModG4 != nullptr)
613+
{
614+
condMod = getIGAFlagModifier(condModG4);
615+
// in case for min/max sel instruction, it could have CondMod but has no flag registers
616+
if (condModG4->getBase() != nullptr) {
617+
flagReg = getIGAFlagReg(condModG4->getBase());
618+
// pred and condMod Flags must be the same
619+
assert(!hasPredFlag || predFlag == flagReg);
620+
}
621+
}
622+
}
623+
595624
void BinaryEncodingIGA::DoAll()
596625
{
597626
FixInst();
@@ -675,17 +704,7 @@ void BinaryEncodingIGA::DoAll()
675704
MaskCtrl maskCtrl = getIGAMaskCtrl(inst->opcode() == G4_jmpi ? true : inst->isWriteEnableInst());
676705
FlagModifier condModifier = FlagModifier::NONE;
677706

678-
if (opSpec->supportsPredication())
679-
{
680-
flagReg = getIGAFlagReg(inst);
681-
pred = getIGAPredication(inst->getPredicate());
682-
}
683-
if (opSpec->supportsFlagModifier() ||
684-
(inst->getCondMod() != nullptr && inst->getCondMod()->getMod() != G4_CondModifier::Mod_cond_undef))
685-
{
686-
flagReg = getIGAFlagReg(inst);
687-
condModifier = getIGAFlagModifier(inst);
688-
}
707+
getIGAFlagInfo(inst, opSpec, pred, condModifier, flagReg);
689708

690709
if (opSpec->isBranching())
691710
{

visa/BinaryEncodingIGA.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -392,35 +392,22 @@ class BinaryEncodingIGA
392392
return b;
393393
}
394394

395-
iga::RegRef getIGAFlagReg(G4_INST *inst)
395+
void getIGAFlagInfo(
396+
G4_INST* inst, const iga::OpSpec* opSpec, iga::Predication& pred,
397+
iga::FlagModifier& condMod, iga::RegRef& flagReg);
398+
399+
iga::RegRef getIGAFlagReg(G4_VarBase* g4Base)
396400
{
397401
iga::RegRef reg = iga::REGREF_INVALID;
398-
G4_Predicate* predG4 = inst->getPredicate();
399402
bool flagRegNumValid = true;
400-
if (predG4)
401-
{
402-
reg.regNum =
403-
(uint8_t)predG4->getBase()->ExRegNum(flagRegNumValid);
404-
reg.subRegNum = (uint8_t)predG4->getBase()->asRegVar()->getPhyRegOff();
405-
}
406-
407-
G4_CondMod* condModG4 = inst->getCondMod();
408-
if (condModG4)
409-
{
410-
G4_VarBase* flagReg = condModG4->getBase();
411-
if (flagReg != NULL)
412-
{
413-
reg.regNum = (uint8_t)flagReg->ExRegNum(flagRegNumValid);
414-
reg.subRegNum = (uint8_t)flagReg->asRegVar()->getPhyRegOff();
415-
}
416-
}
403+
reg.regNum = (uint8_t)g4Base->ExRegNum(flagRegNumValid);
417404
ASSERT_USER(flagRegNumValid, "Unable to retrieve flag Reg Num for predicate or conditional modifier.");
405+
reg.subRegNum = (uint8_t)g4Base->asRegVar()->getPhyRegOff();
418406
return reg;
419407
}
420408

421-
iga::FlagModifier getIGAFlagModifier(G4_INST *inst) const
409+
iga::FlagModifier getIGAFlagModifier(G4_CondMod* cMod) const
422410
{
423-
auto cMod = inst->getCondMod();
424411
if (cMod == nullptr)
425412
{
426413
return iga::FlagModifier::NONE;

visa/iga/IGALibrary/Backend/GED/Decoder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,10 @@ FlagRegInfo DecoderBase::decodeFlagRegInfo(bool imm64Src0Overlaps) {
14531453
// GEN12 SWSB overlaps CondModifier and Imm64 values
14541454
GED_DECODE_RAW(GED_COND_MODIFIER, condMod, CondModifier);
14551455
fri.modifier = GEDToIGATranslation::translate(condMod);
1456-
} else if (m_opSpec->isMathSubFunc() && m_opSpec->isMacro()) {
1456+
} else if (m_opSpec->hasImplicitFlagModifier()) {
14571457
// math.inv and math.rsqrtm both implicitly support EO
1458+
// currently math is the only case, and its flagModifier must be EO
1459+
assert(m_opSpec->isMathSubFunc());
14581460
fri.modifier = FlagModifier::EO;
14591461
}
14601462

visa/iga/IGALibrary/Models/OpSpec.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ namespace iga
597597
bool supportsFlagModifier() const {
598598
return hasAttrs(Attr::SUPPORTS_FLAGMODIFIER);
599599
}
600+
bool hasImplicitFlagModifier() const {
601+
// math.invm and math.sqtrm has implicit flag modifier, which
602+
// that flag register must be exisited
603+
return isMathSubFunc() && isMacro();
604+
}
600605
bool supportsSaturation() const {
601606
return hasAttrs(Attr::SUPPORTS_SATURATION);
602607
}

0 commit comments

Comments
 (0)