gem5  v21.1.0.2
sc_bit.hh
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_bit.h -- Bit class.
23 
24  Original Author: Stan Y. Liao, Synopsys, Inc.
25 
26  *****************************************************************************/
27 
28 /*****************************************************************************
29 
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32 
33  Name, Affiliation, Date:
34  Description of Modification:
35 
36  *****************************************************************************/
37 
38 // $Log: sc_bit.h,v $
39 // Revision 1.2 2011/08/07 18:54:19 acg
40 // Philipp A. Hartmann: remove friend function declarations that implement
41 // code, and clean up how bit and logic operators are defined in general.
42 //
43 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
44 // SystemC 2.3
45 //
46 // Revision 1.6 2006/05/08 17:49:59 acg
47 // Andy Goodrich: Added David Long's declarations for friend operators,
48 // functions, and methods, to keep the Microsoft compiler happy.
49 //
50 // Revision 1.5 2006/04/12 20:17:52 acg
51 // Andy Goodrich: enabled deprecation message for sc_bit.
52 //
53 // Revision 1.4 2006/01/24 20:50:55 acg
54 // Andy Goodrich: added warnings indicating that sc_bit is deprecated and that
55 // the C bool data type should be used in its place.
56 //
57 // Revision 1.3 2006/01/13 18:53:53 acg
58 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
59 // the source.
60 //
61 
62 #ifndef __SYSTEMC_EXT_DT_BIT_SC_BIT_HH__
63 #define __SYSTEMC_EXT_DT_BIT_SC_BIT_HH__
64 
65 #include <iostream>
66 
67 #include "../int/sc_nbdefs.hh"
68 
69 namespace sc_dt
70 {
71 
72 // classes defined in this module
73 class sc_bit;
74 
75 // forward class declarations
76 class sc_logic;
77 
78 extern void sc_deprecated_sc_bit();
79 
80 // ----------------------------------------------------------------------------
81 // CLASS : sc_bit
82 //
83 // Bit class.
84 // Note: VSIA compatibility indicated.
85 // ----------------------------------------------------------------------------
86 
87 class sc_bit
88 {
89  // support methods
90 
91  static void invalid_value(char);
92  static void invalid_value(int);
93 
94  static bool
95  to_value(char c)
96  {
97  if (c != '0' && c != '1') {
99  }
100  return (c == '0' ? false : true);
101  }
102 
103  static bool
104  to_value(int i)
105  {
106  if (i != 0 && i != 1) {
107  invalid_value(i);
108  }
109  return (i == 0 ? false : true);
110  }
111  static bool to_value(bool b) { return b; }
112 
113 #define DEFN_TO_VALUE_T(tp) \
114  static bool to_value(tp i) { return to_value((int)i); }
115 
116  DEFN_TO_VALUE_T(unsigned)
117  DEFN_TO_VALUE_T(long)
118  DEFN_TO_VALUE_T(unsigned long)
121 
122 #undef DEFN_TO_VALUE_T
123 
124  public:
125  // constructors
126  // MANDATORY
127  sc_bit() : m_val(false) { sc_deprecated_sc_bit(); }
128 
129 #define DEFN_CTOR_T(tp) \
130  explicit sc_bit(tp a) : m_val(to_value(a)) { sc_deprecated_sc_bit(); }
131 
132  DEFN_CTOR_T(bool)
133  DEFN_CTOR_T(char)
134  DEFN_CTOR_T(int)
135  DEFN_CTOR_T(unsigned)
136  DEFN_CTOR_T(long)
137  DEFN_CTOR_T(unsigned long)
140 
141 #undef DEFN_CTOR_T
142 
143  explicit sc_bit(const sc_logic &a); // non-VSIA
144 
145  // copy constructor
146  // MANDATORY
147  sc_bit(const sc_bit &a) : m_val(a.m_val) {}
148 
149  // destructor
150  // MANDATORY
151  ~sc_bit() {}
152 
153  // assignment operators
154  // MANDATORY
155  sc_bit &
156  operator = (const sc_bit &b)
157  {
158  m_val = b.m_val;
159  return *this;
160  }
161 
162 #define DEFN_ASN_OP_T(op, tp) \
163  sc_bit &operator op(tp b) { return (*this op sc_bit(b)); }
164 #define DEFN_ASN_OP(op) \
165  DEFN_ASN_OP_T(op,int) \
166  DEFN_ASN_OP_T(op,bool) \
167  DEFN_ASN_OP_T(op,char)
168 
169  DEFN_ASN_OP(=)
172  DEFN_ASN_OP_T(=,long)
173  DEFN_ASN_OP_T(=,unsigned long)
174 
175  sc_bit &operator = (const sc_logic &b); // non-VSIA
176 
177  // bitwise assignment operators
179  operator &= (const sc_bit &b)
180  {
181  m_val = (m_val && b.m_val);
182  return *this;
183  }
184 
185  sc_bit &
186  operator |= (const sc_bit &b)
187  {
188  m_val = (m_val || b.m_val);
189  return *this;
190  }
191 
192  sc_bit &
194  {
195  m_val = (m_val != b.m_val);
196  return *this;
197  }
198 
199  DEFN_ASN_OP(&=)
200  DEFN_ASN_OP(|=)
201  DEFN_ASN_OP(^=)
202 
203 #undef DEFN_ASN_OP_T
204 #undef DEFN_ASN_OP
205 
206  // conversions
207  // MANDATORY
208 
209  // implicit conversion to bool
210  operator bool () const { return m_val; }
211 
212  // non-VSIA
213  bool operator ! () const { return !m_val; }
214 
215 
216  // explicit conversions - non-VSIA
217  bool to_bool() const { return m_val; }
218  char to_char() const { return (m_val ? '1' : '0'); }
219 
220  // relational operators and functions
221  // MANDATORY
222  friend bool operator == (const sc_bit &a, const sc_bit &b);
223  friend bool operator != (const sc_bit &a, const sc_bit &b);
224 
225  // bitwise operators and functions
226 
227  // bitwise complement
228  // MANDATORY
229  friend const sc_bit operator ~ (const sc_bit &a);
230 
231  // RECOMMENDED
232  sc_bit &
233  b_not()
234  {
235  m_val = (!m_val);
236  return *this;
237  }
238 
239  // binary bit-wise operations
240  friend const sc_bit operator | (const sc_bit &a, const sc_bit &b);
241  friend const sc_bit operator & (const sc_bit &a, const sc_bit &b);
242  friend const sc_bit operator ^ (const sc_bit &a, const sc_bit &b);
243 
244  // other methods
245  void print(::std::ostream &os=::std::cout) const { os << to_bool(); }
246  void scan(::std::istream & =::std::cin);
247 
248  private:
249  bool m_val;
250 };
251 
252 // ----------------------------------------------------------------------------
253 // relational operators and functions
254 
255 #define DEFN_BIN_FUN_T(ret,fun,tp) \
256  inline ret fun(const sc_bit& a, tp b) { return fun(a, sc_bit(b)); } \
257  inline ret fun(tp b, const sc_bit &a) { return fun(sc_bit(a), b); }
258 
259 #define DEFN_BIN_FUN(ret,fun) \
260  DEFN_BIN_FUN_T(ret,fun,bool) \
261  DEFN_BIN_FUN_T(ret,fun,char) \
262  DEFN_BIN_FUN_T(ret,fun,int)
263 
264 // MANDATORY
265 inline bool
266 operator == (const sc_bit &a, const sc_bit &b)
267 {
268  return (a.m_val == b.m_val);
269 }
270 
271 inline bool
272 operator != (const sc_bit &a, const sc_bit &b)
273 {
274  return (a.m_val != b.m_val);
275 }
276 
277 DEFN_BIN_FUN(bool, operator ==)
278 DEFN_BIN_FUN(bool, operator !=)
279 
280 // OPTIONAL
281 
282 inline bool equal(const sc_bit &a, const sc_bit &b) { return (a == b); }
283 
284 inline bool not_equal(const sc_bit &a, const sc_bit &b) { return (a != b); }
285 
288 
289 // ----------------------------------------------------------------------------
290 // bitwise operators and functions
291 
292 // bitwise complement
293 
294 // MANDATORY
295 inline const sc_bit operator ~ (const sc_bit &a) { return sc_bit(!a.m_val); }
296 
297 // OPTIONAL
298 inline const sc_bit b_not(const sc_bit &a) { return (~a); }
299 
300 // RECOMMENDED
301 inline void b_not(sc_bit &r, const sc_bit &a) { r = (~a); }
302 
303 // binary bit-wise operations
304 // MANDATORY
305 inline const sc_bit
306 operator & (const sc_bit &a, const sc_bit &b)
307 {
308  return sc_bit(a.m_val && b.m_val);
309 }
310 
311 inline const sc_bit
312 operator | (const sc_bit &a, const sc_bit &b)
313 {
314  return sc_bit(a.m_val || b.m_val);
315 }
316 
317 inline const sc_bit
318 operator ^ (const sc_bit &a, const sc_bit &b)
319 {
320  return sc_bit(a.m_val != b.m_val);
321 }
322 
323 DEFN_BIN_FUN(const sc_bit,operator&)
324 DEFN_BIN_FUN(const sc_bit,operator|)
325 DEFN_BIN_FUN(const sc_bit,operator^)
326 
327 // OPTIONAL
328 inline const sc_bit b_and(const sc_bit &a, const sc_bit &b) { return a & b; }
329 inline const sc_bit b_or(const sc_bit &a, const sc_bit &b) { return a | b; }
330 inline const sc_bit b_xor(const sc_bit &a, const sc_bit &b) { return a ^ b; }
331 
333 DEFN_BIN_FUN(const sc_bit,b_or)
335 
336 // RECOMMENDED
337 
338 #define DEFN_TRN_FUN_T(fun,tp) \
339  inline void \
340  fun(sc_bit &r, const sc_bit &a, tp b) \
341  { r = fun(a, sc_bit(b)); } \
342  inline void \
343  fun(sc_bit &r, tp a, const sc_bit &b) \
344  { r = fun(sc_bit(a), b); }
345 
346 #define DEFN_TRN_FUN(fun) \
347  inline void \
348  fun(sc_bit &r, const sc_bit &a, const sc_bit &b) { r = fun(a , b); } \
349  DEFN_TRN_FUN_T(fun, int) \
350  DEFN_TRN_FUN_T(fun, bool) \
351  DEFN_TRN_FUN_T(fun, char)
352 
356 
357 #undef DEFN_BIN_FUN_T
358 #undef DEFN_BIN_FUN
359 #undef DEFN_TRN_FUN_T
360 #undef DEFN_TRN_FUN
361 
362 
363 // ----------------------------------------------------------------------------
364 
365 inline ::std::ostream &
366 operator << (::std::ostream &os, const sc_bit &a)
367 {
368  a.print(os);
369  return os;
370 }
371 
372 inline ::std::istream &
373 operator >> (::std::istream &is, sc_bit &a)
374 {
375  a.scan(is);
376  return is;
377 }
378 
379 } // namespace sc_dt
380 
381 #endif // __SYSTEMC_EXT_DT_BIT_SC_BIT_HH__
sc_dt::not_equal
bool not_equal(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:315
sc_dt::operator|
sc_signed operator|(const sc_unsigned &u, const sc_int_base &v)
Definition: sc_signed.cc:791
sc_dt::equal
bool equal(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:313
sc_dt::sc_deprecated_sc_bit
void sc_deprecated_sc_bit()
Definition: sc_bit.cc:150
sc_dt::sc_bit::operator^
const friend sc_bit operator^(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:349
sc_dt::sc_bit::~sc_bit
~sc_bit()
Definition: sc_bit.hh:182
sc_dt
Definition: sc_bit.cc:67
sc_dt::sc_bit::to_bool
bool to_bool() const
Definition: sc_bit.hh:248
sc_dt::operator<<
sc_signed operator<<(const sc_signed &u, const sc_int_base &v)
Definition: sc_signed.cc:853
sc_dt::sc_bit::operator|
const friend sc_bit operator|(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:343
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:65
sc_dt::sc_bit::invalid_value
static void invalid_value(char)
Definition: sc_bit.cc:110
sc_dt::sc_logic
Definition: sc_logic.hh:130
sc_dt::sc_bit::b_not
sc_bit & b_not()
Definition: sc_bit.hh:264
sc_dt::operator^
sc_signed operator^(const sc_unsigned &u, const sc_int_base &v)
Definition: sc_signed.cc:822
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
sc_dt::operator==
bool operator==(const sc_signed &u, const sc_int_base &v)
Definition: sc_signed.cc:879
gem5::MipsISA::is
Bitfield< 24, 22 > is
Definition: pra_constants.hh:235
sc_dt::sc_bit::operator=
sc_bit & operator=(const sc_bit &b)
Definition: sc_bit.hh:187
sc_dt::b_and
const sc_bit b_and(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:359
DEFN_BIN_FUN
#define DEFN_BIN_FUN(ret, fun)
Definition: sc_bit.hh:290
sc_dt::sc_bit::operator~
const friend sc_bit operator~(const sc_bit &a)
Definition: sc_bit.hh:326
DEFN_ASN_OP
#define DEFN_ASN_OP(op)
Definition: sc_bit.hh:195
gem5::ArmISA::b
Bitfield< 7 > b
Definition: misc_types.hh:381
DEFN_CTOR_T
#define DEFN_CTOR_T(tp)
Definition: sc_bit.hh:160
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
DEFN_TO_VALUE_T
#define DEFN_TO_VALUE_T(tp)
Definition: sc_bit.hh:144
sc_dt::sc_bit::scan
void scan(::std::istream &=::std::cin)
Definition: sc_bit.cc:142
sc_dt::operator!=
bool operator!=(const sc_signed &u, const sc_int_base &v)
Definition: sc_signed.cc:892
sc_dt::sc_bit
Definition: sc_bit.hh:118
sc_dt::sc_bit::operator==
friend bool operator==(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:297
sc_dt::sc_bit::print
void print(::std::ostream &os=::std::cout) const
Definition: sc_bit.hh:276
sc_dt::int64
int64_t int64
Definition: sc_nbdefs.hh:205
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
sc_dt::sc_bit::to_value
static bool to_value(char c)
Definition: sc_bit.hh:126
sc_dt::sc_bit::sc_bit
sc_bit()
Definition: sc_bit.hh:158
DEFN_TRN_FUN
#define DEFN_TRN_FUN(fun)
Definition: sc_bit.hh:377
sc_dt::b_or
const sc_bit b_or(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:360
sc_dt::operator>>
sc_signed operator>>(const sc_signed &u, const sc_int_base &v)
Definition: sc_signed.cc:866
sc_dt::sc_bit::m_val
bool m_val
Definition: sc_bit.hh:280
sc_dt::sc_bit::operator&
const friend sc_bit operator&(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:337
sc_dt::sc_bit::operator!=
friend bool operator!=(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:303
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
DEFN_ASN_OP_T
#define DEFN_ASN_OP_T(op, tp)
Definition: sc_bit.hh:193
gem5::MipsISA::r
r
Definition: pra_constants.hh:98
sc_dt::sc_bit::operator^=
sc_bit & operator^=(const sc_bit &b)
Definition: sc_bit.hh:224
sc_dt::sc_bit::operator!
bool operator!() const
Definition: sc_bit.hh:244
sc_dt::sc_bit::to_char
char to_char() const
Definition: sc_bit.hh:249
sc_dt::b_xor
const sc_bit b_xor(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:361
sc_dt::sc_bit::operator|=
sc_bit & operator|=(const sc_bit &b)
Definition: sc_bit.hh:217
sc_dt::operator&
sc_signed operator&(const sc_unsigned &u, const sc_int_base &v)
Definition: sc_signed.cc:760
sc_dt::b_not
const sc_bit b_not(const sc_bit &a)
Definition: sc_bit.hh:329

Generated on Tue Sep 21 2021 12:25:52 for gem5 by doxygen 1.8.17