OpenASIP  2.0
Public Member Functions | Private Types | Private Attributes | List of all members
BitMatrix Class Reference

#include <BitMatrix.hh>

Inheritance diagram for BitMatrix:
Inheritance graph
Collaboration diagram for BitMatrix:
Collaboration graph

Public Member Functions

 BitMatrix (int width, int height, bool initialValue)
 
 BitMatrix (const BitMatrix &another)
 
virtual ~BitMatrix ()
 
bool bitAt (int column, int row) const
 
void setBit (int column, int row, bool value)
 
void setAllToZero ()
 
void setAllToOne ()
 
void shiftLeft ()
 
void orWith (const BitMatrix &another)
 
bool conflictsWith (const BitMatrix &another) const
 
int rowCount () const
 
int columnCount () const
 
std::string toString () const
 
std::string toDotString () const
 
bool operator== (const BitMatrix &other) const
 
bool operator< (const BitMatrix &rightHand) const
 

Private Types

typedef unsigned RowWord
 

Private Attributes

RowWordmatrix_
 
const int rows_
 
const int columns_
 
const int wordsPerRow_
 

Detailed Description

Models a bit matrix.

The implementation should be quite efficient. It uses natural words of the machine to store the bits to provide fast logical operations on larger bit chunks at the same time. Especially functions such as fully ORing and ANDing two bit matrices should be quite efficient. Checking a single matrix element is couple of cycles slower than the naive implementation of storing one bit per word. The main methods are inline non-virtual methods for fastest possible access.

Definition at line 49 of file BitMatrix.hh.

Member Typedef Documentation

◆ RowWord

typedef unsigned BitMatrix::RowWord
private

Definition at line 73 of file BitMatrix.hh.

Constructor & Destructor Documentation

◆ BitMatrix() [1/2]

BitMatrix::BitMatrix ( int  width,
int  height,
bool  initialValue 
)

Builds a bit matrix of given size and default content.

Parameters
widthThe width of the matrix.
heightThe height of the matrix.
initialValueThe initial value for elements.

Definition at line 46 of file BitMatrix.cc.

46  :
47  rows_(height), columns_(width), wordsPerRow_(
48  static_cast<int>(
49  std::ceil(columns_ / float(sizeof(RowWord) * BYTE_BITWIDTH)))) {
50 
52 
53  RowWord word = 0;
54  if (initialValue) {
55  word = ~word;
56  }
57  for (int row = 0; row < rows_; ++row) {
58  for (int col = 0; col < wordsPerRow_; ++col) {
59  matrix_[row * wordsPerRow_ + col] = word;
60  }
61  }
62 }

References matrix_, rows_, and wordsPerRow_.

◆ BitMatrix() [2/2]

BitMatrix::BitMatrix ( const BitMatrix another)

Copy constructor.

Definition at line 75 of file BitMatrix.cc.

75  :
76  rows_(another.rows_), columns_(another.columns_),
77  wordsPerRow_(another.wordsPerRow_) {
78 
80 
81  for (int row = 0; row < rows_; ++row) {
82  for (int col = 0; col < wordsPerRow_; ++col) {
83  matrix_[row * wordsPerRow_ + col] =
84  another.matrix_[row * wordsPerRow_ + col];
85  }
86  }
87 }

References matrix_, rows_, and wordsPerRow_.

◆ ~BitMatrix()

BitMatrix::~BitMatrix ( )
virtual

Frees the bit matrix content storage.

Definition at line 67 of file BitMatrix.cc.

67  {
68  delete[] matrix_;
69  matrix_ = NULL;
70 }

References matrix_.

Member Function Documentation

◆ bitAt()

bool BitMatrix::bitAt ( int  column,
int  row 
) const

◆ columnCount()

int BitMatrix::columnCount ( ) const

◆ conflictsWith()

bool BitMatrix::conflictsWith ( const BitMatrix another) const

◆ operator<()

bool BitMatrix::operator< ( const BitMatrix rightHand) const

Returns true in case the given matrix is "smaller" than this one.

The one that has the first non-equal non-zero matrix element is considered larger. That is, the matrix is considered as a bit string. This is an arbitrary ordering constraint to make it possible to store BitMatrices in sets.

Parameters
rightHandThe right hand side of the comparison.
Returns
True in case the the right hand is considered larger.

Definition at line 192 of file BitMatrix.cc.

192  {
193 
194  for (int row = 0; row < rows_; ++row) {
195  for (int column = 0; column < columns_; ++column) {
196  bool left = bitAt(column, row);
197  bool right = rightHand.bitAt(column, row);
198  if (left != right)
199  return static_cast<int>(left) < static_cast<int>(right);
200  }
201  }
202  // they are equal
203  return false;
204 }

References bitAt(), columns_, and rows_.

Here is the call graph for this function:

◆ operator==()

bool BitMatrix::operator== ( const BitMatrix other) const

Compares two bit matrices..

Parameters
otherThe RT to compare to.
Returns
True in case all values in both reservation tables are equal and the dimensions are the same.

Definition at line 143 of file BitMatrix.cc.

143  {
144 
145  if (other.rows_ != rows_ || other.columns_ != columns_)
146  return false;
147 
148  for (int row = 0; row < rows_; ++row) {
149  for (int col = 0; col < columns_; ++col) {
150  if (other.bitAt(col, row) != bitAt(col, row))
151  return false;
152  }
153  }
154  return true;
155 }

References bitAt(), columns_, and rows_.

Here is the call graph for this function:

◆ orWith()

void BitMatrix::orWith ( const BitMatrix another)

◆ rowCount()

int BitMatrix::rowCount ( ) const

◆ setAllToOne()

void BitMatrix::setAllToOne ( )

Sets all bits to one.

Definition at line 106 of file BitMatrix.cc.

106  {
107 
108  for (int row = 0; row < rows_; ++row) {
109  for (int col = 0; col < wordsPerRow_; ++col) {
110  matrix_[row * wordsPerRow_ + col] = ~0;
111  }
112  }
113 }

References matrix_, rows_, and wordsPerRow_.

◆ setAllToZero()

void BitMatrix::setAllToZero ( )

Sets all bits to zero.

Definition at line 93 of file BitMatrix.cc.

93  {
94 
95  for (int row = 0; row < rows_; ++row) {
96  for (int col = 0; col < wordsPerRow_; ++col) {
97  matrix_[row * wordsPerRow_ + col] = 0;
98  }
99  }
100 }

References matrix_, rows_, and wordsPerRow_.

Referenced by DCMFUResourceConflictDetector::reset(), and ReservationTableFUResourceConflictDetector::reset().

◆ setBit()

void BitMatrix::setBit ( int  column,
int  row,
bool  value 
)

◆ shiftLeft()

void BitMatrix::shiftLeft ( )

◆ toDotString()

std::string BitMatrix::toDotString ( ) const

Returns a textual description of the matrix suitable to be used as a dot edge/node label.

Returns
A string describing the matrix.

Definition at line 164 of file BitMatrix.cc.

164  {
165 
166  std::string theString = "";
167  for (int row = 0; row < rows_; ++row) {
168  for (int column = 0; column < columns_;
169  ++column) {
170  if (bitAt(column, row))
171  theString += "1 ";
172  else
173  theString += "0 ";
174  }
175  theString += "\\n";
176  }
177  return theString;
178 }

References bitAt(), columns_, and rows_.

Here is the call graph for this function:

◆ toString()

std::string BitMatrix::toString ( ) const

ASCII representation of the bit matrix.

For debugging and testing.

Returns
A string representation of the matrix.

Definition at line 124 of file BitMatrix.cc.

124  {
125  std::ostringstream s;
126  for (int row = 0; row < rows_; ++row) {
127  for (int col = 0; col < columns_; ++col) {
128  s << bitAt(col, row) << " ";
129  }
130  s << std::endl;
131  }
132  return s.str();
133 }

References bitAt(), columns_, and rows_.

Here is the call graph for this function:

Member Data Documentation

◆ columns_

const int BitMatrix::columns_
private

Definition at line 79 of file BitMatrix.hh.

Referenced by operator<(), operator==(), toDotString(), and toString().

◆ matrix_

RowWord* BitMatrix::matrix_
private

Definition at line 75 of file BitMatrix.hh.

Referenced by BitMatrix(), setAllToOne(), setAllToZero(), and ~BitMatrix().

◆ rows_

const int BitMatrix::rows_
private

◆ wordsPerRow_

const int BitMatrix::wordsPerRow_
private

Definition at line 81 of file BitMatrix.hh.

Referenced by BitMatrix(), setAllToOne(), and setAllToZero().


The documentation for this class was generated from the following files:
BitMatrix::columns_
const int columns_
Definition: BitMatrix.hh:79
BitMatrix::wordsPerRow_
const int wordsPerRow_
Definition: BitMatrix.hh:81
BitMatrix::rows_
const int rows_
Definition: BitMatrix.hh:77
BitMatrix::matrix_
RowWord * matrix_
Definition: BitMatrix.hh:75
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
BitMatrix::RowWord
unsigned RowWord
Definition: BitMatrix.hh:73
BitMatrix::bitAt
bool bitAt(int column, int row) const