Bitstream Interpretation Library (BIL)  0.1
xdlcmpAlgo.cpp
Go to the documentation of this file.
1 
6 #include <algorithm>
7 #include <iterator>
10 
11 using namespace bil;
12 
13 const char* const PIPSPRESENT1_MSG = "PIPs present in reference design, but not in test design:\n";
14 const char* const PIPSPRESENT2_MSG = "\nPIPs present in test design, but not in reference design:\n";
15 const char* const PIPSSTATS1_MSG = "\nPIPs in reference design: ";
16 const char* const PIPSSTATS2_MSG = "Correct PIPs in test design: ";
17 const char* const PIPSSTATS3_MSG = "Missing PIPs in test design: ";
18 const char* const PIPSSTATS4_MSG = "Incorrect PIPs in test design: ";
19 const char* const PIP_MSG = "pip";
20 const char ENDLN = '\n';
21 
22 
23 void getPIPs(const Design& design, PIPRefs& pipRefs)
24 {
25  // clear old data
26  pipRefs.clear();
27 
28  // collect all PIPs from all nets
29  const Nets& nets = design.nets();
30  size_t netCount = nets.size();
31  for (size_t i = 0; i < netCount; ++i)
32  {
33  const Net& net = nets[i];
34  const PIPRefs& srcPipRefs = net.pipRefs();
35  pipRefs.insert(pipRefs.end(), srcPipRefs.begin(), srcPipRefs.end());
36  }
37 
38  // sort them
39  std::sort(pipRefs.begin(), pipRefs.end());
40 }
41 
42 
43 void comparePIPs(const PIPRefs& refPIPRefs, const PIPRefs& testPIPRefs,
44  const Device& device, std::ostream& outputStream)
45 {
46  // cache pointers to tiles and tile types
47  const Tiles& tiles = device.tiles();
48  const TileTypes& tileTypes = device.tileTypes();
49 
50  // flag vector for test PIPs
51  std::vector<bool> correctPips;
52  correctPips.resize(testPIPRefs.size(), false);
53 
54  // iterators for test PIPs
55  PIPRefs::const_iterator itBegin = testPIPRefs.begin();
56  PIPRefs::const_iterator itEnd = testPIPRefs.end();
57  PIPRefs::const_iterator it;
58 
59  // stats counters
60  size_t correctPIPCount = 0;
61  size_t missingPIPCount = 0;
62  size_t incorrectPIPCount = 0;
63 
64  // loop over all reference PIPs and check, if they are in test PIPs
65  outputStream << PIPSPRESENT1_MSG;
66  size_t refPipCount = refPIPRefs.size();
67  for (size_t i = 0; i < refPipCount; ++i)
68  {
69  const PIPRef& refPIPRef = refPIPRefs[i];
70  it = std::find(itBegin, itEnd, refPIPRef);
71  if (it != itEnd)
72  {
73  size_t testPipIndex = std::distance(itBegin, it);
74  correctPips[testPipIndex] = true;
75  ++correctPIPCount;
76  }
77  else
78  {
79  outputStream << PIP_MSG << pipRefString(refPIPRef, tiles, tileTypes) << ENDLN;
80  ++missingPIPCount;
81  }
82  }
83 
84  // loop over all test PIPs and check, if they are in reference PIPs
85  outputStream << PIPSPRESENT2_MSG;
86  size_t testPipCount = testPIPRefs.size();
87  for (size_t i = 0; i < testPipCount; ++i)
88  {
89  if (correctPips[i]) continue;
90  const PIPRef& testPIPRef = testPIPRefs[i];
91  outputStream << PIP_MSG << pipRefString(testPIPRef, tiles, tileTypes) << ENDLN;
92  ++incorrectPIPCount;
93  }
94 
95  // print stats
96  outputStream << PIPSSTATS1_MSG << refPipCount << ENDLN;
97  outputStream << PIPSSTATS2_MSG << correctPIPCount << ENDLN;
98  outputStream << PIPSSTATS3_MSG << missingPIPCount << ENDLN;
99  outputStream << PIPSSTATS4_MSG << incorrectPIPCount;
100 }