CGRA-ME
BitSetting.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * The software programs comprising "CGRA-ME" and the documentation provided
3  * with them are copyright by its authors and the University of Toronto. Only
4  * non-commercial, not-for-profit use of this software is permitted without ex-
5  * plicit permission. This software is provided "as is" with no warranties or
6  * guarantees of support. See the LICENCE for more details. You should have re-
7  * ceived a copy of the full licence along with this software. If not, see
8  * <http://cgra-me.ece.utoronto.ca/license/>.
9  ******************************************************************************/
10 
11 #ifndef __BITSETTING_H__
12 #define __BITSETTING_H__
13 
14 #include <iosfwd>
15 #include <string>
16 #include <vector>
17 
18 enum class BitSetting {
19  LOW,
20  HIGH,
24 };
25 
26 template<typename T>
27 T from_bool(bool b);
28 
29 template<>
32 
33 std::ostream& operator<<(std::ostream& os, const BitSetting& bs);
34 std::ostream& operator<<(std::ostream& os, const std::vector<BitSetting>& bits);
35 
38 };
39 
40 inline BitSettingForVerilog for_verilog(const BitSetting& bs) { return { bs }; }
41 std::ostream& operator<<(std::ostream& os, const BitSettingForVerilog& bs);
42 
43 template<typename INTEGRAL>
44 std::vector<BitSetting>& push_back_int(std::vector<BitSetting>& v, const INTEGRAL& value, int num_bits) {
45  for (int ibit = num_bits; ibit != 0; --ibit) {
46  v.push_back(from_bool<BitSetting>((value >> (ibit-1)) % 2));
47  }
48  return v;
49 }
50 
51 template<typename INTEGRAL>
52 std::vector<BitSetting> bitsettings_from_int(const INTEGRAL& value, int num_bits) {
53  std::vector<BitSetting> result;
54  push_back_int(result, value, num_bits);
55  return result;
56 }
57 
58 class BitConfig {
59  public:
60  BitConfig(int n_contexts) : bitSettings(n_contexts){};
61 
62  // Add bit setting for next cycle
63  void add(std::vector<BitSetting> bitsetting, int cycle) {
64  bitSettings[cycle] = std::move(bitsetting);
65  };
66 
67  void setUsedCycles(int uc){ used_cycles = uc;}
68  int getUsedCycles()const {return used_cycles;}
69 
70  // Add a bit to the end of the bit setting at cycle `cycle.
71  // void add(BitSetting bitsetting, int cycle) {
72  // bitSettings[cycle].emplace_back(bitsetting);
73  // }
74 
75  const std::vector<BitSetting>& operator[](int cycle) const {
76  return bitSettings[cycle];
77  }
78 
79  auto begin() const {return bitSettings.begin();}
80  auto end() const {return bitSettings.end();}
81 
82  const std::vector<std::vector<BitSetting>>& getBitSetting() const {
83  return bitSettings;
84  }
85  private:
86  // Outer vector keeps track of BitSetting per cycle
87  // Inner vector are the bits for that cycle
88  std::vector<std::vector<BitSetting>> bitSettings;
89  int used_cycles = 0;
90 };
91 
92 #endif /* __BITSETTING_H__ */
BitSetting::HIGH
@ HIGH
BitConfig
Definition: BitSetting.h:58
BitSetting::DONT_CARE_PREFER_HIGH
@ DONT_CARE_PREFER_HIGH
BitSetting::HIGH_IMPEDANCE
@ HIGH_IMPEDANCE
BitSetting
BitSetting
Definition: BitSetting.h:18
BitSetting::DONT_CARE_PREFER_LOW
@ DONT_CARE_PREFER_LOW
push_back_int
std::vector< BitSetting > & push_back_int(std::vector< BitSetting > &v, const INTEGRAL &value, int num_bits)
Definition: BitSetting.h:44
BitConfig::add
void add(std::vector< BitSetting > bitsetting, int cycle)
Definition: BitSetting.h:63
from_bool< BitSetting >
BitSetting from_bool< BitSetting >(bool b)
Definition: BitSetting.cpp:17
BitConfig::end
auto end() const
Definition: BitSetting.h:80
BitConfig::begin
auto begin() const
Definition: BitSetting.h:79
BitSetting::LOW
@ LOW
BitConfig::bitSettings
std::vector< std::vector< BitSetting > > bitSettings
Definition: BitSetting.h:88
force_to_rail
BitSetting force_to_rail(const BitSetting &bs)
Definition: BitSetting.cpp:25
BitConfig::operator[]
const std::vector< BitSetting > & operator[](int cycle) const
Definition: BitSetting.h:75
from_bool
T from_bool(bool b)
BitConfig::setUsedCycles
void setUsedCycles(int uc)
Definition: BitSetting.h:67
BitConfig::BitConfig
BitConfig(int n_contexts)
Definition: BitSetting.h:60
BitSettingForVerilog::val
BitSetting val
Definition: BitSetting.h:37
BitConfig::getUsedCycles
int getUsedCycles() const
Definition: BitSetting.h:68
for_verilog
BitSettingForVerilog for_verilog(const BitSetting &bs)
Definition: BitSetting.h:40
operator<<
std::ostream & operator<<(std::ostream &os, const BitSetting &bs)
Definition: BitSetting.cpp:38
BitConfig::getBitSetting
const std::vector< std::vector< BitSetting > > & getBitSetting() const
Definition: BitSetting.h:82
BitConfig::used_cycles
int used_cycles
Definition: BitSetting.h:89
BitSettingForVerilog
Definition: BitSetting.h:36
bitsettings_from_int
std::vector< BitSetting > bitsettings_from_int(const INTEGRAL &value, int num_bits)
Definition: BitSetting.h:52