15inline constexpr uint64_t
MAIN_FREQ = 3579545ULL * 960;
17static_assert(
MAIN_FREQ < (1ULL << 32),
"must fit in 32 bit");
40 : time(uint64_t(duration *
MAIN_FREQ + 0.5)) {}
53 [[nodiscard]]
constexpr uint64_t
length()
const {
return time; }
71 uint64_t result = l.time / r.time;
74 assert(result ==
unsigned(result));
76 return unsigned(result);
79 uint64_t result = (time + d.time - 1) / d.time;
81 assert(result ==
unsigned(result));
83 return unsigned(result);
86 {
return narrow_cast<double>(time) / narrow_cast<double>(d.time); }
89 { time *= fact;
return *
this; }
91 { time = narrow_cast<uint64_t>(narrow_cast<double>(time) * fact);
return *
this; }
93 { time = narrow_cast<uint64_t>(narrow_cast<double>(time) / fact);
return *
this; }
102 [[nodiscard]]
constexpr unsigned getTicksAt(
unsigned freq)
const
107 assert(result ==
unsigned(result));
109 return unsigned(result);
119 return EmuDuration(std::numeric_limits<uint64_t>::max());
122 template<
typename Archive>
125 ar.serialize(
"time", time);
139 : time(T(e.length()))
141 assert(e.length() <= std::numeric_limits<T>::max());
158 inline constexpr uint64_t max32 = std::numeric_limits<uint32_t>::max();
159 inline constexpr uint64_t max16 = std::numeric_limits<uint16_t>::max();
160 inline constexpr uint64_t max8 = std::numeric_limits<uint8_t >::max();
162template<u
int64_t MAX>
constexpr EmuDurationCompactStorage(EmuDuration e)
void serialize(Archive &ar, unsigned)
static constexpr EmuDuration sec(unsigned x)
constexpr unsigned divUp(EmuDuration::param d) const
constexpr EmuDuration(double duration)
constexpr uint64_t length() const
constexpr EmuDuration(uint64_t n)
constexpr friend unsigned operator/(const EmuDuration &l, const EmuDuration &r)
constexpr EmuDuration()=default
constexpr EmuDuration & operator/=(double fact)
static constexpr EmuDuration infinity()
constexpr friend EmuDuration operator/(const EmuDuration &l, unsigned fact)
constexpr friend EmuDuration operator%(const EmuDuration &l, const EmuDuration &r)
static constexpr EmuDuration epsilon()
static constexpr EmuDuration hz(unsigned x)
constexpr EmuDuration & operator*=(double fact)
constexpr EmuDuration divRoundUp(unsigned fact) const
static constexpr EmuDuration msec(unsigned x)
constexpr friend EmuDuration operator+(const EmuDuration &l, const EmuDuration &r)
constexpr double toDouble() const
constexpr EmuDuration & operator*=(unsigned fact)
constexpr unsigned getTicksAt(unsigned freq) const
constexpr auto operator<=>(const EmuDuration &) const =default
static constexpr EmuDuration zero()
static constexpr EmuDuration usec(unsigned x)
constexpr double div(EmuDuration::param d) const
constexpr friend EmuDuration operator*(const EmuDuration &l, uint64_t fact)
This file implemented 3 utility functions:
EmuDurationCompactStorage< uint32_t > EmuDuration32
constexpr double RECIP_MAIN_FREQ
std::conditional_t<(MAX > detail::max32), EmuDuration, std::conditional_t<(MAX > detail::max16), EmuDuration32, std::conditional_t<(MAX > detail::max8), EmuDuration16, EmuDuration8 > > > EmuDurationStorageFor
constexpr unsigned MAIN_FREQ32
constexpr uint64_t MAIN_FREQ