Byte Sizes

ChampSim provides a strong type to represent a unit of byte size. Objects of this type are convertible to other byte sizes, but are more difficult to unintentionally use in arithmetic operations.

template<typename Rep, typename Unit>
class size

A class to represent data sizes as they are passed around the program. This type is modeled after std::chrono::duration. The units are known as part of the size, but the types are convertible.

Template Parameters:
  • Rep – The type of the underlying representation.

  • Unit – A specialization of std::ratio that represents the multiple of a single byte.

Public Functions

inline explicit constexpr size(rep other)

Construct the size with the given value

template<typename Rep2, typename Unit2>
inline constexpr size(const size<Rep2, Unit2> &other)

Implicitly convert between data sizes.

This permits constructions like

void func(champsim::data::kibibytes x);
func(champsim::data::bytes{1024});
inline constexpr auto count() const

Unwrap the underlying value.

enum class champsim::data::bits : uint64_t

A strong type to represent a bit width. Being an enum prevents arbitrary arithmetic from being performed.

Values:

Convenience specializations

ChampSim provides a number of ratio specializations for use in sizes:

using champsim::kibi = std::ratio<(1LL << 10)>
using champsim::mebi = std::ratio<(1LL << 20)>
using champsim::gibi = std::ratio<(1LL << 30)>
using champsim::tebi = std::ratio<(1LL << 40)>
using champsim::pebi = std::ratio<(1LL << 50)>
using champsim::exbi = std::ratio<(1LL << 60)>

These types are also used in the convenience specializations:

using champsim::data::bytes = size<long long, std::ratio<1>>

Convenience definitions for common data types

using champsim::data::kibibytes = size<long long, kibi>
using champsim::data::mebibytes = size<long long, mebi>
using champsim::data::gibibytes = size<long long, gibi>
using champsim::data::tebibytes = size<long long, tebi>

Literals

constexpr auto champsim::data::data_literals::operator""_b(unsigned long long val) -> bits

Specify a literal number of champsim::data::bits.

constexpr auto champsim::data::data_literals::operator""_B(unsigned long long val) -> size<long long, std::ratio<1>>

Specify a literal number of champsim::data::bytes.

constexpr auto champsim::data::data_literals::operator""_kiB(unsigned long long val) -> size<long long, kibi>

Specify a literal number of champsim::data::kibibytes.

constexpr auto champsim::data::data_literals::operator""_MiB(unsigned long long val) -> size<long long, mebi>

Specify a literal number of champsim::data::mebibytes.

constexpr auto champsim::data::data_literals::operator""_GiB(unsigned long long val) -> size<long long, gibi>

Specify a literal number of champsim::data::gibibytes.

constexpr auto champsim::data::data_literals::operator""_TiB(unsigned long long val) -> size<long long, tebi>

Specify a literal number of champsim::data::tebibytes.