component lut5 """Arbitrary 5-input logic function based on a look-up table"""; pin in bit in_0; pin in bit in_1; pin in bit in_2; pin in bit in_3; pin in bit in_4; pin out bit out; param rw u32 function; function _ nofp; description """ .B lut5 constructs an arbitrary logic function with up to 5 inputs using a \\fBl\\fRook-\\fBu\\fRp \\fBt\\fRable. The function is specified by \\fBfunction\\fR. The necessary value for \\fBfunction\\fR can be determined by writing the truth table, and computing the sum of the \\fBweights\\fR for which the output value should be \\fRTRUE\\fR. .PP .SS Example Functions A 5-input \\fIand\\fR function is TRUE only when all the inputs are true, so the correct value for \\fBfunction\\fR is \\fB0x80000000\\fR. .PP A 5-input \\fIor\\fR function is TRUE whenever any of the inputs are true, so the correct value for \\fBfunction\\fR is \\fB0xffffffffe\\fR. .PP A 2-input \\fIxor\\fR function is TRUE whenever exactly one of the inputs is true, so the correct value for \\fBfunction\\fR is \\fB0x6\\fR. Only \\fBin-0\\fR and \\fBin-1\\fR should be connected to signals, because if any other bit is \\fBTRUE\\fR then the output will be \\fBFALSE\\fR. .ie '\*[.T]'html' \\{\\ .HTML \\ \\ \\ \\ \\ \\
Weights for each line of truth table \\
Bit 4Bit 3Bit 2Bit 1Bit 0 Weight \\
000000x1 \\
000010x2 \\
000100x4 \\
000110x8 \\
001000x10 \\
001010x20 \\
001100x40 \\
001110x80 \\
010000x100 \\
010010x200 \\
010100x400 \\
010110x800 \\
011000x1000 \\
011010x2000 \\
011100x4000 \\
011110x8000 \\
100000x10000 \\
100010x20000 \\
100100x40000 \\
100110x80000 \\
101000x100000 \\
101010x200000 \\
101100x400000 \\
101110x800000 \\
110000x1000000 \\
110010x2000000 \\
110100x4000000 \\
110110x8000000 \\
111000x10000000 \\
111010x20000000 \\
111100x40000000 \\
111110x80000000 \\} .el \\{\\ .TS box tab(;); cb s s s s s cb cb cb cb cb | cb c c c c c | r. Weights for each line of truth table _ Bit 4;Bit 3;Bit 2;Bit 1;Bit 0; Weight _ 0;0;0;0;0;0x1 0;0;0;0;1;0x2 0;0;0;1;0;0x4 0;0;0;1;1;0x8 0;0;1;0;0;0x10 0;0;1;0;1;0x20 0;0;1;1;0;0x40 0;0;1;1;1;0x80 0;1;0;0;0;0x100 0;1;0;0;1;0x200 0;1;0;1;0;0x400 0;1;0;1;1;0x800 0;1;1;0;0;0x1000 0;1;1;0;1;0x2000 0;1;1;1;0;0x4000 0;1;1;1;1;0x8000 1;0;0;0;0;0x10000 1;0;0;0;1;0x20000 1;0;0;1;0;0x40000 1;0;0;1;1;0x80000 1;0;1;0;0;0x100000 1;0;1;0;1;0x200000 1;0;1;1;0;0x400000 1;0;1;1;1;0x800000 1;1;0;0;0;0x1000000 1;1;0;0;1;0x2000000 1;1;0;1;0;0x4000000 1;1;0;1;1;0x8000000 1;1;1;0;0;0x10000000 1;1;1;0;1;0x20000000 1;1;1;1;0;0x40000000 1;1;1;1;1;0x80000000 .TE \\} """; license "GPL"; ;; FUNCTION(_) { int shift = 0; if(in_0) shift += 1; if(in_1) shift += 2; if(in_2) shift += 4; if(in_3) shift += 8; if(in_4) shift += 16; out = (function & (1<