完整版放在我的下载中,需要的同学可以参考,包括参考书籍《自己动手写CPU》
暂停机制
指令位于第n个阶段,那么保持第n阶段之前的各个阶段的寄存器保持不变,同时pc值保持不变
假设EX阶段要求暂停
CTRL模块
接受各阶段的流水线暂停请求信号
接受来自ID,EX模块的stallreq暂停信号,进行判断,将stall结果输出到PC,IF/ID, ID, ID/EX, EX, EX/MEM, MEM/WB
`include "defines.v"
module ctrl(
input wire rst,
input wire stallreq_from_id,
input wire stallreq_from_ex,
output reg[5:0] stall
);
always @ (*) begin
if(rst == `RstEnable) begin
stall <= 6'b000000;
end else if(stallreq_from_ex == `Stop) begin
stall <= 6'b001111;
end else if(stallreq_from_id == `Stop) begin
stall <= 6'b000111;
end else begin
stall <= 6'b000000;
end //if
end //always
endmodule
PC, IF/ID, ID, ID/EX, EX, EX/MEM, MEM都需要添加信号,以及对应的机制
乘累加,乘累减
`define EXE_MADD 6'b000000
`define EXE_MADDU 6'b000001
`define EXE_MSUB 6'b000100
`define EXE_MSUBU 6'b000101
//R型指令
// 31-26 25-21 20-16 15-11 10-6 5-0
// special2 rs rt 00000 00000 madd {HI,LO} <- {HI,LO} + rs*rt
// special2 rs rt 00000 00000 maddu
// special2 rs rt 00000 00000 msub {HI,LO} <- {HI,LO} - rs*rt
// special2 rs rt 00000 00000 msubu
`define EXE_MADD_OP 8'b1