forked from dirjud/Nitro-Parts-lib-Xilinx
-
Notifications
You must be signed in to change notification settings - Fork 3
/
LUT4.v
57 lines (38 loc) · 1.2 KB
/
LUT4.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
`timescale 1 ps / 1 ps
module LUT4 (O, I0, I1, I2, I3);
parameter INIT = 16'h0000;
input I0, I1, I2, I3;
output O;
reg O;
reg tmp;
always @( I3 or I2 or I1 or I0 ) begin
tmp = I0 ^ I1 ^ I2 ^ I3;
if ( tmp == 0 || tmp == 1)
O = INIT[{I3, I2, I1, I0}];
else
O = lut4_mux4 ( {lut4_mux4 ( INIT[15:12], {I1, I0}),
lut4_mux4 ( INIT[11:8], {I1, I0}),
lut4_mux4 ( INIT[7:4], {I1, I0}),
lut4_mux4 ( INIT[3:0], {I1, I0}) }, {I3, I2});
end
function lut4_mux4;
input [3:0] d;
input [1:0] s;
begin
if ((s[1]^s[0] ==1) || (s[1]^s[0] ==0))
lut4_mux4 = d[s];
else if ((d[0] === d[1]) && (d[2] === d[3]) && (d[0] === d[2]))
lut4_mux4 = d[0];
else if ((s[1] == 0) && (d[0] === d[1]))
lut4_mux4 = d[0];
else if ((s[1] == 1) && (d[2] === d[3]))
lut4_mux4 = d[2];
else if ((s[0] == 0) && (d[0] === d[2]))
lut4_mux4 = d[0];
else if ((s[0] == 1) && (d[1] === d[3]))
lut4_mux4 = d[1];
else
lut4_mux4 = 1'bx;
end
endfunction
endmodule