OpenASIP  2.0
BitMatrix.hh
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 BitMatrix.hh
26  *
27  * Declaration of BitMatrix class
28  *
29  * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_BIT_MATRIX_HH
34 #define TTA_BIT_MATRIX_HH
35 
36 #include <string>
37 
38 /**
39  * Models a bit matrix.
40  *
41  * The implementation should be quite efficient. It uses natural words of
42  * the machine to store the bits to provide fast logical operations on
43  * larger bit chunks at the same time. Especially functions such as fully ORing
44  * and ANDing two bit matrices should be quite efficient. Checking a single
45  * matrix element is couple of cycles slower than the naive implementation
46  * of storing one bit per word. The main methods are inline non-virtual
47  * methods for fastest possible access.
48  */
49 class BitMatrix {
50 public:
51  BitMatrix(int width, int height, bool initialValue);
52  BitMatrix(const BitMatrix& another);
53  virtual ~BitMatrix();
54 
55  bool bitAt(int column, int row) const;
56  void setBit(int column, int row, bool value);
57  void setAllToZero();
58  void setAllToOne();
59  void shiftLeft();
60  void orWith(const BitMatrix& another);
61  bool conflictsWith(const BitMatrix& another) const;
62 
63  int rowCount() const;
64  int columnCount() const;
65 
66  std::string toString() const;
67  std::string toDotString() const;
68 
69  bool operator==(const BitMatrix& other) const;
70  bool operator<(const BitMatrix& rightHand) const;
71 private:
72  // Storage for bits of a row in the reservation table.
73  typedef unsigned RowWord;
74  // The contents of the matrix.
76  // Count of rows in the matrix.
77  const int rows_;
78  // Count of columns in the matrix.
79  const int columns_;
80  // Count of words per row to store the bits.
81  const int wordsPerRow_;
82 };
83 
84 #include "BitMatrix.icc"
85 
86 #endif
BitMatrix
Definition: BitMatrix.hh:49
BitMatrix::orWith
void orWith(const BitMatrix &another)
BitMatrix::toDotString
std::string toDotString() const
Definition: BitMatrix.cc:164
BitMatrix.icc
BitMatrix::toString
std::string toString() const
Definition: BitMatrix.cc:124
BitMatrix::setAllToZero
void setAllToZero()
Definition: BitMatrix.cc:93
BitMatrix::columns_
const int columns_
Definition: BitMatrix.hh:79
BitMatrix::operator<
bool operator<(const BitMatrix &rightHand) const
Definition: BitMatrix.cc:192
BitMatrix::rowCount
int rowCount() const
BitMatrix::operator==
bool operator==(const BitMatrix &other) const
Definition: BitMatrix.cc:143
BitMatrix::wordsPerRow_
const int wordsPerRow_
Definition: BitMatrix.hh:81
BitMatrix::shiftLeft
void shiftLeft()
BitMatrix::rows_
const int rows_
Definition: BitMatrix.hh:77
BitMatrix::BitMatrix
BitMatrix(int width, int height, bool initialValue)
Definition: BitMatrix.cc:46
BitMatrix::~BitMatrix
virtual ~BitMatrix()
Definition: BitMatrix.cc:67
BitMatrix::matrix_
RowWord * matrix_
Definition: BitMatrix.hh:75
BitMatrix::RowWord
unsigned RowWord
Definition: BitMatrix.hh:73
BitMatrix::columnCount
int columnCount() const
BitMatrix::bitAt
bool bitAt(int column, int row) const
BitMatrix::setAllToOne
void setAllToOne()
Definition: BitMatrix.cc:106
BitMatrix::setBit
void setBit(int column, int row, bool value)
BitMatrix::conflictsWith
bool conflictsWith(const BitMatrix &another) const