Working branching.
This commit is contained in:
parent
23656db068
commit
cfce1b6b54
7 changed files with 31 additions and 23 deletions
|
@ -136,6 +136,9 @@ class CPU extends MultiIOModule {
|
||||||
IF.io.branchAddress := EXBarrier.out.ALUResult
|
IF.io.branchAddress := EXBarrier.out.ALUResult
|
||||||
|
|
||||||
// Stall
|
// Stall
|
||||||
IF.io.stall := IDBarrier.stall || ID.io.stall
|
IF.io.stall := IDBarrier.stall
|
||||||
IFBarrier.stall := IDBarrier.stall
|
IFBarrier.stall := IDBarrier.stall
|
||||||
|
|
||||||
|
// Flush
|
||||||
|
IFBarrier.flush := EXBarrier.flush
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,12 @@ class EXBarrier extends MultiIOModule {
|
||||||
new Bundle {
|
new Bundle {
|
||||||
val in = Input(new EXBarrierIO)
|
val in = Input(new EXBarrierIO)
|
||||||
val out = Output(new EXBarrierIO)
|
val out = Output(new EXBarrierIO)
|
||||||
|
val flush = Output(Bool())
|
||||||
})
|
})
|
||||||
|
|
||||||
val delay = Reg(new EXBarrierIO)
|
val delay = Reg(new EXBarrierIO)
|
||||||
delay := io.in
|
delay := io.in
|
||||||
io.out := delay
|
io.out := delay
|
||||||
|
|
||||||
|
io.flush := io.in.branch
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ class InstructionDecode extends MultiIOModule {
|
||||||
val branchType = Output(UInt(3.W))
|
val branchType = Output(UInt(3.W))
|
||||||
val jump = Output(Bool())
|
val jump = Output(Bool())
|
||||||
val returnAddr = Output(UInt(32.W))
|
val returnAddr = Output(UInt(32.W))
|
||||||
val stall = Output(Bool())
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,25 +87,11 @@ class InstructionDecode extends MultiIOModule {
|
||||||
io.ALUOp := decoder.ALUop
|
io.ALUOp := decoder.ALUop
|
||||||
io.writeAddrOut := decoder.instruction.registerRd
|
io.writeAddrOut := decoder.instruction.registerRd
|
||||||
|
|
||||||
val stallsRemaining = RegInit(UInt(4.W), 0.U)
|
io.jump := decoder.controlSignals.jump
|
||||||
val stallDelay = stallsRemaining > 0.U
|
io.branchType := decoder.branchType
|
||||||
stallsRemaining := Mux(
|
|
||||||
stallDelay,
|
|
||||||
stallsRemaining - 1.U,
|
|
||||||
Mux(
|
|
||||||
decoder.controlSignals.branch,
|
|
||||||
3.U,
|
|
||||||
0.U
|
|
||||||
))
|
|
||||||
|
|
||||||
val stall = stallsRemaining > 1.U || decoder.controlSignals.branch && !stallDelay
|
|
||||||
io.stall := stall
|
|
||||||
|
|
||||||
io.jump := Mux(stallDelay, false.B, decoder.controlSignals.jump)
|
|
||||||
io.branchType := Mux(stallDelay, branchType.DC, decoder.branchType)
|
|
||||||
io.returnAddr := io.pc + 4.U
|
io.returnAddr := io.pc + 4.U
|
||||||
|
|
||||||
io.writeEnableOut := Mux(stallDelay, false.B, decoder.controlSignals.regWrite)
|
io.writeEnableOut := decoder.controlSignals.regWrite
|
||||||
io.memRead := Mux(stallDelay, false.B, decoder.controlSignals.memRead)
|
io.memRead := decoder.controlSignals.memRead
|
||||||
io.memWrite := Mux(stallDelay, false.B, decoder.controlSignals.memWrite)
|
io.memWrite := decoder.controlSignals.memWrite
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ class IFBarrier extends MultiIOModule {
|
||||||
val instructionIn = Input(new Instruction)
|
val instructionIn = Input(new Instruction)
|
||||||
val instructionOut = Output(new Instruction)
|
val instructionOut = Output(new Instruction)
|
||||||
val stall = Input(Bool())
|
val stall = Input(Bool())
|
||||||
|
val flush = Input(Bool())
|
||||||
})
|
})
|
||||||
|
|
||||||
val PC = RegInit(UInt(32.W), 0.U)
|
val PC = RegInit(UInt(32.W), 0.U)
|
||||||
|
@ -19,11 +20,22 @@ class IFBarrier extends MultiIOModule {
|
||||||
|
|
||||||
val instruction = Reg(new Instruction)
|
val instruction = Reg(new Instruction)
|
||||||
val replay = RegInit(Bool(), false.B)
|
val replay = RegInit(Bool(), false.B)
|
||||||
|
val flushRemaining = RegInit(UInt(2.W), 0.U)
|
||||||
|
flushRemaining := Mux(
|
||||||
|
io.flush,
|
||||||
|
2.U,
|
||||||
|
Mux(
|
||||||
|
flushRemaining === 0.U,
|
||||||
|
0.U,
|
||||||
|
flushRemaining - 1.U
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
replay := io.stall
|
replay := io.stall
|
||||||
instruction := io.instructionIn
|
instruction := io.instructionIn
|
||||||
|
|
||||||
io.instructionOut := Mux(
|
io.instructionOut := Mux(
|
||||||
io.stall,
|
io.stall || io.flush || flushRemaining > 0.U,
|
||||||
Instruction.NOP,
|
Instruction.NOP,
|
||||||
Mux(
|
Mux(
|
||||||
replay,
|
replay,
|
||||||
|
|
|
@ -4,4 +4,7 @@ main:
|
||||||
loop:
|
loop:
|
||||||
addi x2, x2, 1
|
addi x2, x2, 1
|
||||||
blt x2, x1, loop
|
blt x2, x1, loop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
done
|
done
|
|
@ -1,6 +1,8 @@
|
||||||
main:
|
main:
|
||||||
jal x1, end
|
jal x1, end
|
||||||
addi x1, x1, 0
|
addi x1, x1, 0
|
||||||
|
nop
|
||||||
|
nop
|
||||||
done
|
done
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
|
@ -19,7 +19,7 @@ import LogParser._
|
||||||
|
|
||||||
object Manifest {
|
object Manifest {
|
||||||
|
|
||||||
val singleTest = "simpleload.s"
|
val singleTest = "branch.s"
|
||||||
|
|
||||||
val nopPadded = false
|
val nopPadded = false
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue