iT邦幫忙

2026 iThome 鐵人賽

DAY 19
0
Software Development

猴子都寫得出來的 RISC-V OoO CPU系列 第 19 篇

RAR, RAW, WAR, WAW in Out of Order CPU

  • 分享至 

  • xImage
  •  

在實作 OoO CPU 的時候
不免俗的要討論一下這幾個 dependency case
講白話一點是:
「如果我們對同一個 register 讀讀寫寫,哪些是真的要等,哪些是可以亂序執行的呢?」
在這個過程之中,發現了有趣的事情

來看看 agent 的回答

| Relationship | Example |
|---|---|
| RAR | `mul` and `add x5` both read the old `x1` and `x2` |
| RAW | `mul` writes `x3`; `add x4` reads it |
| WAR | `add x5` reads the old `x1`; the later `addi` overwrites `x1` |
| WAW | The first `addi x1` and later instructions both write `x1` |

再來看看下面這個 test case 的實作
RAW WAR WAW and repeated rename

addi x1, x0, 7
addi x2, x0, 3
mul  x3, x1, x2
add  x4, x3, x1
add  x5, x1, x2
addi x1, x0, 5
add  x1, x1, x1
add  x1, x1, x1
add  x6, x1, x4

下面這個是改過的 test case

addi x1, x0, 6
addi x2, x0, 7
mul  x3, x1, x2
add  x4, x3, x0       # RAR with the next instruction on x3
addi x5, x3, 1        # x5 = 43
addi x5, x0, 9        # WAW with previous instruction; x5 = 9
add  x6, x5, x7       # RAW from x5 = 9; reads old x7 = 0; x6 = 9
addi x7, x0, 1        # WAR with previous instruction's x7 read

git link with tag: https://github.com/hsufit/TINY5_OOO/tree/ithome2026_D19


上一篇
Dual Issue Out of Order CPU Instruction Issue
下一篇
Out of Order CPU Rename
系列文
猴子都寫得出來的 RISC-V OoO CPU 共 22 篇
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言