60a61
> loopSetMask((1 << (logSizeLoopPred - logLoopTableAssoc)) - 1),
62c63,66
< withLoopBits(params->withLoopBits)
---
> withLoopBits(params->withLoopBits),
> useDirectionBit(params->useDirectionBit),
> useSpeculation(params->useSpeculation),
> useHashing(params->useHashing)
85c89,95
< return (((pc_in >> instShiftAmt) & mask) << logLoopTableAssoc);
---
> Addr pc = pc_in >> instShiftAmt;
> if (useHashing) {
> // copied from TAGE-SC-L
> // (http://www.jilp.org/cbp2016/code/AndreSeznecLimited.tar.gz)
> pc ^= (pc_in >> (instShiftAmt + logLoopTableAssoc));
> }
> return ((pc & mask) << logLoopTableAssoc);
87a98,107
> int
> LTAGE::finallindex(int index, int lowPcBits, int way) const
> {
> // copied from TAGE-SC-L
> // (http://www.jilp.org/cbp2016/code/AndreSeznecLimited.tar.gz)
> return (useHashing ? (index ^ ((lowPcBits >> way) << logLoopTableAssoc)) :
> (index))
> + way;
> }
>
90c110
< LTAGE::getLoop(Addr pc, LTageBranchInfo* bi) const
---
> LTAGE::getLoop(Addr pc, LTageBranchInfo* bi, bool speculative) const
97a118,122
> if (useHashing) {
> bi->loopTag ^= ((pc >> (pcShift + logSizeLoopPred)) & loopTagMask);
> bi->loopLowPcBits = (pc >> pcShift) & loopSetMask;
> }
>
99c124,125
< if (ltable[bi->loopIndex + i].tag == bi->loopTag) {
---
> int idx = finallindex(bi->loopIndex, bi->loopLowPcBits, i);
> if (ltable[idx].tag == bi->loopTag) {
102,108c128,136
< ltable[bi->loopIndex + i].confidence == confidenceThreshold;
< bi->currentIter = ltable[bi->loopIndex + i].currentIterSpec;
< if (ltable[bi->loopIndex + i].currentIterSpec + 1 ==
< ltable[bi->loopIndex + i].numIter) {
< return !(ltable[bi->loopIndex + i].dir);
< }else {
< return (ltable[bi->loopIndex + i].dir);
---
> ltable[idx].confidence == confidenceThreshold;
>
> uint16_t iter = speculative ? ltable[idx].currentIterSpec
> : ltable[idx].currentIter;
>
> if ((iter + 1) == ltable[idx].numIter) {
> return useDirectionBit ? !(ltable[idx].dir) : false;
> } else {
> return useDirectionBit ? (ltable[idx].dir) : true;
116c144
< LTAGE::specLoopUpdate(Addr pc, bool taken, LTageBranchInfo* bi)
---
> LTAGE::specLoopUpdate(bool taken, LTageBranchInfo* bi)
119c147
< int index = lindex(pc);
---
> int index = finallindex(bi->loopIndex, bi->loopLowPcBits, bi->loopHit);
132c160
< int idx = bi->loopIndex + bi->loopHit;
---
> int idx = finallindex(bi->loopIndex, bi->loopLowPcBits, bi->loopHit);
161c189
< if (taken != ltable[idx].dir) {
---
> if (taken != (useDirectionBit ? ltable[idx].dir : true)) {
170c198
< ltable[idx].dir = taken;
---
> ltable[idx].dir = taken; // ignored if no useDirectionBit
192c220,222
< } else if (taken) {
---
> } else if (useDirectionBit ?
> ((bi->loopPredValid ? bi->loopPred : bi->tagePred) != taken) :
> taken) {
201c231
< ltable[idx].dir = !taken;
---
> ltable[idx].dir = !taken; // ignored if no useDirectionBit
227c257,258
< bi->loopPred = getLoop(branch_pc, bi); // loop prediction
---
> // loop prediction
> bi->loopPred = getLoop(branch_pc, bi, useSpeculation);
236a268,271
>
> if (useSpeculation) {
> specLoopUpdate(pred_taken, bi);
> }
239d273
< specLoopUpdate(branch_pc, pred_taken, bi);
249,250c283,289
< // first update the loop predictor
< loopUpdate(branch_pc, taken, bi);
---
> if (useSpeculation) {
> // recalculate loop prediction without speculation
> // It is ok to overwrite the loop prediction fields in bi
> // as the stats have already been updated with the previous
> // values
> bi->loopPred = getLoop(branch_pc, bi, false);
> }
259a299,300
> loopUpdate(branch_pc, taken, bi);
>
272c313,315
< int idx = bi->loopIndex + bi->loopHit;
---
> int idx = finallindex(bi->loopIndex,
> bi->loopLowPcBits,
> bi->loopHit);
284c327,329
< int idx = bi->loopIndex + bi->loopHit;
---
> int idx = finallindex(bi->loopIndex,
> bi->loopLowPcBits,
> bi->loopHit);