divider control signal simplificaiton

This commit is contained in:
David Harris 2021-10-10 10:55:02 -07:00
parent c2bb0324c6
commit 6988c8c37c
2 changed files with 12 additions and 13 deletions

View File

@ -32,9 +32,9 @@ module intdivrestoring (
input logic reset, input logic reset,
input logic StallM, FlushM, input logic StallM, FlushM,
input logic DivSignedE, W64E, input logic DivSignedE, W64E,
input logic DivStartE, input logic DivE,
input logic [`XLEN-1:0] SrcAE, SrcBE, input logic [`XLEN-1:0] SrcAE, SrcBE,
output logic BusyE, DivDoneM, output logic DivBusyE,
output logic [`XLEN-1:0] QuotM, RemM output logic [`XLEN-1:0] QuotM, RemM
); );
@ -44,7 +44,8 @@ module intdivrestoring (
localparam STEPBITS = $clog2(`XLEN/`DIV_BITSPERCYCLE); localparam STEPBITS = $clog2(`XLEN/`DIV_BITSPERCYCLE);
logic [STEPBITS:0] step; logic [STEPBITS:0] step;
logic Div0E, Div0M; logic Div0E, Div0M;
logic DivInitE, SignXE, SignXM, SignDE, SignDM, NegWM, NegQM; logic DivStartE, SignXE, SignXM, SignDE, SignDM, NegWM, NegQM;
logic BusyE, DivDoneM;
logic [`XLEN-1:0] WNextE, XQNextE; logic [`XLEN-1:0] WNextE, XQNextE;
@ -54,6 +55,9 @@ module intdivrestoring (
//flopen #(`XLEN) xsavereg(~clk, DivStartE, SrcAE, XSavedE); //flopen #(`XLEN) xsavereg(~clk, DivStartE, SrcAE, XSavedE);
// flopen #(`XLEN) dsavereg(~clk, DivStartE, SrcBE, DSavedE); // flopen #(`XLEN) dsavereg(~clk, DivStartE, SrcBE, DSavedE);
assign DivStartE = DivE & ~BusyE & ~DivDoneM;
assign DivBusyE = BusyE | DivStartE;
// Handle sign extension for W-type instructions // Handle sign extension for W-type instructions
generate generate
if (`XLEN == 64) begin // RV64 has W-type instructions if (`XLEN == 64) begin // RV64 has W-type instructions
@ -112,26 +116,23 @@ module intdivrestoring (
mux3 #(`XLEN) qmux(XQM, XQnM, {`XLEN{1'b1}}, {Div0M, NegQM}, QuotM); // Q taken from XQ register, negated if necessary, or all 1s when dividing by zero mux3 #(`XLEN) qmux(XQM, XQnM, {`XLEN{1'b1}}, {Div0M, NegQM}, QuotM); // Q taken from XQ register, negated if necessary, or all 1s when dividing by zero
mux3 #(`XLEN) remmux(WM, WnM, XSavedM, {Div0M, NegWM}, RemM); // REM taken from W register, negated if necessary, or from X when dividing by zero mux3 #(`XLEN) remmux(WM, WnM, XSavedM, {Div0M, NegWM}, RemM); // REM taken from W register, negated if necessary, or from X when dividing by zero
// Divider FSM to sequence Init, Busy, and Done // Divider FSM to sequence Busy, and Done
always_ff @(posedge clk) always_ff @(posedge clk)
if (reset) begin if (reset) begin
BusyE = 0; DivDoneM = 0; step = 0; DivInitE = 0; BusyE = 0; DivDoneM = 0; step = 0;
end else if (DivStartE & ~StallM) begin end else if (DivStartE & ~StallM) begin
if (Div0E) DivDoneM = 1; if (Div0E) DivDoneM = 1;
else begin else begin
BusyE = 1; step = 0; DivInitE = 1; // *** can drop DivInit BusyE = 1; step = 0;
end end
end else if (BusyE & ~DivDoneM) begin // pause one cycle at beginning of signed operations for absolute value end else if (BusyE & ~DivDoneM) begin // pause one cycle at beginning of signed operations for absolute value
DivInitE = 0;
step = step + 1; step = step + 1;
if (step[STEPBITS] | (`XLEN==64) & W64E & step[STEPBITS-1]) begin // complete in half the time for W-type instructions if (step[STEPBITS] | (`XLEN==64) & W64E & step[STEPBITS-1]) begin // complete in half the time for W-type instructions
step = 0;
BusyE = 0; BusyE = 0;
DivDoneM = 1; DivDoneM = 1;
end end
end else if (DivDoneM) begin end else if (DivDoneM) begin
DivDoneM = StallM; DivDoneM = StallM;
BusyE = 0;
end end
endmodule endmodule

View File

@ -48,7 +48,7 @@ module muldiv (
logic [`XLEN-1:0] QuotM, RemM; logic [`XLEN-1:0] QuotM, RemM;
logic [`XLEN*2-1:0] ProdE, ProdM; logic [`XLEN*2-1:0] ProdE, ProdM;
logic DivStartE, BusyE, DivDoneM; logic DivE;
logic DivSignedE; logic DivSignedE;
logic W64M; logic W64M;
@ -59,11 +59,9 @@ module muldiv (
// Divide // Divide
// Start a divide when a new division instruction is received and the divider isn't already busy or finishing // Start a divide when a new division instruction is received and the divider isn't already busy or finishing
assign DivE = MulDivE & Funct3E[2]; assign DivE = MulDivE & Funct3E[2];
assign DivStartE = MulDivE & Funct3E[2] & ~BusyE & ~DivDoneM;
assign DivSignedE = ~Funct3E[0]; assign DivSignedE = ~Funct3E[0];
assign DivBusyE = BusyE | DivStartE;
intdivrestoring div(.clk, .reset, .StallM, .FlushM, intdivrestoring div(.clk, .reset, .StallM, .FlushM,
.DivSignedE, .W64E, .DivStartE, .SrcAE, .SrcBE, .BusyE, .DivDoneM, .QuotM, .RemM); .DivSignedE, .W64E, .DivE, .SrcAE, .SrcBE, .DivBusyE, .QuotM, .RemM);
// Result multiplexer // Result multiplexer
always_comb always_comb