RAS Return Stack 四指针工作模式动画
RAS Return Stack 四指针工作模式动画
这篇记录的是一个 return address stack RTL 里的四个核心指针,以及它们在 CALL、RET、COMMIT、FLUSH 下的变化。下面的交互动画按照 RTL 行为建模,可以直接点击按钮观察每个表项和指针位置。
指针含义
spec_wr_ptr:speculative table 的写指针,call 预测时写入新的返回地址。spec_top_ptr:等待 commit 的 speculative entry 头指针,对应 RTL 里的rs_spec_bp。cmt_top_ptr:committed stack 的 top 指针,对应COMM_SP。RET 读取的是cmt_top_ptr - 1。cmt_btm_ptr:committed stack 的 bottom 指针,对应COMM_BP,栈满时前移。
需要注意的是,RET 的输出不一定来自 committed table。RTL 里会用 comm_retstk_ptr 去扫描 speculative entries 的 saved committed pointer tag;如果命中 speculative override,那么 call 还没 commit 时,RET 也能直接从 speculative entry 输出返回地址。
交互动画
操作对应关系
CALL:写 speculative entry,推进spec_wr_ptr,同时 BRI 里的COMM_SP也推进;committed table 本身还没有写。RET:按cmt_top_ptr - 1产生读指针,优先使用 matching speculative override,否则读 committed entry。CALL + RET:建模同一预测窗口里 push 和 pop 同时发生的情况,spec_wr_ptr前进,cmt_top_ptr保持。COMMIT:把spec_top_ptr指向的 entry 搬到 committed table,并推进spec_top_ptr;commit 不推进cmt_top_ptr。FLUSH:按保存的 BRI checkpoint 恢复指针,committed table 不被清空。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Chilh!
评论


