RAS Return Stack 四指针工作模式动画

这篇记录的是一个 return address stack RTL 里的四个核心指针,以及它们在 CALLRETCOMMITFLUSH 下的变化。下面的交互动画按照 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 不被清空。