|
|
|
@@ -1,82 +1,79 @@ |
|
|
|
package FiveStage |
|
|
|
|
|
|
|
import chisel3._ |
|
|
|
import chisel3.util.ShiftRegister |
|
|
|
import chisel3.experimental.MultiIOModule |
|
|
|
|
|
|
|
|
|
|
|
class IFBarrier extends Module { |
|
|
|
class IFBundle extends Bundle { |
|
|
|
val PC = UInt() |
|
|
|
val instruction = new Instruction |
|
|
|
object BarrierReg { |
|
|
|
def apply[T <: Data](in: T)(implicit freeze: Bool): Data = { |
|
|
|
val reg = RegNext(in) |
|
|
|
val old = RegNext(reg) |
|
|
|
|
|
|
|
when (freeze) { |
|
|
|
reg := old |
|
|
|
} |
|
|
|
|
|
|
|
reg |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val io = IO(new Bundle { |
|
|
|
val in = Input(new IFBundle) |
|
|
|
val out = Output(new IFBundle) |
|
|
|
}) |
|
|
|
class Barrier[B <: Bundle](b: B) extends MultiIOModule { |
|
|
|
implicit val freeze = IO(Input(Bool())) |
|
|
|
val in = IO(Input(b)) |
|
|
|
val out = IO(Output(b)) |
|
|
|
|
|
|
|
io.out.instruction := io.in.instruction |
|
|
|
io.out.PC := ShiftRegister(io.in.PC, 1) |
|
|
|
out := BarrierReg(in) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class IDBarrier extends Module { |
|
|
|
class IDBundle extends Bundle { |
|
|
|
val PC = UInt() |
|
|
|
val instruction = new Instruction |
|
|
|
val controlSignals = new ControlSignals |
|
|
|
val branchType = UInt(3.W) |
|
|
|
val reg1 = UInt(32.W) |
|
|
|
val reg2 = UInt(32.W) |
|
|
|
val imm = UInt(32.W) |
|
|
|
val ALUop = UInt(4.W) |
|
|
|
} |
|
|
|
class IFBundle extends Bundle { |
|
|
|
val PC = UInt() |
|
|
|
val instruction = new Instruction |
|
|
|
} |
|
|
|
|
|
|
|
val io = IO(new Bundle { |
|
|
|
val in = Input(new IDBundle) |
|
|
|
val out = Output(new IDBundle) |
|
|
|
}) |
|
|
|
|
|
|
|
io.out := ShiftRegister(io.in, 1) |
|
|
|
class IFBarrier extends Barrier(new IFBundle) { |
|
|
|
out.instruction := in.instruction |
|
|
|
out.PC := BarrierReg(in.PC) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class EXBarrier extends Module { |
|
|
|
class EXBundle extends Bundle { |
|
|
|
val PC = UInt() |
|
|
|
val instruction = new Instruction |
|
|
|
val controlSignals = new ControlSignals |
|
|
|
val reg2 = UInt(32.W) |
|
|
|
val result = UInt(32.W) |
|
|
|
val branch = Bool() |
|
|
|
} |
|
|
|
class IDBundle extends IFBundle { |
|
|
|
val controlSignals = new ControlSignals |
|
|
|
val branchType = UInt(3.W) |
|
|
|
val reg1 = UInt(32.W) |
|
|
|
val reg2 = UInt(32.W) |
|
|
|
val imm = UInt(32.W) |
|
|
|
val ALUop = UInt(4.W) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val io = IO(new Bundle { |
|
|
|
val in = Input(new EXBundle) |
|
|
|
val out = Output(new EXBundle) |
|
|
|
}) |
|
|
|
class IDBarrier extends Barrier(new IDBundle) {} |
|
|
|
|
|
|
|
io.out := ShiftRegister(io.in, 1) |
|
|
|
|
|
|
|
class EXBundle extends IFBundle { |
|
|
|
val controlSignals = new ControlSignals |
|
|
|
val reg2 = UInt(32.W) |
|
|
|
val result = UInt(32.W) |
|
|
|
val branch = Bool() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MEMBarrier extends Module { |
|
|
|
class MEMBundle extends Bundle { |
|
|
|
val PC = UInt() |
|
|
|
val instruction = new Instruction |
|
|
|
val controlSignals = new ControlSignals |
|
|
|
val result = UInt(32.W) |
|
|
|
val dataOut = UInt(32.W) |
|
|
|
} |
|
|
|
class EXBarrier extends Barrier(new EXBundle) {} |
|
|
|
|
|
|
|
|
|
|
|
class MEMBundle extends IFBundle { |
|
|
|
val controlSignals = new ControlSignals |
|
|
|
val result = UInt(32.W) |
|
|
|
val dataOut = UInt(32.W) |
|
|
|
} |
|
|
|
|
|
|
|
val io = IO(new Bundle { |
|
|
|
val in = Input(new MEMBundle) |
|
|
|
val out = Output(new MEMBundle) |
|
|
|
}) |
|
|
|
|
|
|
|
io.out.PC := ShiftRegister(io.in.PC, 1) |
|
|
|
io.out.instruction := ShiftRegister(io.in.instruction, 1) |
|
|
|
io.out.controlSignals := ShiftRegister(io.in.controlSignals, 1) |
|
|
|
io.out.result := ShiftRegister(io.in.result, 1) |
|
|
|
io.out.dataOut := io.in.dataOut |
|
|
|
class MEMBarrier extends Barrier(new MEMBundle) { |
|
|
|
out.PC := BarrierReg(in.PC) |
|
|
|
out.instruction := BarrierReg(in.instruction) |
|
|
|
out.controlSignals := BarrierReg(in.controlSignals) |
|
|
|
out.result := BarrierReg(in.result) |
|
|
|
out.dataOut := in.dataOut |
|
|
|
} |