Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 18, 2019

No description provided.

@ghost ghost requested a review from powerjg February 18, 2019 23:00
Copy link
Contributor

@powerjg powerjg left a 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 :).

@@ -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())
Copy link
Contributor

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.

@@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto style.

@@ -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())
Copy link
Contributor

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 {
Copy link
Contributor

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/components/global-predictor.scala Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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.

// Connect the branchAdd unit
//immGen.io.instruction := io.imem.instruction
branchAdd.io.inputx := pc
when (io.imem.instruction(6,0) === "b1100011".U) {
Copy link
Contributor

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?

@@ -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


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newlines?

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete if unneeded!

@@ -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) {
Copy link
Contributor

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???

@powerjg
Copy link
Contributor

powerjg commented Feb 21, 2019

Just thought of something else here: Let's make this be another file: pipelined-opt/cpu.scala and the name of the new CPU design be PipelinedOptCPU (for optimized).

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.

Copy link
Contributor

@powerjg powerjg left a 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this IO.

Copy link
Author

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this wire?

Copy link
Author

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)))
Copy link
Contributor

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

val wbcontrol = new WBControl
val rs1 = UInt(5.W) //pipelined only
val rs2 = UInt(5.W) //pipelined only
val prediction = Bool()
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a whitespace change.

} .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))
Copy link
Contributor

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.

Copy link
Author

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.

// 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this counter?

Copy link
Author

@ghost ghost Feb 25, 2019

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant