Skip to content

Commit 53cc11c

Browse files
committed
designs/asap7/mac: added a MAC as a test-case for retiming
Signed-off-by: Øyvind Harboe <[email protected]>
1 parent 0c88c88 commit 53cc11c

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

flow/designs/asap7/mac/config.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export DESIGN_NAME = mac
2+
export VERILOG_FILES = designs/src/mac/mac.v
3+
export SDC_FILE = designs/asap7/mac/constraints.sdc
4+
export PLATFORM = asap7
5+
export PLACE_DENSITY= 0.30
6+
export CORE_UTILIZATION = 0.50
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set clk_name clock
2+
set clk_port_name clock
3+
set clk_period 250
4+
5+
source $env(PLATFORM_DIR)/constraints.sdc

flow/designs/src/mac/mac.v

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module mac (
2+
input logic clock,
3+
input logic [15:0] a,
4+
input logic [15:0] b,
5+
input logic valid_in,
6+
output logic [31:0] acc_out,
7+
output logic valid_out
8+
);
9+
// Pipeline registers for a, b, and valid
10+
logic [15:0] a_pipe [0:3];
11+
logic [15:0] b_pipe [0:3];
12+
logic valid_pipe [0:3];
13+
logic [31:0] mul_result;
14+
logic [31:0] acc;
15+
16+
always_ff @(posedge clock) begin
17+
// Stage 0: input register
18+
a_pipe[0] <= a;
19+
b_pipe[0] <= b;
20+
valid_pipe[0] <= valid_in;
21+
22+
// Stages 1-3: pipeline shift
23+
a_pipe[1] <= a_pipe[0];
24+
b_pipe[1] <= b_pipe[0];
25+
valid_pipe[1] <= valid_pipe[0];
26+
27+
a_pipe[2] <= a_pipe[1];
28+
b_pipe[2] <= b_pipe[1];
29+
valid_pipe[2] <= valid_pipe[1];
30+
31+
a_pipe[3] <= a_pipe[2];
32+
b_pipe[3] <= b_pipe[2];
33+
valid_pipe[3] <= valid_pipe[2];
34+
35+
// Stage 4: multiply and accumulate
36+
mul_result <= a_pipe[3] * b_pipe[3];
37+
if (valid_pipe[3])
38+
acc <= acc + mul_result;
39+
end
40+
41+
assign acc_out = acc;
42+
assign valid_out = valid_pipe[3];
43+
endmodule

0 commit comments

Comments
 (0)