-
Notifications
You must be signed in to change notification settings - Fork 0
(WIP) Hazard Interface example from Jang et al. '24 #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ngernest
wants to merge
2
commits into
main
Choose a base branch
from
hazard_interfaces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // A simple hazard interface, in the style of Jang et al. (2024). | ||
|
|
||
| // Suppose we have a RISC-V CPU that uses the 5 usual stages | ||
| // (Fetch-Decode-Execute-Memory-Write), and we want to execute | ||
| // instructions `I1, I2`: | ||
| // ``` | ||
| // I1: ld r2, 0(r1) # Load mem[r1] into r2 | ||
| // I2: sub r3, r4, r2 # Set r3 := r4 - r2 | ||
| // ``` | ||
| // `r2` appears in both instructions, so there is a data dependency. | ||
| // In particular, when I1 is at the execute stage and I2 is at the decode stage, | ||
| // I2 must be stalled since `r2` is unavailable (it is still being computed). | ||
| // I2 can only proceed when I1 is at the memory stage and communicates | ||
| // the value of `r2` via a bypass. | ||
|
|
||
| // A *hazard interfaces* generalizes ready-valid interface, by allowing | ||
| // the receiver to send back an extra `resolver` signal on top of the | ||
| // usual `ready` bit. This example encodes it. | ||
|
|
||
| // This is a read-after-write data hazard check: | ||
| // on top of sending back an availability ("ready") bit, | ||
| // the sender indicates whih register it has locked (it is currently writing to), | ||
| // and whether the locked register contains a valid value, | ||
| // so that the sender can stall if there's a conflict (i.e. if the sender | ||
| // needs to use the same register). | ||
|
|
||
| // The transfer only fires when ready(payload, resolver) holds: | ||
| // `DUT.o_available = true && !(DUT.o_lock_valid && DUT.o_locked_reg == src_reg)` | ||
|
|
||
| // In standard valid-ready, the sender would just send back one single `ready` | ||
| // bit, so this example is not expressible. | ||
|
|
||
| // This interface is written from the perspective of the receiver, | ||
| // so the backward signals are output fields. | ||
| struct HazardInterface { | ||
| // Forward signals (sender -> receiver): the "payload" | ||
| in i_valid: u1, | ||
| in i_src_reg: u5, // The register being read by the sender's stage | ||
| in i_payload: u32, | ||
|
|
||
| // Backward signals (receiver -> sender) | ||
| out o_available: u1, // This is the same as the ready bit | ||
| out o_locked_reg: u5, // Which register is currently locked by the receiver | ||
| out o_lock_valid: u1, // Whether the register contains a valid value | ||
| } | ||
|
|
||
| #[idle] | ||
| prot idle<DUT: HazardInterface>() { | ||
| DUT.i_valid := 1'b0; | ||
| DUT.i_src_reg := X; | ||
| DUT.i_payload := X; | ||
| step(); | ||
| } | ||
|
|
||
| // Sends a `payload` from the `src_reg` from the sender to the reciever | ||
| prot send_data<DUT: HazardInterface>(in src_reg: u5, in payload: u32) { | ||
| DUT.i_valid := 1'b1; | ||
| DUT.i_src_reg := src_reg; | ||
| DUT.i_payload := payload; | ||
|
|
||
| // Keep waiting if the receiver is not ready (not availalbe), | ||
| // and if the receiver has locked the same register as `src_reg` | ||
| // (and the register contains a value value) | ||
| // Note: this while-loop is the key difference from ready-valid, | ||
| // in usual ready-valid we'd just have `while (DUT.o_ready == 0) { step(); }` | ||
| // Note: this doesn't work right now b/c our DSL doesn't support `||` or `&&` | ||
| while (DUT.o_available == 1'b0 || (DUT.o_lock_valid == 1'b1 && DUT.o_locked_reg == src_reg)) { | ||
| step(); | ||
| } | ||
|
|
||
| // Data transfer occurs during this cycle | ||
| step(); | ||
|
|
||
| DUT.i_valid := X; | ||
| DUT.i_src_reg := X; | ||
| DUT.i_payload := X; | ||
| step(); | ||
| } | ||
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ngernest :
||and&&is something we should totally add!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh great! I was hoping to use this as an example as a potential agenda item for the meeting later today (whether to add
&&and||)