Bitstream Interpretation Library (BIL)  0.1
DeviceCfgDbStats.cpp
Go to the documentation of this file.
1 
6 #include <iomanip>
8 #include <util/HexPrint.hpp>
9 
10 using namespace bil;
11 
12 
13 const char* const STATMSG_TILETYPE = "Tile type: ";
14 const char* const STATMSG_CSCOUNT = "\n\tNumber of PIP control sets: ";
15 const char* const STATMSG_CSHEADER = "\tPIP control set ";
16 const char* const STATMSG_BITOFFSETS = ":\n\t\tBit offsets: ";
17 const char* const STATMSG_BITVALUES = "\n\t\tBit values:\n";
18 const char* const STATMSG_NOTISOLATED = "NOT ISOLATED";
19 const char* const STATMSG_ZEROED = "ZEROED";
20 const char* const STATMSG_OUTOF = " out of ";
21 const char* const STATMSG_PIPSISOLATED = "PIPs isolated: ";
22 const char* const STATMSG_PIPSZEROED = "PIPs zeroed: ";
23 const char* const STATMSG_PIPSNOTISOLATED = "PIPs not isolated: ";
24 const char* const STATMSG_PERCENTBEGIN = " (";
25 const char* const STATMSG_PERCENTEND = "%)";
26 const char* const STATMSG_PIPINDENT = "\t\t\t";
27 const char* const STATMSG_ENDP = "\n\n";
28 const char* const STATMSG_COMMA = ", ";
29 const char* const STATMSG_COLON = ": ";
30 const char STATMSG_SPACE = ' ';
31 const char STATMSG_INDENTCHAR = '\t';
32 const char STATMSG_ENDLN = '\n';
33 
34 
36  const Device& device, std::ostream& outStream)
37 {
38  // save output stream pointer
39  m_outputStream = &outStream;
40 
41  // reset stats
42  m_devicePIPCount = 0;
43  m_deviceIsolatedPIPCount = 0;
44  m_deviceZeroPIPCount = 0;
45  m_deviceNotIsolatedPIPCount = 0;
46 
47  // save data base pointers
48  const TileTypeCfgDbs& tileTypeDbs = db.tileTypeDbs();
49  const TileTypes& tileTypes = device.tileTypes();
50 
51  // loop over all tile types and their data bases and print their stats
52  size_t tileTypeDbCount = tileTypeDbs.size();
53  for (size_t i = 0; i < tileTypeDbCount; ++i)
54  {
55  const TileTypeCfgDb& tileTypeDb = tileTypeDbs[i];
56  const TileType& tileType = tileTypes.at(tileTypeDb.typeIndex());
57  printTileType(tileTypeDb, tileType);
58  }
59 
60  // print global stats
61  printPIPCounts(0, m_devicePIPCount, m_deviceIsolatedPIPCount,
62  m_deviceZeroPIPCount, m_deviceNotIsolatedPIPCount);
63 }
64 
65 
66 void DeviceCfgDbStats::printTileType(const TileTypeCfgDb& db,
67  const TileType& tileType)
68 {
69  // get PIP control sets, wires, and PIPs of this tile type
70  const PIPControlSets& pipControlSets = db.pipControlSets();
71  size_t pipControlSetCount = pipControlSets.size();
72  const Wires& wires = tileType.wires();
73  const PIPs& pips = tileType.pips();
74 
75  // reset tile type stats
76  m_tileTypePIPCount = 0;
77  m_tileTypeIsolatedPIPCount = 0;
78  m_tileTypeZeroPIPCount = 0;
79  m_tileTypeNotIsolatedPIPCount = 0;
80 
81  // print header for this tile type
82  (*m_outputStream) << STATMSG_TILETYPE << tileType.name();
83  (*m_outputStream) << STATMSG_CSCOUNT << pipControlSetCount << STATMSG_ENDP;
84 
85  // loop over all control sets and print them
86  for (size_t i = 0; i < pipControlSetCount; ++i)
87  {
88  const PIPControlSet& pipControlSet = pipControlSets[i];
89  printPIPControlSet(pipControlSet, i, wires, pips);
90  }
91 
92  // print tile type stats
93  printPIPCounts(1, m_tileTypePIPCount, m_tileTypeIsolatedPIPCount,
94  m_tileTypeZeroPIPCount, m_tileTypeNotIsolatedPIPCount);
95 
96  // increment global stats by this tile type stats
97  m_devicePIPCount += m_tileTypePIPCount;
98  m_deviceIsolatedPIPCount += m_tileTypeIsolatedPIPCount;
99  m_deviceZeroPIPCount += m_tileTypeZeroPIPCount;
100  m_deviceNotIsolatedPIPCount += m_tileTypeNotIsolatedPIPCount;
101 }
102 
103 
104 void DeviceCfgDbStats::printPIPControlSet(const PIPControlSet& cs,
105  size_t csIndex, const Wires& wires, const PIPs& pips)
106 {
107  // reset control set stats
108  size_t isolatedPIPCount = 0;
109  size_t zeroPIPCount = 0;
110  size_t notIsolatedPIPCount = 0;
111 
112  // print control set header
113  (*m_outputStream) << STATMSG_CSHEADER << csIndex;
114 
115  // print bit offsets
116  (*m_outputStream) << STATMSG_BITOFFSETS;
117  const BitPositions& bitPositions = cs.bitPositions();
118  size_t bitPositionCount = bitPositions.size();
119  for (size_t i = 0; i < bitPositionCount; ++i)
120  {
121  if (i != 0) (*m_outputStream) << STATMSG_COMMA;
122  (*m_outputStream) << bitPositions[i];
123  }
124 
125  // print pip bit values
126  (*m_outputStream) << STATMSG_BITVALUES;
127  const PIPBitValues& pipBitValues = cs.pipBitValues();
128  size_t pipCount = pipBitValues.size();
129  for (size_t i = 0; i < pipCount; ++i)
130  {
131  // get PIP bit value
132  const PIPBitValue& pipBitValue = pipBitValues[i];
133 
134  // get PIP and print it
135  const PIP& pip = pips.at(pipBitValue.pipIndex());
136  const Wire& startWire = wires.at(pip.startWireIndex());
137  const Wire& endWire = wires.at(pip.endWireIndex());
138  (*m_outputStream) << STATMSG_PIPINDENT << startWire.name() << STATMSG_SPACE;
139  (*m_outputStream) << PIPDirection::toString(pip.direction()) << STATMSG_SPACE;
140  (*m_outputStream) << endWire.name() << STATMSG_COLON;
141 
142  // print PIP bit value
143  boost::uint32_t value = pipBitValue.bitValue();
144  if (0 != (value & PIPBitValue::VALUE_UNUSED))
145  {
146  (*m_outputStream) << STATMSG_NOTISOLATED;
147  ++notIsolatedPIPCount;
148  }
149  else if (0 == value)
150  {
151  (*m_outputStream) << STATMSG_ZEROED;
152  ++zeroPIPCount;
153  }
154  else
155  {
156  (*m_outputStream) << hexString(value);
157  ++isolatedPIPCount;
158  }
159  (*m_outputStream) << STATMSG_ENDLN;
160  }
161  (*m_outputStream) << STATMSG_ENDLN;
162 
163  // increment tile type stats by control set stats
164  m_tileTypePIPCount += pipCount;
165  m_tileTypeIsolatedPIPCount += isolatedPIPCount;
166  m_tileTypeZeroPIPCount += zeroPIPCount;
167  m_tileTypeNotIsolatedPIPCount += notIsolatedPIPCount;
168 }
169 
170 
171 void DeviceCfgDbStats::printPIPCounts(size_t indent, size_t total,
172  size_t isolated, size_t zero, size_t notIsolated)
173 {
174  // set up indentation
175  std::string indentStr(indent, STATMSG_INDENTCHAR);
176  // set up percentage output
177  float fTotal = ((total != 0) ? (100.0f / total) : 0);
178  (*m_outputStream) << std::fixed << std::setprecision(1);
179 
180  // print stats for isolated PIPs
181  (*m_outputStream) << indentStr << STATMSG_PIPSISOLATED << isolated;
182  (*m_outputStream) << STATMSG_OUTOF << total;
183  if (0 != total) (*m_outputStream) << STATMSG_PERCENTBEGIN << (isolated*fTotal) << STATMSG_PERCENTEND;
184  (*m_outputStream) << STATMSG_ENDLN;
185 
186  // print stats for zeroed PIPs
187  (*m_outputStream) << indentStr << STATMSG_PIPSZEROED << zero;
188  (*m_outputStream) << STATMSG_OUTOF << total;
189  if (0 != total) (*m_outputStream) << STATMSG_PERCENTBEGIN << (zero*fTotal) << STATMSG_PERCENTEND;
190  (*m_outputStream) << STATMSG_ENDLN;
191 
192  // print stats for not isolated PIPs
193  (*m_outputStream) << indentStr << STATMSG_PIPSNOTISOLATED << notIsolated;
194  (*m_outputStream) << STATMSG_OUTOF << total;
195  if (0 != total) (*m_outputStream) << STATMSG_PERCENTBEGIN << (notIsolated*fTotal) << STATMSG_PERCENTEND;
196  (*m_outputStream) << STATMSG_ENDP;
197 }