⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memoryblock.java

📁 一种将c高级语言转化给VHDL的编译器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * LA-CC 05-135 Trident 0.7.1Copyright NoticeCopyright 2006 (c) the Regents of the University of California.This Software was produced under a U.S. Government contract(W-7405-ENG-36) by Los Alamos National Laboratory, which is operatedby the University of California for the U.S. Department of Energy. TheU.S. Government is licensed to use, reproduce, and distribute thisSoftware. Permission is granted to the public to copy and use thisSoftware without charge, provided that this Notice and any statementof authorship are reproduced on all copies. Neither the Government northe University makes any warranty, express or implied, or assumes anyliability or responsibility for the user of this Software. */package fp.hardware;import java.util.*;import fp.flowgraph.*;/** This class saves information about memories on the target FPGA including * their sizes and which arrays have been allocated to them. *  * @author Kris Peterson */public class MemoryBlock{  private HashMap _infoOnArrays;    /** ROM flag   */  private boolean _isROM;  /** only one address flag   */  private boolean _onlyOneAddy;  /** size of memory words in bits   */  private int _wordSize;  /** read latency of memory   */  private float _initReadLatency;  /** time between pipelined reads   */  private float _normalReadLatency;  /** write latency of memory   */  private float _initWriteLatency;  /** time between pipelined writes   */  private float _normalWriteLatency;  /** total size of memory bits   */  private int _memSize;  private int _totMemSizeLeft;     /** number of read data ports   */  private int _numOfReadBus;  /** number of write data ports   */  private int _numOfWriteBus;    /** variable used by bus count methods, see below   */  private int _index;  /** for saving number of reads   */  private ArrayList _readBusUseCnts;  /** for saving number of writes   */  private ArrayList _writeBusUseCnts;     /** the following are variables used for keeping track of memory reads and   * writes at specific times.   */  private HashMap _writeIndexAtTime;  private HashMap _readIndexAtTime;  private HashMap _readBusUseCntAtTime;  private HashMap _writeBusUseCntAtTime;      /** for saving arrays and their locations   */  //private ArrayList _varSpaces;  /** for saving space left in different memory words   */  //private ArrayList _memLeftInSpace;    /** for saving array packing information   */  private ArrayList _listOfArrayVarGroupings;  private String _name;  private long _addr;    private HashSet _arraysInThisMem;  private float _highestStopAddr;  private int _stopListIndex;  private ArrayList _stopList;    public MemoryBlock() {    this(false, false, 0, 0, 0, 0, 0, 0, 0, 0);  }    /**    * The four simplest types of memories (handled by this code) can fit in these categories:   *    * true dual port, where there is a read port, a write port, a read address port, and a write address port.   * partial dual port, where there is a read port, a write port, but only one address port for both data ports.   * 1 port RAM, where there is one data port for both reads and writes   * 1 port ROM, where there is one data port, which can only be read.   *    * These special cases need to be handled differently than other memory types.  Other memory types,   * just have as many read and write buses as defined by the vars, numOfReadBus and numOfWriteBus.   *    * To recognize one of these special memory types, I use the boolean variables, isROM and onlyOneAddy.   * A memory with 1 read bus, 1 write bus, but where onlyOneAddy is true is partial dual port.   * If the sum of the number of read busses and write busses is 1 and isROM is false, then this is a   * 1 port RAM.  If the number of read busses is 1 and isROM is true, this is a 1 port ROM.   */  public MemoryBlock(boolean isROM, boolean onlyOneAddy, int wordSize,                      float initReadLatency, float normalReadLatency, 		     float initWriteLatency, float normalWriteLatency, 		     int memSize, int numOfReadBus, int numOfWriteBus) {    _infoOnArrays = new HashMap();    _isROM = isROM;    _onlyOneAddy = onlyOneAddy;    _wordSize = wordSize;    _initReadLatency = initReadLatency;    _normalReadLatency = normalReadLatency;    _initWriteLatency = initWriteLatency;    _normalWriteLatency = normalWriteLatency;    _memSize = memSize;    _totMemSizeLeft  = memSize;        //new memory stuff    _arraysInThisMem = new HashSet();    _highestStopAddr = 0;    _stopListIndex = 0;    _stopList = new ArrayList();    _stopList.add(new Float(0.0));        _numOfReadBus = numOfReadBus;    _numOfWriteBus = numOfWriteBus;        //_memLeftInSpace = new ArrayList();    //_varSpaces = new ArrayList();    //for(int i=0; i < memSize/wordSize; i++) {    //  _memLeftInSpace.add(new Integer(wordSize));    //  _varSpaces.add(new ArrayList());    //}    _listOfArrayVarGroupings = new ArrayList();    _index = 0;    _readBusUseCnts = new ArrayList();    _writeBusUseCnts = new ArrayList();    if((_onlyOneAddy && (_numOfReadBus == 1) && (_numOfWriteBus == 1))          || (_numOfReadBus + _numOfWriteBus == 1)) {      _readBusUseCnts.add(new Integer(0));    }    else {      for(int i=0;i<numOfReadBus;i++)        _readBusUseCnts.add(new Integer(0));      for(int i=0;i<numOfWriteBus;i++)        _writeBusUseCnts.add(new Integer(0));    }         _writeIndexAtTime = new HashMap();    _readIndexAtTime = new HashMap();    _readBusUseCntAtTime = new HashMap();    _writeBusUseCntAtTime = new HashMap();  }        public boolean gibtEsGenugPlatzHier(float start, float stop, int wordSize) {      int totUsedWordSize = 0;//System.out.println("start " + start + " stop " + stop + " wordSize " + wordSize);    for (Iterator its = ((HashSet)_arraysInThisMem).iterator();     	  its.hasNext(); ) {      ArrayInfo arr = (ArrayInfo)its.next();      //System.out.println("arr " + arr.getVar());      //System.out.println("arr getStart " + arr.getStart());      //System.out.println("arr getStop " + arr.getStop());      if(((arr.getStart() <= start) && (start <= arr.getStop()))||         ((arr.getStart() <= stop) && (stop <= arr.getStop())))        totUsedWordSize += arr.getWordSize();          }    //System.out.println("totUsedWordSize " + totUsedWordSize + " _wordSize " + _wordSize);    if(totUsedWordSize + wordSize > _wordSize)      return false;    else      return true;    }     public float getHighestStopAddr() {return _highestStopAddr;}  public void resetStopListIndex() {_stopListIndex=0;}  public float nextStopAddr() {    //if(_stopListIndex >= _stopList.size())    //  return 0;    Float currentStopAddr = ((Float)_stopList.get(_stopListIndex));    while(_stopList.get(_stopListIndex) == currentStopAddr)      _stopListIndex++;        return ((Float)_stopList.get(_stopListIndex)).floatValue();  }     /** Using this method, all the memory parameters can be set simultaneously.   * I've never actually used it though.  I always just use the constructor to   * do this.   *    * @param isROM is the memory a ROM?   * @param onlyOneAddy Does it only have 1 address bus?   * @param wordSize what is the word size of the memory?   * @param initReadLatency what is the initial read latency?   * @param normalReadLatency can reads be pipelined and if so, what is     *      the minimum allowed time between reads?   * @param initWriteLatency what is the initial write latency?   * @param normalWriteLatency can writes be pipelined and if so, what is   *      the minimum allowed time between writes?   * @param memSize size of memory bits   * @param numOfReadBus number of data read ports   * @param numOfWriteBus number of data write ports   */  public void setAllValues(boolean isROM, boolean onlyOneAddy, int wordSize,                            float initReadLatency, float normalReadLatency,                            float initWriteLatency, float normalWriteLatency,                            int memSize, int numOfReadBus, int numOfWriteBus) {    _isROM = isROM;    _onlyOneAddy = onlyOneAddy;    _wordSize = wordSize;    _initReadLatency = initReadLatency;    _normalReadLatency = normalReadLatency;    _initWriteLatency = initWriteLatency;    _normalWriteLatency = normalWriteLatency;    _memSize = memSize;    _numOfReadBus = numOfReadBus;    _numOfWriteBus = numOfWriteBus;  }     /** I think, the get and set methods should all be self explanatory...   */  public boolean getisROM() { return _isROM;}  public boolean getonlyOneAddy() { return _onlyOneAddy;}  public int getWordSize() { return _wordSize;}  public float getInitReadLatency() { return _initReadLatency;}  public float getNormalReadLatency() { return _normalReadLatency;}  public float getInitWriteLatency() { return _initWriteLatency;}  public float getNormalWriteLatency() { return _normalWriteLatency;}  public int getMemSize() { return _memSize;}  public int getTotMemSizeLeft() { return _totMemSizeLeft;}    public int getNumOfReadBus() { return _numOfReadBus;}  public int getNumOfWriteBus() { return _numOfWriteBus;}    /** "@param i   */  //public int getMemSizeLeft(int i) {   //  return (int)(((Integer)(_memLeftInSpace.get(i))).floatValue());  //}  //public ArrayList getVarsAtLoc(int i) { return (ArrayList)(_varSpaces.get(i));}     public void setisROM(boolean isROM) { _isROM = isROM;}  public void setonlyOneAddy(boolean onlyOneAddy) { _onlyOneAddy = onlyOneAddy;}  public void setWordSize(int wordSize) { _wordSize = wordSize;}  public void setInitReadLatency(float initLatency) {     _initReadLatency = initLatency;  }  public void setNormalReadLatency(float normalLatency) {     _normalReadLatency = normalLatency;  }  /** "@param initLatency   */  public void setInitWriteLatency(float initLatency) {     _initWriteLatency = initLatency;  }  /** "@param normalLatency   */  public void setNormalWriteLatency(float normalLatency) {     _normalWriteLatency = normalLatency;  }  /** "@param memSize   */  public void setMemSize(int memSize) { _memSize = memSize;}  public void setTotMemSizeLeft(int memSize) { _totMemSizeLeft = memSize;}     /** "@param numOfReadBus   */  public void setNumOfReadBus(int numOfReadBus) { _numOfReadBus = numOfReadBus;}  public void setNumOfWriteBus(int numOfWriteBus) {     _numOfWriteBus = numOfWriteBus;  }    //public void setMemSizeLeft(int i, int NewMemSize) {   //  _memLeftInSpace.set(i, new Integer(NewMemSize));  //}  /** "@param i   *    * @param i    * @param var_Operand    */  public HashSet getVarsInMem() { return _arraysInThisMem; }  public void saveVarLoc(float i, ArrayInfo var) {     //((ArrayList)(_varSpaces.get(i))).add(var_Operand);    _arraysInThisMem.add(var);    var.setStart(i);    _stopList.add(new Float(var.getStop()));    Collections.sort(_stopList);    _highestStopAddr = Math.max(_highestStopAddr, var.getStop());    _stopListIndex = 0;  }  public void addArrayInfo(AllocateArrays.ArrayInfo a) {    if(a != null)      _infoOnArrays.put(a.name, a);  }  public void removeArrayInfo(AllocateArrays.ArrayInfo a) {    if(a != null)       _infoOnArrays.remove(a.name);  }  public AllocateArrays.ArrayInfo getArrayInfo(String aName) {    return (AllocateArrays.ArrayInfo) _infoOnArrays.get(aName);  }  public HashMap getArrayInfos() { return _infoOnArrays; }  public String getName() { return _name; }  public void setName(String name) { _name = name; }  public void setAddressOffset(long addr) { _addr = addr; }  public long getAddressOffset() { return _addr; }       //_listOfArrayVarGroupings methods:

⌨️ 快捷键说明

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