📄 fpgalutabsolutemapping.java
字号:
/* * FPGALUTMapping.java * * Created on 17 July 2003, 20:34 */package jaga.pj.circuits.fpgaft;import jaga.BitSet;import jaga.pj.circuits.*;/** <p>FPGA LUT Structure is composed of CLBs containing a LUT and an Edge Triggered D-Latch. * Genotype structure: *First nrOuts * ( bitsPerVar + 1 ) define where to get outputs from, ala VassilevMapping.<p> *The rest is divided into genes composed of three sections:<p> *<t>First 2^LUTInputs bits for the Look-Up Table. <p> *<t>Next LUTInputs * ( bitsPerVar + 1 ) bits define where to get inputs of LUT from. <p> *<t> Next bitsPerVar+1 bits define the input of the Latch. <p> * * @author mmg20 */public class FPGALUTAbsoluteMapping implements CircuitMapping { protected int nrIns, nrOuts, nrLUTIns, bitsPerVar; protected ElementDelayModel delayModel; /** Creates a new instance of FPGALUTMapping * @param ins Number of Inputs to Circuit NOT including the Clock for the Latches. * @param outs Number of Outputs to Circuit. * @param lutIns Number of Inputs to Look-Up Tables. * @param bpv Bits Per Variable, defines how many addressable CLBs there will be = 2^bpv-nrIns. * @param delMod The generator of delay values. */ public FPGALUTAbsoluteMapping(int ins, int outs, int bpv, int lutIns, ElementDelayModel delMod) { nrIns = ins; nrOuts = outs; nrLUTIns = lutIns; bitsPerVar = bpv; delayModel = delMod; } /** Takes and individual and an array of arrays of logic elements where this * individual must be instantiated. * @param individual The individual to be mapped into a circuit. * @return Array consisting of three subarrays: The first will represent * the inputs to the circuit and is where the inputs will be fed in. The second * represents the elements that are the outputs of the circuit and is where they * will be read out from. The last is an array with all the elements of the * circuit. */ public SimulatorLogicElement[][] map(BitSet individual) { //System.out.println( individual ); //D int totalIns = nrIns; // Clock is last one int bitsPerAdd = bitsPerVar + 1; // extra bit saying if LUT or Latch SimulatorLogicElement[] inputs = new SimulatorLogicElement[ totalIns ]; SimulatorLogicElement[] outputs = new SimulatorLogicElement[ nrOuts ]; SimulatorFaultyDelayLE[] elements = new SimulatorFaultyDelayLE[ 1 << bitsPerAdd ]; // last nrIns unused, middle nrIns reserved for inputs int LUTSize = 1 << nrLUTIns; int geneSize = LUTSize + ( nrLUTIns + 1 ) * bitsPerAdd; // One for D-Latch input int latchIndexOffset = 1 << bitsPerVar; int nrCLBs = latchIndexOffset - totalIns; int outputDefBlockSize = bitsPerAdd * nrOuts; // 1 - Create LUTs and Latches for( int cll = 0; cll < nrCLBs; cll++ ) { elements[ cll ] = new SimulatorLUT( individual.getBooleanChunk( outputDefBlockSize + cll * geneSize, LUTSize ), delayModel.getDelay() ); elements[ latchIndexOffset + cll ] = new SimulatorEdgeDLatch( delayModel.getDelay() ); } // 1.5 - Create Dummy units for D-Latches in input CLBs /*for( int cll = nrCLBs; cll < latchIndexOffset; cll++ ) { elements[ latchIndexOffset + cll ] = new SimulatorFaultyDelayLE( 0 ); }*/ // Now mapping these to inputs as well. // 2 - Create inputs for( int il = 0; il < totalIns - 1; il++ ) { elements[ latchIndexOffset - il - 1 ] = new SimulatorFaultyDelayLE( 0 ); inputs[ il ] = elements[ latchIndexOffset * 2 - il - 1 ] = elements[ latchIndexOffset - il - 1 ]; } elements[ latchIndexOffset - totalIns ] = elements[ latchIndexOffset * 2 - totalIns ] = elements[ 0 ]; // Map ghost C input to element 0. Before was to input 0 but this created problems with setState SimulatorFaultyDelayLE clockInput = new SimulatorFaultyDelayLE( 0 ); // 3 - Connect & Collapse all elements without inputs into single array SimulatorFaultyDelayLE[] onlyCLBs = new SimulatorFaultyDelayLE[ 2 * nrCLBs ]; int genPos = outputDefBlockSize; for( int cll = 0; cll < nrCLBs; cll++ ) { // 3.1 LUT SimulatorLogicElement[] LUTConn = new SimulatorLogicElement[ nrLUTIns ]; genPos += LUTSize; for( int il = 0; il < nrLUTIns; il++ ) { int iix = individual.bitsToInt( genPos, genPos + bitsPerAdd ); LUTConn[ il ] = elements[ iix ]; genPos += bitsPerAdd; } elements[ cll ].connect( LUTConn ); onlyCLBs[ cll ] = elements[ cll ]; // 3.2 Latch SimulatorLogicElement[] EDLConn = new SimulatorLogicElement[ 2 ]; int iix = individual.bitsToInt( genPos, genPos + bitsPerAdd ); EDLConn[ SimulatorEdgeDLatch.C ] = clockInput; EDLConn[ SimulatorEdgeDLatch.D ] = elements[ iix ]; elements[ latchIndexOffset + cll ].connect( EDLConn ); genPos += bitsPerAdd; onlyCLBs[ nrCLBs + cll ] = elements[ latchIndexOffset + cll ]; } // 5. Connect Outs for( int ol = 0; ol < nrOuts; ol++ ) { int currOut = individual.bitsToInt( ol * bitsPerAdd, ( ol + 1 ) * bitsPerAdd); outputs[ ol ] = elements[ currOut ]; } // 6. Connect Clock //elements[ latchIndexOffset - totalIns ] = clockInput; // not really necesary, will disappear anyway inputs[ totalIns - 1 ] = clockInput; // Debug - Print out everything in els and codes /* for( int el = 0; el < elements.length; el++ ) //onlyCLBs { SimulatorLogicElement currEl = elements[ el ];//onlyCLBs String story = "el " + el + "=" + currEl; if( currEl == null ) { story += "null"; }else { SimulatorLogicElement[] currCons = currEl.getInputs(); if( currCons == null ) { story += "unCon"; }else { for( int il = 0; il < currCons.length; il++ ) { story += " in" + il + "p=" + jaga.ESLib.indexOf( currCons[ il ], elements ); } } } System.out.println( story ); } */ SimulatorLogicElement[][] rv = { inputs, outputs, onlyCLBs }; return rv; } public void resetDelays(Object delayDef) { delayModel.set( delayDef ); } public String toString() { String rv = "FPGALUTAbsoluteMapping with:"; rv += "\n # inputs = " + nrIns; rv += "\n # outputs = " + nrOuts; rv += "\n Bits per Variable = " + bitsPerVar; rv += "\n # LUT inputs = " + nrLUTIns; rv += "\n Delay Model: " + delayModel; return rv; } /** Untested method */ public SimulatorLogicElement getElementFromAddress(SimulatorLogicElement[][] inoutels, int address) { int latchOffset = 1 << bitsPerVar; boolean latch = address > latchOffset; if( latch ) { address -= latchOffset; } if( address > ( latchOffset - nrIns ) ) { return inoutels[ INPUTS ][ latchOffset - 1 - address ]; }else { int newAddress = address; int newLatchOffset = inoutels[ ELEMENTS ].length / 2; if( latch ) { newAddress += newLatchOffset; } return inoutels[ ELEMENTS ][ newAddress ]; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -