Skip to content

Commit 1916c72

Browse files
Introduce partial multiplier
Works like sequential multiplier, but is faster and more expensive :(
1 parent 3d9b9be commit 1916c72

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

Bender.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sources:
1818
- rtl/hwpe_ctrl_package.sv
1919
# Level 1
2020
- rtl/hwpe_ctrl_regfile_latch.sv
21+
- rtl/hwpe_ctrl_partial_mult.sv
2122
- rtl/hwpe_ctrl_seq_mult.sv
2223
- rtl/hwpe_ctrl_uloop.sv
2324
# Level 2

rtl/hwpe_ctrl_partial_mult.sv

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* hwpe_ctrl_partial_mult.sv
3+
* Francesco Conti <f.conti@unibo.it>
4+
*
5+
* Copyright (C) 2014-2024 ETH Zurich, University of Bologna
6+
* Copyright and related rights are licensed under the Solderpad Hardware
7+
* License, Version 0.51 (the "License"); you may not use this file except in
8+
* compliance with the License. You may obtain a copy of the License at
9+
* http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
10+
* or agreed to in writing, software, hardware and materials distributed under
11+
* this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*
15+
* A fully sequential unsigned multiplier. Inputs must
16+
* be kept stable for AW-1 cycles after the start strobe.
17+
*/
18+
19+
20+
module hwpe_ctrl_partial_mult
21+
import hwpe_ctrl_package::*;
22+
#(
23+
parameter int unsigned AW = 8,
24+
parameter int unsigned BW = 8,
25+
parameter int unsigned MULT_BITS = 4
26+
)
27+
(
28+
input logic clk_i,
29+
input logic rst_ni,
30+
input logic clear_i,
31+
input logic start_i,
32+
input logic [AW-1:0] a_i,
33+
input logic [BW-1:0] b_i,
34+
input logic invert_i,
35+
output logic valid_o,
36+
output logic ready_o,
37+
output logic [AW+BW-1:0] prod_o
38+
);
39+
40+
localparam AW_PAD = AW % MULT_BITS == 0 ? AW : AW + MULT_BITS - AW % MULT_BITS;
41+
42+
logic [AW_PAD-1:0] a_pad;
43+
logic [$clog2(AW_PAD/MULT_BITS+1)-1:0] cnt;
44+
logic signed [AW+BW-1:0] shifted;
45+
logic signed [AW+BW-1:0] shifted_or_inverse;
46+
logic valid_q, ready_q;
47+
48+
always_ff @(posedge clk_i or negedge rst_ni)
49+
begin : counter
50+
if(~rst_ni) begin
51+
cnt <= '0;
52+
valid_q <= '0;
53+
ready_q <= 1'b1;
54+
end
55+
else if(clear_i) begin
56+
cnt <= '0;
57+
valid_q <= '0;
58+
ready_q <= 1'b1;
59+
end
60+
else if(cnt == AW_PAD/MULT_BITS - 1) begin
61+
cnt <= 0;
62+
valid_q <= 1'b1;
63+
ready_q <= 1'b1;
64+
end
65+
else if((start_i==1'b1) || (cnt>0)) begin
66+
cnt <= cnt + 1;
67+
valid_q <= 1'b0;
68+
ready_q <= 1'b0;
69+
end
70+
end
71+
assign valid_o = valid_q;
72+
assign ready_o = ready_q;
73+
74+
// pad a_i to a multiple of MULT_BITS
75+
assign a_pad = {{(AW_PAD-AW){a_i[AW-1]}}, a_i};
76+
77+
assign shifted = cnt==AW_PAD/MULT_BITS ? 0 : (((a_pad >> cnt*MULT_BITS) & {{(AW_PAD-MULT_BITS){1'b0}}, {MULT_BITS{1'b1}}}) * b_i) << (cnt / MULT_BITS);
78+
assign shifted_or_inverse = (invert_i ? -shifted : shifted) * 48'sh1;
79+
80+
always_ff @(posedge clk_i or negedge rst_ni)
81+
begin : product
82+
if(~rst_ni) begin
83+
prod_o <= '0;
84+
end
85+
else if(clear_i) begin
86+
prod_o <= '0;
87+
end
88+
else if (start_i) begin
89+
prod_o <= shifted_or_inverse;
90+
end
91+
else if(cnt>0) begin
92+
prod_o <= prod_o + shifted_or_inverse;
93+
end
94+
end
95+
96+
endmodule /* hwpe_ctrl_partial_mult */

src_files.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ hwpe-ctrl:
1212
rtl/hwpe_ctrl_regfile_latch.sv,
1313
rtl/hwpe_ctrl_regfile_latch_test_wrap.sv,
1414
rtl/hwpe_ctrl_slave.sv,
15+
rtl/hwpe_ctrl_partial_mult.sv,
1516
rtl/hwpe_ctrl_seq_mult.sv,
1617
rtl/hwpe_ctrl_uloop.sv,
1718
]

0 commit comments

Comments
 (0)