Skip to content

Commit 354256e

Browse files
weiyu-chensys_zuul
authored andcommitted
Refactor vISA instruction option setter functions.
Change-Id: I81bde0776f6af561c9a60cb85524aed9725ae2a2
1 parent 5a74e4a commit 354256e

File tree

8 files changed

+56
-70
lines changed

8 files changed

+56
-70
lines changed

visa/BinaryEncodingIGA.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,9 @@ void BinaryEncodingIGA::DoAll()
658658
nullptr, G4_nop, nullptr, false, 1, nullptr, nullptr, nullptr, InstOpt_NoCompact));
659659
}
660660
// set all instruction to be NoCompact
661-
for (auto inst : *first_bb) {
662-
inst->setOptions(inst->getOption() | InstOpt_NoCompact);
661+
for (auto inst : *first_bb)
662+
{
663+
inst->setOptionOn(InstOpt_NoCompact);
663664
}
664665
}
665666

visa/Gen4_IR.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,13 @@ uint16_t G4_INST::getMaskOffset() const
11181118
{
11191119
unsigned maskOption = (this->getOption() & InstOpt_QuarterMasks);
11201120

1121-
switch(maskOption)
1121+
if (!builder.hasNibCtrl())
1122+
{
1123+
assert(maskOption != InstOpt_M4 && maskOption != InstOpt_M12 && maskOption != InstOpt_M20 &&
1124+
maskOption != InstOpt_M28 && "nibCtrl is not supported on this platform");
1125+
}
1126+
1127+
switch (maskOption)
11221128
{
11231129
case InstOpt_NoOpt:
11241130
return 0;
@@ -1139,7 +1145,7 @@ uint16_t G4_INST::getMaskOffset() const
11391145
case InstOpt_M28:
11401146
return 28;
11411147
default:
1142-
MUST_BE_TRUE( 0, "Incorrect instruction execution mask" );
1148+
MUST_BE_TRUE(0, "Incorrect instruction execution mask");
11431149
return 0;
11441150
}
11451151
}

visa/Gen4_IR.hpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -848,46 +848,35 @@ class G4_INST
848848

849849
void computeARFRightBound();
850850

851+
static bool isMaskOption(G4_InstOption opt)
852+
{
853+
return (opt & InstOpt_QuarterMasks) != 0;
854+
}
855+
851856
void setOptions(unsigned int o)
852857
{
853858
unsigned int oldMaskOffset = getMaskOffset();
854859
option = o;
855860
unsigned int newMaskOffset = getMaskOffset();
856861

857-
if( oldMaskOffset != newMaskOffset )
862+
if (oldMaskOffset != newMaskOffset)
858863
{
859864
// Change in mask offset requires change in
860865
// bounds for pred/cond mod/impl acc src/dst
861866
computeARFRightBound();
862867
}
863868
}
864869

865-
void setOptionOn(unsigned int o)
870+
void setOptionOn(G4_InstOption o)
866871
{
867-
unsigned int oldMaskOffset = getMaskOffset();
872+
assert(!isMaskOption(o) && "use setMaskOption() to change emask instead");
868873
option |= o;
869-
unsigned int newMaskOffset = getMaskOffset();
870-
871-
if( oldMaskOffset != newMaskOffset )
872-
{
873-
// Change in mask offset requires change in
874-
// bounds for pred/cond mod/impl acc src/dst
875-
computeARFRightBound();
876-
}
877874
}
878875

879-
void setOptionOff(unsigned int o)
876+
void setOptionOff(G4_InstOption o)
880877
{
881-
unsigned int oldMaskOffset = getMaskOffset();
878+
assert(!isMaskOption(o) && "use setMaskOption() to change emask instead");
882879
option &= (~o);
883-
unsigned int newMaskOffset = getMaskOffset();
884-
885-
if( oldMaskOffset != newMaskOffset )
886-
{
887-
// Change in mask offset requires change in
888-
// bounds for pred/cond mod/impl acc src/dst
889-
computeARFRightBound();
890-
}
891880
}
892881
unsigned int getOption() const {return option;}
893882
unsigned int getMaskOption() const {return option & InstOpt_Masks;}
@@ -899,6 +888,19 @@ class G4_INST
899888
setOptions((option & ~InstOpt_QuarterMasks) | opt);
900889
}
901890

891+
void setNoMask(bool clearEMask)
892+
{
893+
if (clearEMask)
894+
{
895+
// Clear the M0/M4/M8 emask as well
896+
setOptions((getOption() & ~InstOpt_Masks) | InstOpt_WriteEnable);
897+
}
898+
else
899+
{
900+
setOptionOn(InstOpt_WriteEnable);
901+
}
902+
}
903+
902904
bool is1QInst() const { return execSize == 8 && getMaskOffset() == 0; }
903905
bool isWriteEnableInst() const { return (option & InstOpt_WriteEnable) ? true : false; }
904906
bool isYieldInst() const { return (option & InstOpt_Switch) ? true : false; }

visa/HWConformity.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ G4_DstRegRegion* HWConformity::insertMovAfter( INST_LIST_ITER& it, G4_DstRegRegi
207207
inst->setSaturate(false);
208208
}
209209

210-
inst->setExecSize( newExecSize );
210+
inst->setExecSize(newExecSize);
211211
if (newExecSize == 1)
212212
{
213-
inst->setOptions((inst->getOption() & ~InstOpt_Masks ) | InstOpt_WriteEnable);
213+
inst->setNoMask(true);
214214
}
215215

216216
return builder.Create_Dst_Opnd_From_Dcl( dcl, scale);
@@ -945,7 +945,7 @@ bool HWConformity::fixLine(INST_LIST_ITER it, G4_BB *bb)
945945
G4_INST* newInst = builder.createMov(mov_size, new_dst_opnd, src0, InstOpt_NoOpt, false);
946946
if (bb->isInSimdFlow())
947947
{
948-
newInst->setOptions((newInst->getOption() & ~InstOpt_Masks) | InstOpt_WriteEnable);
948+
newInst->setNoMask(true);
949949
}
950950
bb->insert(it, newInst);
951951
inst->setSrc(new_src0_opnd, 0);
@@ -2322,7 +2322,7 @@ bool HWConformity::fixMULInst( INST_LIST_ITER &i, G4_BB *bb )
23222322

23232323
if (bb->isInSimdFlow())
23242324
{
2325-
inst->setOptions((inst->getOption() & ~InstOpt_Masks) | InstOpt_WriteEnable);
2325+
inst->setNoMask(true);
23262326
}
23272327

23282328
if (pred != NULL) {
@@ -2663,7 +2663,7 @@ void HWConformity::fixMULHInst( INST_LIST_ITER &i, G4_BB *bb )
26632663

26642664
if (bb->isInSimdFlow())
26652665
{
2666-
newMul->setOptions( ( inst_opt & ~InstOpt_Masks ) | InstOpt_WriteEnable );
2666+
newMul->setNoMask(true);
26672667
}
26682668
inst->setOpcode( G4_mach );
26692669

visa/Optimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6795,7 +6795,7 @@ bool Optimizer::foldPseudoAndOr(G4_BB* bb, INST_LIST_ITER& ii)
67956795
inst->isSplitSend() &&
67966796
!(inst->getSrc(1)->isNullReg()))
67976797
{
6798-
inst->setOptions(inst->getOption() | InstOpt_NoPreempt);
6798+
inst->setOptionOn(InstOpt_NoPreempt);
67996799
}
68006800

68016801
if (inst->isSend() && !inst->isNoPreemptInst() && builder.needsNoPreemptR2ForSend())
@@ -6806,7 +6806,7 @@ bool Optimizer::foldPseudoAndOr(G4_BB* bb, INST_LIST_ITER& ii)
68066806
unsigned LB = Src0->getLinearizedStart();
68076807
if (LB == 2 * GENX_GRF_REG_SIZ)
68086808
{
6809-
inst->setOptions(inst->getOption() | InstOpt_NoPreempt);
6809+
inst->setOptionOn(InstOpt_NoPreempt);
68106810
}
68116811
}
68126812
}

visa/ReduceExecSize.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ void HWConformity::splitInstruction(INST_LIST_ITER iter, G4_BB* bb, bool compOpt
10481048

10491049
if (isSIMDCFInst)
10501050
{
1051-
firstMov->setOptions((inst->getOption() & ~InstOpt_Masks) | InstOpt_WriteEnable);
1051+
firstMov->setNoMask(true);
10521052
}
10531053
}
10541054

@@ -1634,11 +1634,11 @@ void HWConformity::saveDst( INST_LIST_ITER& it, uint8_t stride, G4_BB *bb )
16341634
unsigned int new_option = inst->getOption();
16351635

16361636
G4_INST* newInst = builder.createMov(execSize, tmpDstOpnd, srcRegion, new_option, false);
1637-
if( bb->isInSimdFlow() )
1637+
if (bb->isInSimdFlow())
16381638
{
1639-
newInst->setOptions( ( inst->getOption() & ~InstOpt_Masks ) | InstOpt_WriteEnable );
1639+
newInst->setNoMask(true);
16401640
}
1641-
bb->insert( it, newInst );
1641+
bb->insert(it, newInst);
16421642
inst->setDest(builder.duplicateOperand( tmpDstOpnd ) );
16431643
}
16441644

@@ -1658,7 +1658,7 @@ void HWConformity::restoreDst( INST_LIST_ITER& it, G4_DstRegRegion *origDst, G4_
16581658
G4_INST* newInst = builder.createMov(execSize, origDst, srcRegion, new_option, false);
16591659
if (bb->isInSimdFlow())
16601660
{
1661-
newInst->setOptions((inst->getOption() & ~InstOpt_Masks) | InstOpt_WriteEnable);
1661+
newInst->setNoMask(true);
16621662
}
16631663
INST_LIST_ITER iter = it;
16641664
iter++;

visa/TranslationInterface.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ int IR_Builder::translateVISASyncInst(ISA_Opcode opcode, unsigned int mask)
19851985
G4_DstRegRegion* dstOpnd = createDst(getBuiltinR0()->getRegVar(), 0, 0, 1, Type_UD);
19861986

19871987
G4_INST* nop = createMov(1, dstOpnd, srcOpnd, InstOpt_NoOpt, true);
1988-
nop->setOptions(nop->getOption() | InstOpt_Switch);
1988+
nop->setOptionOn(InstOpt_Switch);
19891989
}
19901990
}
19911991
break;
@@ -7634,8 +7634,8 @@ int IR_Builder::translateVISAURBWrite3DInst(
76347634
// shl (8) M2.0<1>:ud cmask<8;8,1>:ud 0x10:uw
76357635
auto payloadUDRegRgnRow2 = createDst(payloadUD->getRegVar(), regOff++, 0, 1, Type_UD);
76367636

7637-
G4_INST* channelMaskInst = createInst(nullptr, G4_shl, nullptr, false, 8, payloadUDRegRgnRow2, channelMask, createImm(16, Type_UW), 0);
7638-
channelMaskInst->setOptionOn( instOpt );
7637+
createInst(nullptr, G4_shl, nullptr, false, 8, payloadUDRegRgnRow2, channelMask, createImm(16, Type_UW),
7638+
instOpt);
76397639
}
76407640

76417641
G4_Declare* vertexDataDcl = numOut == 0 ? NULL : vertexData->getBase()->asRegVar()->getDeclare();
@@ -7653,8 +7653,7 @@ int IR_Builder::translateVISAURBWrite3DInst(
76537653

76547654
G4_SrcRegRegion* vertexSrcRegRgnRowi = createSrcRegRegion(Mod_src_undef, Direct, vertexDataDcl->getRegVar(), startSrcRow++, 0, getRegionStride1(), Type_F);
76557655

7656-
G4_INST* vertexDataMovInst = createMov( 8, payloadTypedRegRowRgni, vertexSrcRegRgnRowi, InstOpt_NoOpt, true );
7657-
vertexDataMovInst->setOptionOn( instOpt );
7656+
createMov( 8, payloadTypedRegRowRgni, vertexSrcRegRgnRowi, instOpt, true );
76587657
}
76597658
}
76607659
else
@@ -10795,8 +10794,7 @@ void IR_Builder::Copy_SrcRegRegion_To_Payload( G4_Declare* payload, unsigned int
1079510794

1079610795
G4_SrcRegRegion* srcRgn = createSrcRegRegion( *src );
1079710796
srcRgn->setType( payload->getElemType() );
10798-
G4_INST* refCopy = createMov(exec_size, payloadDstRgn, srcRgn, InstOpt_NoOpt, true );
10799-
refCopy->setOptionOn(emask);
10797+
createMov(exec_size, payloadDstRgn, srcRgn, emask, true );
1080010798
if (G4_Type_Table[payload->getElemType()].byteSize == 2)
1080110799
{
1080210800
// for half float each source occupies 1 GRF regardless of execution size

visa/ifcvt.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,10 @@ namespace {
125125
}
126126

127127
/// getEMaskBits() -
128-
unsigned getEMaskBits(unsigned maskOpt, unsigned execSize) const {
128+
unsigned getEMaskBits(unsigned maskOffset, unsigned execSize) const
129+
{
129130
uint64_t Val = ((uint64_t)1 << execSize) - 1;
130-
switch (maskOpt) {
131-
case InstOpt_NoOpt:
132-
return unsigned(Val);
133-
case InstOpt_M0:
134-
return unsigned(Val << 0);
135-
case InstOpt_M4:
136-
return unsigned(Val << 4);
137-
case InstOpt_M8:
138-
return unsigned(Val<< 8);
139-
case InstOpt_M12:
140-
return unsigned(Val << 12);
141-
case InstOpt_M16:
142-
return unsigned(Val << 16);
143-
case InstOpt_M20:
144-
return unsigned(Val << 20);
145-
case InstOpt_M24:
146-
return unsigned(Val << 24);
147-
case InstOpt_M28:
148-
return unsigned(Val << 28);
149-
}
150-
ASSERT_USER(false, "Invalid mask option!");
151-
return 0;
131+
return (uint32_t) (Val << maskOffset);
152132
}
153133

154134
/// getnnerMostIf - If the given BB is the head of an innermost IF
@@ -317,10 +297,9 @@ namespace {
317297
"Unexpected 'NoMask' in 'if' emask.");
318298

319299
unsigned maskBits =
320-
getEMaskBits(maskOpt & InstOpt_QuarterMasks, I->getExecSize());
300+
getEMaskBits(I->getMaskOffset(), I->getExecSize());
321301
unsigned ifMaskBits =
322-
getEMaskBits(ifMaskOpt & InstOpt_QuarterMasks,
323-
ifInst->getExecSize());
302+
getEMaskBits(ifInst->getMaskOffset(), ifInst->getExecSize());
324303
// Skip if emask bits in 'if' cannot cover the one from the given
325304
// instruction.
326305
if ((~ifMaskBits) & maskBits)

0 commit comments

Comments
 (0)