summaryrefslogtreecommitdiff
path: root/rtl/gfx/fold_flow.sv
blob: 1d9c0f221f79a6ec916b7f626262891c8ce332a9 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
`include "gfx/gfx_defs.sv"

module fold_flow
(
	input  logic  clk,
	              rst_n,

	input  logic  in_valid,
	              out_ready,

	output logic  in_ready,
	              out_valid,
	              stall,
	              feedback,
	              feedback_last
);

	logic skid_ready;
	index4 rounds[`FP_ADD_STAGES], last_round;

	assign in_ready = skid_ready && !feedback;

	assign feedback = last_round[1] ^ last_round[0];
	assign feedback_last = last_round[1];

	assign last_round = rounds[`FP_ADD_STAGES - 1];

	skid_flow skid
	(
		.in_valid(last_round == `INDEX4_MAX),
		.in_ready(skid_ready),
		.*
	);

	always_ff @(posedge clk or negedge rst_n)
		if (!rst_n)
			rounds[0] <= `INDEX4_MIN;
		else if (!stall)
			unique case (last_round)
				2'b01:
					rounds[0] <= 2'b10;

				2'b10: 
					rounds[0] <= 2'b11;

				2'b00, 2'b11:
					rounds[0] <= {1'b0, in_valid};
			endcase

	genvar i;
	generate
		for (i = 1; i < `FP_ADD_STAGES; ++i) begin: pipeline
			always_ff @(posedge clk or negedge rst_n)
				if (!rst_n)
					rounds[i] <= `INDEX4_MIN;
				else if (in_ready)
					rounds[i] <= rounds[i - 1];
		end
	endgenerate

endmodule