-
Notifications
You must be signed in to change notification settings - Fork 1
/
maxpool.v
114 lines (90 loc) · 3.75 KB
/
maxpool.v
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
`timescale 1ns / 1ps
module maxpool(image_out,clk,rst);
output reg [15:0]image_out;
input clk,rst;
// bits depth
reg [9:0] image_addr[3:0];
reg [9:0]last_coloum_value;
reg stride;
wire [15:0] image_value[3:0];
always @ (posedge clk or posedge rst)
begin
if (rst==1)
begin
image_out=0;
image_addr[0]=0; image_addr[1]=1;
image_addr[2]=26; image_addr[3]=27;
stride=2;
last_coloum_value=25;
end
else begin
if (image_value[0]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[0];
end
if (image_value[1]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[1];
end
if (image_value[2]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[2];
end
if (image_value[3]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[3];
end
if (image_addr[1]!== last_coloum_value)
begin
image_addr[0]=image_addr[0]+stride;
image_addr[1]=image_addr[1]+stride;
image_addr[2]=image_addr[2]+stride;
image_addr[3]=image_addr[3]+stride;
if (image_value[0]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[0];
end
if (image_value[1]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[1];
end
if (image_value[2]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[2];
end
if (image_value[3]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[3];
end
end
else begin
if (image_addr[3]!== 783)
image_addr[0]=image_addr[0]+2;
image_addr[1]=image_addr[1]+2;
image_addr[2]=image_addr[2]+2;
image_addr[3]=image_addr[3]+2;
last_coloum_value =last_coloum_value+26;
if (image_value[0]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[0];
end
if (image_value[1]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[1];
end
if (image_value[2]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[2];
end
if (image_value[3]>=image_value[1] && image_value[0]>=image_value[2]&& image_value[0]>=image_value[3])
begin
image_out = image_value[3];
end
end
end
end
image_rom1 A4 (clk,image_addr[0],image_value[0]);
image_rom1 A5 (clk,image_addr[1],image_value[1]);
image_rom1 A6 (clk,image_addr[2],image_value[2]);
image_rom1 A7 (clk,image_addr[3],image_value[3]);
endmodule