-
Notifications
You must be signed in to change notification settings - Fork 38
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
added functionality for always taken and dynamic branch prediction #15
Conversation
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.
This is a good first pass, but there's a lot that needs to be improved here before we can give it to the students.
One big thing: Could you print out the dinocpu pipeline diagram and write on it to show your new pipeline so I can understand this code? Without a diagram this is hard to understand. Plus, we have to give them a diagram anyway.
Also, I have you worked on the local history predictor?
It would have been best to split this into multiple commits. 1) Add branch always taken predictor with options to use that or always not taken 2) add global history predictor 3) add local history predictor.
The global history predictor object needs a lot more documentation both so the students can implement it and so I can understand the code.
Sorry if my review is short. I'm super busy working on a grant right now :).
src/main/scala/pipelined/cpu.scala
Outdated
@@ -97,6 +102,7 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
val branchAdd = Module(new Adder()) | |||
val forwarding = Module(new ForwardingUnit()) //pipelined only | |||
val hazard = Module(new HazardUnit()) //pipelined only | |||
val GlobalPred = Module(new GlobalPredictor()) |
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.
follow the style of other variable names. This should be globalPred
with the first letter not capitalized.
src/main/scala/pipelined/cpu.scala
Outdated
@@ -115,19 +121,52 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
// For wb back to other stages | |||
val write_data = Wire(UInt()) | |||
|
|||
val predict_taken = Wire(UInt()) | |||
val branchins = Wire(UInt()) | |||
val PCPlus4 = Wire(UInt()) |
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.
Ditto style.
src/main/scala/pipelined/cpu.scala
Outdated
@@ -115,19 +121,52 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
// For wb back to other stages | |||
val write_data = Wire(UInt()) | |||
|
|||
val predict_taken = Wire(UInt()) | |||
val branchins = Wire(UInt()) |
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.
What is a "branchins"?
import chisel3.util._ | ||
|
||
|
||
class GlobalPredictor(implicit val conf: CPUConfig) extends Module { |
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.
Please include lots of detailed documentation on each of these I/O wires. I can only guess what they mean.
src/main/scala/pipelined/cpu.scala
Outdated
@@ -148,6 +187,33 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
if_id.pcplusfour := 0.U | |||
} | |||
|
|||
// Connect the branchAdd unit | |||
//immGen.io.instruction := io.imem.instruction |
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.
This seems weird to comment out.
src/main/scala/pipelined/cpu.scala
Outdated
// Connect the branchAdd unit | ||
//immGen.io.instruction := io.imem.instruction | ||
branchAdd.io.inputx := pc | ||
when (io.imem.instruction(6,0) === "b1100011".U) { |
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.
Huh? Can you not use the output from the control for this logic?
src/main/scala/pipelined/cpu.scala
Outdated
@@ -171,6 +237,8 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
// Send the instruction to the immediate generator | |||
immGen.io.instruction := if_id.instruction | |||
|
|||
|
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.
extra newlines?
src/main/scala/pipelined/cpu.scala
Outdated
@@ -268,8 +340,8 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
alu.io.operation := aluControl.io.operation | |||
|
|||
// Connect the branchAdd unit | |||
branchAdd.io.inputx := id_ex.pc | |||
branchAdd.io.inputy := id_ex.imm | |||
//branchAdd.io.inputx := id_ex.pc |
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.
delete if unneeded!
src/main/scala/pipelined/cpu.scala
Outdated
@@ -280,17 +352,38 @@ class PipelinedCPU(implicit val conf: CPUConfig) extends Module { | |||
ex_mem.wbcontrol := id_ex.wbcontrol | |||
|
|||
// Calculate whether which PC we should use and set the taken flag (line 92 in single-cycle/cpu.scala) | |||
when (branchCtrl.io.taken || id_ex.excontrol.jump === 2.U) { | |||
ex_mem.nextpc := branchAdd.io.result | |||
when ((id_ex.predict_taken === 0.U && branchCtrl.io.taken && id_ex.instruction(6,0) === "b1100011".U) || id_ex.excontrol.jump === 2.U) { |
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.
Why do you have to use the instruction bits like this. Can't you use the control information???
Just thought of something else here: Let's make this be another file: The main difference for the optimized CPU will be that (most of) the branch resolution will be done in the decode stage instead of memory. |
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.
Filipe, please update the comments before our meeting tomorrow as specified below.
I'm disappointed in the code created here. I'm going to have to re-do all of this to make it understandable and usable by the students. It would be most helpful if you could update the code with some comments so I can understand what's going on.
//n: history bits | ||
|
||
class BranchPredictor(l:Int, m:Int, n:Int, typepredictor:String) extends Module { | ||
val io = IO(new Bundle { |
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.
Please document this IO.
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.
Will do.
|
||
val regs = Reg(Vec(1<<(m+n), UInt(l.W))) | ||
val history = Reg(UInt(n.W)) | ||
val branch_address = Wire(UInt((m+n).W)) |
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.
What is this wire?
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.
Will add comments explaining.
val prediction = Output(UInt(1.W)) | ||
}) | ||
|
||
val regs = Reg(Vec(1<<(m+n), UInt(l.W))) |
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.
Please make comments on what each of the variables are used for. What
src/main/scala/pipelined/cpu.scala
Outdated
val wbcontrol = new WBControl | ||
val rs1 = UInt(5.W) //pipelined only | ||
val rs2 = UInt(5.W) //pipelined only | ||
val prediction = Bool() |
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.
Why did this change so much? Was it just a whitespace change (which should not be in the diff) or am I missing something?
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.
Its a whitespace change.
src/main/scala/pipelined/cpu.scala
Outdated
} .elsewhen (id_ex.excontrol.jump === 3.U) { | ||
ex_mem.nextpc := alu.io.result & Cat(Fill(31, 1.U), 0.U) | ||
ex_mem.taken := true.B | ||
val branchPredictorControl = Wire(UInt(2.W)) |
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.
Wow! What is going on here??
If this logic really is this complicated, then it shouldn't be in the CPU, it should be in its own module. However, I don't understand at all what this logic is doing.
Please add significant documentation to explain what is going on here.
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.
I will add comments explaining.
src/main/scala/pipelined/cpu.scala
Outdated
// From memory back to fetch. Since we don't decide whether to take a branch or not until the memory stage. | ||
val next_pc = Wire(UInt()) | ||
|
||
// For wb back to other stages | ||
val write_data = Wire(UInt()) | ||
val write_data = Wire(UInt()) | ||
val counter = Reg(UInt(32.W)) |
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.
What is this counter?
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.
the counter is a reg i kept to count the number of branch mispredictions.
Signed-off-by: Jason Lowe-Power <[email protected]>
Signed-off-by: Jason Lowe-Power <[email protected]>
Signed-off-by: Jason Lowe-Power <[email protected]>
Signed-off-by: Jason Lowe-Power <[email protected]>
No description provided.