127 for (
int i = 0; i < socketNav.
count(); i++) {
131 if (suitable != NULL) {
155 for (
int i = 0; i < isNav.
count(); i++) {
157 int width = slot->
width();
165 for (
int i = 0; i < busNav.
count(); i++) {
177 if (itNav.
count() > 1) {
184 for (
int i = 0; i < fNav.
count(); i++) {
200 std::string name = format->
name();
203 if (name ==
"riscv_r_type") {
214 std::string(
"opcode"), *instrFormat);
219 std::vector<std::string> operations = format->
operations();
221 unsigned int amountOfCustomOps = 10;
222 for (
const std::string& op : operations) {
226 unsigned int customEncoding = 0b0001011;
228 if (
TCEString(op).lower() ==
"stdout_riscv") {
229 customEncoding = 0b0001011;
231 customEncoding += (amountOfCustomOps << 7);
234 assert(amountOfCustomOps < 127);
238 }
else if (name ==
"riscv_i_type") {
251 std::string(
"opcode"), *instrFormat);
255 std::vector<std::string> operations = format->
operations();
256 for (
const std::string& op : operations) {
263 }
else if (name ==
"riscv_s_type") {
275 std::string(
"opcode"), *instrFormat);
278 std::vector<std::string> operations = format->
operations();
279 for (
const std::string& op : operations) {
286 }
else if (name ==
"riscv_b_type") {
300 std::string(
"opcode"), *instrFormat);
303 std::vector<std::string> operations = format->
operations();
304 for (
const std::string& op : operations) {
311 }
else if (name ==
"riscv_u_type") {
316 std::string(
"opcode"), *instrFormat);
321 std::vector<std::string> operations = format->
operations();
322 for (
const std::string& op : operations) {
329 }
else if (name ==
"riscv_j_type") {
334 std::string(
"opcode"), *instrFormat);
342 std::vector<std::string> operations = format->
operations();
343 for (
const std::string& op : operations) {
369 for (
int i = 0; i < itNav.
count(); i++) {
371 int thisRequires = 0;
374 for (
int i = 0; i < iuNav.
count(); i++) {
382 if (thisRequires > fieldCount) {
383 fieldCount = thisRequires;
390 std::vector<int> fieldWidths(fieldCount, 0);
392 for (
int i = 0; i < itNav.
count(); i++) {
396 std::set<ImmediateUnit*> dstUnits;
397 for (
int i = 0; i < iuNav.
count(); i++) {
406 std::multiset<int> requiredSizes;
407 for (set<ImmediateUnit*>::const_iterator iter = dstUnits.begin();
408 iter != dstUnits.end(); iter++) {
411 requiredSizes.insert(
418 for (multiset<int>::const_reverse_iterator iter =
419 requiredSizes.rbegin();
420 iter != requiredSizes.rend(); iter++) {
421 if (fieldWidths[counter] < *iter) {
422 fieldWidths[counter] = *iter;
429 typedef std::pair<InstructionTemplate*, ImmediateUnit*> ImmDstMapping;
430 std::set<ImmDstMapping> mappedDestinations;
431 for (
int i = fieldCount-1; i >= 0; i--) {
432 unsigned int fieldWidth = fieldWidths[i];
435 for (
int i = 0; i < itNav.
count(); i++) {
437 for (
int i = 0; i < iuNav.
count(); i++) {
441 static_cast<unsigned int>(
446 ImmDstMapping(iTemp, iu))) {
448 mappedDestinations.insert(ImmDstMapping(iTemp, iu));
464 string busName = slot.
name();
467 Bus* bus = busNav.
item(busName);
486 if (longImmWidth > slot.
width()) {
488 if (gField == NULL) {
508 for (
int i = 0; i < itNav.
count(); i++) {
526 Bus* bus = busNav.
item(busName);
527 bool createNopField =
true;
531 createNopField =
false;
536 if (dstSockets == 0) {
541 *bus, Socket::INPUT);
543 if (createNopField) {
544 socketCodeWidths.insert(0);
546 multiset<Encoding> encodings;
549 set<Socket*> handledSockets;
550 multiset<int>::reverse_iterator scIter = socketCodeWidths.rbegin();
551 bool nopEncodingSet =
false;
552 for (multiset<Encoding>::const_iterator encIter = encodings.begin();
553 encIter != encodings.end(); encIter++) {
555 int scWidth = *scIter;
556 if (scWidth == 0 && !nopEncodingSet && createNopField) {
559 nopEncodingSet =
true;
562 for (
int i = 0; i < dstSockets; i++) {
564 i, *bus, Socket::INPUT);
566 if (scTable == NULL && scWidth == 0 &&
570 handledSockets.insert(&
socket);
572 }
else if (scTable != NULL && scWidth == scTable->
width() &&
574 handledSockets, &
socket)) {
578 handledSockets.insert(&
socket);
599 Bus* bus = busNav.
item(busName);
600 bool createNopField =
true;
604 createNopField =
false;
608 int srcSockets =
socketCount(*bus, Socket::OUTPUT);
613 *bus, Socket::OUTPUT);
614 for (
int i = 0; i < srcBridges; i++) {
615 socketCodeWidths.insert(0);
617 if (shortImmSupport) {
621 if (createNopField) {
622 socketCodeWidths.insert(0);
625 multiset<Encoding> encodings;
629 set<Socket*> handledSockets;
631 bool nopEncodingSet =
false;
632 bool immEncodingSet = !shortImmSupport;
633 multiset<int>::reverse_iterator scIter = socketCodeWidths.rbegin();
634 for (multiset<Encoding>::const_iterator encIter = encodings.begin();
635 encIter != encodings.end(); encIter++) {
637 int scWidth = *scIter;
638 if (scWidth == 0 && !nopEncodingSet && createNopField) {
640 nopEncodingSet =
true;
644 immEncodingSet =
true;
646 bool socketFound =
false;
648 for (
int i = 0; i < srcSockets; i++) {
650 i, *bus, Socket::OUTPUT);
652 if (scTable == NULL && scWidth == 0 &&
656 handledSockets.insert(&
socket);
659 }
else if (scTable != NULL && scWidth == scTable->
width() &&
661 handledSockets, &
socket)) {
665 handledSockets.insert(&
socket);
672 assert(nextBridge < srcBridges);
676 bridge.
name(), enc.first, enc.second, field);
696 Bus* bus = busNav.
item(busName);
700 for (
int i = 0; i < guards; i++) {
706 if (portGuard != NULL) {
711 }
else if (regGuard != NULL) {
715 }
else if (ucGuard != NULL) {
752 for (SCTableMap::const_iterator iter =
scTableMap_.begin();
754 const Socket* toCheck = (*iter).first;
756 return (*iter).second;
790 typedef std::set<Socket*> SocketSet;
803 return sockets.size();
822 typedef std::vector<Socket*> SocketTable;
825 SocketTable connectedSockets;
833 connectedSockets,
socket)) {
834 connectedSockets.push_back(
socket);
840 assert(connectedSockets.size() >
static_cast<size_t>(index));
841 return *connectedSockets[index];
867 }
else if (rfPort != NULL &&
889 const Socket& socket)
const {
892 multiset<int> indexWidths;
900 if (fuParent != NULL) {
901 int encodingsNeeded(0);
902 if (
dynamic_cast<BaseFUPort*
>(port)->isOpcodeSetting() &&
908 for (
int i = 0; i < encodingsNeeded; i++) {
909 indexWidths.insert(0);
914 indexWidths.insert(indexWidth);
919 multiset<Encoding> encodings;
923 if (encodings.size() == 0) {
928 assert(iu != NULL || rf != NULL);
936 set<Port*> handledPorts;
937 multiset<int>::const_reverse_iterator indexWidthIter =
938 indexWidths.rbegin();
939 for (multiset<Encoding>::const_iterator encIter = encodings.begin();
940 encIter != encodings.end();) {
941 int indexWidth = *indexWidthIter;
956 if (iuParent != NULL) {
958 if (reqIndexWidth == indexWidth) {
960 iuParent->
name(), enc.first, enc.second,
961 reqIndexWidth, table);
964 handledPorts.insert(port);
967 }
else if (rfParent != NULL) {
969 if (reqIndexWidth == indexWidth) {
971 rfParent->
name(), enc.first, enc.second,
972 reqIndexWidth, table);
975 handledPorts.insert(port);
979 if (indexWidth != 0) {
987 map<string,int> opcodeSet;
988 assert(*indexWidthIter == 0);
991 for (
int opIndex = 0;
1000 for (map<string,int>::iterator
1001 iter = opcodeSet.begin();
1002 iter != opcodeSet.end(); iter++) {
1009 operation->
name(), enc.first, enc.second,
1016 fuParent->
name(), fuPort->
name(), enc.first,
1021 handledPorts.insert(port);
1043 std::multiset<int> socketCodeWidths;
1048 if (scTable == NULL) {
1049 socketCodeWidths.insert(0);
1051 socketCodeWidths.insert(scTable->
width());
1055 return socketCodeWidths;
1071 std::set<Port*> socket1Ports;
1072 std::set<Port*> socket2Ports;
1074 for (
int i = 0; i < socket1.
portCount(); i++) {
1075 socket1Ports.insert(socket1.
port(i));
1078 for (
int i = 0; i < socket2.
portCount(); i++) {
1079 socket2Ports.insert(socket2.
port(i));
1082 if (socket1Ports == socket2Ports) {
1105 for (
int i = 0; i < bridgeNav.
count(); i++) {
1132 for (
int i = 0; i < bridgeNav.
count(); i++) {
1135 if (count == index) {
1145 return *bridgeNav.
item(0);
1198 const std::multiset<int>& oppositeFieldWidths,
1200 std::multiset<Encoding>& encodings) {
1202 if (oppositeFieldWidths.size() < 1) {
1208 unsigned int remainder = 0;
1209 unsigned int encodingsLeft = oppositeFieldWidths.size();
1210 unsigned int prevEncoding = 0;
1211 unsigned int nextEncoding = 0;
1212 unsigned int prevOppositeFieldWidth = 0;
1214 for (multiset<int>::reverse_iterator iter = oppositeFieldWidths.rbegin();
1215 iter != oppositeFieldWidths.rend(); iter++) {
1216 unsigned int oppositeFieldWidth = *iter;
1217 if (iter == oppositeFieldWidths.rbegin()) {
1219 encodings.insert(
Encoding(nextEncoding, 0));
1222 nextEncoding = prevEncoding + 1;
1226 unsigned int setEncodingCount =
1227 oppositeFieldWidths.size() - encodingsLeft;
1228 remainder = (remainder << 1) + setEncodingCount;
1231 if (oppositeFieldWidth == prevOppositeFieldWidth) {
1232 encodings.insert(
Encoding(nextEncoding, 0));
1234 assert(oppositeFieldWidth < prevOppositeFieldWidth);
1235 unsigned int freeBits =
1236 prevOppositeFieldWidth - oppositeFieldWidth;
1239 unsigned int expansion = 0;
1240 while (remainder << expansion < encodingsLeft) {
1241 if (expansion < freeBits) {
1247 nextEncoding = nextEncoding << expansion;
1248 encodings.insert(
Encoding(nextEncoding, 0));
1249 remainder = remainder << expansion;
1252 prevOppositeFieldWidth = oppositeFieldWidth;
1255 prevEncoding = nextEncoding;
1258 assert(encodings.size() == oppositeFieldWidths.size());
1270 std::multiset<Encoding>& encodings,
1273 multiset<Encoding> newSet;
1274 for (multiset<Encoding>::iterator iter = encodings.begin();
1275 iter != encodings.end(); iter++) {
1276 unsigned int encoding = iter->first;
1277 unsigned int extraBits = iter->second;
1278 extraBits += bitCount;
1279 newSet.insert(
Encoding(encoding, extraBits));
1283 encodings.insert(newSet.begin(), newSet.end());
1300 for (
int i = 0; i < itNav.
count(); i++) {
1302 for (
int i = 0; i < iTemp->
slotCount(); ++i) {
1304 maxWidth < iTemp->slot(i)->width()) {