00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "torc/architecture/Segments.hpp"
00020 #include <iostream>
00021
00022 namespace torc {
00023 namespace architecture {
00024
00025 const Segments::SegmentReference Segments::SegmentReference::sTrivialSegmentReference;
00026
00027 Segments::Segments(void) : mCompactSegments(), mTilewireSegments(), mIrregularArcs(),
00028 mCompactSegmentCount(), mIrregularArcCount(), mTotalWireCount(), mTotalSegmentCount() {
00029 std::cerr << "WARNING: Need to check segment packing." << std::endl;
00030 }
00031
00032 size_t Segments::readTilewireSegments(DigestStream& inStream) {
00033
00034 size_t bytesReadOffset = inStream.getBytesRead();
00035 TileCount tileCount;
00036 uint16_t tileWireCount = 0;
00037 uint16_t extraWireCount = 0;
00038 WireIndex wireIndex;
00039
00040
00041
00042
00043 string sectionName;
00044 inStream.readSectionHeader(sectionName);
00045
00046 if(sectionName != ">>>>TileSegs>>>>") throw -1;
00047
00048
00049 inStream.read(tileCount);
00050 mTilewireSegments.setSize(tileCount);
00051 std::cout << "\tReading " << tileCount << " tiles..." << std::endl;
00052
00053 for(TileIndex i; i < tileCount; i++) {
00054
00055 inStream.read(tileWireCount);
00056 mTilewireSegments[i].setSize(tileWireCount);
00057
00058
00059
00060
00061 inStream.read(extraWireCount);
00062
00063
00064 mTotalWireCount += tileWireCount - extraWireCount;
00065
00066 for(WireIndex j; j < extraWireCount; j++) {
00067
00068 inStream.read(wireIndex);
00069
00070
00071
00072
00073
00074
00075 mTilewireSegments[i][wireIndex].undefine();
00076
00077 }
00078
00079 }
00080
00081
00082
00083 return inStream.getBytesRead() - bytesReadOffset;
00084 }
00085
00086 size_t Segments::readSegments(DigestStream& inStream, bool inExtendedAnchorTileCount) {
00087
00088 size_t bytesReadOffset = inStream.getBytesRead();
00089 uint16_t wireCount = 0;
00090 uint32_t offsetCount = 0;
00091 WireIndex wireIndex;
00092 TileOffset tileOffset;
00093 TileIndex rootTileIndex;
00094
00095
00096 string sectionName;
00097 inStream.readSectionHeader(sectionName);
00098
00099 if(sectionName != ">>>>Segments>>>>") throw -1;
00100
00101
00102 inStream.read(mCompactSegmentCount);
00103 mCompactSegments.setSize(mCompactSegmentCount);
00104 std::cout << "\tReading " << mCompactSegmentCount << " segments..." << std::endl;
00105
00106 for(CompactSegmentIndex i; i < mCompactSegmentCount; i++) {
00107
00108 inStream.read(wireCount);
00109 mCompactSegments[i].setSize(wireCount);
00110
00111 for(WireIndex j; j < wireCount; j++) {
00112
00113 inStream.read(wireIndex);
00114 inStream.read(tileOffset);
00115
00116 mCompactSegments[i][j] = CompactSegmentTilewire(wireIndex, tileOffset);
00117 }
00118
00119 if(inExtendedAnchorTileCount) {
00120
00121 inStream.read(offsetCount);
00122 } else {
00123
00124 uint16_t shortOffsetCount;
00125 inStream.read(shortOffsetCount);
00126 offsetCount = shortOffsetCount;
00127 }
00128
00129 for(uint32_t j = 0; j < offsetCount; j++) {
00130 mTotalSegmentCount++;
00131
00132 inStream.read(rootTileIndex);
00133
00134 for(WireIndex k; k < wireCount; k++) {
00135 const CompactSegmentTilewire compactSegmentTilewire = mCompactSegments[i][k];
00136 TileIndex tileIndex = TileIndex(rootTileIndex + compactSegmentTilewire.getTileOffset());
00137 WireIndex wireIndex = compactSegmentTilewire.getWireIndex();
00138 const SegmentReference& existing = mTilewireSegments[tileIndex][wireIndex];
00139 if(existing.getCompactSegmentIndex() != 0 || existing.getAnchorTileIndex() != 0) {
00140 std::cerr << "WARNING: Overwriting mTilewireSegments[" << tileIndex << "][" << wireIndex << "]: "
00141 << "conflict is " << i << "@" << rootTileIndex << " versus " << existing.getCompactSegmentIndex()
00142 << "@" << existing.getAnchorTileIndex() << std::endl;
00143 }
00144 mTilewireSegments[tileIndex][wireIndex] = SegmentReference(i, rootTileIndex);
00145 }
00146 }
00147 }
00148 std::cout << "\t" << mTotalSegmentCount << " total segments" << std::endl;
00149
00150
00151 return inStream.getBytesRead() - bytesReadOffset;
00152 }
00153
00154 size_t Segments::readIrregularArcs(DigestStream& inStream) {
00155
00156 size_t bytesReadOffset = inStream.getBytesRead();
00157 TileCount tileCount;
00158 uint16_t arcCount = 0;
00159 WireIndex sourceWireIndex;
00160 WireIndex sinkWireIndex;
00161
00162
00163 string sectionName;
00164 inStream.readSectionHeader(sectionName);
00165
00166 if(sectionName != ">>>>IrrgArcs>>>>") throw -1;
00167
00168
00169 inStream.read(tileCount);
00170 mIrregularArcs.setSize(tileCount);
00171 std::cout << "\tReading irregular arcs for " << tileCount << " tiles..." << std::endl;
00172
00173 for(TileIndex i; i < tileCount; i++) {
00174 Array<IrregularArc>& irregularArcs = mIrregularArcs[i];
00175
00176 inStream.read(arcCount);
00177 irregularArcs.setSize(arcCount);
00178
00179 for(uint16_t j = 0; j < arcCount; j++) {
00180
00181 inStream.read(sourceWireIndex);
00182 inStream.read(sinkWireIndex);
00183
00184 irregularArcs[j] = IrregularArc(sourceWireIndex, sinkWireIndex);
00185 }
00186 }
00187
00188
00189 return inStream.getBytesRead() - bytesReadOffset;
00190 }
00191
00192
00193
00194 const Segments::IrregularArc* Segments::getIrregularArc(TileIndex inTileIndex,
00195 WireIndex inSourceWireIndex, WireIndex inSinkWireIndex) {
00196
00197 const Array<IrregularArc>& irregularArcs = mIrregularArcs[inTileIndex];
00198
00199 Array<IrregularArc>::const_iterator p = irregularArcs.begin();
00200 Array<IrregularArc>::const_iterator e = irregularArcs.end();
00201 while(p < e) {
00202
00203 WireIndex sourceWireIndex = p->getSourceWireIndex();
00204 if(sourceWireIndex < inSourceWireIndex) { p++; continue; }
00205 if(sourceWireIndex > inSourceWireIndex) return NULL;
00206
00207 WireIndex sinkWireIndex = p->getSinkWireIndex();
00208 if(sinkWireIndex < inSinkWireIndex) { p++; continue; }
00209 if(sinkWireIndex > inSinkWireIndex) return NULL;
00210
00211 return p;
00212 }
00213
00214 return 0;
00215 }
00216
00217 }
00218 }