英特尔有一个硬件事件计数器,称为:
BR_MISP_RETIRED.ALL_BRANCHES
描述中说:
Mispredicted macro branch instructions retired.
但是退役的指令是那些正确需要的指令:
Modern processors execute much more instructions that the program flow needs. This is called "speculative execution".
Then the instructions that were "proven" as indeed needed by flow are "retired".
https://software.intel.com/en-us/forums/topic/311170
那么一个分支如何才能错误预测指导也被证明是需要的吗?
最佳答案
乱序机器通过同时推测过去的多个分支来工作。当发现分支被错误预测时,CPU 将清除任何不需要的状态并将执行返回到该指令,以便可以采用正确的路径。
因此,虽然许多推测执行的指令(包括分支)被丢弃,但导致错误预测分支的单个指令不会被丢弃。该分支指令在被错误预测后生效并退出。
这个计数器似乎记录了这样的指令。
关于performance - 分支指令如何被错误预测和停用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28258274/