lab-04 (WIP): unsigned mult working

This commit is contained in:
Yuri Tatishchev 2024-10-08 14:48:44 -07:00
parent 6fa94cfe59
commit 73aa647c9b
Signed by: CaZzzer
GPG Key ID: 28BE602058C08557
3 changed files with 62 additions and 1 deletions

View File

@ -36,6 +36,8 @@ A=10; B=20; // Y = 10 * 20 = 200
#1 result[i] = {HI,LO}; i=i+1;
#1 A=10; B=19; // Y = 10 * 19 = 190
#1 result[i] = {HI,LO}; i=i+1;
#1 A=32'h00d96027; B=32'h7c32b43c; // Y = 0x0d96027 * 0x7c32b43c = 0x 006975a0 b62bf524
#1 result[i] = {HI,LO}; i=i+1;
#1 A=32'h70000000; B=32'h70000000;
#1 result[i] = {HI,LO}; i=i+1;
#1

View File

@ -80,3 +80,19 @@ generate
end
endgenerate
endmodule
// 32-bit buffer
module BUF32_1x1(Y,A);
//output
output [31:0] Y;
//input
input [31:0] A;
genvar i;
generate
for (i = 0; i < 32; i = i + 1)
begin : buf32_gen_loop
buf buf32_inst(Y[i], A[i]);
end
endgenerate
endmodule

45
mult.v
View File

@ -39,6 +39,49 @@ output [31:0] LO;
input [31:0] A;
input [31:0] B;
// TBD
// partial sums
wire [31:0] Y [31:0];
// first partial is just
AND32_2x1 partial_1(Y[0], A, {32{B[0]}});
// put lowest bit from first partial into result
buf (LO[0], Y[0][0]);
// carries from partial adders
wire CI[31:0];
// first carry is always 0
buf (CI[0], 0);
genvar i;
generate
for (i = 0; i < 31; i = i + 1)
begin : mult32u_gen_loop
// multiply A by a single digit in B
wire [31:0] A_and;
AND32_2x1 partial_and_inst(A_and, A, {32{B[i+1]}});
// calc the next partial and carry (i + 1)
RC_ADD_SUB_32 partial_add_inst(.Y(Y[i+1]), .CO(CI[i+1]), .A(A_and), .B({CI[i],Y[i][31:1]}), .SnA(1'b0));
// put lowest bit from calc into result
buf (LO[i+1], Y[i+1][0]);
end
endgenerate
// last partial is HI
// multiply A by a most significant digit in B
//wire [31:0] A_and;
//AND32_2x1 partial32_and(A_and, A, {32{B[31]}});
// calc HI
//RC_ADD_SUB_32 partial32_add(.Y(HI), .A(A_and), .B({CI[30],Y[30][31:1]}), .SnA(1'b0));
// put lowest bit from calc into result
//buf (LO[31], HI[0]);
// last partial is HI
BUF32_1x1 buf_hi(HI, {CI[31],Y[31][31:1]});
endmodule