有一些关于分支预测的问题我无法自信地弄清楚。假设我必须使用静态分支预测器。
- 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?
即使建议了一些包含数据路径的适当引用,这也会非常有帮助。提前致谢。
最佳答案
我想可能有很多不同的机制,但有一些快速的答案:
- 分支预测当然需要在指令解码之前,在获取阶段发生。否则,您将解码不正确的指令。
- 你通常会用预测的分支指令给出额外的信息,比如预测的目标。分支将被执行,如果实际目标与预测目标不匹配,则需要冲洗管道。
- 这实际上取决于实现。如果分支被执行,你可以使用真正的目标,就像一个没有被预测到的分支。
- 你当然需要一种机制来恢复,或者等待分支解决,直到你写出结果。这会浪费一些时间,但不会像未预测到的分支那么多。
关于architecture - 了解分支预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36484034/