File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ set clk_name clock
2+ set clk_port_name clock
3+ set clk_period 250
4+
5+ source $env(PLATFORM_DIR) /constraints.sdc
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments