OpenASIP  2.0
BEMTester.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file BEMTester.cc
26  *
27  * Implementation of BEMTester class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <algorithm>
34 
35 #include "BEMTester.hh"
36 #include "BEMTools.hh"
37 #include "SlotField.hh"
38 #include "MoveSlot.hh"
39 #include "SocketEncoding.hh"
40 #include "SourceField.hh"
41 #include "GuardField.hh"
42 #include "GPRGuardEncoding.hh"
43 #include "FUGuardEncoding.hh"
45 #include "DestinationField.hh"
46 #include "BridgeEncoding.hh"
47 #include "ImmediateEncoding.hh"
48 #include "NOPEncoding.hh"
49 #include "SocketCodeTable.hh"
50 #include "FUPortCode.hh"
51 #include "RFPortCode.hh"
52 #include "IUPortCode.hh"
53 #include "MathTools.hh"
54 
55 /**
56  * Tests whether the given encoding can be added to the given slot
57  * field.
58  *
59  * The encoding can not be added to the slot field if some other
60  * socket encoding, bridge encoding, immediate encoding or NOP
61  * encoding has exactly the same bits in same positions. For example,
62  * if socket (and bridge) ID's are in the left end of the slot field,
63  * the encodings '1001' and '10' would conflict, since in both cases
64  * the two leftmost bits in the field are '10'.
65  *
66  * @param field The slot field.
67  * @param encoding The encoding.
68  * @param extraBits The number of extra bits in the encoding.
69  * @return True if the encoding can be added to the slot field, otherwise
70  * false.
71  */
72 bool
74  SlotField& field,
75  unsigned int encoding,
76  unsigned int extraBits) {
77 
78  unsigned int encodingWidth = MathTools::bitLength(encoding) +
79  extraBits;
80 
81  int socketEncodings = field.socketEncodingCount();
82  for (int i = 0; i < socketEncodings; i++) {
83  SocketEncoding& existingEnc = field.socketEncoding(i);
84  int alignment = calculateAlignment(
85  encodingWidth, existingEnc.socketIDWidth(), field);
86  int commonBits = commonBitCount(
87  encoding, extraBits, existingEnc.encoding(),
88  existingEnc.extraBits(), alignment);
89  if (commonBits == static_cast<int>(MathTools::bitLength(encoding))
90  + static_cast<int>(extraBits) ||
91  commonBits == existingEnc.socketIDWidth()) {
92  return false;
93  }
94  }
95 
96  SourceField* sField = dynamic_cast<SourceField*>(&field);
97  if (sField != NULL) {
98  int bridgeEncodings = sField->bridgeEncodingCount();
99  for (int i = 0; i < bridgeEncodings; i++) {
100  BridgeEncoding& existingEnc = sField->bridgeEncoding(i);
101  int alignment = calculateAlignment(
102  encodingWidth, existingEnc.width(), field);
103  int commonBits = commonBitCount(
104  encoding, extraBits, existingEnc.encoding(),
105  existingEnc.extraBits(), alignment);
106  if (commonBits == static_cast<int>(
107  MathTools::bitLength(encoding)) +
108  static_cast<int>(extraBits) ||
109  commonBits == existingEnc.width()) {
110  return false;
111  }
112  }
113 
114  if (sField->hasImmediateEncoding()) {
115  ImmediateEncoding& immEnc = sField->immediateEncoding();
116  int alignment = calculateAlignment(
117  encodingWidth, immEnc.width(), field);
118  int commonBits = commonBitCount(
119  encoding, extraBits, immEnc.encoding(), immEnc.extraBits(),
120  alignment);
121  if (commonBits ==
122  static_cast<int>(MathTools::bitLength(encoding)) +
123  static_cast<int>(extraBits) ||
124  commonBits == immEnc.width()) {
125  return false;
126  }
127  }
128 
129  if (sField->hasNoOperationEncoding()) {
130  NOPEncoding& nopEnc = sField->noOperationEncoding();
131  int alignment = calculateAlignment(
132  encodingWidth, nopEnc.width(), field);
133  int commonBits = commonBitCount(
134  encoding, extraBits, nopEnc.encoding(), nopEnc.extraBits(),
135  alignment);
136  if (commonBits == static_cast<int>(
137  MathTools::bitLength(encoding)) +
138  static_cast<int>(extraBits) ||
139  commonBits == nopEnc.width()) {
140  return false;
141  }
142  }
143 
144  }
145  return true;
146 }
147 
148 /**
149  * Tests whether the given priority encoding can be added to the given move
150  * slot field.
151  *
152  * The encoding can be added to the slot if it distinguishable from the other
153  * encodings in the slot. The encoding is distinguishable if there is no
154  * guard, source and destination field encoding combination that could be
155  * misunderstood as the given encoding.
156  *
157  * The tested encoding is treated as it has higher priority in decoding. That
158  * is, is the given encoding is present in the move slot, then any other
159  * encoding bits (non-overlapping with the given encoding) in the slot does
160  * not have effect.
161  *
162  * The tested encoding can cross boundaries of guard, source and destination
163  * fields, overlapping multiple fields. A par of the encoding (i.e.
164  * overlapping some slot field) may be indistinguishable as long as some other
165  * parts are distinguishable.
166  *
167  * @param slot The slot where the encoding could be added.
168  * @param encoding The encoding value. Avoid using zero value since its bit
169  * width is zero too. Instead, use one extrabit denote zero
170  * value.
171  * @param extraBits The extra bits (zeroes) of the the encoding at the left
172  * side.
173  * @param offset The position of the encoding from LSB position of the slot.
174  * Zero means that the given encoding is right aligned in the
175  * slot.
176  * @return True if the encoding is distinguishable from the other
177  * encodings and, therefore, can be added to the slot.
178  */
179 bool
181  MoveSlot& slot, unsigned int encoding, unsigned int extraBits,
182  int offset) {
183  bool canAdd = false;
184  int encWidth = BEMTools::encodingWidth(encoding, extraBits);
185  unsigned truncatedEnc;
186  unsigned truncatedWidth;
187  int offsetInField;
188 
189  if (encWidth + offset > slot.width()) {
190  // The move NOP encoding can be always added if (part of the) it is
191  // located out side of the move slot fields.
192  // note: this assumes that the move slot does not have other kinds of
193  // move encodings.
194  return true;
195  }
196 
197  if (fieldsOverlap(slot.guardField(), encWidth, offset)) {
198  std::tie(truncatedEnc, truncatedWidth, offsetInField) = splitEncoding(
199  encoding, encWidth, slot.guardField().width(),
200  offset - slot.guardField().bitPosition());
201 
202  canAdd = canAdd || !conflictsWithGuardEncoding(
203  slot.guardField(), truncatedEnc,
204  truncatedWidth, offsetInField);
205  }
206 
207  if (fieldsOverlap(slot.sourceField(), encWidth, offset)) {
208  const SourceField& field = slot.sourceField();
209  std::tie(truncatedEnc, truncatedWidth, offsetInField) = splitEncoding(
210  encoding, encWidth, field.width(), offset - field.bitPosition());
211 
212  canAdd =
213  canAdd || !conflictsWithSourceEncodings(
214  field, truncatedEnc, truncatedWidth, offsetInField);
215  }
216 
217  if (fieldsOverlap(slot.destinationField(), encWidth, offset)) {
218  const DestinationField& field = slot.destinationField();
219  std::tie(truncatedEnc, truncatedWidth, offsetInField) = splitEncoding(
220  encoding, encWidth, field.width(), offset - field.bitPosition());
221 
222  canAdd =
224  field, truncatedEnc, truncatedWidth, offsetInField);
225  }
226 
227  return canAdd;
228 }
229 
230 /**
231  * Tells whether the given port encoding can be added to the given socket
232  * code table.
233  *
234  * The given encoding is be ambiguous with some other FU port encoding or RF
235  * port encoding in the socket code table if all the bits of the encoding are
236  * the same with the bits of another encoding in the same position of the
237  * field. For example, encodings 1011 and 11 are ambiguous if the LSBs of
238  * the encodings are in the same position.
239  *
240  * @param table The socket code table.
241  * @param encoding The encoding.
242  * @param extraBits The number of extra bits in the encoding.
243  * @return True if the encoding can be added to the socket code table,
244  * otherwise false.
245  */
246 bool
248  SocketCodeTable& table,
249  unsigned int encoding,
250  unsigned int extraBits) {
251 
252  int encodingWidth = MathTools::bitLength(encoding) + extraBits;
253 
254  int fuPortEncodings = table.fuPortCodeCount();
255  for (int i = 0; i < fuPortEncodings; i++) {
256  FUPortCode& code = table.fuPortCode(i);
257  int commonBits = commonBitCount(
258  encoding, extraBits, code.encoding(), code.extraBits(),
259  code.encodingWidth() - encodingWidth);
260  if (commonBits == encodingWidth ||
261  commonBits == code.encodingWidth()) {
262  return false;
263  }
264  }
265 
266  int rfPortEncodings = table.rfPortCodeCount();
267  for (int i = 0; i < rfPortEncodings; i++) {
268  RFPortCode& code = table.rfPortCode(i);
269  int commonBits = commonBitCount(
270  encoding, extraBits, code.encoding(), code.extraBits(),
271  code.encodingWidth() - encodingWidth);
272  if (commonBits == encodingWidth ||
273  commonBits == code.encodingWidth()) {
274  return false;
275  }
276  }
277 
278  int iuPortEncodings = table.iuPortCodeCount();
279  for (int i = 0; i < iuPortEncodings; i++) {
280  IUPortCode& code = table.iuPortCode(i);
281  int commonBits = commonBitCount(
282  encoding, extraBits, code.encoding(), code.extraBits(),
283  code.encodingWidth() - encodingWidth);
284  if (commonBits == encodingWidth ||
285  commonBits == code.encodingWidth()) {
286  return false;
287  }
288  }
289 
290  return true;
291 }
292 
293 
294 /**
295  * Tells the number of common bits in the same positions in the given
296  * encodings. The LSB bit of the encodings may not be in the same position.
297  * That is defined by the alignment parameter.
298  *
299  * @param enc1 The first encoding.
300  * @param extraBits1 The number of extra zero bits in the first encoding.
301  * @param enc2 The second encoding.
302  * @param extraBits2 The number of extra zero bits in the second encoding.
303  * @param alignment The number of bits the second encoding has in the right
304  * side of the first encoding (negative if the LSB bit of
305  * the second encoding is on the left side of the LSB bit of
306  * the first encoding).
307  */
308 int
310  unsigned int enc1,
311  unsigned int extraBits1,
312  unsigned int enc2,
313  unsigned int extraBits2,
314  int alignment) {
315 
316  int commonBits(0);
317 
318  int enc1Offset = 0;
319  int enc2Offset = 0;
320 
321  if (alignment > 0) {
322  enc2Offset = alignment;
323  } else if (alignment < 0) {
324  enc1Offset = alignment * (-1);
325  }
326 
327  int maxEnc1Offset = MathTools::bitLength(enc1) + extraBits1 - 1;
328  int maxEnc2Offset = MathTools::bitLength(enc2) + extraBits2 - 1;
329 
330  while (enc1Offset <= maxEnc1Offset && enc2Offset <= maxEnc2Offset) {
331  if (MathTools::bit(enc1, enc1Offset) ==
332  MathTools::bit(enc2, enc2Offset)) {
333  commonBits++;
334  }
335  enc1Offset++;
336  enc2Offset++;
337  }
338 
339  return commonBits;
340 }
341 
342 /**
343  * Calculates the alignment of encodings that has the given widths when they
344  * are added to the given slot field.
345  *
346  * @param enc1Width Width of the first encoding.
347  * @param enc2Width Width of the second encoding.
348  * @param field The slot field.
349  * @return The alignment.
350  */
351 int
353  unsigned int enc1Width,
354  unsigned int enc2Width,
355  const SlotField& field) {
356 
358  return 0;
359  } else {
360  return enc2Width - enc1Width;
361  }
362 }
363 
364 /**
365  * Checks if a field relatively at position to an instruction field do
366  * overlap.
367  *
368  * @verbatim
369  * |<- instruction field ->|
370  * |<-- width -->|<---- pos --|
371  * ------------------------------0
372  * => true
373  * @endverbatim
374  *
375  * @param with
376  * @param toFieldWidth
377  * @param toFieldPos The relative position of the field to the instruction
378  * field.
379  * @return True if the fields do overlap. Otherwise false.
380  */
381 bool
383  const InstructionField& with, unsigned int toFieldWidth, int toFieldPos) {
384  return fieldsOverlap(
385  with.width(), with.bitPosition(), toFieldWidth, toFieldPos);
386 }
387 
388 /**
389  * Checks if the given fields overlaps
390  *
391  * @verbatim
392  * |- pos1 -->|
393  * |<------ width1 ------>|
394  * |<- width2 ->| |
395  * |<- pos2 -|
396  * <- + 0
397  * ->| |<- overlaps => true
398  * @endverbatim
399  *
400  * @param width1 The width of the 1st field.
401  * @param pos1 The position of the 1st field.
402  * @param width2 The width of the 2nd field.
403  * @param pos2 The position of the 2nd field.
404  * @return True if there is overlap. Otherwise return false.
405  */
406 bool
408  unsigned width1, int pos1, unsigned width2, int pos2) {
409  // positive = overlapping width, negative = separation width
410  return (std::min(
411  pos1 + static_cast<int>(width1),
412  pos2 + static_cast<int>(width2)) -
413  std::max(pos1, pos2)) > 0;
414 }
415 
416 /**
417  * Checks that the given encoding and others in the field can be distinguished
418  * from each other.
419  *
420  * @param field The guard field.
421  * @param encoding The encoding.
422  * @param width The width of the encoding where the encoding value is right
423  * aligned.
424  * @param offset The relative position of the encoding to the field's LSB.
425  * Positive shifts the encoding towards MSB and vice versa.
426  * @return True if the encoding can not be distinguished from another
427  * encoding.
428  */
429 bool
431  const GuardField& field, unsigned int encoding, unsigned int /*width*/,
432  int offset) {
433  for (int i = 0; i < field.gprGuardEncodingCount(); i++) {
434  const GPRGuardEncoding& grdEnc = field.gprGuardEncoding(i);
435 
437  grdEnc.encoding(), 0, encoding, offset, field.width())) {
438  return true;
439  }
440  }
441 
442  for (int i = 0; i < field.fuGuardEncodingCount(); i++) {
443  const FUGuardEncoding& grdEnc = field.fuGuardEncoding(i);
444 
446  grdEnc.encoding(), 0, encoding, offset, field.width())) {
447  return true;
448  }
449  }
450 
451  if (field.hasUnconditionalGuardEncoding(false)) {
452  const UnconditionalGuardEncoding& grdEnc =
453  field.unconditionalGuardEncoding(false);
454 
456  grdEnc.encoding(), 0, encoding, offset, field.width())) {
457  return true;
458  }
459  }
460 
461  if (field.hasUnconditionalGuardEncoding(true)) {
462  const UnconditionalGuardEncoding& grdEnc =
463  field.unconditionalGuardEncoding(true);
464 
466  grdEnc.encoding(), 0, encoding, offset, field.width())) {
467  return true;
468  }
469  }
470 
471  return false;
472 }
473 
474 /**
475  * Checks that the given encoding and others in the field can be distinguished
476  * from each other.
477  *
478  * @param field The source field.
479  * @param encoding The encoding.
480  * @param width The width of the encoding where the encoding value is right
481  * aligned.
482  * @param offset The relative position of the encoding to the field's LSB.
483  * Positive shifts the encoding towards MSB and vice versa.
484  * @return True if the encoding can not be distinguished from another
485  * encoding.
486  */
487 bool
489  const SourceField& field, unsigned int encoding, unsigned int width,
490  int offset) {
491  unsigned truncatedEncoding;
492  unsigned truncatedWidth;
493  unsigned truncatedOffset;
494 
495  for (int i = 0; i < field.socketEncodingCount(); i++) {
496  const SocketEncoding& socketEnc = field.socketEncoding(i);
497 
498  bool socketIDOverlap = fieldsOverlap(
499  socketEnc.socketIDWidth(), socketEnc.socketIDPosition(), width,
500  offset);
501  std::tie(truncatedEncoding, truncatedWidth, truncatedOffset) =
502  splitEncodingTo(socketEnc, encoding, width, offset);
503  bool socketIDMatch = MathTools::bitFieldsEquals(
504  socketEnc.encoding(), truncatedOffset, truncatedEncoding, 0,
505  truncatedWidth);
506 
507  const SocketCodeTable& scTable = socketEnc.socketCodes();
508  // Get the part that overlaps with port codes.
509  std::tie(truncatedEncoding, truncatedWidth, truncatedOffset) =
511  encoding, width, scTable.width(),
512  offset - socketEnc.socketCodePosition());
513  bool socketCodeOverlap = truncatedWidth > 0;
514  bool socketCodeMatch = conflictsWithSocketTableEncodings(
515  scTable, truncatedEncoding, truncatedWidth, truncatedOffset);
516 
517  if (socketIDOverlap) {
518  if (socketCodeMatch && socketIDMatch && socketCodeMatch) {
519  return true;
520  } else if (!socketCodeOverlap && socketIDMatch) {
521  return true;
522  }
523  } else if (socketCodeOverlap && socketCodeMatch) {
524  return true;
525  }
526  }
527 
528  // check against simm
529  if (field.hasImmediateEncoding()) {
530  const ImmediateEncoding& simmEnc = field.immediateEncoding();
531  std::tie(truncatedEncoding, truncatedWidth, truncatedOffset) =
533  encoding, width, simmEnc.encodingWidth(),
534  offset - simmEnc.encodingPosition());
535 
537  simmEnc.encoding(), truncatedOffset, truncatedEncoding, 0,
538  truncatedWidth)) {
539  return true;
540  }
541  }
542 
543  return false;
544 }
545 
546 /**
547  * Checks that the given encoding and others in the field can be distinguished
548  * from each other.
549  *
550  * @param field The destination field.
551  * @param encoding The encoding.
552  * @param width The width of the encoding where the encoding value is right
553  * aligned.
554  * @param offset The relative position of the encoding to the field's LSB.
555  * Positive shifts the encoding towards MSB and vice versa.
556  * @return True if the encoding can not be distinguished from another
557  * encoding.
558  */
559 bool
561  const DestinationField& field, unsigned int encoding, unsigned int width,
562  int offset) {
563  unsigned truncatedEncoding;
564  unsigned truncatedWidth;
565  unsigned truncatedOffset;
566 
567  for (int i = 0; i < field.socketEncodingCount(); i++) {
568  const SocketEncoding& socketEnc = field.socketEncoding(i);
569  std::tie(truncatedEncoding, truncatedWidth, truncatedOffset) =
570  splitEncodingTo(socketEnc, encoding, width, offset);
571 
572  bool socketIDOverlap = fieldsOverlap(
573  socketEnc.socketIDWidth(), socketEnc.socketIDPosition(), width,
574  offset);
575  bool socketIDMatch = MathTools::bitFieldsEquals(
576  socketEnc.encoding(), truncatedOffset, truncatedEncoding, 0,
577  truncatedWidth);
578 
579  const SocketCodeTable& scTable = socketEnc.socketCodes();
580  // Get the part that overlaps with port codes.
581  std::tie(truncatedEncoding, truncatedWidth, truncatedOffset) =
583  encoding, width, scTable.width(),
584  offset - socketEnc.socketCodePosition());
585 
586  bool socketCodeOverlap = truncatedWidth > 0;
587  bool socketCodeMatch = conflictsWithSocketTableEncodings(
588  scTable, truncatedEncoding, truncatedWidth, truncatedOffset);
589 
590  if (socketIDOverlap) {
591  if (socketCodeOverlap && socketIDMatch && socketCodeMatch) {
592  return true;
593  } else if (!socketCodeOverlap && socketIDMatch) {
594  return true;
595  }
596  } else if (socketCodeOverlap && socketCodeMatch) {
597  return true;
598  }
599  }
600 
601  return false;
602 }
603 
604 /**
605  * Checks that the given encoding and others in the socket table can be
606  * distinguished from each other.
607  *
608  * @param scTable The socket code table.
609  * @param encoding The encoding.
610  * @param width The width of the encoding where the encoding value is right
611  * aligned.
612  * @param offset The relative position of the encoding to the field's LSB.
613  * Positive shifts the encoding towards MSB and vice versa.
614  * @return True if the encoding can not be distinguished from another
615  * encoding.
616  */
617 bool
619  const SocketCodeTable& scTable, unsigned int encoding, unsigned int width,
620  int offset) {
621  // The conflict checking assumes that port code is encoded as:
622  // |<- width ->|
623  // | encoding |<- (offset > 0) ------------------------|
624  // | extrabits | port code encoding | unused bits | index width |
625  // |<- socket code table width ->|
626  // msb lsb: 0
627  // note: port code encoding is left aligned and index bits are right
628  // aligned, leaving unused bits between them if table width
629  // is wider than the port code width.
630 
631  for (int i = 0; i < scTable.portCodeCount(); i++) {
632  const PortCode& portCode = scTable.portCode(i);
633  // Check port code encoding
634  if (portCode.encodingWidth() > 0) {
635  // note: extrabits of SocketCodeTable are not considered.
637  encoding, 0, portCode.encoding(),
638  portCode.encodingWidth() - width, width)) {
639  return true;
640  }
641  }
642 
643  // Check index part
644  if (portCode.indexWidth() > 0) {
645  if (fieldsOverlap(portCode.indexWidth(), 0, width, offset)) {
646  // todo/note: check if suggested encoding lands on unused
647  // index (when isMaxIndexSet() == true. Currently the feature
648  // is not used anywhere).
649  return true;
650  }
651  }
652  }
653  return false;
654 }
655 
656 /**
657  *
658  * Splits encoding to the target field.
659  *
660  * the splitted encoding is returned as tuple where the 1st item is encoding
661  * bits leaving out non-overlapping bits, the 2nd item is resulted width
662  * (width of overlap) and the 3rd item is position of the resulted encoding
663  * within the target field.
664  *
665  * @verbatim
666  * msb lsb
667  * |<- encoding width ->|
668  * |00001010110100100100|
669  * |<-- offset (>0) --|
670  * |<- target width ->|
671  *----------------------------------------------
672  * result encoding: |0100100|
673  * result width: |<----->|<-- offset (>0) --|
674  * @endverbatim
675  */
676 std::tuple<unsigned, unsigned, int>
678  unsigned encoding, unsigned encodingWidth, unsigned targetWidth,
679  int offsetToTarget) {
680  long int resultWidth =
681  std::min(
682  static_cast<int>(targetWidth),
683  offsetToTarget + static_cast<int>(encodingWidth)) -
684  std::max(0, offsetToTarget);
685 
686  if (offsetToTarget > static_cast<int>(targetWidth) || resultWidth <= 0) {
687  return std::make_tuple(0, 0, 0);
688  }
689 
690  unsigned resultEncoding = encoding;
691  int resultOffset = offsetToTarget;
692 
693  if (offsetToTarget < 0) {
694  assert(-offsetToTarget < 32 && "Invalid shift amount.");
695  resultEncoding = resultEncoding >> -offsetToTarget;
696  resultOffset = 0;
697  }
698  assert(resultWidth < 32 && "Invalid shift amount.");
699  unsigned mask = ~(~(0u) << resultWidth);
700  resultEncoding &= mask;
701  return std::make_tuple(resultEncoding, resultWidth, resultOffset);
702 }
703 
704 /**
705  * Splits the given encoding that overlaps with the SocketEncoding.
706  *
707  * Returns tuple where the 1st item is encoding bits leaving out
708  * non-overlapping bits, the 2nd item is resulted width (width of the overlap)
709  * and the 3rd item is position of the resulted encoding within the
710  * SocketEncoding.
711  */
712 std::tuple<unsigned, unsigned, int>
714  const SocketEncoding& socketEncoding, unsigned encoding,
715  unsigned encodingWidth, int offsetToTarget) {
716  return splitEncoding(
717  encoding, encodingWidth, socketEncoding.socketIDWidth(),
718  offsetToTarget - socketEncoding.socketIDPosition());
719 }
UnconditionalGuardEncoding.hh
SlotField::noOperationEncoding
NOPEncoding & noOperationEncoding() const
Definition: SlotField.cc:281
IUPortCode.hh
InstructionField::bitPosition
int bitPosition() const
Definition: InstructionField.cc:132
SocketCodeTable::rfPortCodeCount
int rfPortCodeCount() const
Definition: SocketCodeTable.cc:471
PortCode
Definition: PortCode.hh:45
DestinationField
Definition: DestinationField.hh:44
MoveSlot
Definition: MoveSlot.hh:60
GuardField::fuGuardEncoding
FUGuardEncoding & fuGuardEncoding(int index) const
Definition: GuardField.cc:387
SocketCodeTable::fuPortCode
FUPortCode & fuPortCode(int index) const
Definition: SocketCodeTable.cc:308
GuardField.hh
SourceField::hasImmediateEncoding
bool hasImmediateEncoding() const
Definition: SourceField.cc:279
IUPortCode
Definition: IUPortCode.hh:41
BridgeEncoding
Definition: BridgeEncoding.hh:47
SocketCodeTable.hh
SocketCodeTable::rfPortCode
RFPortCode & rfPortCode(int index) const
Definition: SocketCodeTable.cc:484
RFPortCode.hh
RFPortCode
Definition: RFPortCode.hh:44
FUPortCode
Definition: FUPortCode.hh:47
GuardField
Definition: GuardField.hh:55
SocketCodeTable::fuPortCodeCount
int fuPortCodeCount() const
Definition: SocketCodeTable.cc:295
ImmediateEncoding.hh
SocketEncoding::socketCodePosition
int socketCodePosition() const
Definition: SocketEncoding.cc:203
GuardField::unconditionalGuardEncoding
UnconditionalGuardEncoding & unconditionalGuardEncoding(bool inverted) const
Definition: GuardField.cc:490
SlotField::hasNoOperationEncoding
bool hasNoOperationEncoding() const
Definition: SlotField.cc:267
SourceField.hh
BEMTester::fieldsOverlap
static bool fieldsOverlap(const InstructionField &with, unsigned int toFieldWidth, int toFieldPos)
Definition: BEMTester.cc:382
FUGuardEncoding
Definition: FUGuardEncoding.hh:47
SlotField::socketEncoding
SocketEncoding & socketEncoding(int index) const
Definition: SlotField.cc:170
ImmediateEncoding::width
virtual int width() const
Definition: ImmediateEncoding.cc:207
MoveSlot.hh
BridgeEncoding.hh
SocketCodeTable::portCodeCount
int portCodeCount() const
Definition: SocketCodeTable.cc:648
InstructionField
Definition: InstructionField.hh:43
SocketCodeTable
Definition: SocketCodeTable.hh:68
BEMTester::conflictsWithGuardEncoding
static bool conflictsWithGuardEncoding(const GuardField &field, unsigned int encoding, unsigned int width, int offset)
Definition: BEMTester.cc:430
assert
#define assert(condition)
Definition: Application.hh:86
GuardField::gprGuardEncoding
GPRGuardEncoding & gprGuardEncoding(int index) const
Definition: GuardField.cc:290
Encoding::width
virtual int width() const
Definition: Encoding.cc:130
PortCode::extraBits
unsigned int extraBits() const
Definition: PortCode.cc:177
SlotField.hh
FUGuardEncoding.hh
PortCode::indexWidth
int indexWidth() const
Definition: PortCode.cc:215
MoveSlot::guardField
GuardField & guardField() const
Definition: MoveSlot.cc:215
SourceField::immediateEncoding
ImmediateEncoding & immediateEncoding() const
Definition: SourceField.cc:293
InstructionField::width
virtual int width() const =0
SocketCodeTable::iuPortCode
IUPortCode & iuPortCode(int index) const
Definition: SocketCodeTable.cc:600
SlotField::width
virtual int width() const
Definition: SlotField.cc:307
BEMTester.hh
BEMTester::commonBitCount
static int commonBitCount(unsigned int enc1, unsigned int extraBits1, unsigned int enc2, unsigned int extraBits2, int alignment)
Definition: BEMTester.cc:309
NOPEncoding.hh
BEMTester::calculateAlignment
static int calculateAlignment(unsigned int enc1, unsigned int enc2, const SlotField &field)
Definition: BEMTester.cc:352
SourceField::width
virtual int width() const
Definition: SourceField.cc:308
Encoding::encoding
unsigned int encoding() const
Definition: Encoding.cc:108
GuardField::hasUnconditionalGuardEncoding
bool hasUnconditionalGuardEncoding(bool inverted) const
Definition: GuardField.cc:471
SlotField::componentIDPosition
BinaryEncoding::Position componentIDPosition() const
Definition: SlotField.cc:296
GuardEncoding::encoding
unsigned int encoding() const
Definition: GuardEncoding.cc:112
MoveSlot::width
virtual int width() const
Definition: MoveSlot.cc:406
MoveSlot::sourceField
SourceField & sourceField() const
Definition: MoveSlot.cc:277
NOPEncoding
Definition: NOPEncoding.hh:44
SocketEncoding.hh
GPRGuardEncoding.hh
BEMTester::conflictsWithDestinationEncodings
static bool conflictsWithDestinationEncodings(const DestinationField &field, unsigned int encoding, unsigned int width, int offset)
Definition: BEMTester.cc:560
MathTools::bit
static bool bit(ULongWord integer, unsigned int index)
BEMTester::canAddPortEncoding
static bool canAddPortEncoding(SocketCodeTable &table, unsigned int encoding, unsigned int extraBits)
Definition: BEMTester.cc:247
PortCode::encodingWidth
int encodingWidth() const
Definition: PortCode.cc:204
GuardField::gprGuardEncodingCount
int gprGuardEncodingCount() const
Definition: GuardField.cc:276
ImmediateEncoding::encodingWidth
int encodingWidth() const
Definition: ImmediateEncoding.cc:155
SocketEncoding::socketIDWidth
int socketIDWidth() const
Definition: SocketEncoding.cc:264
BEMTester::splitEncoding
static std::tuple< unsigned, unsigned, int > splitEncoding(unsigned encoding, unsigned encodingWidth, unsigned targetWidth, int offsetToTarget)
Definition: BEMTester.cc:677
SocketEncoding::socketIDPosition
int socketIDPosition() const
Definition: SocketEncoding.cc:249
SocketCodeTable::iuPortCodeCount
int iuPortCodeCount() const
Definition: SocketCodeTable.cc:587
GuardField::fuGuardEncodingCount
int fuGuardEncodingCount() const
Definition: GuardField.cc:373
BinaryEncoding::RIGHT
@ RIGHT
Definition: BinaryEncoding.hh:65
SlotField
Definition: SlotField.hh:58
BEMTester::splitEncodingTo
static std::tuple< unsigned, unsigned, int > splitEncodingTo(const SocketEncoding &socketEncoding, unsigned encoding, unsigned encodingWidth, int offsetToTarget)
Definition: BEMTester.cc:713
BEMTester::conflictsWithSourceEncodings
static bool conflictsWithSourceEncodings(const SourceField &field, unsigned int encoding, unsigned int width, int offset)
Definition: BEMTester.cc:488
MathTools::bitLength
static unsigned int bitLength(long unsigned int number)
ImmediateEncoding::encodingPosition
int encodingPosition() const
Definition: ImmediateEncoding.cc:166
SourceField::bridgeEncodingCount
int bridgeEncodingCount() const
Definition: SourceField.cc:209
BEMTester::canAddComponentEncoding
static bool canAddComponentEncoding(SlotField &field, unsigned int encoding, unsigned int extraBits)
Definition: BEMTester.cc:73
SlotField::socketEncodingCount
int socketEncodingCount() const
Definition: SlotField.cc:156
SocketCodeTable::portCode
PortCode & portCode(int index) const
Definition: SocketCodeTable.cc:662
MoveSlot::destinationField
DestinationField & destinationField() const
Definition: MoveSlot.cc:341
SourceField::bridgeEncoding
BridgeEncoding & bridgeEncoding(const std::string &bridge) const
Definition: SourceField.cc:191
DestinationField.hh
MathTools.hh
ImmediateEncoding
Definition: ImmediateEncoding.hh:44
BEMTools.hh
SocketEncoding::socketCodes
SocketCodeTable & socketCodes() const
Definition: SocketEncoding.cc:191
SocketEncoding
Definition: SocketEncoding.hh:51
BEMTester::conflictsWithSocketTableEncodings
static bool conflictsWithSocketTableEncodings(const SocketCodeTable &scTable, unsigned int encoding, unsigned int width, int offset)
Definition: BEMTester.cc:618
GPRGuardEncoding
Definition: GPRGuardEncoding.hh:47
FUPortCode.hh
PortCode::encoding
unsigned int encoding() const
Definition: PortCode.cc:164
UnconditionalGuardEncoding
Definition: UnconditionalGuardEncoding.hh:47
BEMTools::encodingWidth
static unsigned encodingWidth(unsigned encoding, unsigned extrabits)
Definition: BEMTools.cc:46
SocketCodeTable::width
int width() const
Definition: SocketCodeTable.cc:200
Encoding::extraBits
unsigned int extraBits() const
Definition: Encoding.cc:119
GuardField::width
virtual int width() const
Definition: GuardField.cc:533
BEMTester::canAddComponentPriorityEncoding
static bool canAddComponentPriorityEncoding(MoveSlot &slot, unsigned int encoding, unsigned int extraBits, int offset=0)
Definition: BEMTester.cc:180
MathTools::bitFieldsEquals
static bool bitFieldsEquals(unsigned enc1, unsigned pos1, unsigned enc2, unsigned pos2, unsigned width)
SourceField
Definition: SourceField.hh:48