00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef SC_TIME_H
00029 #define SC_TIME_H
00030
00031
00032 #include "sysc/datatypes/int/sc_nbdefs.h"
00033 #include "sysc/datatypes/fx/scfx_ieee.h"
00034 #include "sysc/utils/sc_iostream.h"
00035
00036 namespace sc_core {
00037
00038 class sc_simcontext;
00039
00040
00041
00042 const sc_time operator + ( const sc_time&, const sc_time& );
00043 const sc_time operator - ( const sc_time&, const sc_time& );
00044 const sc_time operator * ( const sc_time&, double );
00045 const sc_time operator * ( double, const sc_time& );
00046 const sc_time operator / ( const sc_time&, double );
00047 double operator / ( const sc_time&, const sc_time& );
00048
00049
00050
00051
00052
00053
00054
00055
00056 enum sc_time_unit
00057 {
00058 SC_FS = 0,
00059 SC_PS,
00060 SC_NS,
00061 SC_US,
00062 SC_MS,
00063 SC_SEC
00064 };
00065
00066
00067
00068
00069
00070
00071
00072
00073 class sc_time
00074 {
00075 public:
00076
00077 typedef sc_dt::uint64 value_type;
00078
00079
00080
00081 sc_time();
00082 sc_time( double, sc_time_unit );
00083 sc_time( double, sc_time_unit, sc_simcontext* );
00084 sc_time( const sc_time& );
00085
00086 static sc_time from_value( value_type );
00087
00088
00089 sc_time( double, bool scale );
00090 sc_time( value_type, bool scale );
00091
00092
00093
00094 sc_time& operator = ( const sc_time& );
00095
00096
00097
00098
00099 value_type value() const;
00100 double to_double() const;
00101 double to_default_time_units() const;
00102 double to_seconds() const;
00103 const std::string to_string() const;
00104
00105
00106
00107
00108 bool operator == ( const sc_time& ) const;
00109 bool operator != ( const sc_time& ) const;
00110 bool operator < ( const sc_time& ) const;
00111 bool operator <= ( const sc_time& ) const;
00112 bool operator > ( const sc_time& ) const;
00113 bool operator >= ( const sc_time& ) const;
00114
00115
00116
00117
00118 sc_time& operator += ( const sc_time& );
00119 sc_time& operator -= ( const sc_time& );
00120
00121 friend const sc_time operator + ( const sc_time&, const sc_time& );
00122 friend const sc_time operator - ( const sc_time&, const sc_time& );
00123
00124 sc_time& operator *= ( double );
00125 sc_time& operator /= ( double );
00126 sc_time& operator %= ( const sc_time& );
00127
00128 friend const sc_time operator * ( const sc_time&, double );
00129 friend const sc_time operator * ( double, const sc_time& );
00130 friend const sc_time operator / ( const sc_time&, double );
00131 friend double operator / ( const sc_time&, const sc_time& );
00132 friend const sc_time operator % ( const sc_time&, const sc_time& );
00133
00134
00135
00136
00137 void print( ::std::ostream& os = std::cout ) const;
00138
00139 private:
00140
00141 value_type m_value;
00142 };
00143
00144
00145
00146
00147 inline ::std::ostream& operator << ( ::std::ostream&, const sc_time& );
00148
00149
00150
00151
00152
00153
00154 inline
00155 sc_time::sc_time()
00156 : m_value( 0 )
00157 {}
00158
00159 inline
00160 sc_time::sc_time( const sc_time& t )
00161 : m_value( t.m_value )
00162 {}
00163
00164
00165
00166
00167 inline
00168 sc_time&
00169 sc_time::operator = ( const sc_time& t )
00170 {
00171 m_value = t.m_value;
00172 return *this;
00173 }
00174
00175
00176
00177
00178 inline
00179 sc_time::value_type
00180 sc_time::value() const
00181 {
00182 return m_value;
00183 }
00184
00185
00186 inline
00187 double
00188 sc_time::to_double() const
00189 {
00190 return sc_dt::uint64_to_double( m_value );
00191 }
00192
00193
00194
00195
00196 inline
00197 bool
00198 sc_time::operator == ( const sc_time& t ) const
00199 {
00200 return ( m_value == t.m_value );
00201 }
00202
00203 inline
00204 bool
00205 sc_time::operator != ( const sc_time& t ) const
00206 {
00207 return ( m_value != t.m_value );
00208 }
00209
00210 inline
00211 bool
00212 sc_time::operator < ( const sc_time& t ) const
00213 {
00214 return ( m_value < t.m_value );
00215 }
00216
00217 inline
00218 bool
00219 sc_time::operator <= ( const sc_time& t ) const
00220 {
00221 return ( m_value <= t.m_value );
00222 }
00223
00224 inline
00225 bool
00226 sc_time::operator > ( const sc_time& t ) const
00227 {
00228 return ( m_value > t.m_value );
00229 }
00230
00231 inline
00232 bool
00233 sc_time::operator >= ( const sc_time& t ) const
00234 {
00235 return ( m_value >= t.m_value );
00236 }
00237
00238
00239
00240
00241 inline
00242 sc_time&
00243 sc_time::operator += ( const sc_time& t )
00244 {
00245 m_value += t.m_value;
00246 return *this;
00247 }
00248
00249 inline
00250 sc_time&
00251 sc_time::operator -= ( const sc_time& t )
00252 {
00253 m_value -= t.m_value;
00254 return *this;
00255 }
00256
00257
00258 inline
00259 const sc_time
00260 operator + ( const sc_time& t1, const sc_time& t2 )
00261 {
00262 return sc_time( t1 ) += t2;
00263 }
00264
00265 inline
00266 const sc_time
00267 operator - ( const sc_time& t1, const sc_time& t2 )
00268 {
00269 return sc_time( t1 ) -= t2;
00270 }
00271
00272
00273 inline
00274 sc_time&
00275 sc_time::operator *= ( double d )
00276 {
00277
00278 volatile double tmp = sc_dt::uint64_to_double( m_value ) * d + 0.5;
00279 m_value = SCAST<sc_dt::int64>( tmp );
00280 return *this;
00281 }
00282
00283 inline
00284 sc_time&
00285 sc_time::operator /= ( double d )
00286 {
00287
00288 volatile double tmp = sc_dt::uint64_to_double( m_value ) / d + 0.5;
00289 m_value = SCAST<sc_dt::int64>( tmp );
00290 return *this;
00291 }
00292
00293 inline
00294 sc_time&
00295 sc_time::operator %= ( const sc_time& t )
00296 {
00297 m_value %= t.m_value;
00298 return *this;
00299 }
00300
00301 inline
00302 const sc_time
00303 operator * ( const sc_time& t, double d )
00304 {
00305 sc_time tmp( t );
00306 return tmp *= d;
00307 }
00308
00309 inline
00310 const sc_time
00311 operator * ( double d, const sc_time& t )
00312 {
00313 sc_time tmp( t );
00314 return tmp *= d;
00315 }
00316
00317 inline
00318 const sc_time
00319 operator / ( const sc_time& t, double d )
00320 {
00321 sc_time tmp( t );
00322 return tmp /= d;
00323 }
00324
00325 inline
00326 double
00327 operator / ( const sc_time& t1, const sc_time& t2 )
00328 {
00329 return ( t1.to_double() / t2.to_double() );
00330 }
00331
00332 inline
00333 const sc_time
00334 operator % ( const sc_time& t1, const sc_time& t2 )
00335 {
00336 sc_time tmp(t1);
00337 return tmp %= t2;
00338 }
00339
00340
00341
00342 inline
00343 ::std::ostream&
00344 operator << ( ::std::ostream& os, const sc_time& t )
00345 {
00346 t.print( os );
00347 return os;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357 struct sc_time_params
00358 {
00359 double time_resolution;
00360 bool time_resolution_specified;
00361 bool time_resolution_fixed;
00362
00363 sc_time::value_type default_time_unit;
00364 bool default_time_unit_specified;
00365
00366 sc_time_params();
00367 ~sc_time_params();
00368 };
00369
00370
00371
00372
00373 extern const sc_time SC_ZERO_TIME;
00374
00375
00376
00377
00378 extern void sc_set_time_resolution( double, sc_time_unit );
00379 extern sc_time sc_get_time_resolution();
00380
00381 extern void sc_set_default_time_unit( double, sc_time_unit );
00382 extern sc_time sc_get_default_time_unit();
00383
00384 }
00385
00386 #endif
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412