Skip to content

Commit

Permalink
sc_max_time: implement via constexpr sc_time::max
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp A. Hartmann <[email protected]>
  • Loading branch information
pah committed Nov 21, 2024
1 parent 5ee23dc commit b1acc0c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
19 changes: 6 additions & 13 deletions src/sysc/kernel/sc_simcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ sc_simcontext::init()
m_collectable = new sc_process_list;
m_time_params = new sc_time_params;
m_curr_time = SC_ZERO_TIME;
m_max_time = SC_ZERO_TIME;
m_change_stamp = 0;
m_delta_count = 0;
m_initial_delta_count_at_current_time = 0;
Expand Down Expand Up @@ -406,8 +405,8 @@ sc_simcontext::sc_simcontext() :
m_write_check(SC_SIGNAL_WRITE_CHECK_DEFAULT_), m_next_proc_id(-1),
m_child_events(), m_child_objects(), m_delta_events(), m_timed_events(0),
m_trace_files(), m_something_to_trace(false), m_runnable(0), m_collectable(0),
m_time_params(), m_curr_time(SC_ZERO_TIME), m_max_time(SC_ZERO_TIME),
m_change_stamp(0), m_delta_count(0), m_initial_delta_count_at_current_time(0),
m_time_params(), m_change_stamp(0),
m_delta_count(0), m_initial_delta_count_at_current_time(0),
m_forced_stop(false), m_paused(false),
m_ready_to_simulate(false), m_elaboration_done(false),
m_execution_phase(phase_initialize), m_error(0),
Expand Down Expand Up @@ -877,7 +876,7 @@ sc_simcontext::simulate( const sc_time& duration )
return;
}

sc_time non_overflow_time = max_time() - m_curr_time;
sc_time non_overflow_time = sc_time::max() - m_curr_time;
if ( duration > non_overflow_time )
{
SC_REPORT_ERROR(SC_ID_SIMULATION_TIME_OVERFLOW_, "");
Expand Down Expand Up @@ -1640,7 +1639,7 @@ SC_API sc_time sc_time_to_pending_activity( const sc_simcontext* simc_p )
// If there is an activity pending at the current time
// return a delta of zero.

sc_time result=SC_ZERO_TIME; // time of pending activity.
sc_time result; // time of pending activity.

if ( simc_p->pending_activity_at_current_time() )
{
Expand All @@ -1651,7 +1650,7 @@ SC_API sc_time sc_time_to_pending_activity( const sc_simcontext* simc_p )

else
{
result = simc_p->max_time();
result = sc_time::max();
simc_p->next_time(result);
result -= sc_time_stamp();
}
Expand Down Expand Up @@ -1757,7 +1756,7 @@ sc_start( const sc_time& duration, sc_starvation_policy p )
SC_API void
sc_start()
{
sc_start( sc_max_time() - sc_time_stamp(),
sc_start( sc_time::max() - sc_time_stamp(),
SC_EXIT_ON_STARVATION );
}

Expand Down Expand Up @@ -1812,12 +1811,6 @@ SC_API sc_object* sc_find_object( const char* name )
}


SC_API const sc_time&
sc_max_time()
{
return sc_get_curr_simcontext()->max_time();
}

SC_API const sc_time&
sc_time_stamp()
{
Expand Down
23 changes: 7 additions & 16 deletions src/sysc/kernel/sc_simcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ class SC_API sc_simcontext
friend SC_API void sc_set_default_time_unit( double, sc_time_unit );
friend SC_API sc_time sc_get_default_time_unit();

const sc_time& max_time() const;
const sc_time& time_stamp() const;

sc_dt::uint64 change_stamp() const;
Expand Down Expand Up @@ -422,8 +421,7 @@ class SC_API sc_simcontext

sc_time_params* m_time_params;
sc_time m_curr_time;
mutable sc_time m_max_time;


sc_invoke_method* m_method_invoker_p;
sc_dt::uint64 m_change_stamp; // "time" change occurred.
sc_dt::uint64 m_delta_count;
Expand Down Expand Up @@ -604,18 +602,6 @@ sc_simcontext::next_proc_id()
return ( ++ m_next_proc_id );
}


inline
const sc_time&
sc_simcontext::max_time() const
{
if ( m_max_time == SC_ZERO_TIME )
{
m_max_time = sc_time::from_value( ~sc_dt::UINT64_ZERO );
}
return m_max_time;
}

inline
sc_dt::uint64
sc_simcontext::change_stamp() const
Expand Down Expand Up @@ -773,7 +759,12 @@ sc_set_random_seed( unsigned int seed_ );

extern SC_API void sc_initialize();

extern SC_API const sc_time& sc_max_time(); // Get maximum time value.
inline const sc_time& sc_max_time() // Get maximum time value.
{
static constexpr sc_time max_time = sc_time::max();
return max_time;
}

extern SC_API const sc_time& sc_time_stamp(); // Current simulation time.
extern SC_API double sc_simulation_time(); // Current time in default time units.

Expand Down
15 changes: 15 additions & 0 deletions src/sysc/kernel/sc_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class SC_API sc_time
static sc_time from_value( value_type );
static sc_time from_seconds( double );

static constexpr sc_time max();

// relational operators

bool operator == ( const sc_time& ) const;
Expand Down Expand Up @@ -168,6 +170,9 @@ class SC_API sc_time
void print( ::std::ostream& os = std::cout ) const;

private: // implementation-defined
struct max_time_tag {};
explicit constexpr sc_time( max_time_tag );

sc_time( double, sc_time_unit, sc_simcontext* );

private:
Expand Down Expand Up @@ -244,6 +249,16 @@ sc_time::from_seconds( double v )
return sc_time( v, SC_SEC );
}

inline constexpr
sc_time::sc_time( max_time_tag )
: m_value( ~value_type{} )
{}

inline constexpr
sc_time sc_time::max()
{
return sc_time( max_time_tag{} );
}


// conversion functions
Expand Down

0 comments on commit b1acc0c

Please sign in to comment.