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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 uint64 sc_signed_subref_r::concat_get_uint64() const
00046 {
00047 sc_unsigned a( m_obj_p, m_left, m_right );
00048 return a.to_uint64();
00049 }
00050
00051
00052 bool sc_signed_subref_r::concat_get_ctrl(sc_digit* dst_p, int low_i ) const
00053 {
00054 sc_unsigned a( m_obj_p, m_left, m_right );
00055 return a.concat_get_ctrl( dst_p, low_i );
00056 }
00057
00058
00059 bool sc_signed_subref_r::concat_get_data(sc_digit* dst_p, int low_i ) const
00060 {
00061 sc_unsigned a( m_obj_p, m_left, m_right );
00062 return a.concat_get_data( dst_p, low_i );
00063 }
00064
00065
00066
00067
00068 sc_signed_subref_r::operator sc_unsigned () const
00069 {
00070 return sc_unsigned( m_obj_p, m_left, m_right );
00071 }
00072
00073
00074
00075
00076 int
00077 sc_signed_subref_r::to_int() const
00078 {
00079 sc_unsigned a( m_obj_p, m_left, m_right );
00080 return a.to_int();
00081 }
00082
00083 unsigned int
00084 sc_signed_subref_r::to_uint() const
00085 {
00086 sc_unsigned a( m_obj_p, m_left, m_right );
00087 return a.to_uint();
00088 }
00089
00090 long
00091 sc_signed_subref_r::to_long() const
00092 {
00093 sc_unsigned a( m_obj_p, m_left, m_right );
00094 return a.to_long();
00095 }
00096
00097 unsigned long
00098 sc_signed_subref_r::to_ulong() const
00099 {
00100 sc_unsigned a( m_obj_p, m_left, m_right );
00101 return a.to_ulong();
00102 }
00103
00104 int64
00105 sc_signed_subref_r::to_int64() const
00106 {
00107 sc_unsigned a( m_obj_p, m_left, m_right );
00108 return a.to_int64();
00109 }
00110
00111 uint64
00112 sc_signed_subref_r::to_uint64() const
00113 {
00114 sc_unsigned a( m_obj_p, m_left, m_right );
00115 return a.to_uint64();
00116 }
00117
00118 double
00119 sc_signed_subref_r::to_double() const
00120 {
00121 sc_unsigned a( m_obj_p, m_left, m_right );
00122 return a.to_double();
00123 }
00124
00125
00126
00127
00128 const std::string
00129 sc_signed_subref_r::to_string( sc_numrep numrep ) const
00130 {
00131 sc_unsigned a( length() );
00132 a = *this;
00133 return a.to_string( numrep );
00134 }
00135
00136 const std::string
00137 sc_signed_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
00138 {
00139 sc_unsigned a( length() );
00140 a = *this;
00141 return a.to_string( numrep, w_prefix );
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 const sc_signed_subref&
00154 sc_signed_subref::operator = ( const sc_signed_subref_r& a )
00155 {
00156 return operator = ( (sc_unsigned)( a ) );
00157 }
00158
00159 const sc_signed_subref&
00160 sc_signed_subref::operator = ( const sc_signed_subref& v )
00161 {
00162 if( this == &v ) {
00163 return *this;
00164 }
00165 return operator = ( (sc_unsigned)( v ) );
00166 }
00167
00168 const sc_signed_subref&
00169 sc_signed_subref::operator = ( const sc_signed& v )
00170 {
00171 int l = sc_min( m_left, v.nbits - 1 + m_right );
00172 for( int i = m_right; i <= l; ++ i ) {
00173 m_obj_p->set( i, v.test( i - m_right ) );
00174 }
00175 return *this;
00176 }
00177
00178 const sc_signed_subref&
00179 sc_signed_subref::operator = ( const sc_unsigned_subref_r& v )
00180 {
00181 return operator = ( (sc_unsigned)( v ) );
00182 }
00183
00184 const sc_signed_subref&
00185 sc_signed_subref::operator = ( const sc_unsigned& v )
00186 {
00187 int l = sc_min( m_left, v.nbits - 1 + m_right );
00188 for( int i = m_right; i <= l; ++ i ) {
00189 m_obj_p->set( i, v.test( i - m_right ) );
00190 }
00191 return *this;
00192 }
00193
00194 const sc_signed_subref&
00195 sc_signed_subref::operator = ( unsigned long v )
00196 {
00197 for( int i = m_right; i <= m_left; ++ i ) {
00198 m_obj_p->set( i, static_cast<bool>( v & 1 ) );
00199 v >>= 1;
00200 }
00201 return *this;
00202 }
00203
00204 const sc_signed_subref&
00205 sc_signed_subref::operator = ( long v )
00206 {
00207 unsigned long v2 = (unsigned long) v;
00208 for( int i = m_right; i <= m_left; ++ i ) {
00209 m_obj_p->set( i, static_cast<bool>( v2 & 1 ) );
00210 v2 >>= 1;
00211 }
00212 return *this;
00213 }
00214
00215 const sc_signed_subref&
00216 sc_signed_subref::operator = ( uint64 v )
00217 {
00218 for( int i = m_right; i <= m_left; ++ i ) {
00219 m_obj_p->set( i, static_cast<bool>( v & 1 ) );
00220 v >>= 1;
00221 }
00222 return *this;
00223 }
00224
00225 const sc_signed_subref&
00226 sc_signed_subref::operator = ( int64 v )
00227 {
00228 uint64 v2 = (uint64) v;
00229 for( int i = m_right; i <= m_left; ++ i ) {
00230 m_obj_p->set( i, static_cast<bool>( v2 & 1 ) );
00231 v2 >>= 1;
00232 }
00233 return *this;
00234 }
00235
00236 const sc_signed_subref&
00237 sc_signed_subref::operator = ( double v )
00238 {
00239 is_bad_double(v);
00240
00241 int nb = m_left - m_right + 1;
00242 int nd = DIV_CEIL(nb);
00243
00244 #ifdef SC_MAX_NBITS
00245 sc_digit d[MAX_NDIGITS];
00246 #else
00247 sc_digit *d = new sc_digit[nd];
00248 #endif
00249
00250 if (v < 0)
00251 v = -v;
00252
00253 register int i = 0;
00254
00255 while (floor(v) && (i < nd)) {
00256 #ifndef WIN32
00257 d[i++] = (sc_digit) floor(remainder(v, DIGIT_RADIX));
00258 #else
00259 d[i++] = (sc_digit) floor(fmod(v, DIGIT_RADIX));
00260 #endif
00261 v /= DIGIT_RADIX;
00262 }
00263
00264 vec_zero(i, nd, d);
00265
00266 sc_digit val = 1;
00267 int j = 0;
00268
00269 i = 0;
00270
00271 while (i < nb) {
00272
00273 m_obj_p->set(i + m_right, (bool) (d[j] & val));
00274
00275 ++i;
00276
00277 if (i % BITS_PER_DIGIT == 0) {
00278 val = 1;
00279 ++j;
00280 }
00281 else
00282 val <<= 1;
00283 }
00284
00285 #ifndef SC_MAX_NBITS
00286 delete [] d;
00287 #endif
00288
00289 return *this;
00290 }
00291
00292 const sc_signed_subref&
00293 sc_signed_subref::operator = ( const sc_int_base& a )
00294 {
00295 return operator = ( (int64) a );
00296 }
00297
00298 const sc_signed_subref&
00299 sc_signed_subref::operator = ( const sc_uint_base& a )
00300 {
00301 return operator = ( (uint64) a );
00302 }
00303
00304
00305
00306
00307 void sc_signed_subref::concat_set( int64 src, int low_i )
00308 {
00309 int i;
00310 int l;
00311 bool sign = src < 0;
00312
00313 if ( low_i < 64 )
00314 {
00315 src = src >> low_i;
00316 l = sc_min( m_left, (63-low_i) + m_right );
00317 for( i = m_right; i <= l; ++ i ) {
00318 m_obj_p->set( i, src & 1 );
00319 src = src >> 1;
00320 }
00321 for ( ; i <= m_left; i++ ) m_obj_p->set(i, sign);
00322 }
00323 else
00324 {
00325 for( i = m_right; i <= m_left; ++ i ) m_obj_p->set(i, sign);
00326 }
00327 }
00328
00329 void sc_signed_subref::concat_set( const sc_signed& src, int low_i )
00330 {
00331 int i;
00332 int l;
00333 int src_i;
00334 bool sign = src.test(src.nbits-1);
00335 l = src.nbits - (low_i+1);
00336 if ( l >= 0 )
00337 {
00338 l = sc_min( m_left, l + m_right );
00339 src_i = low_i;
00340 for( i = m_right; i <= l; ++ i, src_i++ ) {
00341 m_obj_p->set( i, src.test( src_i ) );
00342 }
00343 for ( ; i <= m_left; i++ ) m_obj_p->set(i, sign);
00344 }
00345 else
00346 {
00347 for( i = m_right; i <= m_left; ++ i ) m_obj_p->set(i, sign);
00348 }
00349 }
00350
00351 void sc_signed_subref::concat_set( const sc_unsigned& src, int low_i )
00352 {
00353 int i;
00354 int l;
00355 int src_i;
00356 l = src.nbits - (low_i+2);
00357 if ( l >= 0 )
00358 {
00359 l = sc_min( m_left, l + m_right );
00360 src_i = low_i;
00361 for( i = m_right; i <= l; ++ i, src_i++ ) {
00362 m_obj_p->set( i, src.test( src_i ) );
00363 }
00364 for ( ; i <= m_left; i++ ) m_obj_p->set(false);
00365 }
00366 else
00367 {
00368 for( i = m_right; i <= m_left; ++ i ) m_obj_p->set(false);
00369 }
00370 }
00371
00372 void sc_signed_subref::concat_set( uint64 src, int low_i )
00373 {
00374 int i;
00375 int l;
00376
00377 if ( low_i < 64 )
00378 {
00379 src = src >> low_i;
00380 l = sc_min( m_left, (63-low_i) + m_right );
00381 for( i = m_right; i <= l; ++ i ) {
00382 m_obj_p->set( i, src & 1 );
00383 src = src >> 1;
00384 }
00385 for ( ; i <= m_left; i++ ) m_obj_p->set(false);
00386 }
00387 else
00388 {
00389 for( i = m_right; i <= m_left; ++ i ) m_obj_p->set(false);
00390 }
00391 }
00392
00393
00394 void
00395 sc_signed_subref::scan( ::std::istream& is )
00396 {
00397 std::string s;
00398 is >> s;
00399 *this = s.c_str();
00400 }
00401
00402
00403