torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Xdl2Bit.cpp File Reference

Convert an XDL to bitstream by merging the compressed bitstreams from library. More...

#include <algorithm>
#include "Xdl2Bit.h"
#include "torc/packer/Virtex5PrimitiveStructure.hpp"
#include "torc/architecture/DDB.hpp"
#include "torc/common/DirectoryTree.hpp"
#include "torc/Physical.hpp"
#include "torc/Bitstream.hpp"
#include "SharedFunctions.hpp"
+ Include dependency graph for Xdl2Bit.cpp:

Go to the source code of this file.

Functions

static std::vector< uint32_t > gLUTWordsForOne (4, 0xFFFFFFFF)
 
void convertXdlToBitstream (DesignSharedPtr inDesignPtr, Bitstream &outBitstream, const Sites &sites, const Tiles &tiles, TiletypeElementMap &library)
 
void assembleInstances (DesignSharedPtr inDesignPtr, Bitstream &outBitstream, const Sites &sites, const Tiles &tiles, TiletypeElementMap &library)
 
void assembleRambInstance (InstanceSharedPtr instance, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, TiletypeElementMap &library)
 
void assembleNets (DesignSharedPtr inDesignPtr, Bitstream &outBitstream, const Sites &sites, const Tiles &tiles, TiletypeElementMap &library)
 
VirtexFrameBlocks GetFrameBlocksFromSiteName (Bitstream &inBitstream, const std::string &siteName, const Sites &sites, const Tiles &tiles, uint32_t &outWordOffset)
 
VirtexFrameBlocks GetFrameBlocksFromTileIndex (Bitstream &inBitstream, TileIndex tileIndex, const Tiles &tiles, uint32_t &outWordOffset)
 
void checkValidityAndMergeBitstream (std::string elementName, std::string configVal, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
 
void MergeCompressedBitToMainBits (const std::vector< uint32_t > &bitAddresses, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, uint32_t blockIndex=0)
 
void mergeLutBits (const std::string &elementName, const std::string &configValue, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, ElementConfigMap &elementMap)
 
void mergeLutRamOrRomBits (const std::string &elementName, const std::string &configVal, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, TiletypeElementMap &library)
 
void mergeCompoundSettingBits (std::string element1Name, std::string config1Val, InstanceSharedPtr instancePtr, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
 
void mergeDspMaskOrPattern (std::string elementName, std::string configVal, InstanceSharedPtr instancePtr, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
 
void mergeRambInitBits (const std::string &configVal, uint32_t memoryInitRow, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, const vector< uint32_t > &bitAddresses, uint32_t block)
 
bool isLutEquationSetting (const std::string &configValue)
 
bool isLutRamOrRomSetting (const std::string &configVal)
 
bool isMemoryInitSetting (const std::string &configName)
 
bool isMemoryParityInitSetting (const std::string &configName)
 
bool siteExistsInLibrary (const std::string &siteType, TiletypeElementMap &library)
 
bool elementAndConfigExistInLibrary (const std::string &elementName, const std::string &configValue, ElementConfigMap &elementMap)
 
static TiletypeElementMap populateLibraryMap (boost::filesystem::path libDBPath)
 
int main (int argc, char **argv)
 Converts XDL file to bitstream by merging primitive bitstreams from library. More...
 
void PushFrameToStack (std::string literal)
 
void DoBinaryOperation (std::string operation)
 
bool isSiteTypeSupported (const std::string &siteType)
 
bool isRambSite (const std::string &siteType)
 

Variables

static vector< vector< uint32_t > > gStackOfFrames
 
static uint32_t gCurrentReferenceFrameIndex
 
static uint32_t gCUrrentReferenceWordIndex
 
static ConfigBitMap gcurrentConfigBitMap
 
static std::string gLUTEquationLeft
 

Detailed Description

Convert an XDL to bitstream by merging the compressed bitstreams from library.

Definition in file Xdl2Bit.cpp.

Function Documentation

void assembleInstances ( DesignSharedPtr  inDesignPtr,
Bitstream outBitstream,
const Sites sites,
const Tiles tiles,
TiletypeElementMap library 
)

Definition at line 247 of file Xdl2Bit.cpp.

248  {
249 
250  std::cout << "Going through instances..." << std::endl;
251  // Get instances begin and end
252  InstanceSharedPtrVector::const_iterator pInstance = inDesignPtr->instancesBegin();
253  InstanceSharedPtrVector::const_iterator eInstance = inDesignPtr->instancesEnd();
254 
255  // Iterate over all the instances
256  while(pInstance != eInstance) {
257 
258  InstanceSharedPtr instancePtr = *pInstance;
259  const std::string &siteType = instancePtr->getType();
260 
261  // Check if instance is placed on supported site type
262  if(isSiteTypeSupported(instancePtr->getType()) && siteExistsInLibrary(siteType, library)) {
263 
264  std::string siteName = instancePtr->getSite();
265 
266  // Get the frame set for this site
267  uint32_t wordOffset = 0;
268  VirtexFrameBlocks frameBlocks = GetFrameBlocksFromSiteName(outBitstream, siteName,
269  sites, tiles, wordOffset);
270 
271  std::cout << "Instance " << instancePtr->getName() << " placed on site "
272  << siteName << " has " << instancePtr->getConfigCount()
273  << " configs set." << std::endl;
274 
275  // RAMB sites are handled in a slightly different manner
276  if(isRambSite(siteType)) {
277  assembleRambInstance(instancePtr, outBitstream, frameBlocks,
278  wordOffset, library);
279  } else {
280 
281  // Get the element to config map for the given site type
282  ElementConfigMap elementMap = library[siteType];
283 
284  // Go over all the configurations of the instance
285  ConfigMap::const_iterator pConfig = instancePtr->configBegin();
286  ConfigMap::const_iterator eConfig = instancePtr->configEnd();
287 
288  while(pConfig != eConfig) {
289 
290  std::cout << "\tWorking on config " << pConfig->first << "::"
291  << pConfig->second.getValue() << std::endl;
292  // Lut equation has to be handled differently from other config setting.
293  // The boolean operation in the LUT equation have to be performed on the relevant bits.
294  if(isLutEquationSetting(pConfig->second.getValue())) {
295  mergeLutBits(pConfig->first, pConfig->second.getValue(), outBitstream,
296  frameBlocks, wordOffset, elementMap);
297  } // LUT ROM and RAM settings also need special care
298  else if(isLutRamOrRomSetting(pConfig->second.getValue())) {
299  mergeLutRamOrRomBits(pConfig->first,
300  pConfig->second.getValue(), outBitstream, frameBlocks, wordOffset,
301  library);
302  } // Some elements together effect the bitstream.
303  else if(elementNeedsCompoundSetting(pConfig->first)) {
304  mergeCompoundSettingBits(pConfig->first, pConfig->second.getValue(),
305  instancePtr, elementMap, frameBlocks, wordOffset, outBitstream);
306  } // The DSP MASK and PATTERN have hex values
307  else if(DSPMaskOrPatternConfig(instancePtr->getType(), pConfig->first)) {
308  mergeDspMaskOrPattern(pConfig->first, pConfig->second.getValue(),
309  instancePtr, elementMap, frameBlocks, wordOffset, outBitstream);
310  } else {
311  // Merge compressed bitstream to main bitstream if valid setting
312  checkValidityAndMergeBitstream(pConfig->first, pConfig->second.getValue(),
313  elementMap, frameBlocks, wordOffset, outBitstream);
314  }
315  std::cout << "\t------------------" << std::endl;
316  pConfig++;
317  }
318  }
319  } else {
320  std::cout << "Site " << instancePtr->getType() << " not supported." << std::endl;
321  }
322  pInstance++;
323  }
324 }
void mergeDspMaskOrPattern(std::string elementName, std::string configVal, InstanceSharedPtr instancePtr, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:725
bool siteExistsInLibrary(const std::string &siteType, TiletypeElementMap &library)
Definition: Xdl2Bit.cpp:116
bool DSPMaskOrPatternConfig(const std::string &siteType, const std::string &elementName)
void mergeCompoundSettingBits(std::string element1Name, std::string config1Val, InstanceSharedPtr instancePtr, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:686
std::string string
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
void assembleRambInstance(InstanceSharedPtr instance, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, TiletypeElementMap &library)
Definition: Xdl2Bit.cpp:328
void mergeLutBits(const std::string &elementName, const std::string &configValue, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, ElementConfigMap &elementMap)
Definition: Xdl2Bit.cpp:551
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
void mergeLutRamOrRomBits(const std::string &elementName, const std::string &configVal, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, TiletypeElementMap &library)
Definition: Xdl2Bit.cpp:628
bool isLutRamOrRomSetting(const std::string &configVal)
Definition: Xdl2Bit.cpp:104
bool isSiteTypeSupported(const std::string &siteType)
Definition: Xdl2Bit.cpp:875
bool isRambSite(const std::string &siteType)
Definition: Xdl2Bit.cpp:881
bool isLutEquationSetting(const std::string &configValue)
Definition: Xdl2Bit.cpp:100
VirtexFrameBlocks GetFrameBlocksFromSiteName(Bitstream &inBitstream, const std::string &siteName, const Sites &sites, const Tiles &tiles, uint32_t &outWordOffset)
Definition: Xdl2Bit.cpp:458
bool elementNeedsCompoundSetting(std::string elementName)
void checkValidityAndMergeBitstream(std::string elementName, std::string configVal, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:495
std::map< const std::string, ConfigBitMap > ElementConfigMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void assembleNets ( DesignSharedPtr  inDesignPtr,
Bitstream outBitstream,
const Sites sites,
const Tiles tiles,
TiletypeElementMap library 
)

Definition at line 418 of file Xdl2Bit.cpp.

419  {
420 
421  // Get the iterators to nets
422  NetSharedPtrVector::const_iterator pNets = inDesignPtr->netsBegin();
423  NetSharedPtrVector::const_iterator eNets = inDesignPtr->netsEnd();
424 
425  std::cout << "Working on NETs... count: " << inDesignPtr->getNetCount() << std::endl;
426  // Go over all the nets
427  while(pNets != eNets) {
428 
429  NetSharedPtr netPtr = *pNets;
430  std::cout << "Net: " << netPtr->getName() << std::endl;
431 
432  // Go over all the pips in the net
433  Net::PipConstIterator pPips = netPtr->pipsBegin();
434  Net::PipConstIterator ePips = netPtr->pipsEnd();
435  while(pPips != ePips) {
436 
437  // Get word offset for this tile
438  TileIndex tileIndex = tiles.findTileIndex(pPips->getTileName());
439  const TileInfo& tileInfo = tiles.getTileInfo(tileIndex);
440  std::string tileType = tiles.getTileTypeName(tileInfo.getTypeIndex());
441  uint32_t wordOffset = 0;
442  VirtexFrameBlocks frameBlocks = GetFrameBlocksFromTileIndex(outBitstream, tileIndex,
443  tiles, wordOffset);
444 
445  ElementConfigMap elementMap = library[tileType];
446  std::cout << "\tTile " << tileInfo.getName() << " Src: " << pPips->getSourceWireName()
447  << std::endl;
448  checkValidityAndMergeBitstream(pPips->getSourceWireName(), pPips->getSinkWireName(),
449  elementMap, frameBlocks, wordOffset, outBitstream);
450  pPips++;
451  }
452 
453  pNets++;
454  }
455 }
Encapsulation of a tile index in an unsigned 32-bit integer.
PipVector::const_iterator PipConstIterator
Constant iterator to Pip objects.
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
std::string string
VirtexFrameBlocks GetFrameBlocksFromTileIndex(Bitstream &inBitstream, TileIndex tileIndex, const Tiles &tiles, uint32_t &outWordOffset)
Definition: Xdl2Bit.cpp:470
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
const char * getTileTypeName(TileTypeIndex inTileTypeIndex) const
Returns the tile type name for the given tile type index.
Definition: Tiles.hpp:164
const TileTypeIndex & getTypeIndex(void) const
Returns the tile type index for this tile.
Definition: TileInfo.hpp:92
TileIndex findTileIndex(const string &inName) const
Returns the tile index for the given tile name.
Definition: Tiles.hpp:170
const char * getName(void) const
Returns the name for this tile.
Definition: TileInfo.hpp:98
void checkValidityAndMergeBitstream(std::string elementName, std::string configVal, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:495
std::map< const std::string, ConfigBitMap > ElementConfigMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void assembleRambInstance ( InstanceSharedPtr  instance,
Bitstream outBitstream,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
TiletypeElementMap library 
)

Definition at line 328 of file Xdl2Bit.cpp.

329  {
330 
331  // Get the element to config map for the given site type
332  ElementConfigMap elementMap = library[instance->getType()];
333 
334  std::cout << " Instance " << instance->getName() << " has " << instance->getConfigCount()
335  << " configs set." << std::endl;
336 
337  // Open the RAMBIT file and store data in a vector
338  // This file stores memory address to bitstream address map
339  std::string rambBitFileName = "library/memory/bram-map.bits";
340  std::ifstream rambBitFile(rambBitFileName.c_str(), std::ios::binary);
341  if(!rambBitFile.is_open()) {
342  std::cout << "Could not open file " << rambBitFileName << std::endl;
343  return;
344  }
345  std::vector<uint32_t> bitAddresses;
346  uint32_t count = 0, bitAddress = 0;
347  while(!rambBitFile.eof()) {
348  // One number is ignored.
349  rambBitFile.read((char *) &count, 4);
350  rambBitFile.read((char *) &bitAddress, 4);
351  bitAddress = ntohl(bitAddress);
352  bitAddresses.push_back(bitAddress);
353  }
354  rambBitFile.close();
355 
356  // Open the RAMB parity bit file and store the data in a vector
357  std::string rambParityBitFileName = "library/memory/bram-map-par.bits";
358  std::ifstream rambParityBitFile(rambParityBitFileName.c_str(), std::ios::binary);
359  if(!rambParityBitFile.is_open()) {
360  std::cout << "Could not open file " << rambParityBitFileName << std::endl;
361  return;
362  }
363  std::vector<uint32_t> parityBitAddresses;
364  count = 0, bitAddress = 0;
365  while(!rambParityBitFile.eof()) {
366  rambParityBitFile.read((char *) &count, 4);
367  rambParityBitFile.read((char *) &bitAddress, 4);
368  bitAddress = ntohl(bitAddress);
369  parityBitAddresses.push_back(bitAddress);
370  }
371  rambParityBitFile.close();
372 
373  // Before going over configs, merge the RAMB base bits.
374  MergeCompressedBitToMainBits(elementMap[instance->getType()]["BASE"], outBitstream,
375  frameBlocks, wordOffset);
376 
377  // Go over all the configurations of the instance
378  ConfigMap::const_iterator pConfig = instance->configBegin();
379  ConfigMap::const_iterator eConfig = instance->configEnd();
380  while(pConfig != eConfig) {
381 
382  std::cout << "\tBRAM Working on config " << pConfig->first << " value "
383  << pConfig->second.getValue() << std::endl;
384 
385  // RAMB memory and parity init values have to be handled differently.
386  // The boolean operation in the LUT equation have to be performed on the relevant bits.
387  if(isMemoryInitSetting(pConfig->first)) {
388 
389  // Get the row number from config name. Last two character are row number in hex form.
390  std::stringstream ssRow;
391  uint32_t memoryInitRow;
392  ssRow << std::hex << pConfig->first.substr(pConfig->first.length() - 2, 2);
393  ssRow >> memoryInitRow;
394 
395  mergeRambInitBits(pConfig->second.getValue(), memoryInitRow,
396  outBitstream, frameBlocks, wordOffset, bitAddresses, 1);
397  } else if(isMemoryParityInitSetting(pConfig->first)) {
398 
399  // Get the row number from config name. Last two character are row number in hex form.
400  std::stringstream ssRow;
401  uint32_t memoryInitRow;
402  ssRow << std::hex << pConfig->first.substr(pConfig->first.length() - 2, 2);
403  ssRow >> memoryInitRow;
404  mergeRambInitBits(pConfig->second.getValue(), memoryInitRow,
405  outBitstream, frameBlocks, wordOffset, parityBitAddresses, 1);
406  } else {
407  // Merge compressed bitstream to main bitstream
408  checkValidityAndMergeBitstream(pConfig->first, pConfig->second.getValue(), elementMap,
409  frameBlocks, wordOffset, outBitstream);
410  }
411  std::cout << "------------------" << std::endl;
412  pConfig++;
413  }
414 }
void MergeCompressedBitToMainBits(const std::vector< uint32_t > &bitAddresses, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, uint32_t blockIndex=0)
Definition: Xdl2Bit.cpp:518
bool isMemoryParityInitSetting(const std::string &configName)
Definition: Xdl2Bit.cpp:112
void mergeRambInitBits(const std::string &configVal, uint32_t memoryInitRow, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, const vector< uint32_t > &bitAddresses, uint32_t block)
Definition: Xdl2Bit.cpp:753
std::string string
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
bool isMemoryInitSetting(const std::string &configName)
Definition: Xdl2Bit.cpp:108
void checkValidityAndMergeBitstream(std::string elementName, std::string configVal, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:495
std::map< const std::string, ConfigBitMap > ElementConfigMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void checkValidityAndMergeBitstream ( std::string  elementName,
std::string  configVal,
const ElementConfigMap elementMap,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
Bitstream outBitstream 
)

Definition at line 495 of file Xdl2Bit.cpp.

497  {
498 
499  ElementConfigMap::const_iterator elementIter = elementMap.find(elementName);
500  // If element found in the map
501  if(elementIter != elementMap.end()) {
502  ConfigBitMap::const_iterator configIter = elementIter->second.find(configVal);
503  //If config value found in the config to bit map
504  if(configIter != elementIter->second.end()) {
505  MergeCompressedBitToMainBits(configIter->second, outBitstream, frameBlocks, wordOffset,
506  0);
507  } else {
508  std::cout << "Config " << configVal << " for element " << elementName
509  << " not found in library." << std::endl;
510  }
511  } else {
512  std::cout << "Element " << elementName << " not found in library." << std::endl;
513  }
514 }
void MergeCompressedBitToMainBits(const std::vector< uint32_t > &bitAddresses, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, uint32_t blockIndex=0)
Definition: Xdl2Bit.cpp:518

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void convertXdlToBitstream ( DesignSharedPtr  inDesignPtr,
Bitstream outBitstream,
const Sites sites,
const Tiles tiles,
TiletypeElementMap library 
)

Definition at line 230 of file Xdl2Bit.cpp.

231  {
232 
233  assembleInstances(inDesignPtr, outBitstream, sites, tiles, library);
234 
235  assembleNets(inDesignPtr, outBitstream, sites, tiles, library);
236 
237  // Update the frame words in packets
238  Virtex5 *virtexBitstreamPtr = dynamic_cast<Virtex5 *>(&outBitstream);
239  if(virtexBitstreamPtr) {
240  virtexBitstreamPtr->updateFullFrameBlocks();
241  }
242 
243 }
void assembleInstances(DesignSharedPtr inDesignPtr, Bitstream &outBitstream, const Sites &sites, const Tiles &tiles, TiletypeElementMap &library)
Definition: Xdl2Bit.cpp:247
void assembleNets(DesignSharedPtr inDesignPtr, Bitstream &outBitstream, const Sites &sites, const Tiles &tiles, TiletypeElementMap &library)
Definition: Xdl2Bit.cpp:418
Virtex5 bitstream.
Definition: Virtex5.hpp:41
DEPRECATED void updateFullFrameBlocks(void)
Transfers frame block data into the full bitstream frame packet.
Definition: Virtex5.cpp:1025

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DoBinaryOperation ( std::string  operation)

Definition at line 817 of file Xdl2Bit.cpp.

817  {
818 
819  bool debug = false;
820 
821  if(debug) {
822  std::cout << "In DoBinaryOperation " << operation << std::endl;
823  }
824  std::vector<uint32_t> lutWords1 = gStackOfFrames.back();
825  std::vector<uint32_t> lutWordsNew;
826  gStackOfFrames.pop_back();
827  std::vector<uint32_t> lutWords2;
828  if(operation == "OR" || operation == "AND" || operation == "XOR") {
829  lutWords2 = gStackOfFrames.back();
830  gStackOfFrames.pop_back();
831  } else if(operation == "NOT") {
832  lutWords2 = gLUTWordsForOne;
833  } else {
834  cout << "Unknown operation " << operation << std::endl;
835  return;
836  }
837  std::vector<uint32_t>::const_iterator pWord1 = lutWords1.begin();
838  std::vector<uint32_t>::const_iterator eWord1 = lutWords1.end();
839  std::vector<uint32_t>::const_iterator pWord2 = lutWords2.begin();
840  std::vector<uint32_t>::const_iterator eWord2 = lutWords2.end();
841  if(operation == "OR") {
842  while(pWord1 != eWord1 && pWord2 != eWord2) {
843  lutWordsNew.push_back((*pWord1 | *pWord2));
844  pWord1++;
845  pWord2++;
846  }
847  } else if(operation == "AND") {
848  while(pWord1 != eWord1) {
849  lutWordsNew.push_back((*pWord1 & *pWord2));
850  pWord1++;
851  pWord2++;
852  }
853  } else if(operation == "XOR" || operation == "NOT") {
854  while(pWord1 != eWord1) {
855  lutWordsNew.push_back((*pWord1 ^ *pWord2));
856  pWord1++;
857  pWord2++;
858  }
859  }
860 
861  if(debug) {
862  std::cout << "LUT frames after the logic " << std::endl;
863  for(std::vector<uint32_t>::const_iterator iter = lutWordsNew.begin(); iter
864  != lutWordsNew.end(); iter++) {
865  std::cout << " " << Hex32(*iter);
866  }
867  std::cout << std::endl;
868  }
869 
870  gStackOfFrames.push_back(lutWordsNew);
871 
872 }
static vector< vector< uint32_t > > gStackOfFrames
Definition: Xdl2Bit.cpp:36
static std::vector< uint32_t > gLUTWordsForOne(4, 0xFFFFFFFF)

+ Here is the call graph for this function:

bool elementAndConfigExistInLibrary ( const std::string &  elementName,
const std::string &  configValue,
ElementConfigMap elementMap 
)

Definition at line 121 of file Xdl2Bit.cpp.

121  {
122  // Check if element exists
123  ElementConfigMap::iterator pElement = elementMap.find(elementName);
124  if(pElement != elementMap.end()) {
125 
126  // Check if config exists
127  ConfigBitMap::iterator pConfig = pElement->second.find(configValue);
128  if(pConfig != pElement->second.end())
129  return true;
130  }
131  std::cout << "Element " << elementName << " with config " << configValue << " not found in library" << std::endl;
132  return false;
133 }

+ Here is the caller graph for this function:

VirtexFrameBlocks GetFrameBlocksFromSiteName ( Bitstream inBitstream,
const std::string &  siteName,
const Sites sites,
const Tiles tiles,
uint32_t &  outWordOffset 
)

Definition at line 458 of file Xdl2Bit.cpp.

459  {
460 
461  SiteIndex siteIndex = sites.findSiteIndex(siteName);
462  const Site& site = sites.getSite(siteIndex);
463 
464  // look up the site tile index
465  TileIndex tileIndex = site.getTileIndex();
466  return GetFrameBlocksFromTileIndex(inBitstream, tileIndex, tiles, outWordOffset);
467 }
Encapsulation of a tile index in an unsigned 32-bit integer.
VirtexFrameBlocks GetFrameBlocksFromTileIndex(Bitstream &inBitstream, TileIndex tileIndex, const Tiles &tiles, uint32_t &outWordOffset)
Definition: Xdl2Bit.cpp:470
Encapsulation of a device logic site.
Definition: Site.hpp:30
SiteIndex findSiteIndex(const string &inName) const
Returns the site index for the given site name.
Definition: Sites.hpp:134
TileIndex getTileIndex(void) const
Returns the index of the containing tile.
Definition: Site.hpp:83
const Site & getSite(SiteIndex inSiteIndex) const
Returns the site for the specified index.
Definition: Sites.hpp:129
Encapsulation of a site index in an unsigned 32-bit integer.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

VirtexFrameBlocks GetFrameBlocksFromTileIndex ( Bitstream inBitstream,
TileIndex  tileIndex,
const Tiles tiles,
uint32_t &  outWordOffset 
)

Definition at line 470 of file Xdl2Bit.cpp.

471  {
472 
473  const TileInfo& tileInfo = tiles.getTileInfo(tileIndex);
474  const TileRow &tileRow = tileInfo.getRow();
475  const TileCol &tileCol = tileInfo.getCol();
476 
477  Virtex5 *virtex5BitStream = dynamic_cast<Virtex5 *> (&inBitstream);
478  uint32_t bitIndexBegin = 0, bitIndexEnd = 0;
479  uint32_t primaryXdlCol = virtex5BitStream->getPrimaryXdlColumn(tileCol);
480  VirtexFrameBlocks returnFrameBlocks = virtex5BitStream->getXdlFrames(tileRow, primaryXdlCol,
481  bitIndexBegin, bitIndexEnd);
482 
483  // Each frame covers the full height of clock region which contains many rows of tiles.
484  // The library contains configuration bits only for the first row. So the word index has to
485  // be offset to reach the correct row. The bit index remains same across rows.
486  outWordOffset = 0;
487  if(bitIndexBegin != bitIndexEnd) {
488  outWordOffset = Virtex5::eFrameLength - (bitIndexEnd >> 5); // eFrameLength is number of words in a frame
489  }
490 
491  return returnFrameBlocks;
492 }
const TileCol & getCol(void) const
Returns the column for this tile.
Definition: TileInfo.hpp:96
Encapsulation of a tile row in an unsigned 16-bit integer.
const TileRow & getRow(void) const
Returns the row for this tile.
Definition: TileInfo.hpp:94
Encapsulation of a tile column in an unsigned 16-bit integer.
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
Virtex5 bitstream.
Definition: Virtex5.hpp:41
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
VirtexFrameBlocks getXdlFrames(uint32_t inXdlRow, uint32_t inXdlCol, uint32_t &outBeginBit, uint32_t &outEndBit, uint32_t inBlockCount=eBlockTypeCount)
Returns frames for specified XDL tile coordinates. inXldRow The XDL row coordinate. inXdlCol The XDL column coordinate. outBeginBit The bit index of the beginning of the requested tile. outEndBit The bit index of the end of the requested tile. inBlockCount The highest block type requested (8 for Xilinx architectures).
Definition: Virtex5.cpp:1091
uint32_t getPrimaryXdlColumn(uint32_t inXdlCol)
Returns the primary column corresponding to the given column. If immediately to the left of a BRAM...
Definition: Virtex5.cpp:1176

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static std::vector<uint32_t> gLUTWordsForOne ( ,
0xFFFFFFFF   
)
static

+ Here is the caller graph for this function:

bool isLutEquationSetting ( const std::string &  configValue)

Definition at line 100 of file Xdl2Bit.cpp.

100  {
101  return regex_match(configValue, kLUTConfigRegEx);
102 }

+ Here is the caller graph for this function:

bool isLutRamOrRomSetting ( const std::string &  configVal)

Definition at line 104 of file Xdl2Bit.cpp.

104  {
105  return regex_match(configVal, kLUTRAMorROMConfigRegEx);
106 }

+ Here is the caller graph for this function:

bool isMemoryInitSetting ( const std::string &  configName)

Definition at line 108 of file Xdl2Bit.cpp.

108  {
109  return configName.length() == 7 && configName.substr(0, 5).compare("INIT_") == 0;
110 }

+ Here is the caller graph for this function:

bool isMemoryParityInitSetting ( const std::string &  configName)

Definition at line 112 of file Xdl2Bit.cpp.

112  {
113  return configName.substr(0, 6).compare("INITP_") == 0;
114 }

+ Here is the caller graph for this function:

bool isRambSite ( const std::string &  siteType)

Definition at line 881 of file Xdl2Bit.cpp.

881  {
882  if(siteType.length() > 3) {
883  return siteType.substr(0, 4).compare("RAMB") == 0;
884  }
885  return false;
886 }

+ Here is the caller graph for this function:

bool isSiteTypeSupported ( const std::string &  siteType)

Definition at line 875 of file Xdl2Bit.cpp.

875  {
876  return (siteType.compare("SLICEL") == 0 || siteType.compare("SLICEM") == 0 || siteType.compare(
877  "RAMB36_EXP") == 0 || siteType.compare("DSP48E") == 0);
878 }

+ Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Converts XDL file to bitstream by merging primitive bitstreams from library.

Definition at line 139 of file Xdl2Bit.cpp.

139  {
140 
141  if(argc != 3) {
142  std::cerr << "Usage: " << argv[0] << " <XDL file path> <library path>" << std::endl;
143  return -1;
144  }
145 
146  // Initialize the DirectoryTree class
147  torc::common::DirectoryTree directoryTree(argv[0]);
148 
149  // Open the XDL file and check if it opens successfully
150  std::string xdlFileName(argv[1]);
151  std::fstream xdlFileStream(xdlFileName.c_str());
152  if(!xdlFileStream.good()) {
153  std::cout << "Could not open file " << xdlFileName << std::endl;
154  return -1;
155  }
156 
157  // Check if the library path exists
158  boost::filesystem::path libraryPath(argv[2]);
159  if(!boost::filesystem::exists(libraryPath)) {
160  std::cout << "Library folder - " << libraryPath.string() << " - does not exist "
161  << std::endl;
162  return -1;
163  }
164 
165  // This map holds which elements have compound setting
167 
168  // Import the XDL file
170  importer(xdlFileStream, xdlFileName);
171  // Get the design pointer
172  DesignSharedPtr designPtr = importer.getDesignPtr();
173  // Get the part number
174  std::string partNumber = designPtr->getDevice();
175  // Open the database and get sites and tiles
176  DDB ddb(partNumber);
177 
178  const Sites &sites = ddb.getSites();
179  const Tiles &tiles = ddb.getTiles();
180 
181  // Get null bitstream file path
182  boost::filesystem::path nullBTPath = libraryPath / "null_bitstreams";
183  std::string nullBitFileName = partNumber + ".bit";
184  nullBTPath = nullBTPath / nullBitFileName;
185  if(!boost::filesystem::exists(nullBTPath)) {
186  std::cout << "Null bitstream file - " << nullBTPath.string() << " - does not exist."
187  << std::endl;
188  return -1;
189  }
190 
191  // Get the compressed bitstreams library database file path
192  std::string libDBFileName = ddb.getFamilyName() + ".ldb";
193  boost::filesystem::path libDBPath = libraryPath / libDBFileName;
194  if(!boost::filesystem::exists(libDBPath)) {
195  std::cout << "Library database file - " << libDBPath.string() << " - does not exist."
196  << std::endl;
197  return -1;
198  }
199 
200  // Populate map data structure from the library database
201  TiletypeElementMap library = populateLibraryMap(libDBPath);
202 
203  // Open a NULL bitstream of the Device
204  std::ifstream nullBitstream;
205  nullBitstream.open(nullBTPath.string().c_str());
206 
207  Virtex5 bitstream;
208  bitstream.read(nullBitstream);
209  bitstream.setDesignName(designPtr->getName());
210  bitstream.initializeDeviceInfo(bitstream.getDeviceName());
211  bitstream.initializeFrameMaps();
212  bitstream.initializeFullFrameBlocks();
213 
214  // Go over the XDL and merge the required bits to bitstream
215  convertXdlToBitstream(designPtr, bitstream, sites, tiles, library);
216 
217  // Write the bitstream to a file.
218  std::string customBitstreamPath =
219  boost::filesystem::path(xdlFileName).replace_extension().string() + ".custom.bit";
220  std::ofstream customBitstreamFile(customBitstreamPath.c_str(), std::ios::binary);
221  std::cout << "Writing custom bitstream file " << customBitstreamPath << std::endl;
222  bitstream.write(customBitstreamFile);
223 
224  xdlFileStream.close();
225  customBitstreamFile.close();
226  return 0;
227 }
virtual void initializeFrameMaps(void)
Initialize the maps between frame indexes and frame addresses.
Definition: Virtex5.cpp:528
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
DesignSharedPtr getDesignPtr(void)
Returns a shared pointer for the design.
const string & getDeviceName(void) const
Return the device name.
void convertXdlToBitstream(DesignSharedPtr inDesignPtr, Bitstream &outBitstream, const Sites &sites, const Tiles &tiles, TiletypeElementMap &library)
Definition: Xdl2Bit.cpp:230
void InitializeCompoundSettingsMap()
std::string string
Virtex5 bitstream.
Definition: Virtex5.hpp:41
void setDesignName(const string &inDesignName)
Set the design name.
Site type and population data for the family and the device.
Definition: Sites.hpp:45
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
const Array< const Site > & getSites(void) const
Returns the sites for this family.
Definition: Sites.hpp:127
Encapsulation of filesystem paths that are used by the library.
boost::filesystem::path path
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
std::map< const std::string, ElementConfigMap > TiletypeElementMap
DEPRECATED void initializeFullFrameBlocks(void)
Loads full bitstream frames into block data structure.
Definition: Virtex5.cpp:1004
void write(std::ostream &inStream, uint8_t inVal)
Write a uint8_t to the stream.
Importer from XDL format into a physical design.
virtual void read(std::istream &inStream, bool inCleanDateAndTime=true)
Read the bitstream header and packets from a stream.
static TiletypeElementMap populateLibraryMap(boost::filesystem::path libDBPath)
Definition: Xdl2Bit.cpp:888
virtual void initializeDeviceInfo(const std::string &inDeviceName)
Initialize the device information.
Definition: Virtex5.cpp:412

+ Here is the call graph for this function:

void mergeCompoundSettingBits ( std::string  element1Name,
std::string  config1Val,
InstanceSharedPtr  instancePtr,
const ElementConfigMap elementMap,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
Bitstream outBitstream 
)

Definition at line 686 of file Xdl2Bit.cpp.

688  {
689 
690  std::vector<std::string> compoundElements = gCompoundSettingsMap[element1Name];
691  // For now assume there is only on element in the vector, i.e. there is a compound
692  // setting with only two elements.
693  if(compoundElements.size() != 1) {
694  std::cout << "Compound setting with more than two elements not handled currently"
695  << std::endl;
696  } else {
697 
698  std::cout << "\tIt is a compound setting." << std::endl;
699 
700  // The two element names will be concatenated to form a compound element name Element1Element2.
701  // Similarly two config settings will be concatenated to form a compound config name.
702  std::string element2Name = compoundElements[0];
703  std::string compoundElementName = element1Name + element2Name;
704 
705  // Find the 2nd element config in the instance
706  std::string config2Val, config2Name;
707  instancePtr->getConfig(element2Name, config2Name, config2Val);
708 
709  // Element 2 config not set
710  if(config2Val.compare(kConfigOff) == 0) {
711  std::cout << "Illegal configuration. Element " << element2Name << " must be set "
712  << " along with element " << element1Name << std::endl;
713  return;
714  }
715 
716  // Get compound config val
717  std::string compoundConfigVal = config1Val + config2Val;
718 
719  // Verify setting and merge bits
720  checkValidityAndMergeBitstream(compoundElementName, compoundConfigVal, elementMap,
721  frameBlocks, wordOffset, outBitstream);
722  }
723 }
const std::string kConfigOff
std::string string
CompoundSettingMap gCompoundSettingsMap
void checkValidityAndMergeBitstream(std::string elementName, std::string configVal, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:495

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MergeCompressedBitToMainBits ( const std::vector< uint32_t > &  bitAddresses,
Bitstream outBitstream,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
uint32_t  blockIndex = 0 
)

Definition at line 518 of file Xdl2Bit.cpp.

520  {
521 
522  int32_t numSetBits = bitAddresses.size();
523  std::cout << "\tNumber of bits set: " << numSetBits << std::endl;
524 
525  VirtexFrameSet& frameSet = frameBlocks.mBlock[blockIndex];
526  if(!frameSet.empty()) {
527  for(int i = 0; i < numSetBits; i++) {
528  uint32_t bitAddr = bitAddresses[i];
529  int32_t bitIndex = bitAddr & 0x000000FF; // get the lowest byte
530  int32_t wordIndex = (bitAddr & 0x0000FF00) >> 8;
531  // Library setting is for first row of clock region. Word index has to be offset to reach the correct row.
532  wordIndex += wordOffset;
533  int32_t frameIndex = (bitAddr & 0xFFFF0000) >> 16;
534  std::cout << "\t Frame: " << Hex32(frameIndex) << " Word: " << Hex32(wordIndex)
535  << " bit: " << Hex32(bitIndex) << std::endl;
536  VirtexFrameSharedPtr virtexFrame = frameSet[frameIndex];
537 
538  VirtexFrame::word_t currentWord = virtexFrame->getWords()[wordIndex];
539  VirtexFrame::word_t word = (1 << (bitIndex)) | currentWord;
540  virtexFrame->setWord(wordIndex, word);
541 
542  }
543  } else {
544  std::cout << "Unknown frame type." << std::endl;
545  }
546 
547 }
FrameSet< FRAME_TYPE > mBlock[Bitstream::eBlockTypeCount]
FrameSets for each of the eight block types.
Definition: FrameSet.hpp:88
boost::shared_ptr< VirtexFrame > VirtexFrameSharedPtr
Virtex frame type.
Definition: Frame.hpp:108
WORD_TYPE word_t
Frame word type.
Definition: Frame.hpp:48

+ Here is the caller graph for this function:

void mergeDspMaskOrPattern ( std::string  elementName,
std::string  configVal,
InstanceSharedPtr  instancePtr,
const ElementConfigMap elementMap,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
Bitstream outBitstream 
)

Definition at line 725 of file Xdl2Bit.cpp.

727  {
728 
729  std::vector<uint32_t> bitAddresses;
730 
731  // Go over all the characters of the config val string
732  for(uint32_t charIndex = 0; charIndex < configVal.length(); charIndex++) {
733  std::stringstream sshexChar;
734  sshexChar << std::hex << configVal[configVal.length() - charIndex - 1];
735  uint32_t hexDigit;
736  sshexChar >> hexDigit;
737  // Go over all the bits of the hex digit
738  for(int bitIndex = 0; hexDigit != 0; bitIndex++) {
739  if(hexDigit & 1) {
740  int configBitIndex = (charIndex << 2) + bitIndex;
741  std::stringstream ssConfigBitIndex;
742  ssConfigBitIndex << configBitIndex;
743  checkValidityAndMergeBitstream(elementName, ssConfigBitIndex.str(), elementMap,
744  frameBlocks, wordOffset, outBitstream);
745  }
746  hexDigit = hexDigit >> 1;
747  }
748  }
749 }
void checkValidityAndMergeBitstream(std::string elementName, std::string configVal, const ElementConfigMap &elementMap, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, Bitstream &outBitstream)
Definition: Xdl2Bit.cpp:495

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mergeLutBits ( const std::string &  elementName,
const std::string &  configValue,
Bitstream outBitstream,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
ElementConfigMap elementMap 
)

Definition at line 551 of file Xdl2Bit.cpp.

553  {
554 
555  // Get the right hand side and lefthand side of the LUT equation.
556  std::vector<std::string> splitVector;
557  boost::algorithm::split(splitVector, configValue, boost::algorithm::is_any_of("="));
558 
559  // The left side tell which output (O5 or O6) is being affected. Store it in a global
560  // so that it can be used by functions called from bison
561  gLUTEquationLeft = splitVector[0];
562  std::string equationRight = splitVector[1];
563 
564  // Store the frames for LUT setting constant 1. XOR with these frames give NOT functionality.
565  std::string lutEquationForOne = gLUTEquationLeft + "=1";
566 
567  // Currently all the frames of a LUT setting are not stored. We know only 4 words get affected by LUT setting -
568  // 4 frames and a word in each frame. So instead we store only 4 words and the frame index and word index.
569  if(elementAndConfigExistInLibrary(elementName, lutEquationForOne, elementMap)) {
570  gcurrentConfigBitMap = elementMap[elementName];
571  std::vector<uint32_t> bitAddressesForOne = gcurrentConfigBitMap[lutEquationForOne];
572 
573  gCurrentReferenceFrameIndex = bitAddressesForOne[0] >> 16;
574  gCUrrentReferenceWordIndex = (bitAddressesForOne[0] & 0x0000FF00) >> 8;
575 
576  gLUTWordsForOne.clear();
577  gLUTWordsForOne.resize(4, uint32_t(0));
578  for(std::vector<uint32_t>::const_iterator bitIter = bitAddressesForOne.begin(); bitIter
579  != bitAddressesForOne.end(); bitIter++) {
580  int32_t bitIndex = (*bitIter) & 0x000000FF;
581  int32_t frameIndex = (*bitIter) >> 16;
582  uint32_t frameWord = 1 << (bitIndex - 1);
583 
585  - gCurrentReferenceFrameIndex] | frameWord;
586  }
587 
588  // Set the string to be scanned
589  yy_scan_string(equationRight.c_str());
590  // Call the Bison parse function
591  int parseResult = yyparse();
592 
593  if(parseResult != 0) {
594  std::cout << "Error in parsing LUT equation " << configValue << std::endl;
595  exit(-1);
596  }
597 
598  // Build bit addresses out of the last frame in gStackOfFrames
599  std::vector<uint32_t> combinedLUTWords = gStackOfFrames[0];
600  std::vector<uint32_t> bitAddresses;
601  uint32_t frameOffset = 0;
602  for(std::vector<uint32_t>::const_iterator wordIter = combinedLUTWords.begin(); wordIter
603  != combinedLUTWords.end(); wordIter++, frameOffset++) {
604 
605  uint32_t tempWord = *wordIter;
606  uint32_t bitIndex = 1;
607  while(tempWord != 0) {
608 
609  // check if the LSB is 1
610  if(tempWord & 1) {
611  // store the combined address
612  bitAddresses.push_back(((gCurrentReferenceFrameIndex + frameOffset) << 16)
613  | (gCUrrentReferenceWordIndex << 8) | bitIndex);
614  }
615  tempWord = tempWord >> 1;
616  bitIndex++;
617  }
618  }
619 
620  MergeCompressedBitToMainBits(bitAddresses, outBitstream, frameBlocks, wordOffset);
621  gStackOfFrames.clear();
622  }
623 }
void MergeCompressedBitToMainBits(const std::vector< uint32_t > &bitAddresses, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, uint32_t blockIndex=0)
Definition: Xdl2Bit.cpp:518
static vector< vector< uint32_t > > gStackOfFrames
Definition: Xdl2Bit.cpp:36
static std::string gLUTEquationLeft
Definition: Xdl2Bit.cpp:42
static ConfigBitMap gcurrentConfigBitMap
Definition: Xdl2Bit.cpp:41
static uint32_t gCUrrentReferenceWordIndex
Definition: Xdl2Bit.cpp:38
std::string string
static uint32_t gCurrentReferenceFrameIndex
Definition: Xdl2Bit.cpp:37
static std::vector< uint32_t > gLUTWordsForOne(4, 0xFFFFFFFF)
bool elementAndConfigExistInLibrary(const std::string &elementName, const std::string &configValue, ElementConfigMap &elementMap)
Definition: Xdl2Bit.cpp:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mergeLutRamOrRomBits ( const std::string &  elementName,
const std::string &  configVal,
Bitstream outBitstream,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
TiletypeElementMap library 
)

Definition at line 628 of file Xdl2Bit.cpp.

630  {
631 
632  // Since memory content are similar for SLICEL and SLICEM,
633  // they are stored in library under element name SLICE
634  ElementConfigMap &elementMap = library["SLICE"];
635 
636  // Get the right hand side and lefthand side of the LUT equation.
637  std::vector<std::string> splitVector;
638  boost::algorithm::split(splitVector, configVal, boost::algorithm::is_any_of("="));
639  // Remove the first two characters - 0x - from the hex value
640  std::string memoryValue = splitVector[1].substr(2);
641 
642  if(memoryValue.length() != 8 && memoryValue.length() != 16) {
643  std::cout << "Error: Illegal configuration of element " << elementName << std::endl;
644  return;
645  }
646 
647  // When output O5 of LUT is configured, it has only 8 hex characters in the memory string,
648  // and they belong to the higher memory address of 16 hex characters.
649  if(memoryValue.length() == 8) {
650  memoryValue = "00000000" + memoryValue;
651  }
652 
653  // Get the bit address vector
654  // Since X5LUT and X6LUT use the same memory address to bit address map,
655  // element name is changed to use only 1st letter of the name, viz X (A, B, C or D)
656  // and config name is changed to ROM
657  std::string elementNameForMemoryMode = elementName.substr(0, 1);
658  std::vector<uint32_t> bitAddressesForROM;
659 
660  if(!elementAndConfigExistInLibrary(elementNameForMemoryMode, "ROM", elementMap))
661  return;
662 
663  bitAddressesForROM = elementMap[elementNameForMemoryMode]["ROM"];
664  std::vector<uint32_t> bitAddresses;
665  // Iterate over the memory string from left to right
666  for(uint32_t charIndex = 0; charIndex < memoryValue.length(); charIndex++) {
667 
668  std::stringstream sshexChar;
669  sshexChar << std::hex << memoryValue[charIndex];
670  uint32_t hexDigit;
671  sshexChar >> hexDigit;
672  // Go over the bits of the hex digit from left to right
673  for(int bitIndex = 0; hexDigit != 0; bitIndex++) {
674  if(hexDigit & 8) {
675  uint32_t memoryAddress = (charIndex << 2) + bitIndex;
676  std::stringstream ssConfigBitIndex;
677  ssConfigBitIndex << memoryAddress;
678  bitAddresses.push_back(bitAddressesForROM[memoryAddress]);
679  }
680  hexDigit = hexDigit << 1;
681  }
682  }
683  MergeCompressedBitToMainBits(bitAddresses, outBitstream, frameBlocks, wordOffset, 0);
684 }
void MergeCompressedBitToMainBits(const std::vector< uint32_t > &bitAddresses, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, uint32_t blockIndex=0)
Definition: Xdl2Bit.cpp:518
std::string string
bool elementAndConfigExistInLibrary(const std::string &elementName, const std::string &configValue, ElementConfigMap &elementMap)
Definition: Xdl2Bit.cpp:121
std::map< const std::string, ConfigBitMap > ElementConfigMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mergeRambInitBits ( const std::string &  configVal,
uint32_t  memoryInitRow,
Bitstream outBitstream,
VirtexFrameBlocks frameBlocks,
uint32_t  wordOffset,
const vector< uint32_t > &  bitAddresses,
uint32_t  block 
)

Definition at line 753 of file Xdl2Bit.cpp.

755  {
756 
757  vector<uint32_t> bitAddresses; // vector to hold bit addresses of set memory bits
758 
759  uint32_t configValLength = configVal.length();
760  uint32_t numBitsPerConfig = configValLength << 2; // 4 bits every hex character
761 
762  // Go over the memory string from right to left
763  for(uint32_t charIndex = 0; charIndex < configValLength; charIndex++) {
764  std::stringstream sshexChar;
765  sshexChar << std::hex << configVal[configValLength - charIndex - 1];
766  uint32_t hexDigit;
767  sshexChar >> hexDigit;
768  // Go over the bits of hex digit from right to left
769  for(int bitIndex = 0; hexDigit != 0; bitIndex++) {
770  if(hexDigit & 1) {
771  // Get memory address of set bit taking into account which row of memory is being processed
772  uint32_t configBitIndex = (charIndex << 2) + bitIndex;
773  uint32_t memoryAddress = memoryInitRow * numBitsPerConfig + configBitIndex;
774 
775  bitAddresses.push_back(ramBitAddress[memoryAddress]);
776  }
777  hexDigit = hexDigit >> 1;
778  }
779  }
780  MergeCompressedBitToMainBits(bitAddresses, outBitstream, frameBlocks, wordOffset, block);
781 }
void MergeCompressedBitToMainBits(const std::vector< uint32_t > &bitAddresses, Bitstream &outBitstream, VirtexFrameBlocks &frameBlocks, uint32_t wordOffset, uint32_t blockIndex=0)
Definition: Xdl2Bit.cpp:518

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static TiletypeElementMap populateLibraryMap ( boost::filesystem::path  libDBPath)
static

Definition at line 888 of file Xdl2Bit.cpp.

888  {
889 
890  TiletypeElementMap tileMap;
891  std::ifstream libDB(libDBPath.string().c_str(), std::ios::binary);
892  if(!libDB.good()) {
893  std::cout << "Could not open DB file " << libDBPath.string() << std::endl;
894  libDB.exceptions(std::ios::failbit);
895  exit(-1);
896  }
897  std::cout << "Opened DB file " << libDBPath.string() << std::endl;
898  char buffer[1024];
899  libDB.read(buffer, 16);
900  buffer[16] = '\0';
901  std::string libDBSanity(buffer);
902  std::cout << "Sanity string " << libDBSanity << std::endl;
903  if(libDBSanity != "<<<<BITLIBDB>>>>") {
904  std::cout << "This file seems to be currupt- " << libDBPath.string() << std::endl;
905  exit(-1);
906  }
907  uint32_t tileTypeCount = 0;
908  libDB.read((char *) &tileTypeCount, sizeof(uint32_t));
909  std::cout << "Tile type count " << tileTypeCount << std::endl;
910  for(uint32_t tileIndex = 0; tileIndex < tileTypeCount; tileIndex++) {
911  uint32_t tileNameCharCount = 0;
912  libDB.read((char *) &tileNameCharCount, 4);
913  libDB.read(buffer, tileNameCharCount);
914  buffer[tileNameCharCount] = '\0';
915  std::string tileType(buffer);
916  uint32_t elementCount = 0;
917  libDB.read((char *) &elementCount, 4);
918  // std::cout << "Tile type " << tileType << ". Element count " << elementCount << std::endl;
919 
920  ElementConfigMap elementMap;
921 
922  // Iterate over the elements
923  for(uint32_t elementIndex = 0; elementIndex < elementCount; elementIndex++) {
924  // Get element name char count
925  uint32_t elementCharCount = 0;
926  libDB.read((char *) &elementCharCount, 4);
927  libDB.read(buffer, elementCharCount);
928  buffer[elementCharCount] = '\0';
929  std::string element(buffer);
930 
931  uint32_t configCount = 0;
932  libDB.read((char *) &configCount, 4);
933 
934  // std::cout << " Element " << element << ". Config count " << configCount << std::endl;
935 
936  ConfigBitMap configMap;
937 
938  // Iterate over configs
939  for(uint32_t configIndex = 0; configIndex < configCount; configIndex++) {
940  uint32_t configCharCount = 0;
941  libDB.read((char *) &configCharCount, 4);
942  // std::cout << "\tConfig char count " << configCharCount;
943  libDB.read(buffer, configCharCount);
944  buffer[configCharCount] = '\0';
945  std::string config(buffer);
946  // std::cout << "\t" << config << std::endl;
947 
948  // Read the compressed word count
949  uint32_t wordCount = 0;
950  libDB.read((char *) &wordCount, 4);
951  std::vector<uint32_t> words;
952  uint32_t word;
953  for(uint32_t i = 0; i < wordCount; i++) {
954  libDB.read((char *) &word, 4);
955 
956  words.push_back(word);
957  }
958  configMap[config] = words;
959  }
960  elementMap[element] = configMap;
961 
962  }
963  tileMap[tileType] = elementMap;
964 
965  }
966  return tileMap;
967 }
std::string string
std::map< const std::string, std::vector< uint32_t > > ConfigBitMap
std::map< const std::string, ElementConfigMap > TiletypeElementMap
std::map< const std::string, ConfigBitMap > ElementConfigMap

+ Here is the caller graph for this function:

void PushFrameToStack ( std::string  literal)

Definition at line 784 of file Xdl2Bit.cpp.

784  {
785 
786  bool debug = false;
787 
788  if(debug) {
789  std::cout << "In PushFrameToStack " << literal << std::endl;
790  }
791 
792  std::vector<uint32_t> bitAddresses = gcurrentConfigBitMap[gLUTEquationLeft + "=" + literal];
793 
794  // We know LUT bits go across 4 frames and effect the same word in each frame
795  std::vector<uint32_t> lutWords(4, 0);
796  for(std::vector<uint32_t>::const_iterator bitIter = bitAddresses.begin(); bitIter
797  != bitAddresses.end(); bitIter++) {
798  int32_t bitIndex = (*bitIter) & 0x000000FF;
799  int32_t frameIndex = (*bitIter) >> 16;
800  uint32_t frameWord = 1 << (bitIndex - 1);
801 
802  lutWords[frameIndex - gCurrentReferenceFrameIndex] = lutWords[frameIndex
803  - gCurrentReferenceFrameIndex] | frameWord;
804  }
805 
806  if(debug) {
807  for(std::vector<uint32_t>::const_iterator iter = lutWords.begin(); iter != lutWords.end(); iter++) {
808  std::cout << " " << Hex32(*iter);
809  }
810  std::cout << std::endl;
811  }
812 
813  gStackOfFrames.push_back(lutWords);
814 
815 }
static vector< vector< uint32_t > > gStackOfFrames
Definition: Xdl2Bit.cpp:36
static std::string gLUTEquationLeft
Definition: Xdl2Bit.cpp:42
static ConfigBitMap gcurrentConfigBitMap
Definition: Xdl2Bit.cpp:41
static uint32_t gCurrentReferenceFrameIndex
Definition: Xdl2Bit.cpp:37
bool siteExistsInLibrary ( const std::string &  siteType,
TiletypeElementMap library 
)

Definition at line 116 of file Xdl2Bit.cpp.

116  {
117  TiletypeElementMap::iterator pLibrary = library.find(siteType);
118  return (pLibrary != library.end());
119 }

+ Here is the caller graph for this function:

Variable Documentation

ConfigBitMap gcurrentConfigBitMap
static

Definition at line 41 of file Xdl2Bit.cpp.

uint32_t gCurrentReferenceFrameIndex
static

Definition at line 37 of file Xdl2Bit.cpp.

uint32_t gCUrrentReferenceWordIndex
static

Definition at line 38 of file Xdl2Bit.cpp.

std::string gLUTEquationLeft
static

Definition at line 42 of file Xdl2Bit.cpp.

vector<vector<uint32_t> > gStackOfFrames
static

Definition at line 36 of file Xdl2Bit.cpp.