There are some queries about branch prediction that I am not able to confidently figure out.Assume that I have to work with a static branch predictor.
- At which stage of the pipeline should branch prediction happen?
- How to know that a prediction has gone wrong? How does the datapath come to know that a misprediction has happened?
- If it comes to know that a misprediction has happened, how does it send the signal to take up the not-taken branch?
- After it has gone wrong, I have to take up that address that was not taken earlier. In the meanwhile, what if some memory-write or register-write has happened? How to prevent it from happening?
It will be very helpful even if some proper references with datapath in them are suggested. Thanks in advance.
I took my time reading the reference manual for the Cortex-A8: http://infocenter.arm.com/help/topic/com.arm.doc.ddi0344k/DDI0344K_cortex_a8_r3p2_trm.pdf
From section 5.1:
Basically this means that static branch prediction always assume branches to be false. This is different compared to PowerPC that have "special instructions" for hinting the processor about taken/not-taken branches (postfix +/-).
From section 1.3.1:
From section 7.6.2:
I interpret this as nothing reaches the execution stage while a branch is being processed. If mispredition occurs, as discovered when executing a branch in Instruction Execute, all instructions in the pipeline are "flushed". They are never executed. That should answer question 2 and 4. Not so sure about how the "marking" is performed.
(For the record I find the PowerPC reference manuals (e500/e600) I´m used to being much easier to understand because of the many instruction timing samples.)
I guess that there are many different mechanisms that are possible, but some quick answers: