From 73aa647c9bf68369b095b91a43ffa599f3f55857 Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Tue, 8 Oct 2024 14:48:44 -0700 Subject: [PATCH] lab-04 (WIP): unsigned mult working --- TESTBENCH/mult_tb.v | 2 ++ logic_32_bit.v | 16 ++++++++++++++++ mult.v | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/TESTBENCH/mult_tb.v b/TESTBENCH/mult_tb.v index 3111ef0..cd44040 100644 --- a/TESTBENCH/mult_tb.v +++ b/TESTBENCH/mult_tb.v @@ -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 diff --git a/logic_32_bit.v b/logic_32_bit.v index d02d6ce..df558e3 100755 --- a/logic_32_bit.v +++ b/logic_32_bit.v @@ -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 diff --git a/mult.v b/mult.v index ddb65d8..d14f038 100644 --- a/mult.v +++ b/mult.v @@ -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