Bitstream Interpretation Library (BIL)  0.1
CfgDecoder.cpp
Go to the documentation of this file.
1 
7 
8 using namespace bil;
9 
10 
11 void CfgDecoder::decode(CfgExtractor& extractor, const DeviceCfgDb& db,
12  const Device& device)
13 {
14  // clear out old results
15  m_pipRefs.clear();
16 
17  // cache pointers to tiles
18  const Tiles& tiles = device.tiles();
19 
20  // loop over all tile type data bases
21  const TileTypeCfgDbs& tileTypeDbs = db.tileTypeDbs();
22  size_t tileTypeDbCount = tileTypeDbs.size();
23  for (size_t i = 0; i < tileTypeDbCount; ++i)
24  {
25  // get current data base and do decoding for that tile type
26  const TileTypeCfgDb& tileTypeDb = tileTypeDbs[i];
27  decodeTileType(extractor, tileTypeDb, tiles);
28  }
29 }
30 
31 
32 void CfgDecoder::decodeTileType(CfgExtractor& extractor,
33  const TileTypeCfgDb& tileTypeDb, const Tiles& tiles)
34 {
35  // get PIP control sets for that tile type
36  const PIPControlSets& pipControlSets = tileTypeDb.pipControlSets();
37 
38  // loop over all tiles
39  size_t tileCount = tiles.size();
40  for (size_t i = 0; i < tileCount; ++i)
41  {
42  // get current tile, check its type, and gets its position
43  const Tile& tile = tiles[i];
44  if (tile.typeIndex() != tileTypeDb.typeIndex()) continue;
45  unsigned tileRow = tile.row();
46  unsigned tileColumn = tile.column();
47 
48  // get configuration data size of this tile
49  size_t dataWordCount = extractor.getDataWordCount(tileRow, tileColumn);
50  if (0 == dataWordCount) continue;
51 
52  // enlarge buffer to hold this data and copy data into it
53  if (m_buffer.size() < dataWordCount) m_buffer.resize(dataWordCount);
54  extractor.getDataWords(tileRow, tileColumn, &(m_buffer[0]), dataWordCount);
55 
56  // decode PIPs on current tile
57  decodeTilePIPs(pipControlSets, i);
58  }
59 }
60 
61 
62 void CfgDecoder::decodeTilePIPs(const PIPControlSets& pipControlSets,
63  size_t tileIndex)
64 {
65  // loop over all control sets
66  size_t pipControlSetCount = pipControlSets.size();
67  for (size_t i = 0; i < pipControlSetCount; ++i)
68  {
69  // get current control set and its sub objects
70  const PIPControlSet& pipControlSet = pipControlSets[i];
71  const BitPositions& bitPositions = pipControlSet.bitPositions();
72  const PIPBitValues& pipBitValues = pipControlSet.pipBitValues();
73 
74  // get value from configuration data consisting of all designated bits
75  boost::uint32_t cfgValue = 0;
76  size_t bitPositionCount = bitPositions.size();
77  for (size_t j = bitPositionCount; j-- > 0;)
78  {
79  // get bit position
80  size_t bitPosition = bitPositions[j];
81 
82  // get bit value on that position
83  size_t wordIndex = bitPosition >> 5;
84  boost::uint32_t wordBits = m_buffer.at(wordIndex);
85  size_t wordBitIndex = bitPosition & 0x1f;
86  wordBits = (wordBits >> wordBitIndex) & 1;
87 
88  // shift this bit into value
89  cfgValue = (cfgValue << 1) | wordBits;
90  }
91 
92  // a null value always corresponds to no PIPs
93  if (0 == cfgValue) continue;
94 
95  // search for matches of this value
96  size_t pipBitValuesCount = pipBitValues.size();
97  for (size_t j = 0; j < pipBitValuesCount; ++j)
98  {
99  // get values of all PIPs
100  const PIPBitValue& pipBitValue = pipBitValues[j];
101 
102  // compare them to extracted value
103  boost::uint32_t value = pipBitValue.bitValue();
104  if (cfgValue < value) break;
105  if (cfgValue != value) continue;
106  if (0 != (value & PIPBitValue::VALUE_UNUSED)) continue;
107 
108  // if they match, add a PIPRef for this found PIP
109  size_t count = m_pipRefs.size();
110  m_pipRefs.push_back(PIPRef());
111  PIPRef& pipRef = m_pipRefs[count];
112  // fill it
113  pipRef.tileIndex(tileIndex);
114  pipRef.pipIndex(pipBitValue.pipIndex());
115  }
116  }
117 }
118 
119 
121 {
122  return m_pipRefs;
123 }