On Mar 26, 2011, at 3:17 PM, reena panda wrote:

> Hi,
> 
> I am using m5 in ALPHA FS mode, with O3 CPU model. I was going through the 
> fetch/decode stage implementation in m5. But I can't understand properly, the 
> way branch misprediction is handled in the decode/fetch stage of pipeline. 
> Please correct me if I am wrong, but the way it is currently implemented in 
> m5 is as follows:-
> 
> Suppose an unconditional branch(PC = x, say) is fetched in the fetch cycle, 
> its branch prediction history is immediately updated as a "taken branch". Now 
> lets say, its actual target is "Y". But suppose the entry corresponding to 
> the branch PC (x) is not found in the BTB, then the next PC and nextNPC are 
> still updated to x+4, x+8 respectively. Since unconditional branches can be 
> resolved in the decode stage, the following check is correctly performed in 
> decodeInsts function (in decode_impl.hh):-
> 
>     if (inst->branchTarget() != inst->readPredPC()) {
>                 ++decodeBranchMispred;
>                 squash(inst, inst->threadNumber);
>     }
> 
> But what is odd is that in squash function, the following information is sent 
> back to fetch stage:-
> 
>     toFetch->decodeInfo[tid].nextPC      = inst->branchTarget();
>     toFetch->decodeInfo[tid].nextNPC     = inst->branchTarget() + 
> sizeof(TheISA::MachInst);
>     toFetch->decodeInfo[tid].branchTaken     = inst->readNextPC() != 
> (inst->readPC() + sizeof(TheISA::MachInst));
> 
> The third statement is odd because it compares nextPC with PC( i.e, x+4 with 
> x+4) yields branch direction as "not-taken", Which is wrong and would update 
> the branch predictors incorrectly. Branch is actually an "unconditional taken 
> branch" in the example. Then, should not the last line be something like 
> this:-
>     toFetch->decodeInfo[tid].branchTaken     =  inst->branchTarget() != 
> (inst->readPC() + sizeof(TheISA::MachInst));     
> 
> Please point if I am missing something here? I can't understand the working 
> correctly. Also, can some one give me pointers on how to infer total branch 
> misprediction statistics from the stats.txt file, the stats seem to be 
> scattered across the different pipeline stages. Are they all disjoint/or is 
> there any degree of overlap between them? 
This might be a bug, but it might be that nextPc gets updated along the way. 
Without diving into the code I don't really know, however have you tried your 
fix? Does it work? Do branch predictions go down when running code after you 
make the fix?

Ali


_______________________________________________
m5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/m5-users

Reply via email to