-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_op.v
54 lines (35 loc) · 1.28 KB
/
matrix_op.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
module matrix_op(first, second, result);
parameter size = 1;
parameter operation = 0;
parameter length = 8;
input [size*size*length-1 :0] first;
input [size*size*length-1:0] second;
output [size*size*length-1:0] result;
genvar i,j;
generate
for(i = 0; i < size; i = i+1) begin : row_generation
for (j = 0; j < size; j = j + 1) begin : column_generation
case (operation)
0: summ _summ(first[(length*(size*i + j + 1)) -1 : length*(size*i + j)],second[(length*(size*i + j + 1)) -1 : length*(size*i + j)],result[(length*(size*i + j + 1)) -1 : length*(size*i + j)]);
1: sub _sub(first[(length*(size*i + j + 1)) -1 : length*(size*i + j)],second[(length*(size*i + j + 1)) -1 : length*(size*i + j)],result[(length*(size*i + j + 1)) -1 : length*(size*i + j)]);
2: set _set(first[(length*(size*j + i + 1)) -1 : length*(size*j + i)],result[(length*(size*i + j + 1)) -1 : length*(size*i + j)]);
endcase
end
end
endgenerate
endmodule
module summ(Ain, Bin,Sout);
input [7:0] Ain, Bin;
output [7:0] Sout;
assign Sout = Ain + Bin;
endmodule
module sub(Ain, Bin,Sout);
input [7:0] Ain, Bin;
output [7:0] Sout;
assign Sout = Ain - Bin;
endmodule
module set(Ain,Sout);
input [7:0] Ain;
output [7:0] Sout;
assign Sout = Ain;
endmodule