gem5  v22.1.0.0
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_v<T>, "Flag type must be unsigned");
48 
50  T _flags;
51 
52  public:
53  typedef T Type;
54 
67 
68  operator const Type() const { return _flags; }
69 
70  const Flags<T> &
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__
Wrapper that groups a few flag bits under the same undelying container.
Definition: flags.hh:45
T _flags
The undelying container of the flags' bits.
Definition: flags.hh:47
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
void set(Type mask)
Set all flag's bits matching the given mask.
Definition: flags.hh:116
Flags(Type flags=0)
Initialize flags with a given value.
Definition: flags.hh:66
bool allSet(Type mask) const
Verifies whether no bits matching the given mask are set.
Definition: flags.hh:91
bool isSet(Type mask) const
Verifies whether any bit matching the given mask is set.
Definition: flags.hh:83
void clear()
Clear all flag's bits.
Definition: flags.hh:102
void clear(Type mask)
Clear all flag's bits matching the given mask.
Definition: flags.hh:109
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
void set(Type mask, bool condition)
Conditionally set or clear some bits of the flag, given a mask.
Definition: flags.hh:125
bool noneSet(Type mask) const
Verifies whether no bits matching the given mask are set.
Definition: flags.hh:99
const Flags< T > & operator=(T flags)
Definition: flags.hh:71
uint8_t flags
Definition: helpers.cc:66
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:28 for gem5 by doxygen 1.9.1