gem5  v21.1.0.2
flags.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Daniel R. Carvalho
3  * Copyright (c) 2008 The Hewlett-Packard Development Company
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __BASE_FLAGS_HH__
31 #define __BASE_FLAGS_HH__
32 
33 #include <type_traits>
34 
35 namespace gem5
36 {
37 
43 template <typename T>
44 class Flags
45 {
46  private:
47  static_assert(std::is_unsigned<T>::value, "Flag type must be unsigned");
48 
50  T _flags;
51 
52  public:
53  typedef T Type;
54 
66  Flags(Type flags=0) : _flags(flags) {}
67 
68  operator const Type() const { return _flags; }
69 
70  const Flags<T> &
71  operator=(T flags)
72  {
73  _flags = flags;
74  return *this;
75  }
76 
83  bool isSet(Type mask) const { return (_flags & mask); }
84 
91  bool allSet(Type mask) const { return (_flags & mask) == mask; }
92 
99  bool noneSet(Type mask) const { return (_flags & mask) == 0; }
100 
102  void clear() { _flags = 0; }
103 
109  void clear(Type mask) { _flags &= ~mask; }
110 
116  void set(Type mask) { _flags |= mask; }
117 
124  void
125  set(Type mask, bool condition)
126  {
127  condition ? set(mask) : clear(mask);
128  }
129 
140  void
142  {
143  _flags = (_flags & ~mask) | (flags & mask);
144  } // end of api_flags
146 };
147 
148 } // namespace gem5
149 
150 #endif // __BASE_FLAGS_HH__
gem5::Flags::operator=
const Flags< T > & operator=(T flags)
Definition: flags.hh:71
gem5::Flags::set
void set(Type mask)
Set all flag's bits matching the given mask.
Definition: flags.hh:116
gem5::Flags::clear
void clear()
Clear all flag's bits.
Definition: flags.hh:102
gem5::Flags::Flags
Flags(Type flags=0)
Initialize flags with a given value.
Definition: flags.hh:66
gem5::Flags::allSet
bool allSet(Type mask) const
Verifies whether no bits matching the given mask are set.
Definition: flags.hh:91
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::Flags
Wrapper that groups a few flag bits under the same undelying container.
Definition: flags.hh:44
gem5::Flags::isSet
bool isSet(Type mask) const
Verifies whether any bit matching the given mask is set.
Definition: flags.hh:83
gem5::Flags::Type
T Type
Definition: flags.hh:53
gem5::Flags::replace
void replace(Type flags, Type mask)
Replace the contents of the bits matching the mask with the corresponding bits in the provided flags.
Definition: flags.hh:141
gem5::Flags::set
void set(Type mask, bool condition)
Conditionally set or clear some bits of the flag, given a mask.
Definition: flags.hh:125
gem5::Flags::_flags
T _flags
The undelying container of the flags' bits.
Definition: flags.hh:47
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::Flags::clear
void clear(Type mask)
Clear all flag's bits matching the given mask.
Definition: flags.hh:109
gem5::Flags::noneSet
bool noneSet(Type mask) const
Verifies whether no bits matching the given mask are set.
Definition: flags.hh:99

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17