-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartial_result_buffer.sv
38 lines (30 loc) · 1.1 KB
/
partial_result_buffer.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
`include "sys_defs.svh"
module partial_result_buffer(
input clock,
input reset,
input enable,
input [(`OUT_BIN_LEN - 1) : 0] store_vals [(`KERNEL_HEIGHT - 1) : 0],
input [(`INPUT_WIDTH_LOG - 1) : 0] width_index,
output reg [(`OUT_BIN_LEN - 1) : 0] fetch_vals [(`KERNEL_HEIGHT - 1) : 0]
);
reg [(`OUT_BIN_LEN - 1) : 0] stored_partial_sums [(`KERNEL_HEIGHT - 2) : 0][(`INPUT_WIDTH - 1) : 0];
always@(posedge clock) begin
if(reset) begin
for(int i = 0; i < `KERNEL_HEIGHT - 1; i++) begin
for(int j = 0; j < `INPUT_WIDTH; j++) begin
stored_partial_sums[i][j] = 0;
end
end
end else if(enable) begin
for(int i = 0; i < `KERNEL_HEIGHT - 1; i++) begin
stored_partial_sums[i][width_index - (`KERNEL_WIDTH - 1)] = store_vals[i];
end
end
end
always@(*) begin
for (int i = 1; i < `KERNEL_HEIGHT; i = i + 1) begin
fetch_vals[i] = stored_partial_sums[i - 1][width_index];
end
fetch_vals[0] = 0;
end
endmodule