Module Support Library¶
Fixed-width saturating counter¶
- 
template<typename val_type, val_type MAXVAL, val_type MINVAL>
 class base_fwcounter¶
- A fixed-width saturating counter. All arithmetic operations on this value are clamped between the maximum and minimum values. - Template Parameters:
- val_type – The underlying representation of the value. 
- MAXVAL – The maximum to saturate at. 
- MINVAL – The minimum to saturate at. 
 
 - Public Functions - 
base_fwcounter<val_type, MAXVAL, MINVAL> &operator++()¶
- Increment the value, saturating at the maximum value. 
 - 
base_fwcounter<val_type, MAXVAL, MINVAL> &operator--()¶
- Decrement the value, saturating at the minimum value. 
 - 
base_fwcounter<val_type, MAXVAL, MINVAL> &operator+=(base_fwcounter<val_type, MAXVAL, MINVAL>)¶
- Add the other operand to the wrapped value, saturating at the minimum and maximum. 
 - 
base_fwcounter<val_type, MAXVAL, MINVAL> &operator-=(base_fwcounter<val_type, MAXVAL, MINVAL>)¶
- Subtract the other operand from the wrapped value, saturating at the minimum and maximum. 
 - 
base_fwcounter<val_type, MAXVAL, MINVAL> &operator*=(base_fwcounter<val_type, MAXVAL, MINVAL>)¶
- Multiply the wrapped value by the other operand, saturating at the minimum and maximum. 
 - 
base_fwcounter<val_type, MAXVAL, MINVAL> &operator/=(base_fwcounter<val_type, MAXVAL, MINVAL>)¶
- Divide the wrapped value by the other operand, saturating at the minimum and maximum. 
 - 
inline bool is_max() const¶
- Detect whether the counter is saturated at its maximum. 
 - 
inline bool is_min() const¶
- Detect whether the counter is saturated at its minimum. 
 
- 
template<std::size_t WIDTH>
 using champsim::msl::fwcounter = base_fwcounter<signed long long int, (1 << WIDTH) - 1, 0>¶
- 
template<std::size_t WIDTH>
 using champsim::msl::sfwcounter = base_fwcounter<signed long long int, (1 << (WIDTH - 1)) - 1, -(1 << (WIDTH - 1))>¶
Functions for bit operations¶
- 
template<typename T>
 T champsim::msl::next_pow2(T n)¶
- Compute the smallest power of 2 not less than the given integer. 
- 
long long champsim::msl::ipow(long long base, unsigned exp)¶
- Compute an integer power. This function may overflow very easily. Use only for small bases or very small exponents. 
- 
uint64_t champsim::msl::bitmask(champsim::data::bits begin, champsim::data::bits end)¶
- Produce a mask that can be used in a bitwise-and operation to select particular bits of a number. - 0xffff & bitmask(8_b,4_b) == 0xf0; - If - endis not specified, it is defaulted to 0, that is, the least-significant bit.- Note - This should not be used as a mask generator for address types. Use champsim::address_slice instead. - Parameters:
- begin – The most-significant bit of the mask, not inclusive. 
- end – The least-significant bit of the mask, inclusive. 
 
 
- 
uint64_t champsim::msl::bitmask(champsim::data::bits begin)¶
- This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. 
- 
uint64_t champsim::msl::bitmask(std::size_t begin, std::size_t end = 0)¶
- This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. - Deprecated:
- Users should prefer the overload with - champsim::data::bitsparameters.
 
- 
template<typename T>
 auto champsim::msl::splice_bits(T upper, T lower, champsim::data::bits bits_upper, champsim::data::bits bits_lower)¶
- Join two values, selecting some bits from one value and some bits from another. - splice_bits(0xaaaa, 0xbbbb, 8_b, 4_b) == 0xaaba; - If - endis not specified, it is defaulted to 0, that is, the least-significant bit.- Note - This is an implementation detail of champsim::splice(), which should be preferred for address types. This function is provided for general use. - Parameters:
- upper – The operand from which to take the not-selected bits. 
- lower – The operand from which to take the selected bits. 
- bits_upper – The most-significant bit of the mask, not inclusive. 
- bits_lower – The least-significant bit of the mask, inclusive. 
 
 
- 
template<typename T>
 auto champsim::msl::splice_bits(T upper, T lower, champsim::data::bits bits)¶
- This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. 
- 
template<typename T>
 auto champsim::msl::splice_bits(T upper, T lower, std::size_t bits_upper, std::size_t bits_lower)¶
- This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. - Deprecated:
- Users should prefer the overload with - champsim::data::bitsparameters.
 
- 
template<typename T>
 auto champsim::msl::splice_bits(T upper, T lower, std::size_t bits)¶
- This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. - Deprecated:
- Users should prefer the overload with - champsim::data::bitsparameters.