📄 simulatorlut.java
字号:
/*
* SimulatorLUT.java
*
* Created on 25 November 2001, 23:43
*/
package jaga.pj.circuits.fpgaft;
import jaga.BitSet;
import jaga.pj.circuits.*;
/** Faulty Logic Element with delay implementing a Lookup-Table of configurable inputs. <p>
* When cloning one of these, the same lookup table <code>table</code> object will be pointed
* at by the original and the clone. This is OK unless tables are likely to get modified during the
* object's lifetime. The getClone() method should be overriden if this is unacceptable.
* @author Michael Garvie
* @version
*/
public class SimulatorLUT extends SimulatorFaultyDelayLE {
public static final int PRINT_TABLE = 0;
public static final int PRINT_DESCRIPTION = 1;
public static final int PRINT_BUCANON = 2;
public static final String[] DESCRIPTION_LABELS = { "gnd","and", "ab'", "a","a'b", "b","xor", "or", "nor", "nxor", "b'","a+b'", "a'","a'+b", "nand", "v+" };
public static final String[] BUCANON_LABELS = { "?" ,"[a,b]","[a,'b]","a","['a,b]","b","'[a<->b]","[a;b]","'[a;b]","[a<->b]","'b","[a;'b]","'a","['a;b]","'[a,b]","!" };
protected static int mode = PRINT_TABLE;
//BitSet table;
public boolean[] table;
public boolean isLut2; // for performance
/** <p>Creates new SimulatorLUT from a BitSet representing the results of the
* LUT in ascending order having the last input as the lowest significant
* element in the table composition. Eg: if we have</p>
* <p>I0 I1 F
* <p>0 0 0
* <p>0 1 1
* <p>1 0 0
* <p>1 1 1
* <p> then we initiliaze with new BitSet( "0101" ) </p>
* <p>So the input with largest index in the input array is the least significant bit when calculating
* the line in the lookup table. Similar to Little Endian. IE. The string formed by the concatenation
* of input values with I0 on the left and I(n-1) on the right is a binary encoding of the line number
* where the output value for this input combination is to be found in the table. </p>
*
*
* @param table BitSet representing the results of the LUT in ascending order. Its length must be power of two.
*/
public SimulatorLUT( BitSet table, int delay )
{
super( delay );
this.table = new boolean[ table.length() ];
for( int bl = 0; bl < table.length(); bl++ )
{
this.table[ bl ] = table.get( bl );
}
//this.table = table;
if( this.table.length == 4 )
{
isLut2 = true;
}
}
public SimulatorLUT( boolean[] table, int delay )
{
super( delay );
this.table = table;
if( table.length == 4 )
{
isLut2 = true;
}
}
/** Copied from SimulatorDelayLE, coudl have put in here and declared final.. */
public final void sampleInputs()
{
boolean evValue;
if( isLut2 )
{
if( !inputs[ 1 ].getNow() )
{
if( !inputs[ 0 ].getNow() )
{
evValue = table[ 0 ];
}else
{
evValue = table[ 2 ];
}
}else
{
if( !inputs[ 0 ].getNow() )
{
evValue = table[ 1 ];
}else
{
evValue = table[ 3 ];
}
}
/*int acc0 = inputs[ 1 ].getNow()?1:0;
int acc1 = inputs[ 0 ].getNow()?2:0;
lineNumber = acc0 | acc1;*/
}else
{
int lineNumber = 0;
for( int bl = 0; bl < inputs.length; bl++ )
{
if( inputs[ inputs.length - bl - 1 ].getNow() )
{
lineNumber += ( 1 << bl );
}
}
evValue = table[ lineNumber ];
}
//return table[ lineNumber ];
// End SimulatorLUT evaluteNow();
// SimulatorDelayLE sampleInputs() start
// boolean evValue = evaluateNow();
boolean changing = currentOutput ^ nextOutput;
if( ( changing && ( evValue != nextOutput ) ) || ( !changing && ( evValue != currentOutput ) ) )
{
nextOutput = evValue;
delayLeft = delay;
changing = true;
}
}
/** Assumes right number of inputs for size of table.
*/
protected boolean evaluateNow()
{
int lineNumber;
if( isLut2 )
{
if( !inputs[ 1 ].currentOutput )
{
if( !inputs[ 0 ].currentOutput )
{
return table[ 0 ];
}else
{
return table[ 2 ];
}
}else
{
if( !inputs[ 0 ].currentOutput )
{
return table[ 1 ];
}else
{
return table[ 3 ];
}
}
/*int acc0 = inputs[ 1 ].getNow()?1:0;
int acc1 = inputs[ 0 ].getNow()?2:0;
lineNumber = acc0 | acc1;*/
}else
{
lineNumber = 0;
for( int bl = 0; bl < inputs.length; bl++ )
{
if( inputs[ inputs.length - bl - 1 ].getNow() )
{
lineNumber += ( 1 << bl );
}
}
}
//return table.get( lineNumber );
return table[ lineNumber ];
}
public static void setMode( int mode )
{
SimulatorLUT.mode = mode;
}
public int getTable()
{
int rv = jaga.ESLib.boolArr2Int( table );
return rv;
}
public String toString()
{
String rv;
if( mode == PRINT_TABLE )
{
rv = jaga.ESLib.boolArr2String( table );
}else if( mode == PRINT_BUCANON )
{
if( isLut2 )
{
int value = Integer.valueOf( jaga.ESLib.boolArr2String( table ), 2 ).intValue();
rv = BUCANON_LABELS[ value ];
}else
{
rv = "";
}
}else if( mode == PRINT_DESCRIPTION )
{
if( isLut2 )
{
int value = Integer.valueOf( jaga.ESLib.boolArr2String( table ), 2 ).intValue();
rv = DESCRIPTION_LABELS[ value ];
}else
{
rv = "";
int lutIns = jaga.ESLib.log2( table.length );
boolean firstOne = true;
for( int tl = 0; tl < table.length; tl++ )
{
if( table[ tl ] )
{
if( firstOne )
{
firstOne = false;
}else
{
rv += "+";
}
for( int vl = 0; vl < lutIns; vl++ )
{
/*
if( ( tl & ( 1 << ( lutIns - 1 - vl ) ) ) == 0 )
{
rv += "\\overline{";
}
*/
rv += ( ( char ) ( 97 + vl ) );
/*
if( ( tl & ( 1 << ( lutIns - 1 - vl ) ) ) == 0 )
{
rv += "}";
}*/
if( ( tl & ( 1 << ( lutIns - 1 - vl ) ) ) == 0 )
{
rv += "'";
}
}
}
}
}
}else
{
rv = "Invalid Mode";
}
return rv;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -