lut5.comp

来自「CNC 的开放码,EMC2 V2.2.8版」· COMP 代码 · 共 136 行

COMP
136
字号
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 lut5constructs an arbitrary logic function with up to 5 inputs using a\\fBl\\fRook-\\fBu\\fRp \\fBt\\fRable.  The function is specified by the HAL pin\\fBfunction\\fR.  The necessary value for \\fBfunction\\fR can be determinedby writing the truth table, and computing the sum of the \\fBweights\\fR forwhich the output value should be \\fRTRUE\\fR..PP.SS Example FunctionsA 5-input\\fIand\\fR function is TRUE only when all the inputs are true, so the correctvalue for \\fBfunction\\fR is \\fB0x80000000\\fR..PPA 5-input \\fIor\\fRfunction is TRUE whenever any of the inputs are true, so the correct value for\\fBfunction\\fR is \\fB0xffffffffe\\fR..PPA 2-input \\fIxor\\fR function isTRUE 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 beconnected to signals, because if any other bit is \\fBTRUE\\fR then the outputwill be \\fBFALSE\\fR..ie '\*[.T]'html' \\{\\.HTML \\<STYLE> \\#weight TD { text-align: center; padding-left: .5ex; padding-right: .5ex } \\#weight TH { text-align: center; padding-left: .5ex; padding-right: .5ex } \\#weight TD.W { text-align: right; } \\</STYLE> \\<TABLE ID="weight" STYLE="border: 1px solid black; border-collapse: collapse"> \\    <COL SPAN=5 STYLE="margin: .2ex"><COL SPAN=1 STYLE="border-left: 1px solid black"> \\<TR STYLE="border-bottom: 1px solid black"> \\    <TH COLSPAN=6>Weights for each line of truth table \\<TR STYLE="border-bottom: 1px solid black"> \\    <TH>Bit 4<TH>Bit 3<TH>Bit 2<TH>Bit 1<TH>Bit 0<TH> Weight \\<TR><TD>0<TD>0<TD>0<TD>0<TD>0<TD CLASS="w">0x1 \\<TR><TD>0<TD>0<TD>0<TD>0<TD>1<TD CLASS="w">0x2 \\<TR><TD>0<TD>0<TD>0<TD>1<TD>0<TD CLASS="w">0x4 \\<TR><TD>0<TD>0<TD>0<TD>1<TD>1<TD CLASS="w">0x8 \\<TR><TD>0<TD>0<TD>1<TD>0<TD>0<TD CLASS="w">0x10 \\<TR><TD>0<TD>0<TD>1<TD>0<TD>1<TD CLASS="w">0x20 \\<TR><TD>0<TD>0<TD>1<TD>1<TD>0<TD CLASS="w">0x40 \\<TR><TD>0<TD>0<TD>1<TD>1<TD>1<TD CLASS="w">0x80 \\<TR><TD>0<TD>1<TD>0<TD>0<TD>0<TD CLASS="w">0x100 \\<TR><TD>0<TD>1<TD>0<TD>0<TD>1<TD CLASS="w">0x200 \\<TR><TD>0<TD>1<TD>0<TD>1<TD>0<TD CLASS="w">0x400 \\<TR><TD>0<TD>1<TD>0<TD>1<TD>1<TD CLASS="w">0x800 \\<TR><TD>0<TD>1<TD>1<TD>0<TD>0<TD CLASS="w">0x1000 \\<TR><TD>0<TD>1<TD>1<TD>0<TD>1<TD CLASS="w">0x2000 \\<TR><TD>0<TD>1<TD>1<TD>1<TD>0<TD CLASS="w">0x4000 \\<TR><TD>0<TD>1<TD>1<TD>1<TD>1<TD CLASS="w">0x8000 \\<TR><TD>1<TD>0<TD>0<TD>0<TD>0<TD CLASS="w">0x10000 \\<TR><TD>1<TD>0<TD>0<TD>0<TD>1<TD CLASS="w">0x20000 \\<TR><TD>1<TD>0<TD>0<TD>1<TD>0<TD CLASS="w">0x40000 \\<TR><TD>1<TD>0<TD>0<TD>1<TD>1<TD CLASS="w">0x80000 \\<TR><TD>1<TD>0<TD>1<TD>0<TD>0<TD CLASS="w">0x100000 \\<TR><TD>1<TD>0<TD>1<TD>0<TD>1<TD CLASS="w">0x200000 \\<TR><TD>1<TD>0<TD>1<TD>1<TD>0<TD CLASS="w">0x400000 \\<TR><TD>1<TD>0<TD>1<TD>1<TD>1<TD CLASS="w">0x800000 \\<TR><TD>1<TD>1<TD>0<TD>0<TD>0<TD CLASS="w">0x1000000 \\<TR><TD>1<TD>1<TD>0<TD>0<TD>1<TD CLASS="w">0x2000000 \\<TR><TD>1<TD>1<TD>0<TD>1<TD>0<TD CLASS="w">0x4000000 \\<TR><TD>1<TD>1<TD>0<TD>1<TD>1<TD CLASS="w">0x8000000 \\<TR><TD>1<TD>1<TD>1<TD>0<TD>0<TD CLASS="w">0x10000000 \\<TR><TD>1<TD>1<TD>1<TD>0<TD>1<TD CLASS="w">0x20000000 \\<TR><TD>1<TD>1<TD>1<TD>1<TD>0<TD CLASS="w">0x40000000 \\<TR><TD>1<TD>1<TD>1<TD>1<TD>1<TD CLASS="w">0x80000000\\}.el \\{\\.TSbox tab(;);cb s s s s scb cb cb cb cb | cbc  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;0x10;0;0;0;1;0x20;0;0;1;0;0x40;0;0;1;1;0x80;0;1;0;0;0x100;0;1;0;1;0x200;0;1;1;0;0x400;0;1;1;1;0x800;1;0;0;0;0x1000;1;0;0;1;0x2000;1;0;1;0;0x4000;1;0;1;1;0x8000;1;1;0;0;0x10000;1;1;0;1;0x20000;1;1;1;0;0x40000;1;1;1;1;0x80001;0;0;0;0;0x100001;0;0;0;1;0x200001;0;0;1;0;0x400001;0;0;1;1;0x800001;0;1;0;0;0x1000001;0;1;0;1;0x2000001;0;1;1;0;0x4000001;0;1;1;1;0x8000001;1;0;0;0;0x10000001;1;0;0;1;0x20000001;1;0;1;0;0x40000001;1;0;1;1;0x80000001;1;1;0;0;0x100000001;1;1;0;1;0x200000001;1;1;1;0;0x400000001;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<<shift)) != 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?