summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2019-11-09 15:32:15 -0500
committer AJR <ajrhacker@users.noreply.github.com>2019-11-09 16:10:14 -0500
commitd267384837d6bdd12ebff16162750d38803f6287 (patch)
treee361aa86f4fa1e4f80f74167a89268fe4719b22d /src/emu
parentedb7eb0bf0582f984f2e035a4c96f728f92c8a63 (diff)
Make many device_execute_interface functions noexcept, including the "information" overrides. This also covers several time-related functions in attotime, running_machine and emu_timer. (nw)
m6805: Calculate min_cycles and max_cycles once at device_start time (Nw) attotime: Add as_khz and as_mhz (nw)
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/attotime.h48
-rw-r--r--src/emu/diexec.cpp20
-rw-r--r--src/emu/diexec.h32
-rw-r--r--src/emu/emucore.h8
-rw-r--r--src/emu/machine.h2
-rw-r--r--src/emu/schedule.cpp6
-rw-r--r--src/emu/schedule.h12
7 files changed, 69 insertions, 59 deletions
diff --git a/src/emu/attotime.h b/src/emu/attotime.h
index cad95177724..945ed78a87a 100644
--- a/src/emu/attotime.h
+++ b/src/emu/attotime.h
@@ -91,15 +91,15 @@ class attotime
{
public:
// construction/destruction
- constexpr attotime() : m_seconds(0), m_attoseconds(0) { }
+ constexpr attotime() noexcept : m_seconds(0), m_attoseconds(0) { }
/** Constructs with @p secs seconds and @p attos attoseconds. */
- constexpr attotime(seconds_t secs, attoseconds_t attos) : m_seconds(secs), m_attoseconds(attos) { }
+ constexpr attotime(seconds_t secs, attoseconds_t attos) noexcept : m_seconds(secs), m_attoseconds(attos) { }
- constexpr attotime(const attotime& that) : m_seconds(that.m_seconds), m_attoseconds(that.m_attoseconds) { }
+ constexpr attotime(const attotime& that) noexcept : m_seconds(that.m_seconds), m_attoseconds(that.m_attoseconds) { }
// assignment
- attotime& operator=(const attotime& that)
+ attotime &operator=(const attotime& that) noexcept
{
this->m_seconds = that.m_seconds;
this->m_attoseconds = that.m_attoseconds;
@@ -107,23 +107,25 @@ public:
}
// queries
- constexpr bool is_zero() const { return (m_seconds == 0 && m_attoseconds == 0); }
+ constexpr bool is_zero() const noexcept { return (m_seconds == 0 && m_attoseconds == 0); }
/** Test if value is above @ref ATTOTIME_MAX_SECONDS (considered an overflow) */
- constexpr bool is_never() const { return (m_seconds >= ATTOTIME_MAX_SECONDS); }
+ constexpr bool is_never() const noexcept { return (m_seconds >= ATTOTIME_MAX_SECONDS); }
// conversion to other forms
- constexpr double as_double() const { return double(m_seconds) + ATTOSECONDS_TO_DOUBLE(m_attoseconds); }
- constexpr attoseconds_t as_attoseconds() const;
+ constexpr double as_double() const noexcept { return double(m_seconds) + ATTOSECONDS_TO_DOUBLE(m_attoseconds); }
+ constexpr attoseconds_t as_attoseconds() const noexcept;
constexpr double as_hz() const { return m_seconds == 0 ? ATTOSECONDS_TO_HZ(m_attoseconds) : is_never() ? 0.0 : 1.0 / as_double(); }
+ constexpr double as_khz() const { return m_seconds == 0 ? double(ATTOSECONDS_PER_MILLISECOND) / double(m_attoseconds) : is_never() ? 0.0 : 1e-3 / as_double(); }
+ constexpr double as_mhz() const { return m_seconds == 0 ? double(ATTOSECONDS_PER_MICROSECOND) / double(m_attoseconds) : is_never() ? 0.0 : 1e-6 / as_double(); }
u64 as_ticks(u32 frequency) const;
u64 as_ticks(const XTAL &xtal) const { return as_ticks(xtal.value()); }
/** Convert to string using at @p precision */
const char *as_string(int precision = 9) const;
/** @return the attoseconds portion. */
- constexpr attoseconds_t attoseconds() const { return m_attoseconds; }
+ constexpr attoseconds_t attoseconds() const noexcept { return m_attoseconds; }
/** @return the seconds portion. */
- constexpr seconds_t seconds() const { return m_seconds; }
+ constexpr seconds_t seconds() const noexcept { return m_seconds; }
static attotime from_double(double _time);
static attotime from_ticks(u64 ticks, u32 frequency);
@@ -154,8 +156,8 @@ public:
}
// math
- attotime &operator+=(const attotime &right);
- attotime &operator-=(const attotime &right);
+ attotime &operator+=(const attotime &right) noexcept;
+ attotime &operator-=(const attotime &right) noexcept;
attotime &operator*=(u32 factor);
attotime &operator/=(u32 factor);
@@ -175,7 +177,7 @@ public:
//**************************************************************************
/** handle addition between two attotimes */
-inline attotime operator+(const attotime &left, const attotime &right)
+inline attotime operator+(const attotime &left, const attotime &right) noexcept
{
attotime result;
@@ -200,7 +202,7 @@ inline attotime operator+(const attotime &left, const attotime &right)
return result;
}
-inline attotime &attotime::operator+=(const attotime &right)
+inline attotime &attotime::operator+=(const attotime &right) noexcept
{
// if one of the items is never, return never
if (this->m_seconds >= ATTOTIME_MAX_SECONDS || right.m_seconds >= ATTOTIME_MAX_SECONDS)
@@ -225,7 +227,7 @@ inline attotime &attotime::operator+=(const attotime &right)
/** handle subtraction between two attotimes */
-inline attotime operator-(const attotime &left, const attotime &right)
+inline attotime operator-(const attotime &left, const attotime &right) noexcept
{
attotime result;
@@ -246,7 +248,7 @@ inline attotime operator-(const attotime &left, const attotime &right)
return result;
}
-inline attotime &attotime::operator-=(const attotime &right)
+inline attotime &attotime::operator-=(const attotime &right) noexcept
{
// if time1 is never, return never
if (this->m_seconds >= ATTOTIME_MAX_SECONDS)
@@ -291,39 +293,39 @@ inline attotime operator/(const attotime &left, u32 factor)
/** handle comparisons between attotimes */
-inline constexpr bool operator==(const attotime &left, const attotime &right)
+inline constexpr bool operator==(const attotime &left, const attotime &right) noexcept
{
return (left.m_seconds == right.m_seconds && left.m_attoseconds == right.m_attoseconds);
}
-inline constexpr bool operator!=(const attotime &left, const attotime &right)
+inline constexpr bool operator!=(const attotime &left, const attotime &right) noexcept
{
return (left.m_seconds != right.m_seconds || left.m_attoseconds != right.m_attoseconds);
}
-inline constexpr bool operator<(const attotime &left, const attotime &right)
+inline constexpr bool operator<(const attotime &left, const attotime &right) noexcept
{
return (left.m_seconds < right.m_seconds || (left.m_seconds == right.m_seconds && left.m_attoseconds < right.m_attoseconds));
}
-inline constexpr bool operator<=(const attotime &left, const attotime &right)
+inline constexpr bool operator<=(const attotime &left, const attotime &right) noexcept
{
return (left.m_seconds < right.m_seconds || (left.m_seconds == right.m_seconds && left.m_attoseconds <= right.m_attoseconds));
}
-inline constexpr bool operator>(const attotime &left, const attotime &right)
+inline constexpr bool operator>(const attotime &left, const attotime &right) noexcept
{
return (left.m_seconds > right.m_seconds || (left.m_seconds == right.m_seconds && left.m_attoseconds > right.m_attoseconds));
}
-inline constexpr bool operator>=(const attotime &left, const attotime &right)
+inline constexpr bool operator>=(const attotime &left, const attotime &right) noexcept
{
return (left.m_seconds > right.m_seconds || (left.m_seconds == right.m_seconds && left.m_attoseconds >= right.m_attoseconds));
}
/** Convert to an attoseconds value, clamping to +/- 1 second */
-inline constexpr attoseconds_t attotime::as_attoseconds() const
+inline constexpr attoseconds_t attotime::as_attoseconds() const noexcept
{
return
(m_seconds == 0) ? m_attoseconds : // positive values between 0 and 1 second
diff --git a/src/emu/diexec.cpp b/src/emu/diexec.cpp
index 4df8bb33493..a3a042b4d32 100644
--- a/src/emu/diexec.cpp
+++ b/src/emu/diexec.cpp
@@ -92,7 +92,7 @@ device_execute_interface::~device_execute_interface()
// run before we run again
//-------------------------------------------------
-void device_execute_interface::abort_timeslice()
+void device_execute_interface::abort_timeslice() noexcept(MAME_NDEBUG)
{
// ignore if not the executing device
if (!executing())
@@ -207,7 +207,7 @@ void device_execute_interface::trigger(int trigid)
// for a device
//-------------------------------------------------
-attotime device_execute_interface::local_time() const
+attotime device_execute_interface::local_time() const noexcept(MAME_NDEBUG)
{
// if we're active, add in the time from the current slice
if (executing())
@@ -225,7 +225,7 @@ attotime device_execute_interface::local_time() const
// cycles executed on this device
//-------------------------------------------------
-u64 device_execute_interface::total_cycles() const
+u64 device_execute_interface::total_cycles() const noexcept(MAME_NDEBUG)
{
if (executing())
{
@@ -242,7 +242,7 @@ u64 device_execute_interface::total_cycles() const
// of clocks to cycles, rounding down if necessary
//-------------------------------------------------
-u64 device_execute_interface::execute_clocks_to_cycles(u64 clocks) const
+u64 device_execute_interface::execute_clocks_to_cycles(u64 clocks) const noexcept
{
return clocks;
}
@@ -253,7 +253,7 @@ u64 device_execute_interface::execute_clocks_to_cycles(u64 clocks) const
// of cycles to clocks, rounding down if necessary
//-------------------------------------------------
-u64 device_execute_interface::execute_cycles_to_clocks(u64 cycles) const
+u64 device_execute_interface::execute_cycles_to_clocks(u64 cycles) const noexcept
{
return cycles;
}
@@ -265,7 +265,7 @@ u64 device_execute_interface::execute_cycles_to_clocks(u64 cycles) const
// operation can take
//-------------------------------------------------
-u32 device_execute_interface::execute_min_cycles() const
+u32 device_execute_interface::execute_min_cycles() const noexcept
{
return 1;
}
@@ -277,7 +277,7 @@ u32 device_execute_interface::execute_min_cycles() const
// operation can take
//-------------------------------------------------
-u32 device_execute_interface::execute_max_cycles() const
+u32 device_execute_interface::execute_max_cycles() const noexcept
{
return 1;
}
@@ -288,7 +288,7 @@ u32 device_execute_interface::execute_max_cycles() const
// of input lines for the device
//-------------------------------------------------
-u32 device_execute_interface::execute_input_lines() const
+u32 device_execute_interface::execute_input_lines() const noexcept
{
return 0;
}
@@ -299,7 +299,7 @@ u32 device_execute_interface::execute_input_lines() const
// IRQ vector when an acknowledge is processed
//-------------------------------------------------
-u32 device_execute_interface::execute_default_irq_vector(int linenum) const
+u32 device_execute_interface::execute_default_irq_vector(int linenum) const noexcept
{
return 0;
}
@@ -310,7 +310,7 @@ u32 device_execute_interface::execute_default_irq_vector(int linenum) const
// the input line has an asynchronous edge trigger
//-------------------------------------------------
-bool device_execute_interface::execute_input_edge_triggered(int linenum) const
+bool device_execute_interface::execute_input_edge_triggered(int linenum) const noexcept
{
return false;
}
diff --git a/src/emu/diexec.h b/src/emu/diexec.h
index 056033b95c6..565d89c6da2 100644
--- a/src/emu/diexec.h
+++ b/src/emu/diexec.h
@@ -152,12 +152,12 @@ public:
}
// execution management
- device_scheduler &scheduler() const { assert(m_scheduler != nullptr); return *m_scheduler; }
- bool executing() const { return scheduler().currently_executing() == this; }
- s32 cycles_remaining() const { return executing() ? *m_icountptr : 0; } // cycles remaining in this timeslice
- void eat_cycles(int cycles) { if (executing()) *m_icountptr = (cycles > *m_icountptr) ? 0 : (*m_icountptr - cycles); }
- void adjust_icount(int delta) { if (executing()) *m_icountptr += delta; }
- void abort_timeslice();
+ device_scheduler &scheduler() const noexcept(MAME_NDEBUG) { assert(m_scheduler != nullptr); return *m_scheduler; }
+ bool executing() const noexcept(MAME_NDEBUG) { return scheduler().currently_executing() == this; }
+ s32 cycles_remaining() const noexcept(MAME_NDEBUG) { return executing() ? *m_icountptr : 0; } // cycles remaining in this timeslice
+ void eat_cycles(int cycles) noexcept(MAME_NDEBUG) { if (executing()) *m_icountptr = (cycles > *m_icountptr) ? 0 : (*m_icountptr - cycles); }
+ void adjust_icount(int delta) noexcept(MAME_NDEBUG) { if (executing()) *m_icountptr += delta; }
+ void abort_timeslice() noexcept(MAME_NDEBUG);
// input and interrupt management
void set_input_line(int linenum, int state) { m_input[linenum].set_state_synced(state); }
@@ -170,7 +170,7 @@ public:
// suspend/resume
void suspend(u32 reason, bool eatcycles);
void resume(u32 reason);
- bool suspended(u32 reason = SUSPEND_ANY_REASON) const { return (m_nextsuspend & reason) != 0; }
+ bool suspended(u32 reason = SUSPEND_ANY_REASON) const noexcept { return (m_nextsuspend & reason) != 0; }
void yield() { suspend(SUSPEND_REASON_TIMESLICE, false); }
void spin() { suspend(SUSPEND_REASON_TIMESLICE, true); }
void spin_until_trigger(int trigid) { suspend_until_trigger(trigid, true); }
@@ -183,8 +183,8 @@ public:
void signal_interrupt_trigger() { trigger(m_inttrigger); }
// time and cycle accounting
- attotime local_time() const;
- u64 total_cycles() const;
+ attotime local_time() const noexcept(MAME_NDEBUG);
+ u64 total_cycles() const noexcept(MAME_NDEBUG);
// required operation overrides
void run() { execute_run(); }
@@ -195,15 +195,15 @@ public:
protected:
// clock and cycle information getters
- virtual u64 execute_clocks_to_cycles(u64 clocks) const;
- virtual u64 execute_cycles_to_clocks(u64 cycles) const;
- virtual u32 execute_min_cycles() const;
- virtual u32 execute_max_cycles() const;
+ virtual u64 execute_clocks_to_cycles(u64 clocks) const noexcept;
+ virtual u64 execute_cycles_to_clocks(u64 cycles) const noexcept;
+ virtual u32 execute_min_cycles() const noexcept;
+ virtual u32 execute_max_cycles() const noexcept;
// input line information getters
- virtual u32 execute_input_lines() const;
- virtual u32 execute_default_irq_vector(int linenum) const;
- virtual bool execute_input_edge_triggered(int linenum) const;
+ virtual u32 execute_input_lines() const noexcept;
+ virtual u32 execute_default_irq_vector(int linenum) const noexcept;
+ virtual bool execute_input_edge_triggered(int linenum) const noexcept;
// optional operation overrides
virtual void execute_run() = 0;
diff --git a/src/emu/emucore.h b/src/emu/emucore.h
index ef6713c8d8f..530227ad692 100644
--- a/src/emu/emucore.h
+++ b/src/emu/emucore.h
@@ -237,6 +237,14 @@ template <typename T> constexpr auto DEGREE_TO_RADIAN(T const &x) { return (M_PI
#define ENDIAN_VALUE_NE_NNE(endian,neval,nneval) (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval))
+// useful for declaring functions with asserts as conditionally noexcept
+#ifdef NDEBUG
+constexpr bool MAME_NDEBUG = true;
+#else
+constexpr bool MAME_NDEBUG = false;
+#endif
+
+
//**************************************************************************
// EXCEPTION CLASSES
//**************************************************************************
diff --git a/src/emu/machine.h b/src/emu/machine.h
index 8d151bc0c92..a3be1a81f4c 100644
--- a/src/emu/machine.h
+++ b/src/emu/machine.h
@@ -206,7 +206,7 @@ public:
// additional helpers
emu_options &options() const { return m_config.options(); }
- attotime time() const { return m_scheduler.time(); }
+ attotime time() const noexcept(MAME_NDEBUG) { return m_scheduler.time(); }
bool scheduled_event_pending() const { return m_exit_pending || m_hard_reset_pending; }
bool allow_logging() const { return !m_logerror_list.empty(); }
diff --git a/src/emu/schedule.cpp b/src/emu/schedule.cpp
index fbe9f667255..c35e41d0457 100644
--- a/src/emu/schedule.cpp
+++ b/src/emu/schedule.cpp
@@ -209,7 +209,7 @@ void emu_timer::adjust(attotime start_delay, s32 param, const attotime &period)
// timer was started
//-------------------------------------------------
-attotime emu_timer::elapsed() const
+attotime emu_timer::elapsed() const noexcept(MAME_NDEBUG)
{
return machine().time() - m_start;
}
@@ -220,7 +220,7 @@ attotime emu_timer::elapsed() const
// remaining until the timer expires
//-------------------------------------------------
-attotime emu_timer::remaining() const
+attotime emu_timer::remaining() const noexcept(MAME_NDEBUG)
{
attotime curtime = machine().time();
if (curtime >= m_expire)
@@ -356,7 +356,7 @@ device_scheduler::~device_scheduler()
// time - return the current time
//-------------------------------------------------
-attotime device_scheduler::time() const
+attotime device_scheduler::time() const noexcept(MAME_NDEBUG)
{
// if we're currently in a callback, use the timer's expiration time as a base
if (m_callback_timer != nullptr)
diff --git a/src/emu/schedule.h b/src/emu/schedule.h
index f5631a6f816..951bbb045eb 100644
--- a/src/emu/schedule.h
+++ b/src/emu/schedule.h
@@ -64,7 +64,7 @@ class emu_timer
public:
// getters
emu_timer *next() const { return m_next; }
- running_machine &machine() const { assert(m_machine != nullptr); return *m_machine; }
+ running_machine &machine() const noexcept(MAME_NDEBUG) { assert(m_machine != nullptr); return *m_machine; }
bool enabled() const { return m_enabled; }
int param() const { return m_param; }
void *ptr() const { return m_ptr; }
@@ -79,8 +79,8 @@ public:
void adjust(attotime start_delay, s32 param = 0, const attotime &periodicity = attotime::never);
// timing queries
- attotime elapsed() const;
- attotime remaining() const;
+ attotime elapsed() const noexcept(MAME_NDEBUG);
+ attotime remaining() const noexcept(MAME_NDEBUG);
attotime start() const { return m_start; }
attotime expire() const { return m_expire; }
attotime period() const { return m_period; }
@@ -121,10 +121,10 @@ public:
~device_scheduler();
// getters
- running_machine &machine() const { return m_machine; }
- attotime time() const;
+ running_machine &machine() const noexcept { return m_machine; }
+ attotime time() const noexcept(MAME_NDEBUG);
emu_timer *first_timer() const { return m_timer_list; }
- device_execute_interface *currently_executing() const { return m_executing_device; }
+ device_execute_interface *currently_executing() const noexcept { return m_executing_device; }
bool can_save() const;
// execution