[Modified] Change branch site, without stall (need 1 stall)

This commit is contained in:
2023-06-12 15:36:00 +08:00
parent f592606196
commit 8d1aa17074
10 changed files with 93 additions and 144 deletions

View File

@@ -2,12 +2,7 @@ module alu(
input [14:0] alu_op , input [14:0] alu_op ,
input [31:0] alu_src1 , input [31:0] alu_src1 ,
input [31:0] alu_src2 , input [31:0] alu_src2 ,
output [31:0] alu_result , output [31:0] alu_result
output Carry ,
output Sign ,
output Overflow ,
output Zero
); );
wire op_add; wire op_add;
@@ -117,11 +112,5 @@ module alu(
| ({32{op_sll }} & sll_result) | ({32{op_sll }} & sll_result)
| ({32{op_srl|op_sra }} & sr_result) | ({32{op_srl|op_sra }} & sr_result)
| ({32{op_mul|op_mulh|op_mulhu}} & mul_result); | ({32{op_mul|op_mulh|op_mulhu}} & mul_result);
assign Carry = op_sub ^ adder_cout;
assign Sign = alu_result[31];
assign Overflow = (op_add|op_sub) ? ( adder_a[31] & adder_b[31] & adder_cout)
| (~adder_a[31] & ~adder_b[31] & ~adder_cout)
: 1'b0;
assign Zero = (alu_result == 32'b0);
endmodule endmodule

View File

@@ -45,7 +45,6 @@ module exe_stage(
wire es_mem_we; wire es_mem_we;
wire [ 4:0] es_load_op; wire [ 4:0] es_load_op;
wire [ 2:0] es_store_op; wire [ 2:0] es_store_op;
wire [ 8:0] es_branch_op;
wire [ 4:0] es_dest; wire [ 4:0] es_dest;
wire [31:0] es_imm; wire [31:0] es_imm;
wire [31:0] es_pc; wire [31:0] es_pc;
@@ -59,16 +58,15 @@ module exe_stage(
wire es_src2_is_ms_dest; wire es_src2_is_ms_dest;
wire es_data_is_rf_wdata; wire es_data_is_rf_wdata;
assign {es_alu_op , //173:155 assign {es_alu_op , //159:141
es_src1_is_pc , //154:154 es_src1_is_pc , //140:140
es_src2_is_imm , //153:153 es_src2_is_imm , //139:139
es_src2_is_4 , //152:152 es_src2_is_4 , //138:138
es_mem_to_reg , //151:151 es_mem_to_reg , //137:137
es_reg_we , //150:150 es_reg_we , //136:136
es_mem_we , //149:149 es_mem_we , //135:135
es_load_op , //148:142 es_load_op , //134:134
es_store_op , //141:141 es_store_op , //133:133
es_branch_op , //141:133
es_dest , //132:128 es_dest , //132:128
es_imm , //127:96 es_imm , //127:96
es_rf_rdata1 , //95 :64 es_rf_rdata1 , //95 :64
@@ -86,8 +84,6 @@ module exe_stage(
assign ms_alu_result = ms_to_ds_bus; assign ms_alu_result = ms_to_ds_bus;
assign ws_rf_wdata = ws_to_ds_bus; assign ws_rf_wdata = ws_to_ds_bus;
wire [31:0] br_target;
wire [31:0] es_alu_src1 ; wire [31:0] es_alu_src1 ;
wire [31:0] es_alu_src2 ; wire [31:0] es_alu_src2 ;
wire [31:0] es_alu_result; wire [31:0] es_alu_result;
@@ -103,19 +99,13 @@ module exe_stage(
wire [ 1:0] div_op; wire [ 1:0] div_op;
wire div_stall; wire div_stall;
assign es_to_ms_bus = {div_op , //122:121 assign es_to_ms_bus = {div_op , //77:76
br_target , //120:89 es_load_op , //75:71
es_branch_op , //88 :80 es_mem_to_reg , //70:70
es_Carry , //79 :79 es_reg_we , //69:69
es_Sign , //78 :78 es_dest , //68:64
es_Overflow , //77 :77 es_alu_result , //63:32
es_Zero , //76 :76 es_pc //31:0
es_load_op , //75 :71
es_mem_to_reg , //70 :70
es_reg_we , //69 :69
es_dest , //68 :64
es_alu_result , //63 :32
es_pc //31 :0
}; };
assign es_to_fw_bus = {es_rf_rdata2 , assign es_to_fw_bus = {es_rf_rdata2 ,
@@ -171,12 +161,7 @@ module exe_stage(
.alu_op (es_alu_op[14:0]), .alu_op (es_alu_op[14:0]),
.alu_src1 (es_alu_src1 ), .alu_src1 (es_alu_src1 ),
.alu_src2 (es_alu_src2 ), .alu_src2 (es_alu_src2 ),
.alu_result (es_alu_result), .alu_result (es_alu_result)
.Carry (es_Carry ),
.Sign (es_Sign ),
.Overflow (es_Overflow ),
.Zero (es_Zero )
); );
assign data_sram_en = 1'b1; assign data_sram_en = 1'b1;
@@ -196,8 +181,4 @@ module exe_stage(
es_store_op[2] ? es_rf_rdata2 : es_store_op[2] ? es_rf_rdata2 :
32'b0; 32'b0;
assign br_target = (|es_branch_op[7:0]) ? (es_alu_result ) :
( es_branch_op[8] ) ? (es_rf_rdata1 + es_imm) :
0;
endmodule endmodule

View File

@@ -13,10 +13,12 @@ module id_stage(
//to es //to es
output ds_to_es_valid, output ds_to_es_valid,
output [`DS_TO_ES_BUS_WD -1:0] ds_to_es_bus , output [`DS_TO_ES_BUS_WD -1:0] ds_to_es_bus ,
//to fs //to rf
input [`WS_TO_RF_BUS_WD -1:0] ws_to_rf_bus , input [`WS_TO_RF_BUS_WD -1:0] ws_to_rf_bus ,
//to fw //to fw
output [`DS_TO_FW_BUS_WD -1:0] ds_to_fw_bus output [`DS_TO_FW_BUS_WD -1:0] ds_to_fw_bus ,
//to fs
output [`BR_BUS_WD -1:0] br_bus
); );
reg ds_valid ; reg ds_valid ;
@@ -48,7 +50,6 @@ module id_stage(
wire mem_we; wire mem_we;
wire [ 4:0] load_op; wire [ 4:0] load_op;
wire [ 2:0] store_op; wire [ 2:0] store_op;
wire [ 8:0] branch_op;
wire [ 4:0] dest; wire [ 4:0] dest;
wire [31:0] imm; wire [31:0] imm;
@@ -109,8 +110,6 @@ module id_stage(
wire inst_divwu; wire inst_divwu;
wire inst_modwu; wire inst_modwu;
wire dst_is_r1; wire dst_is_r1;
wire [ 4:0] rf_raddr1; wire [ 4:0] rf_raddr1;
@@ -118,16 +117,21 @@ module id_stage(
wire [ 4:0] rf_raddr2; wire [ 4:0] rf_raddr2;
wire [31:0] rf_rdata2; wire [31:0] rf_rdata2;
assign ds_to_es_bus = {alu_op , //173:155 wire rj_eq_rd;
src1_is_pc , //154:154 wire rj_lt_rd_unsign;
src2_is_imm , //153:153 wire rj_lt_rd_sign;
src2_is_4 , //152:152 wire br_taken;
mem_to_reg , //151:151 wire [31:0] br_target;
reg_we , //150:150
mem_we , //149:149 assign ds_to_es_bus = {alu_op , //159:141
load_op , //148:142 src1_is_pc , //140:140
store_op , //141:141 src2_is_imm , //139:139
branch_op , //141:133 src2_is_4 , //138:138
mem_to_reg , //137:137
reg_we , //136:136
mem_we , //135:135
load_op , //134:134
store_op , //133:133
dest , //132:128 dest , //132:128
imm , //127:96 imm , //127:96
rf_rdata1 , //95 :64 rf_rdata1 , //95 :64
@@ -135,10 +139,12 @@ module id_stage(
ds_pc //31 :0 ds_pc //31 :0
}; };
assign ds_to_fw_bus = {rf_raddr1 , rf_raddr2}; assign ds_to_fw_bus = {rf_raddr1 ,
rf_raddr2
};
assign ds_ready_go = 1'b1; assign ds_ready_go = 1'b1;
assign ds_allowin = !ds_valid || ds_ready_go && es_allowin; assign ds_allowin = (!ds_valid || ds_ready_go && es_allowin);
assign ds_to_es_valid = ds_valid && ds_ready_go; assign ds_to_es_valid = ds_valid && ds_ready_go;
always @(posedge clk) begin always @(posedge clk) begin
@@ -215,7 +221,7 @@ module id_stage(
assign inst_bltu = (op[21:19] == 3'b011 ) & op6_d[3'b010]; assign inst_bltu = (op[21:19] == 3'b011 ) & op6_d[3'b010];
assign inst_bgeu = (op[21:19] == 3'b011 ) & op6_d[3'b011]; assign inst_bgeu = (op[21:19] == 3'b011 ) & op6_d[3'b011];
assign alu_op[ 0] = inst_addw | inst_addiw | inst_pcaddu12i | inst_ldb | inst_ldh | inst_ldbu | inst_ldhu | inst_ldw | inst_stb | inst_sth | inst_stw | inst_bl | inst_jirl | inst_b; assign alu_op[ 0] = inst_addw | inst_addiw | inst_pcaddu12i | inst_ldb | inst_ldh | inst_ldbu | inst_ldhu | inst_ldw | inst_stb | inst_sth | inst_stw;
assign alu_op[ 1] = inst_subw; assign alu_op[ 1] = inst_subw;
assign alu_op[ 2] = inst_slt | inst_slti; assign alu_op[ 2] = inst_slt | inst_slti;
assign alu_op[ 3] = inst_sltu | inst_sltui; assign alu_op[ 3] = inst_sltu | inst_sltui;
@@ -252,7 +258,6 @@ module id_stage(
assign mem_to_reg = inst_ldw | inst_ldh | inst_ldb | inst_ldhu | inst_ldbu; assign mem_to_reg = inst_ldw | inst_ldh | inst_ldb | inst_ldhu | inst_ldbu;
assign load_op = {inst_ldhu, inst_ldbu, inst_ldw, inst_ldh, inst_ldb}; assign load_op = {inst_ldhu, inst_ldbu, inst_ldw, inst_ldh, inst_ldb};
assign store_op = {inst_stw , inst_sth , inst_stb}; assign store_op = {inst_stw , inst_sth , inst_stb};
assign branch_op = {inst_jirl, inst_bl , inst_b , inst_bgeu, inst_bltu, inst_bge, inst_blt, inst_bne, inst_beq};
assign dest = dst_is_r1 ? 5'd1 : assign dest = dst_is_r1 ? 5'd1 :
rd; rd;
@@ -270,4 +275,22 @@ module id_stage(
.wdata (rf_wdata ) .wdata (rf_wdata )
); );
assign rj_eq_rd = (rf_rdata1 == rf_rdata2);
assign rj_lt_rd_unsign = (rf_rdata1 < rf_rdata2);
assign rj_lt_rd_sign = (rf_rdata1[31] && ~rf_rdata2[31]) ? 1'b1 :
(~rf_rdata1[31] && rf_rdata2[31]) ? 1'b0 : rj_lt_rd_unsign;
assign br_taken = ( inst_beq && rj_eq_rd
|| inst_bne && !rj_eq_rd
|| inst_blt && rj_lt_rd_sign
|| inst_bge && !rj_lt_rd_sign
|| inst_bltu && rj_lt_rd_unsign
|| inst_bgeu && !rj_lt_rd_unsign
|| inst_jirl
|| inst_bl
|| inst_b
);
assign br_target = ({32{inst_beq || inst_bne || inst_bl || inst_b || inst_blt || inst_bge || inst_bltu || inst_bgeu}} & (ds_pc + imm))
| ({32{inst_jirl}} & (rf_rdata1 + imm)) ;
assign br_bus = {br_taken, br_target};
endmodule endmodule

View File

@@ -29,7 +29,7 @@ module if_stage(
wire br_taken; wire br_taken;
wire [ 31:0] br_target; wire [ 31:0] br_target;
assign {br_taken,br_target} = br_bus; assign {br_taken, br_target} = br_bus;
wire [31:0] fs_inst; wire [31:0] fs_inst;
reg [31:0] fs_pc; reg [31:0] fs_pc;

View File

@@ -12,8 +12,6 @@ module mem_stage(
//to ws //to ws
output ms_to_ws_valid , output ms_to_ws_valid ,
output [`MS_TO_WS_BUS_WD -1:0] ms_to_ws_bus , output [`MS_TO_WS_BUS_WD -1:0] ms_to_ws_bus ,
//to fs
output [`BR_BUS_WD -1:0] br_bus ,
//from data-sram //from data-sram
input [31 :0] data_sram_rdata, input [31 :0] data_sram_rdata,
//to fw //to fw
@@ -29,8 +27,6 @@ module mem_stage(
wire ms_ready_go; wire ms_ready_go;
reg [`ES_TO_MS_BUS_WD -1:0] es_to_ms_bus_r; reg [`ES_TO_MS_BUS_WD -1:0] es_to_ms_bus_r;
wire [31:0] br_target;
wire [ 8:0] ms_branch_op;
wire [ 4:0] ms_load_op; wire [ 4:0] ms_load_op;
wire [ 2:0] ms_store_op; wire [ 2:0] ms_store_op;
wire ms_mem_to_reg; wire ms_mem_to_reg;
@@ -39,32 +35,19 @@ module mem_stage(
wire [31:0] ms_alu_result; wire [31:0] ms_alu_result;
wire [31:0] ms_pc; wire [31:0] ms_pc;
wire [ 1:0] ms_div_op; wire [ 1:0] ms_div_op;
wire ms_Carry ;
wire ms_Sign ;
wire ms_Overflow ;
wire ms_Zero ;
assign {ms_div_op , //122:121 assign {ms_div_op , //77:76
br_target , //120:89 ms_load_op , //75:71
ms_branch_op , //88 :80 ms_mem_to_reg , //70:70
ms_Carry , //79 :79 ms_reg_we , //69:69
ms_Sign , //78 :78 ms_dest , //68:64
ms_Overflow , //77 :77 ms_alu_result , //63:32
ms_Zero , //76 :76 ms_pc //31:0
ms_load_op , //75 :71
ms_mem_to_reg , //70 :70
ms_reg_we , //69 :69
ms_dest , //68 :64
ms_alu_result , //63 :32
ms_pc //31 :0
} = es_to_ms_bus_r; } = es_to_ms_bus_r;
wire br_taken;
wire [31:0] mem_result; wire [31:0] mem_result;
wire [31:0] ms_final_result; wire [31:0] ms_final_result;
assign br_bus = {br_taken, br_target};
assign ms_to_ws_bus = {ms_reg_we , //69:69 assign ms_to_ws_bus = {ms_reg_we , //69:69
ms_dest , //68:64 ms_dest , //68:64
@@ -109,15 +92,4 @@ module mem_stage(
ms_div_op[1] ? mod_result : ms_div_op[1] ? mod_result :
ms_alu_result; ms_alu_result;
assign br_taken = ( ms_branch_op[0] & ms_Zero
| ms_branch_op[1] & !ms_Zero
| ms_branch_op[2] & (ms_Sign != ms_Overflow)
| ms_branch_op[3] & (ms_Zero | (ms_Sign == ms_Overflow))
| ms_branch_op[4] & ms_Carry
| ms_branch_op[5] & (ms_Zero | ~ms_Carry )
| ms_branch_op[6]
| ms_branch_op[7]
| ms_branch_op[8]);
endmodule endmodule

View File

@@ -3,8 +3,8 @@
`define BR_BUS_WD 33 `define BR_BUS_WD 33
`define FS_TO_DS_BUS_WD 64 `define FS_TO_DS_BUS_WD 64
`define DS_TO_ES_BUS_WD 174 `define DS_TO_ES_BUS_WD 160
`define ES_TO_MS_BUS_WD 123 `define ES_TO_MS_BUS_WD 78
`define MS_TO_WS_BUS_WD 70 `define MS_TO_WS_BUS_WD 70
`define WS_TO_RF_BUS_WD 38 `define WS_TO_RF_BUS_WD 38
@@ -12,10 +12,6 @@
`define ES_TO_FW_BUS_WD 12 `define ES_TO_FW_BUS_WD 12
`define MS_TO_FW_BUS_WD 6 `define MS_TO_FW_BUS_WD 6
`define FW_TO_ES_BUS_WD 5 `define FW_TO_ES_BUS_WD 5
`define MS_TO_ES_BUS_WD 32 `define MS_TO_ES_BUS_WD 32
`define WS_TO_ES_BUS_WD 32 `define WS_TO_ES_BUS_WD 32
`define DS_TO_LU_BUS_WD 10
`define ES_TO_LU_BUS_WD 10
`endif `endif

View File

@@ -88,7 +88,9 @@ module mycpu_top(
//to rf: for write back //to rf: for write back
.ws_to_rf_bus (ws_to_rf_bus ), .ws_to_rf_bus (ws_to_rf_bus ),
//to fw //to fw
.ds_to_fw_bus (ds_to_fw_bus ) .ds_to_fw_bus (ds_to_fw_bus ),
//to fs
.br_bus (br_bus )
); );
// EXE stage // EXE stage
exe_stage exe_stage( exe_stage exe_stage(
@@ -149,8 +151,6 @@ module mycpu_top(
//to ws //to ws
.ms_to_ws_valid (ms_to_ws_valid ), .ms_to_ws_valid (ms_to_ws_valid ),
.ms_to_ws_bus (ms_to_ws_bus ), .ms_to_ws_bus (ms_to_ws_bus ),
//to fs
.br_bus (br_bus ),
//from data-sram //from data-sram
.data_sram_rdata(data_sram_rdata), .data_sram_rdata(data_sram_rdata),
//to fw //to fw

View File

@@ -12,10 +12,10 @@ module decoder_5_32(
endmodule endmodule
module decoder_3_8( module decoder_3_8(
input [2:0] in, input [2:0] in,
output [7:0] out output [7:0] out
); );
genvar i; genvar i;
generate for (i=0; i<8; i=i+1) begin : gen_for_dec_3_8 generate for (i=0; i<8; i=i+1) begin : gen_for_dec_3_8

View File

@@ -1,2 +1,2 @@
memory_initialization_radix=16; memory_initialization_radix=16;
memory_initialization_vector=28800401 02800822; memory_initialization_vector=50000000 28800401 02800822;

View File

@@ -29,20 +29,20 @@
<Option Name="IPUserFilesDir" Val="$PIPUSERFILESDIR"/> <Option Name="IPUserFilesDir" Val="$PIPUSERFILESDIR"/>
<Option Name="IPStaticSourceDir" Val="$PIPUSERFILESDIR/ipstatic"/> <Option Name="IPStaticSourceDir" Val="$PIPUSERFILESDIR/ipstatic"/>
<Option Name="EnableBDX" Val="FALSE"/> <Option Name="EnableBDX" Val="FALSE"/>
<Option Name="WTXSimLaunchSim" Val="22"/> <Option Name="WTXSimLaunchSim" Val="29"/>
<Option Name="WTModelSimLaunchSim" Val="0"/> <Option Name="WTModelSimLaunchSim" Val="0"/>
<Option Name="WTQuestaLaunchSim" Val="0"/> <Option Name="WTQuestaLaunchSim" Val="0"/>
<Option Name="WTIesLaunchSim" Val="0"/> <Option Name="WTIesLaunchSim" Val="0"/>
<Option Name="WTVcsLaunchSim" Val="0"/> <Option Name="WTVcsLaunchSim" Val="0"/>
<Option Name="WTRivieraLaunchSim" Val="0"/> <Option Name="WTRivieraLaunchSim" Val="0"/>
<Option Name="WTActivehdlLaunchSim" Val="0"/> <Option Name="WTActivehdlLaunchSim" Val="0"/>
<Option Name="WTXSimExportSim" Val="12"/> <Option Name="WTXSimExportSim" Val="16"/>
<Option Name="WTModelSimExportSim" Val="12"/> <Option Name="WTModelSimExportSim" Val="16"/>
<Option Name="WTQuestaExportSim" Val="12"/> <Option Name="WTQuestaExportSim" Val="16"/>
<Option Name="WTIesExportSim" Val="12"/> <Option Name="WTIesExportSim" Val="16"/>
<Option Name="WTVcsExportSim" Val="12"/> <Option Name="WTVcsExportSim" Val="16"/>
<Option Name="WTRivieraExportSim" Val="12"/> <Option Name="WTRivieraExportSim" Val="16"/>
<Option Name="WTActivehdlExportSim" Val="12"/> <Option Name="WTActivehdlExportSim" Val="16"/>
<Option Name="GenerateIPUpgradeLog" Val="TRUE"/> <Option Name="GenerateIPUpgradeLog" Val="TRUE"/>
<Option Name="XSimRadix" Val="hex"/> <Option Name="XSimRadix" Val="hex"/>
<Option Name="XSimTimeUnit" Val="ns"/> <Option Name="XSimTimeUnit" Val="ns"/>
@@ -138,14 +138,6 @@
<Attr Name="UsedIn" Val="simulation"/> <Attr Name="UsedIn" Val="simulation"/>
</FileInfo> </FileInfo>
</File> </File>
<File Path="$PPRDIR/../../rtl/cpu/loaduse.v">
<FileInfo>
<Attr Name="AutoDisabled" Val="1"/>
<Attr Name="UsedIn" Val="synthesis"/>
<Attr Name="UsedIn" Val="implementation"/>
<Attr Name="UsedIn" Val="simulation"/>
</FileInfo>
</File>
<File Path="$PPRDIR/../../rtl/xilinx_ip/inst_ram/inst_ram.coe"> <File Path="$PPRDIR/../../rtl/xilinx_ip/inst_ram/inst_ram.coe">
<FileInfo> <FileInfo>
<Attr Name="UsedIn" Val="synthesis"/> <Attr Name="UsedIn" Val="synthesis"/>
@@ -258,9 +250,7 @@
<Runs Version="1" Minor="11"> <Runs Version="1" Minor="11">
<Run Id="synth_1" Type="Ft3:Synth" SrcSet="sources_1" Part="xc7a100tcsg324-1" ConstrsSet="constrs_1" Description="Vivado Synthesis Defaults" AutoIncrementalCheckpoint="false" WriteIncrSynthDcp="false" State="current" Dir="$PRUNDIR/synth_1" IncludeInArchive="true"> <Run Id="synth_1" Type="Ft3:Synth" SrcSet="sources_1" Part="xc7a100tcsg324-1" ConstrsSet="constrs_1" Description="Vivado Synthesis Defaults" AutoIncrementalCheckpoint="false" WriteIncrSynthDcp="false" State="current" Dir="$PRUNDIR/synth_1" IncludeInArchive="true">
<Strategy Version="1" Minor="2"> <Strategy Version="1" Minor="2">
<StratHandle Name="Vivado Synthesis Defaults" Flow="Vivado Synthesis 2019"> <StratHandle Name="Vivado Synthesis Defaults" Flow="Vivado Synthesis 2019"/>
<Desc>Vivado Synthesis Defaults</Desc>
</StratHandle>
<Step Id="synth_design"/> <Step Id="synth_design"/>
</Strategy> </Strategy>
<GeneratedRun Dir="$PRUNDIR" File="gen_run.xml"/> <GeneratedRun Dir="$PRUNDIR" File="gen_run.xml"/>
@@ -290,9 +280,7 @@
</Run> </Run>
<Run Id="impl_1" Type="Ft2:EntireDesign" Part="xc7a100tcsg324-1" ConstrsSet="constrs_1" Description="Default settings for Implementation." AutoIncrementalCheckpoint="false" WriteIncrSynthDcp="false" State="current" Dir="$PRUNDIR/impl_1" SynthRun="synth_1" IncludeInArchive="true" GenFullBitstream="true"> <Run Id="impl_1" Type="Ft2:EntireDesign" Part="xc7a100tcsg324-1" ConstrsSet="constrs_1" Description="Default settings for Implementation." AutoIncrementalCheckpoint="false" WriteIncrSynthDcp="false" State="current" Dir="$PRUNDIR/impl_1" SynthRun="synth_1" IncludeInArchive="true" GenFullBitstream="true">
<Strategy Version="1" Minor="2"> <Strategy Version="1" Minor="2">
<StratHandle Name="Vivado Implementation Defaults" Flow="Vivado Implementation 2019"> <StratHandle Name="Vivado Implementation Defaults" Flow="Vivado Implementation 2019"/>
<Desc>Default settings for Implementation.</Desc>
</StratHandle>
<Step Id="init_design"/> <Step Id="init_design"/>
<Step Id="opt_design"/> <Step Id="opt_design"/>
<Step Id="power_opt_design"/> <Step Id="power_opt_design"/>