Skip to content

Commit

Permalink
Merge pull request #696 from pah/apple-zero-max-time
Browse files Browse the repository at this point in the history
sc_time: add constexpr, improve sc_max_time(), cleanup
  • Loading branch information
lmailletcontoz authored Nov 25, 2024
2 parents 1d6a361 + b1acc0c commit 7009ff8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 66 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
5 changes: 0 additions & 5 deletions src/sysc/kernel/sc_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,6 @@ sc_get_default_time_unit()
return sc_time::from_value( time_unit );
}


// ----------------------------------------------------------------------------

const sc_time SC_ZERO_TIME;

} // namespace sc_core

// $Log: sc_time.cpp,v $
Expand Down
52 changes: 20 additions & 32 deletions src/sysc/kernel/sc_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ class SC_API sc_time_tuple;
// integer of at least 64 bits declared as sc_time::value_type.
// ----------------------------------------------------------------------------

#define SC_TIME_DT sc_dt::uint64
#define SC_TIME_DT sc_dt::uint64

// ----------------------------------------------------------------------------
// ENUM : sc_time_unit
//
// Enumeration of time units.
// NOTE: From IEEE Std 1666-2023 onwards, enumeration constant values are
// implementation-defined. The constant values for SC_SEC, SC_MS,
// SC_US, SC_NS, SC_PS and SC_FS follow IEEE Std 1666-2011 to enable
// NOTE: From IEEE Std 1666-2023 onwards, enumeration constant values are
// implementation-defined. The constant values for SC_SEC, SC_MS,
// SC_US, SC_NS, SC_PS and SC_FS follow IEEE Std 1666-2011 to enable
// backwards compatibility.
// ----------------------------------------------------------------------------

enum sc_time_unit { SC_SEC = 5, SC_MS = 4, SC_US = 3, SC_NS = 2,
enum sc_time_unit { SC_SEC = 5, SC_MS = 4, SC_US = 3, SC_NS = 2,
SC_PS = 1, SC_FS = 0, SC_AS = -1, SC_ZS = -2, SC_YS = -3 };

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -116,24 +116,17 @@ class SC_API sc_time

// constructors

sc_time();
sc_time( const sc_time& );
constexpr sc_time() = default;
sc_time( double, sc_time_unit );

// convert time object from string
// For C++ versions prior to C++17, offer some (non-standard) backwards compatibility
// using std::string instead of std::string_view
explicit sc_time( std::string_view strv );
static sc_time from_string( std::string_view strv );

// deprecated, use from_value(v)
sc_time( double, bool scale );
sc_time( value_type, bool scale );

// assignment operator

sc_time& operator = ( const sc_time& );

// conversion functions

value_type value() const; // relative to the time resolution
Expand All @@ -145,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 @@ -175,10 +170,13 @@ 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:
value_type m_value;
value_type m_value{};
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -224,19 +222,9 @@ inline ::std::ostream& operator << ( ::std::ostream&, const sc_time& );

// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

extern SC_API const sc_time SC_ZERO_TIME;

// constructors

inline
sc_time::sc_time()
: m_value( 0 )
{}

inline
sc_time::sc_time( const sc_time& t )
: m_value( t.m_value )
{}
inline constexpr sc_time SC_ZERO_TIME;

inline
sc_time_tuple::sc_time_tuple( value_type v )
Expand All @@ -261,15 +249,15 @@ 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{} )
{}

// assignment operator

inline
sc_time&
sc_time::operator = ( const sc_time& t )
inline constexpr
sc_time sc_time::max()
{
m_value = t.m_value;
return *this;
return sc_time( max_time_tag{} );
}


Expand Down

0 comments on commit 7009ff8

Please sign in to comment.