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 #ifndef MSL_BITS_H
18 #define MSL_BITS_H
19 
20 #include <cstdint>
21 #include <limits>
22 
23 namespace champsim::msl
24 {
25 constexpr unsigned lg2(uint64_t n) { return n < 2 ? 0 : 1 + lg2(n / 2); }
26 
27 constexpr uint64_t bitmask(std::size_t begin, std::size_t end = 0)
28 {
29  return (begin - end < 64) ? ((1ull << (begin - end)) - 1) << end : std::numeric_limits<uint64_t>::max();
30 }
31 
32 constexpr uint64_t splice_bits(uint64_t upper, uint64_t lower, std::size_t bits) { return (upper & ~bitmask(bits)) | (lower & bitmask(bits)); }
33 } // namespace champsim::msl
34 
35 #endif
Definition: bits.h:24
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