ChampSim
bits.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 The ChampSim Contributors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifdef CHAMPSIM_MODULE
18 #error "Modules should include msl/bits.h"
19 #endif
20 
21 #ifndef UTIL_BITS_H
22 #define UTIL_BITS_H
23 
24 #include <utility>
25 
26 #include "../msl/bits.h"
27 
28 namespace champsim
29 {
30 using msl::bitmask;
31 using msl::lg2;
32 using msl::splice_bits;
33 
34 /*
35  * A forward-port of C++23's function of the same name.
36  * This avoids static_cast'ing an enumeration to an integer type other than its underlying type,
37  * an action that could dodge -Wconversion
38  */
39 template <typename E>
40 constexpr std::underlying_type_t<E> to_underlying(E e) noexcept
41 {
42  return static_cast<std::underlying_type_t<E>>(e);
43 }
44 } // namespace champsim
45 
46 #endif
constexpr uint64_t splice_bits(uint64_t upper, uint64_t lower, std::size_t bits)
Definition: bits.h:32
constexpr uint64_t bitmask(std::size_t begin, std::size_t end=0)
Definition: bits.h:27
constexpr unsigned lg2(uint64_t n)
Definition: bits.h:25
Definition: champsim.h:24
constexpr std::underlying_type_t< E > to_underlying(E e) noexcept
Definition: bits.h:40