Line 302... |
Line 302... |
// PIPELINE STAGE #4 :: ALU / Memory
|
// PIPELINE STAGE #4 :: ALU / Memory
|
// Variable declarations
|
// Variable declarations
|
//
|
//
|
//
|
//
|
reg [(AW-1):0] alu_pc;
|
reg [(AW-1):0] alu_pc;
|
reg alu_pc_valid, mem_pc_valid;
|
reg r_alu_pc_valid, mem_pc_valid;
|
|
wire alu_pc_valid;
|
wire alu_phase;
|
wire alu_phase;
|
wire alu_ce, alu_stall;
|
wire alu_ce, alu_stall;
|
wire [31:0] alu_result;
|
wire [31:0] alu_result;
|
wire [3:0] alu_flags;
|
wire [3:0] alu_flags;
|
wire alu_valid, alu_busy;
|
wire alu_valid, alu_busy;
|
Line 373... |
Line 374... |
//
|
//
|
|
|
//
|
//
|
// PIPELINE STAGE #2 :: Instruction Decode
|
// PIPELINE STAGE #2 :: Instruction Decode
|
// Calculate stall conditions
|
// Calculate stall conditions
|
`ifdef OPT_PIPELINED
|
|
assign dcd_ce = ((~dcdvalid)||(~dcd_stalled))&&(~clear_pipeline);
|
assign dcd_ce = ((~dcdvalid)||(~dcd_stalled))&&(~clear_pipeline);
|
`else
|
|
assign dcd_ce = 1'b1;
|
|
`endif
|
|
`ifdef OPT_PIPELINED
|
`ifdef OPT_PIPELINED
|
assign dcd_stalled = (dcdvalid)&&(op_stall);
|
assign dcd_stalled = (dcdvalid)&&(op_stall);
|
`else
|
`else
|
// If not pipelined, there will be no opvalid_ anything, and the
|
// If not pipelined, there will be no opvalid_ anything, and the
|
// op_stall will be false, dcdX_stall will be false, thus we can simply
|
// op_stall will be false, dcdX_stall will be false, thus we can simply
|
Line 426... |
Line 424... |
||(dcdF_stall)
|
||(dcdF_stall)
|
);
|
);
|
assign op_ce = ((dcdvalid)||(dcd_illegal))&&(~op_stall)&&(~clear_pipeline);
|
assign op_ce = ((dcdvalid)||(dcd_illegal))&&(~op_stall)&&(~clear_pipeline);
|
`else
|
`else
|
assign op_stall = (opvalid)&&(~master_ce);
|
assign op_stall = (opvalid)&&(~master_ce);
|
assign op_ce = ((dcdvalid)||(dcd_illegal));
|
assign op_ce = ((dcdvalid)||(dcd_illegal))&&(~clear_pipeline);
|
`endif
|
`endif
|
|
|
//
|
//
|
// PIPELINE STAGE #4 :: ALU / Memory
|
// PIPELINE STAGE #4 :: ALU / Memory
|
// Calculate stall conditions
|
// Calculate stall conditions
|
Line 456... |
Line 454... |
&&(~alu_stall)
|
&&(~alu_stall)
|
&&(~clear_pipeline);
|
&&(~clear_pipeline);
|
`else
|
`else
|
assign alu_stall = ((~master_ce)&&(opvalid_alu))
|
assign alu_stall = ((~master_ce)&&(opvalid_alu))
|
||((opvalid_alu)&&(op_break));
|
||((opvalid_alu)&&(op_break));
|
assign alu_ce = (master_ce)&&((opvalid_alu)||(op_illegal))&&(~alu_stall);
|
assign alu_ce = (master_ce)&&((opvalid_alu)||(op_illegal))&&(~alu_stall)&&(~clear_pipeline);
|
`endif
|
`endif
|
//
|
//
|
|
|
//
|
//
|
// Note: if you change the conditions for mem_ce, you must also change
|
// Note: if you change the conditions for mem_ce, you must also change
|
Line 471... |
Line 469... |
&&(~clear_pipeline);
|
&&(~clear_pipeline);
|
`else
|
`else
|
// If we aren't pipelined, then no one will be changing what's in the
|
// If we aren't pipelined, then no one will be changing what's in the
|
// pipeline (i.e. clear_pipeline), while our only instruction goes
|
// pipeline (i.e. clear_pipeline), while our only instruction goes
|
// through the ... pipeline.
|
// through the ... pipeline.
|
assign mem_ce = (master_ce)&&(opvalid_mem)&&(~mem_stalled);
|
assign mem_ce = (master_ce)&&(opvalid_mem)&&(~mem_stalled)&&(~clear_pipeline);
|
`endif
|
`endif
|
`ifdef OPT_PIPELINED_BUS_ACCESS
|
`ifdef OPT_PIPELINED_BUS_ACCESS
|
assign mem_stalled = (~master_ce)||(alu_busy)||((opvalid_mem)&&(
|
assign mem_stalled = (~master_ce)||(alu_busy)||((opvalid_mem)&&(
|
(mem_pipe_stalled)
|
(mem_pipe_stalled)
|
||((~op_pipe)&&(mem_busy))
|
||((~op_pipe)&&(mem_busy))
|
Line 510... |
Line 508... |
`ifdef OPT_SINGLE_FETCH
|
`ifdef OPT_SINGLE_FETCH
|
wire pf_ce;
|
wire pf_ce;
|
|
|
assign pf_ce = (~pf_valid)&&(~dcdvalid)&&(~opvalid)&&(~alu_valid);
|
assign pf_ce = (~pf_valid)&&(~dcdvalid)&&(~opvalid)&&(~alu_valid);
|
prefetch #(ADDRESS_WIDTH)
|
prefetch #(ADDRESS_WIDTH)
|
pf(i_clk, i_rst, (pf_ce), (~dcd_stalled), pf_pc, gie,
|
pf(i_clk, (i_rst), (pf_ce), (~dcd_stalled), pf_pc, gie,
|
instruction, instruction_pc, instruction_gie,
|
instruction, instruction_pc, instruction_gie,
|
pf_valid, pf_illegal,
|
pf_valid, pf_illegal,
|
pf_cyc, pf_stb, pf_we, pf_addr, pf_data,
|
pf_cyc, pf_stb, pf_we, pf_addr, pf_data,
|
pf_ack, pf_stall, pf_err, i_wb_data);
|
pf_ack, pf_stall, pf_err, i_wb_data);
|
|
|
initial r_dcdvalid = 1'b0;
|
initial r_dcdvalid = 1'b0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (i_rst)
|
if ((i_rst)||(clear_pipeline))
|
r_dcdvalid <= 1'b0;
|
r_dcdvalid <= 1'b0;
|
else if (dcd_ce)
|
else if (dcd_ce)
|
r_dcdvalid <= (pf_valid);
|
r_dcdvalid <= (pf_valid);
|
else if (op_ce)
|
else if (op_ce)
|
r_dcdvalid <= 1'b0;
|
r_dcdvalid <= 1'b0;
|
Line 563... |
Line 561... |
initial r_dcdvalid = 1'b0;
|
initial r_dcdvalid = 1'b0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((i_rst)||(clear_pipeline))
|
if ((i_rst)||(clear_pipeline))
|
r_dcdvalid <= 1'b0;
|
r_dcdvalid <= 1'b0;
|
else if (dcd_ce)
|
else if (dcd_ce)
|
r_dcdvalid <= (pf_valid)&&(~clear_pipeline)&&(~dcd_ljmp)&&((~r_dcdvalid)||(~dcd_early_branch));
|
r_dcdvalid <= (pf_valid)&&(~dcd_ljmp)&&((~r_dcdvalid)||(~dcd_early_branch));
|
else if (op_ce)
|
else if (op_ce)
|
r_dcdvalid <= 1'b0;
|
r_dcdvalid <= 1'b0;
|
assign dcdvalid = r_dcdvalid;
|
assign dcdvalid = r_dcdvalid;
|
`endif
|
`endif
|
|
|
Line 1158... |
Line 1156... |
else if ((alu_ce)||(mem_ce))
|
else if ((alu_ce)||(mem_ce))
|
r_alu_illegal <= op_illegal;
|
r_alu_illegal <= op_illegal;
|
assign alu_illegal = (alu_illegal_op)||(r_alu_illegal);
|
assign alu_illegal = (alu_illegal_op)||(r_alu_illegal);
|
`endif
|
`endif
|
|
|
initial alu_pc_valid = 1'b0;
|
initial r_alu_pc_valid = 1'b0;
|
initial mem_pc_valid = 1'b0;
|
initial mem_pc_valid = 1'b0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (i_rst)
|
if (i_rst)
|
alu_pc_valid <= 1'b0;
|
r_alu_pc_valid <= 1'b0;
|
else
|
else if (alu_ce) // Includes && (~alu_clear_pipeline)
|
alu_pc_valid <= (alu_ce);
|
r_alu_pc_valid <= 1'b1;
|
|
else if ((~alu_busy)||(clear_pipeline))
|
|
r_alu_pc_valid <= 1'b0;
|
|
assign alu_pc_valid = (r_alu_pc_valid)&&(~alu_busy);
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (i_rst)
|
if (i_rst)
|
mem_pc_valid <= 1'b0;
|
mem_pc_valid <= 1'b0;
|
else
|
else
|
mem_pc_valid <= (mem_ce);
|
mem_pc_valid <= (mem_ce);
|
Line 1636... |
Line 1637... |
else if ((dcd_early_branch)&&(~clear_pipeline))
|
else if ((dcd_early_branch)&&(~clear_pipeline))
|
pf_pc <= dcd_branch_pc + 1;
|
pf_pc <= dcd_branch_pc + 1;
|
else if ((new_pc)||((~dcd_stalled)&&(pf_valid)))
|
else if ((new_pc)||((~dcd_stalled)&&(pf_valid)))
|
pf_pc <= pf_pc + {{(AW-1){1'b0}},1'b1};
|
pf_pc <= pf_pc + {{(AW-1){1'b0}},1'b1};
|
`else
|
`else
|
else if (((alu_pc_valid)&&(~clear_pipeline))||(mem_pc_valid))
|
else if ((alu_gie==gie)&&(
|
|
((alu_pc_valid)&&(~clear_pipeline))
|
|
||(mem_pc_valid)))
|
pf_pc <= alu_pc;
|
pf_pc <= alu_pc;
|
`endif
|
`endif
|
|
|
initial new_pc = 1'b1;
|
initial new_pc = 1'b1;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
Line 1705... |
Line 1708... |
assign o_i_count = (alu_pc_valid)&&(~clear_pipeline);
|
assign o_i_count = (alu_pc_valid)&&(~clear_pipeline);
|
|
|
`ifdef DEBUG_SCOPE
|
`ifdef DEBUG_SCOPE
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
o_debug <= {
|
o_debug <= {
|
o_break, i_wb_err, pf_pc[1:0],
|
/*
|
flags,
|
o_break, i_wb_err, pf_pc[1:0],
|
pf_valid, dcdvalid, opvalid, alu_valid, mem_valid,
|
//
|
op_ce, alu_ce, mem_ce,
|
flags,
|
//
|
//
|
master_ce, opvalid_alu, opvalid_mem,
|
pf_valid, dcdvalid, opvalid, alu_valid,
|
//
|
//
|
alu_stall, mem_busy, op_pipe, mem_pipe_stalled,
|
mem_valid,
|
mem_we,
|
op_ce, alu_ce, mem_ce,
|
// ((opvalid_alu)&&(alu_stall))
|
//
|
// ||((opvalid_mem)&&(~op_pipe)&&(mem_busy))
|
master_ce,
|
// ||((opvalid_mem)&&( op_pipe)&&(mem_pipe_stalled)));
|
opvalid_alu, opvalid_mem, alu_stall,
|
// opA[23:20], opA[3:0],
|
//
|
gie, sleep, wr_reg_ce, wr_reg_vl[4:0]
|
mem_busy, op_pipe,
|
|
`ifdef OPT_PIPELINED_BUS_ACCESS
|
|
mem_pipe_stalled,
|
|
`else
|
|
1'b0,
|
|
`endif
|
|
mem_we,
|
|
//
|
|
// ((opvalid_alu)&&(alu_stall))
|
|
// ||((opvalid_mem)&&(~op_pipe)&&(mem_busy))
|
|
// ||((opvalid_mem)&&( op_pipe)&&(mem_pipe_stalled)));
|
|
// opA[23:20], opA[3:0],
|
|
gie, sleep, wr_reg_ce, wr_reg_vl[4:0]
|
|
*/
|
|
|
|
o_break, i_wb_err, o_wb_gbl_cyc, o_wb_gbl_stb,
|
|
pf_valid, dcdvalid, opvalid, alu_valid,
|
|
mem_valid, dcd_ce, op_ce, alu_ce,
|
|
mem_ce,
|
|
dcd_illegal, gie, sleep,
|
|
{ ((o_wb_gbl_cyc)&&(o_wb_gbl_stb)&&(o_wb_we))
|
|
? o_wb_data[15:0]
|
|
: ((o_wb_gbl_cyc)&&(o_wb_gbl_stb)&&(~o_wb_we)&&(i_wb_ack))
|
|
? i_wb_data[15:0]
|
|
: o_wb_addr[15:0]
|
|
}
|
/*
|
/*
|
i_rst, master_ce, (new_pc),
|
i_rst, master_ce, (new_pc),
|
((dcd_early_branch)&&(dcdvalid)),
|
((dcd_early_branch)&&(dcdvalid)),
|
pf_valid, pf_illegal,
|
pf_valid, pf_illegal,
|
op_ce, dcd_ce, dcdvalid, dcd_stalled,
|
op_ce, dcd_ce, dcdvalid, dcd_stalled,
|