minor updates

This commit is contained in:
Blaise Tine 2023-06-29 17:31:14 -04:00
parent fb4f62bab9
commit e214c0b2a8
3 changed files with 67 additions and 62 deletions

View file

@ -111,17 +111,33 @@ module VX_muldiv (
wire mul_ready_in;
wire mul_ready_out = ~stall_out;
VX_serial_mul #(
.A_WIDTH (`XLEN+1),
.LANES (`NUM_THREADS),
.SIGNED (1)
) multiplier (
wire mul_strode;
wire mul_busy;
VX_elastic_adapter mul_elastic_adapter (
.clk (clk),
.reset (reset),
.reset (reset),
.valid_in (mul_valid_in),
.ready_in (mul_ready_in),
.valid_out (mul_valid_out),
.ready_out (mul_ready_out),
.strobe (mul_strode),
.busy (mul_busy)
);
VX_serial_mul #(
.A_WIDTH (`XLEN+1),
.LANES (`NUM_THREADS),
.SIGNED (1)
) serial_mul (
.clk (clk),
.reset (reset),
.strobe (mul_strode),
.busy (mul_busy),
.dataa (mul_in1),
.datab (mul_in2),
.result (mul_result_tmp)
@ -142,7 +158,7 @@ module VX_muldiv (
for (genvar i = 0; i < `NUM_THREADS; ++i) begin
wire [`XLEN:0] mul_in1 = {is_signed_mul_a && alu_in1[i][`XLEN-1], alu_in1[i]};
wire [`XLEN:0] mul_in2 = {is_signed_mul_b && alu_in2[i][`XLEN-1], alu_in2[i]};
wire [`XLEN:0] mul_in2 = {is_signed_mul_b && alu_in2[i][`XLEN-1], alu_in2[i]};
VX_multiplier #(
.A_WIDTH (`XLEN+1),
@ -244,14 +260,10 @@ module VX_muldiv (
wire [`NUM_THREADS-1:0][`XLEN-1:0] div_quotient, div_remainder;
wire is_rem_op_out;
wire is_div_w_out;
wire div_strode;
wire div_busy;
VX_serial_div #(
.WIDTHN (`XLEN),
.WIDTHD (`XLEN),
.WIDTHQ (`XLEN),
.WIDTHR (`XLEN),
.LANES (`NUM_THREADS)
) divide (
VX_elastic_adapter div_elastic_adapter (
.clk (clk),
.reset (reset),
@ -261,6 +273,23 @@ module VX_muldiv (
.valid_out (div_valid_out),
.ready_out (div_ready_out),
.strobe (div_strode),
.busy (div_busy)
);
VX_serial_div #(
.WIDTHN (`XLEN),
.WIDTHD (`XLEN),
.WIDTHQ (`XLEN),
.WIDTHR (`XLEN),
.LANES (`NUM_THREADS)
) serial_div (
.clk (clk),
.reset (reset),
.strobe (div_strode),
.busy (div_busy),
.is_signed (is_signed_op),
.numer (div_in1),
.denom (div_in2),

View file

@ -11,11 +11,8 @@ module VX_serial_div #(
input wire clk,
input wire reset,
input wire valid_in,
output wire ready_in,
input wire ready_out,
output wire valid_out,
input wire strobe,
output wire busy,
input wire is_signed,
input wire [LANES-1:0][WIDTHN-1:0] numer,
@ -37,7 +34,7 @@ module VX_serial_div #(
reg [LANES-1:0] inv_quot, inv_rem;
reg [CNTRW-1:0] cntr;
reg busy, done;
reg busy_r;
for (genvar i = 0; i < LANES; ++i) begin
wire negate_numer = is_signed && numer[i][WIDTHN-1];
@ -46,40 +43,32 @@ module VX_serial_div #(
assign denom_qual[i] = negate_denom ? -$signed(denom[i]) : denom[i];
assign sub_result[i] = working[i][WIDTHN + MIN_ND : WIDTHN] - denom_r[i];
end
wire push = valid_in && ready_in;
wire pop = valid_out && ready_out;
always @(posedge clk) begin
if (reset) begin
busy <= 0;
done <= 0;
busy_r <= 0;
end else begin
if (push) begin
busy <= 1;
if (strobe) begin
busy_r <= 1;
end
if (busy && cntr == 0) begin
busy <= 0;
done <= 1;
end
if (pop) begin
done <= 0;
busy_r <= 0;
end
end
cntr <= cntr - CNTRW'(1);
if (push) begin
if (strobe) begin
cntr <= CNTRW'(WIDTHN-1);
end
end
for (genvar i = 0; i < LANES; ++i) begin
always @(posedge clk) begin
if (push) begin
if (strobe) begin
working[i] <= {{WIDTHD{1'b0}}, numer_qual[i], 1'b0};
denom_r[i] <= denom_qual[i];
inv_quot[i] <= (denom[i] != 0) && is_signed && (numer[i][31] ^ denom[i][31]);
inv_rem[i] <= is_signed && numer[i][31];
end else if (busy) begin
end else if (busy_r) begin
working[i] <= sub_result[i][WIDTHD] ? {working[i][WIDTHN+MIN_ND-1:0], 1'b0} :
{sub_result[i][WIDTHD-1:0], working[i][WIDTHN-1:0], 1'b1};
end
@ -89,9 +78,8 @@ module VX_serial_div #(
assign quotient[i] = inv_quot[i] ? -$signed(q) : q;
assign remainder[i] = inv_rem[i] ? -$signed(r) : r;
end
assign ready_in = ~busy && ~done;
assign valid_out = done;
assign busy = busy_r;
endmodule
`TRACING_ON

View file

@ -15,11 +15,8 @@ module VX_serial_mul #(
input wire clk,
input wire reset,
input wire valid_in,
output wire ready_in,
input wire ready_out,
output wire valid_out,
input wire strobe,
output wire busy,
input wire [LANES-1:0][A_WIDTH-1:0] dataa,
input wire [LANES-1:0][B_WIDTH-1:0] datab,
@ -36,29 +33,21 @@ module VX_serial_mul #(
reg [LANES-1:0][P_WIDTH-1:0] p;
reg [CNTRW-1:0] cntr;
reg busy, done;
wire push = valid_in && ready_in;
wire pop = valid_out && ready_out;
reg busy_r;
always @(posedge clk) begin
if (reset) begin
busy <= 0;
done <= 0;
busy_r <= 0;
end else begin
if (push) begin
busy <= 1;
if (strobe) begin
busy_r <= 1;
end
if (busy && cntr == 0) begin
done <= 1;
end
if (pop) begin
busy <= 0;
done <= 0;
if (busy_r && cntr == 0) begin
busy_r <= 0;
end
end
cntr <= cntr - CNTRW'(1);
if (push) begin
if (strobe) begin
cntr <= CNTRW'(X_WIDTH-1);
end
end
@ -67,7 +56,7 @@ module VX_serial_mul #(
wire [X_WIDTH-1:0] axb = b[i][0] ? a[i] : '0;
always @(posedge clk) begin
if (push) begin
if (strobe) begin
if (SIGNED) begin
a[i] <= X_WIDTH'($signed(dataa[i]));
b[i] <= Y_WIDTH'($signed(datab[i]));
@ -76,7 +65,7 @@ module VX_serial_mul #(
b[i] <= datab[i];
end
p[i] <= 0;
end else if (busy) begin
end else if (busy_r) begin
b[i] <= (b[i] >> 1);
p[i][Y_WIDTH-2:0] <= p[i][Y_WIDTH-1:1];
if (SIGNED) begin
@ -99,8 +88,7 @@ module VX_serial_mul #(
end
`UNUSED_VAR (p)
assign ready_in = ~busy && ~done;
assign valid_out = done;
assign busy = busy_r;
endmodule
`TRACING_ON