sc_fxnum.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_fxnum.h - 
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 // $Log: sc_fxnum.h,v $
00037 // Revision 1.1.1.1  2006/12/15 20:31:36  acg
00038 // SystemC 2.2
00039 //
00040 // Revision 1.3  2006/01/13 18:53:58  acg
00041 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
00042 // the source.
00043 //
00044 
00045 #ifndef SC_FXNUM_H
00046 #define SC_FXNUM_H
00047 
00048 
00049 #include "sysc/datatypes/bit/sc_lv_base.h"
00050 #include "sysc/datatypes/fx/sc_fxval.h"
00051 #include "sysc/datatypes/fx/scfx_params.h"
00052 #include "sysc/datatypes/fx/sc_fxnum_observer.h"
00053 
00054 
00055 namespace sc_core {
00056     class vcd_sc_fxnum_trace;
00057     class vcd_sc_fxnum_fast_trace;
00058     class wif_sc_fxnum_trace;
00059     class wif_sc_fxnum_fast_trace;
00060 };
00061 
00062 
00063 namespace sc_dt
00064 {
00065 
00066 // classes defined in this module
00067 class sc_fxnum_bitref;
00068 class sc_fxnum_fast_bitref;
00069 class sc_fxnum_subref;
00070 class sc_fxnum_fast_subref;
00071 class sc_fxnum;
00072 class sc_fxnum_fast;
00073 
00074 
00075 // ----------------------------------------------------------------------------
00076 //  CLASS : sc_fxnum_bitref
00077 //
00078 //  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
00079 // ----------------------------------------------------------------------------
00080 
00081 class sc_fxnum_bitref
00082 {
00083     friend class sc_fxnum;
00084     friend class sc_fxnum_fast_bitref;
00085 
00086 
00087     bool get() const;
00088     void set( bool );
00089 
00090 
00091     // constructor
00092 
00093     sc_fxnum_bitref( sc_fxnum&, int );
00094 
00095 public:
00096 
00097     // copy constructor
00098 
00099     sc_fxnum_bitref( const sc_fxnum_bitref& );
00100 
00101 
00102     // assignment operators
00103 
00104 #define DECL_ASN_OP_T(op,tp)                                                  \
00105     sc_fxnum_bitref& operator op ( tp );
00106 
00107 #define DECL_ASN_OP(op)                                                       \
00108     DECL_ASN_OP_T(op,const sc_fxnum_bitref&)                                  \
00109     DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&)                             \
00110     DECL_ASN_OP_T(op,const sc_bit&)                                           \
00111     DECL_ASN_OP_T(op,bool)
00112 
00113     DECL_ASN_OP(=)
00114 
00115     DECL_ASN_OP(&=)
00116     DECL_ASN_OP(|=)
00117     DECL_ASN_OP(^=)
00118 
00119 #undef DECL_ASN_OP_T
00120 #undef DECL_ASN_OP
00121 
00122 
00123     // implicit conversion
00124 
00125     operator bool() const;
00126 
00127 
00128     // print or dump content
00129 
00130     void print( ::std::ostream& = ::std::cout ) const;
00131     void scan( ::std::istream& = ::std::cin );
00132     void dump( ::std::ostream& = ::std::cout ) const;
00133 
00134 private:
00135 
00136     sc_fxnum& m_num;
00137     int       m_idx;
00138 
00139 private:
00140 
00141     // disabled
00142     sc_fxnum_bitref();
00143 };
00144 
00145 
00146 // ----------------------------------------------------------------------------
00147 //  CLASS : sc_fxnum_fast_bitref
00148 //
00149 //  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
00150 // ----------------------------------------------------------------------------
00151 
00152 class sc_fxnum_fast_bitref
00153 {
00154     friend class sc_fxnum_fast;
00155     friend class sc_fxnum_bitref;
00156 
00157 
00158     bool get() const;
00159     void set( bool );
00160 
00161 
00162     // constructor
00163 
00164     sc_fxnum_fast_bitref( sc_fxnum_fast&, int );
00165 
00166 public:
00167 
00168     // copy constructor
00169 
00170     sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& );
00171 
00172 
00173     // assignment operators
00174 
00175 #define DECL_ASN_OP_T(op,tp)                                                  \
00176     sc_fxnum_fast_bitref& operator op ( tp );
00177 
00178 #define DECL_ASN_OP(op)                                                       \
00179     DECL_ASN_OP_T(op,const sc_fxnum_bitref&)                                  \
00180     DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&)                             \
00181     DECL_ASN_OP_T(op,const sc_bit&)                                           \
00182     DECL_ASN_OP_T(op,bool)
00183 
00184     DECL_ASN_OP(=)
00185 
00186     DECL_ASN_OP(&=)
00187     DECL_ASN_OP(|=)
00188     DECL_ASN_OP(^=)
00189 
00190 #undef DECL_ASN_OP_T
00191 #undef DECL_ASN_OP
00192 
00193 
00194     // implicit conversion
00195 
00196     operator bool() const;
00197 
00198 
00199     // print or dump content
00200 
00201     void print( ::std::ostream& = ::std::cout ) const;
00202     void scan( ::std::istream& = ::std::cin );
00203     void dump( ::std::ostream& = ::std::cout ) const;
00204 
00205 private:
00206 
00207     sc_fxnum_fast& m_num;
00208     int            m_idx;
00209 
00210 private:
00211 
00212     // disabled
00213     sc_fxnum_fast_bitref();
00214 };
00215 
00216 
00217 // ----------------------------------------------------------------------------
00218 //  CLASS : sc_fxnum_subref
00219 //
00220 //  Proxy class for part-selection in class sc_fxnum,
00221 //  behaves like sc_bv_base.
00222 // ----------------------------------------------------------------------------
00223 
00224 class sc_fxnum_subref
00225 {
00226     friend class sc_fxnum;
00227     friend class sc_fxnum_fast_subref;
00228 
00229     bool get() const;
00230     bool set();
00231 
00232 
00233     // constructor
00234 
00235     sc_fxnum_subref( sc_fxnum&, int, int );
00236 
00237 public:
00238 
00239     // copy constructor
00240 
00241     sc_fxnum_subref( const sc_fxnum_subref& );
00242 
00243 
00244     // destructor
00245 
00246     ~sc_fxnum_subref();
00247 
00248 
00249     // assignment operators
00250 
00251 #define DECL_ASN_OP_T(tp)                                                     \
00252     sc_fxnum_subref& operator = ( tp );
00253 
00254     DECL_ASN_OP_T(const sc_fxnum_subref&)
00255     DECL_ASN_OP_T(const sc_fxnum_fast_subref&)
00256     DECL_ASN_OP_T(const sc_bv_base&)
00257     DECL_ASN_OP_T(const sc_lv_base&)
00258     DECL_ASN_OP_T(const char*)
00259     DECL_ASN_OP_T(const bool*)
00260     DECL_ASN_OP_T(const sc_signed&)
00261     DECL_ASN_OP_T(const sc_unsigned&)
00262     DECL_ASN_OP_T(const sc_int_base&)
00263     DECL_ASN_OP_T(const sc_uint_base&)
00264     DECL_ASN_OP_T(int64)
00265     DECL_ASN_OP_T(uint64)
00266     DECL_ASN_OP_T(int)
00267     DECL_ASN_OP_T(unsigned int)
00268     DECL_ASN_OP_T(long)
00269     DECL_ASN_OP_T(unsigned long)
00270     DECL_ASN_OP_T(char)
00271 
00272 #undef DECL_ASN_OP_T
00273 
00274 #define DECL_ASN_OP_T_A(op,tp)                                                \
00275     sc_fxnum_subref& operator op ## = ( tp );
00276 
00277 #define DECL_ASN_OP_A(op)                                                     \
00278     DECL_ASN_OP_T_A(op,const sc_fxnum_subref&)                                \
00279     DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&)                           \
00280     DECL_ASN_OP_T_A(op,const sc_bv_base&)                                     \
00281     DECL_ASN_OP_T_A(op,const sc_lv_base&)
00282 
00283     DECL_ASN_OP_A(&)
00284     DECL_ASN_OP_A(|)
00285     DECL_ASN_OP_A(^)
00286 
00287 #undef DECL_ASN_OP_T_A
00288 #undef DECL_ASN_OP_A
00289 
00290 
00291     // relational operators
00292 
00293 #define DECL_REL_OP_T(op,tp)                                                  \
00294     friend bool operator op ( const sc_fxnum_subref&, tp );                   \
00295     friend bool operator op ( tp, const sc_fxnum_subref& );
00296 
00297 #define DECL_REL_OP(op)                                                       \
00298     friend bool operator op ( const sc_fxnum_subref&,                         \
00299                   const sc_fxnum_subref& );                       \
00300     friend bool operator op ( const sc_fxnum_subref&,                         \
00301                   const sc_fxnum_fast_subref& );                  \
00302     DECL_REL_OP_T(op,const sc_bv_base&)                                       \
00303     DECL_REL_OP_T(op,const sc_lv_base&)                                       \
00304     DECL_REL_OP_T(op,const char*)                                             \
00305     DECL_REL_OP_T(op,const bool*)                                             \
00306     DECL_REL_OP_T(op,const sc_signed&)                                        \
00307     DECL_REL_OP_T(op,const sc_unsigned&)                                      \
00308     DECL_REL_OP_T(op,int)                                                     \
00309     DECL_REL_OP_T(op,unsigned int)                                            \
00310     DECL_REL_OP_T(op,long)                                                    \
00311     DECL_REL_OP_T(op,unsigned long)
00312 
00313     DECL_REL_OP(==)
00314     DECL_REL_OP(!=)
00315 
00316 #undef DECL_REL_OP_T
00317 #undef DECL_REL_OP
00318 
00319 
00320     // reduce functions
00321 
00322     bool and_reduce() const;
00323     bool nand_reduce() const;
00324     bool or_reduce() const;
00325     bool nor_reduce() const;
00326     bool xor_reduce() const;
00327     bool xnor_reduce() const;
00328 
00329 
00330     // query parameter
00331 
00332     int length() const;
00333 
00334 
00335     // explicit conversions
00336 
00337     int           to_int() const;
00338     unsigned int  to_uint() const;
00339     long          to_long() const;
00340     unsigned long to_ulong() const;
00341     int64         to_int64() const;
00342     uint64        to_uint64() const;
00343 
00344 #ifdef SC_DT_DEPRECATED
00345     int           to_signed() const;
00346     unsigned int  to_unsigned() const;
00347 #endif
00348 
00349     const std::string to_string() const;
00350     const std::string to_string( sc_numrep ) const;
00351     const std::string to_string( sc_numrep, bool ) const;
00352 
00353 
00354     // implicit conversion
00355 
00356     operator sc_bv_base() const;
00357 
00358 
00359     // print or dump content
00360 
00361     void print( ::std::ostream& = ::std::cout ) const;
00362     void scan( ::std::istream& = ::std::cin );
00363     void dump( ::std::ostream& = ::std::cout ) const;
00364 
00365 private:
00366 
00367     sc_fxnum& m_num;
00368     int       m_from;
00369     int       m_to;
00370 
00371     sc_bv_base& m_bv;
00372 
00373 private:
00374 
00375     // disabled
00376     sc_fxnum_subref();
00377 };
00378 
00379 
00380 // ----------------------------------------------------------------------------
00381 //  CLASS : sc_fxnum_fast_subref
00382 //
00383 //  Proxy class for part-selection in class sc_fxnum_fast,
00384 //  behaves like sc_bv_base.
00385 // ----------------------------------------------------------------------------
00386 
00387 class sc_fxnum_fast_subref
00388 {
00389     friend class sc_fxnum_fast;
00390     friend class sc_fxnum_subref;
00391 
00392     bool get() const;
00393     bool set();
00394 
00395 
00396     // constructor
00397 
00398     sc_fxnum_fast_subref( sc_fxnum_fast&, int, int );
00399 
00400 public:
00401 
00402     // copy constructor
00403 
00404     sc_fxnum_fast_subref( const sc_fxnum_fast_subref& );
00405 
00406 
00407     // destructor
00408 
00409     ~sc_fxnum_fast_subref();
00410 
00411 
00412     // assignment operators
00413 
00414 #define DECL_ASN_OP_T(tp)                                                     \
00415     sc_fxnum_fast_subref& operator = ( tp );
00416 
00417     DECL_ASN_OP_T(const sc_fxnum_subref&)
00418     DECL_ASN_OP_T(const sc_fxnum_fast_subref&)
00419     DECL_ASN_OP_T(const sc_bv_base&)
00420     DECL_ASN_OP_T(const sc_lv_base&)
00421     DECL_ASN_OP_T(const char*)
00422     DECL_ASN_OP_T(const bool*)
00423     DECL_ASN_OP_T(const sc_signed&)
00424     DECL_ASN_OP_T(const sc_unsigned&)
00425     DECL_ASN_OP_T(const sc_int_base&)
00426     DECL_ASN_OP_T(const sc_uint_base&)
00427     DECL_ASN_OP_T(int64)
00428     DECL_ASN_OP_T(uint64)
00429     DECL_ASN_OP_T(int)
00430     DECL_ASN_OP_T(unsigned int)
00431     DECL_ASN_OP_T(long)
00432     DECL_ASN_OP_T(unsigned long)
00433     DECL_ASN_OP_T(char)
00434 
00435 #undef DECL_ASN_OP_T
00436 
00437 #define DECL_ASN_OP_T_A(op,tp)                                                \
00438     sc_fxnum_fast_subref& operator op ## = ( tp );
00439 
00440 #define DECL_ASN_OP_A(op)                                                     \
00441     DECL_ASN_OP_T_A(op,const sc_fxnum_subref&)                                \
00442     DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&)                           \
00443     DECL_ASN_OP_T_A(op,const sc_bv_base&)                                     \
00444     DECL_ASN_OP_T_A(op,const sc_lv_base&)
00445 
00446     DECL_ASN_OP_A(&)
00447     DECL_ASN_OP_A(|)
00448     DECL_ASN_OP_A(^)
00449 
00450 #undef DECL_ASN_OP_T_A
00451 #undef DECL_ASN_OP_A
00452 
00453 
00454     // relational operators
00455 
00456 #define DECL_REL_OP_T(op,tp)                                                  \
00457     friend bool operator op ( const sc_fxnum_fast_subref&, tp );              \
00458     friend bool operator op ( tp, const sc_fxnum_fast_subref& );
00459 
00460 #define DECL_REL_OP(op)                                                       \
00461     friend bool operator op ( const sc_fxnum_fast_subref&,                    \
00462                   const sc_fxnum_fast_subref& );                  \
00463     friend bool operator op ( const sc_fxnum_fast_subref&,                    \
00464                   const sc_fxnum_subref& );                       \
00465     DECL_REL_OP_T(op,const sc_bv_base&)                                       \
00466     DECL_REL_OP_T(op,const sc_lv_base&)                                       \
00467     DECL_REL_OP_T(op,const char*)                                             \
00468     DECL_REL_OP_T(op,const bool*)                                             \
00469     DECL_REL_OP_T(op,const sc_signed&)                                        \
00470     DECL_REL_OP_T(op,const sc_unsigned&)                                      \
00471     DECL_REL_OP_T(op,int)                                                     \
00472     DECL_REL_OP_T(op,unsigned int)                                            \
00473     DECL_REL_OP_T(op,long)                                                    \
00474     DECL_REL_OP_T(op,unsigned long)
00475 
00476     DECL_REL_OP(==)
00477     DECL_REL_OP(!=)
00478 
00479 #undef DECL_REL_OP_T
00480 #undef DECL_REL_OP
00481 
00482 
00483     // reduce functions
00484 
00485     bool and_reduce() const;
00486     bool nand_reduce() const;
00487     bool or_reduce() const;
00488     bool nor_reduce() const;
00489     bool xor_reduce() const;
00490     bool xnor_reduce() const;
00491 
00492 
00493     // query parameter
00494 
00495     int length() const;
00496 
00497 
00498     // explicit conversions
00499 
00500     int           to_int() const;
00501     unsigned int  to_uint() const;
00502     long          to_long() const;
00503     unsigned long to_ulong() const;
00504     int64         to_int64() const;
00505     uint64        to_uint64() const;
00506 
00507 #ifdef SC_DT_DEPRECATED
00508     int           to_signed() const;
00509     unsigned int  to_unsigned() const;
00510 #endif
00511 
00512     const std::string to_string() const;
00513     const std::string to_string( sc_numrep ) const;
00514     const std::string to_string( sc_numrep, bool ) const;
00515 
00516 
00517     // implicit conversion
00518 
00519     operator sc_bv_base() const;
00520 
00521 
00522     // print or dump content
00523 
00524     void print( ::std::ostream& = ::std::cout ) const;
00525     void scan( ::std::istream& = ::std::cin );
00526     void dump( ::std::ostream& = ::std::cout ) const;
00527 
00528 private:
00529 
00530     sc_fxnum_fast& m_num;
00531     int            m_from;
00532     int            m_to;
00533 
00534     sc_bv_base& m_bv;
00535 
00536 private:
00537 
00538     // disabled
00539     sc_fxnum_fast_subref();
00540 };
00541 
00542 
00543 // ----------------------------------------------------------------------------
00544 //  CLASS : sc_fxnum
00545 //
00546 //  Base class for the fixed-point types; arbitrary precision.
00547 // ----------------------------------------------------------------------------
00548 
00549 class sc_fxnum
00550 {
00551     friend class sc_fxval;
00552 
00553     friend class sc_fxnum_bitref;
00554     friend class sc_fxnum_subref;
00555     friend class sc_fxnum_fast_bitref;
00556     friend class sc_fxnum_fast_subref;
00557 
00558     friend class sc_core::vcd_sc_fxnum_trace;
00559     friend class sc_core::wif_sc_fxnum_trace;
00560 
00561 protected:
00562 
00563     sc_fxnum_observer* observer() const;
00564 
00565 
00566     void cast();
00567 
00568 
00569     // constructors
00570 
00571     sc_fxnum( const sc_fxtype_params&,
00572           sc_enc,
00573           const sc_fxcast_switch&,
00574           sc_fxnum_observer* );
00575 
00576 #define DECL_CTOR_T(tp)                                                       \
00577     sc_fxnum( tp,                                                             \
00578           const sc_fxtype_params&,                                        \
00579           sc_enc,                                                         \
00580           const sc_fxcast_switch&,                                        \
00581           sc_fxnum_observer* );
00582 
00583     DECL_CTOR_T(int)
00584     DECL_CTOR_T(unsigned int)
00585     DECL_CTOR_T(long)
00586     DECL_CTOR_T(unsigned long)
00587     DECL_CTOR_T(double)
00588     DECL_CTOR_T(const char*)
00589     DECL_CTOR_T(const sc_fxval&)
00590     DECL_CTOR_T(const sc_fxval_fast&)
00591     DECL_CTOR_T(const sc_fxnum&)
00592     DECL_CTOR_T(const sc_fxnum_fast&)
00593 #ifndef SC_FX_EXCLUDE_OTHER
00594     DECL_CTOR_T(int64)
00595     DECL_CTOR_T(uint64)
00596     DECL_CTOR_T(const sc_int_base&)
00597     DECL_CTOR_T(const sc_uint_base&)
00598     DECL_CTOR_T(const sc_signed&)
00599     DECL_CTOR_T(const sc_unsigned&)
00600 #endif
00601 
00602 #undef DECL_CTOR_T
00603 
00604     ~sc_fxnum();
00605 
00606 
00607     // internal use only;
00608     const scfx_rep* get_rep() const;
00609 
00610 public:
00611 
00612     // unary operators
00613 
00614     const sc_fxval operator - () const;
00615     const sc_fxval operator + () const;
00616 
00617 
00618     // unary functions
00619 
00620     friend void neg( sc_fxval&, const sc_fxnum& );
00621     friend void neg( sc_fxnum&, const sc_fxnum& );
00622 
00623 
00624     // binary operators
00625 
00626 #define DECL_BIN_OP_T(op,tp)                                                  \
00627     friend const sc_fxval operator op ( const sc_fxnum&, tp );                \
00628     friend const sc_fxval operator op ( tp, const sc_fxnum& );
00629 
00630 #ifndef SC_FX_EXCLUDE_OTHER
00631 #define DECL_BIN_OP_OTHER(op)                                                 \
00632     DECL_BIN_OP_T(op,int64)                                                   \
00633     DECL_BIN_OP_T(op,uint64)                                                  \
00634     DECL_BIN_OP_T(op,const sc_int_base&)                                      \
00635     DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
00636     DECL_BIN_OP_T(op,const sc_signed&)                                        \
00637     DECL_BIN_OP_T(op,const sc_unsigned&)
00638 #else
00639 #define DECL_BIN_OP_OTHER(op)
00640 #endif
00641 
00642 #define DECL_BIN_OP(op,dummy)                                                 \
00643     friend const sc_fxval operator op ( const sc_fxnum&, const sc_fxnum& );   \
00644     DECL_BIN_OP_T(op,int)                                                     \
00645     DECL_BIN_OP_T(op,unsigned int)                                            \
00646     DECL_BIN_OP_T(op,long)                                                    \
00647     DECL_BIN_OP_T(op,unsigned long)                                           \
00648     DECL_BIN_OP_T(op,double)                                                  \
00649     DECL_BIN_OP_T(op,const char*)                                             \
00650     DECL_BIN_OP_T(op,const sc_fxval&)                                         \
00651     DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
00652     DECL_BIN_OP_T(op,const sc_fxnum_fast&)                                    \
00653     DECL_BIN_OP_OTHER(op)
00654 
00655     DECL_BIN_OP(*,mult)
00656     DECL_BIN_OP(+,add)
00657     DECL_BIN_OP(-,sub)
00658 // don't use macros
00659 //    DECL_BIN_OP(/,div)
00660     friend const sc_fxval operator / ( const sc_fxnum&, const sc_fxnum& );
00661     DECL_BIN_OP_T(/,int)
00662     DECL_BIN_OP_T(/,unsigned int)
00663     DECL_BIN_OP_T(/,long)
00664     DECL_BIN_OP_T(/,unsigned long)
00665     DECL_BIN_OP_T(/,double)
00666     DECL_BIN_OP_T(/,const char*)
00667     DECL_BIN_OP_T(/,const sc_fxval&)
00668     DECL_BIN_OP_T(/,const sc_fxval_fast&)
00669     DECL_BIN_OP_T(/,const sc_fxnum_fast&)
00670 //    DECL_BIN_OP_OTHER(op)
00671 #ifndef SC_FX_EXCLUDE_OTHER
00672     DECL_BIN_OP_T(/,int64)
00673     DECL_BIN_OP_T(/,uint64)
00674     DECL_BIN_OP_T(/,const sc_int_base&)
00675     DECL_BIN_OP_T(/,const sc_uint_base&)
00676     DECL_BIN_OP_T(/,const sc_signed&)
00677     DECL_BIN_OP_T(/,const sc_unsigned&)
00678 #endif
00679 
00680 #undef DECL_BIN_OP_T
00681 #undef DECL_BIN_OP_OTHER
00682 #undef DECL_BIN_OP
00683 
00684     friend const sc_fxval operator << ( const sc_fxnum&, int );
00685     friend const sc_fxval operator >> ( const sc_fxnum&, int );
00686 
00687 
00688     // binary functions
00689 
00690 #define DECL_BIN_FNC_T(fnc,tp)                                                \
00691     friend void fnc ( sc_fxval&, const sc_fxnum&, tp );                       \
00692     friend void fnc ( sc_fxval&, tp, const sc_fxnum& );                       \
00693     friend void fnc ( sc_fxnum&, const sc_fxnum&, tp );                       \
00694     friend void fnc ( sc_fxnum&, tp, const sc_fxnum& );
00695 
00696 #ifndef SC_FX_EXCLUDE_OTHER
00697 #define DECL_BIN_FNC_OTHER(fnc)                                               \
00698     DECL_BIN_FNC_T(fnc,int64)                                                 \
00699     DECL_BIN_FNC_T(fnc,uint64)                                                \
00700     DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
00701     DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
00702     DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
00703     DECL_BIN_FNC_T(fnc,const sc_unsigned&)
00704 #else
00705 #define DECL_BIN_FNC_OTHER(fnc)
00706 #endif
00707 
00708 #define DECL_BIN_FNC(fnc)                                                     \
00709     friend void fnc ( sc_fxval&, const sc_fxnum&, const sc_fxnum& );          \
00710     friend void fnc ( sc_fxnum&, const sc_fxnum&, const sc_fxnum& );          \
00711     DECL_BIN_FNC_T(fnc,int)                                                   \
00712     DECL_BIN_FNC_T(fnc,unsigned int)                                          \
00713     DECL_BIN_FNC_T(fnc,long)                                                  \
00714     DECL_BIN_FNC_T(fnc,unsigned long)                                         \
00715     DECL_BIN_FNC_T(fnc,double)                                                \
00716     DECL_BIN_FNC_T(fnc,const char*)                                           \
00717     DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
00718     DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
00719     DECL_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                  \
00720     DECL_BIN_FNC_OTHER(fnc)
00721 
00722     DECL_BIN_FNC(mult)
00723     DECL_BIN_FNC(div)
00724     DECL_BIN_FNC(add)
00725     DECL_BIN_FNC(sub)
00726 
00727 #undef DECL_BIN_FNC_T
00728 #undef DECL_BIN_FNC_OTHER
00729 #undef DECL_BIN_FNC
00730 
00731     friend void lshift( sc_fxval&, const sc_fxnum&, int );
00732     friend void rshift( sc_fxval&, const sc_fxnum&, int );
00733     friend void lshift( sc_fxnum&, const sc_fxnum&, int );
00734     friend void rshift( sc_fxnum&, const sc_fxnum&, int );
00735 
00736 
00737     // relational (including equality) operators
00738 
00739 #define DECL_REL_OP_T(op,tp)                                                  \
00740     friend bool operator op ( const sc_fxnum&, tp );                          \
00741     friend bool operator op ( tp, const sc_fxnum& );
00742 
00743 #ifndef SC_FX_EXCLUDE_OTHER
00744 #define DECL_REL_OP_OTHER(op)                                                 \
00745     DECL_REL_OP_T(op,int64)                                                   \
00746     DECL_REL_OP_T(op,uint64)                                                  \
00747     DECL_REL_OP_T(op,const sc_int_base&)                                      \
00748     DECL_REL_OP_T(op,const sc_uint_base&)                                     \
00749     DECL_REL_OP_T(op,const sc_signed&)                                        \
00750     DECL_REL_OP_T(op,const sc_unsigned&)
00751 #else
00752 #define DECL_REL_OP_OTHER(op)
00753 #endif
00754 
00755 #define DECL_REL_OP(op)                                                       \
00756     friend bool operator op ( const sc_fxnum&, const sc_fxnum& );             \
00757     DECL_REL_OP_T(op,int)                                                     \
00758     DECL_REL_OP_T(op,unsigned int)                                            \
00759     DECL_REL_OP_T(op,long)                                                    \
00760     DECL_REL_OP_T(op,unsigned long)                                           \
00761     DECL_REL_OP_T(op,double)                                                  \
00762     DECL_REL_OP_T(op,const char*)                                             \
00763     DECL_REL_OP_T(op,const sc_fxval&)                                         \
00764     DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
00765     DECL_REL_OP_T(op,const sc_fxnum_fast&)                                    \
00766     DECL_REL_OP_OTHER(op)
00767 
00768     DECL_REL_OP(<)
00769     DECL_REL_OP(<=)
00770     DECL_REL_OP(>)
00771     DECL_REL_OP(>=)
00772     DECL_REL_OP(==)
00773     DECL_REL_OP(!=)
00774 
00775 #undef DECL_REL_OP_T
00776 #undef DECL_REL_OP_OTHER
00777 #undef DECL_REL_OP
00778 
00779 
00780     // assignment operators
00781 
00782 #define DECL_ASN_OP_T(op,tp)                                                  \
00783     sc_fxnum& operator op( tp );
00784 
00785 #ifndef SC_FX_EXCLUDE_OTHER
00786 #define DECL_ASN_OP_OTHER(op)                                                 \
00787     DECL_ASN_OP_T(op,int64)                                                   \
00788     DECL_ASN_OP_T(op,uint64)                                                  \
00789     DECL_ASN_OP_T(op,const sc_int_base&)                                      \
00790     DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
00791     DECL_ASN_OP_T(op,const sc_signed&)                                        \
00792     DECL_ASN_OP_T(op,const sc_unsigned&)
00793 #else
00794 #define DECL_ASN_OP_OTHER(op)
00795 #endif
00796 
00797 #define DECL_ASN_OP(op)                                                       \
00798     DECL_ASN_OP_T(op,int)                                                     \
00799     DECL_ASN_OP_T(op,unsigned int)                                            \
00800     DECL_ASN_OP_T(op,long)                                                    \
00801     DECL_ASN_OP_T(op,unsigned long)                                           \
00802     DECL_ASN_OP_T(op,double)                                                  \
00803     DECL_ASN_OP_T(op,const char*)                                             \
00804     DECL_ASN_OP_T(op,const sc_fxval&)                                         \
00805     DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
00806     DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
00807     DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
00808     DECL_ASN_OP_OTHER(op)
00809 
00810     DECL_ASN_OP(=)
00811 
00812     DECL_ASN_OP(*=)
00813     DECL_ASN_OP(/=)
00814     DECL_ASN_OP(+=)
00815     DECL_ASN_OP(-=)
00816 
00817     DECL_ASN_OP_T(<<=,int)
00818     DECL_ASN_OP_T(>>=,int)
00819 
00820 #undef DECL_ASN_OP_T
00821 #undef DECL_ASN_OP_OTHER
00822 #undef DECL_ASN_OP
00823 
00824 
00825     // auto-increment and auto-decrement
00826 
00827     const sc_fxval operator ++ ( int );
00828     const sc_fxval operator -- ( int );
00829 
00830     sc_fxnum& operator ++ ();
00831     sc_fxnum& operator -- ();
00832 
00833 
00834     // bit selection
00835 
00836     const sc_fxnum_bitref operator [] ( int ) const;
00837     sc_fxnum_bitref       operator [] ( int );
00838 
00839     const sc_fxnum_bitref bit( int ) const;
00840     sc_fxnum_bitref       bit( int );
00841 
00842 
00843     // part selection
00844 
00845     const sc_fxnum_subref operator () ( int, int ) const;
00846     sc_fxnum_subref       operator () ( int, int );
00847 
00848     const sc_fxnum_subref range( int, int ) const;
00849     sc_fxnum_subref       range( int, int );
00850 
00851 
00852     const sc_fxnum_subref operator () () const;
00853     sc_fxnum_subref       operator () ();
00854 
00855     const sc_fxnum_subref range() const;
00856     sc_fxnum_subref       range();
00857 
00858 
00859     // implicit conversion
00860 
00861     operator double() const;        // necessary evil!
00862 
00863 
00864     // explicit conversion to primitive types
00865 
00866     short          to_short() const;
00867     unsigned short to_ushort() const;
00868     int            to_int() const;
00869     unsigned int   to_uint() const;
00870     long           to_long() const;
00871     unsigned long  to_ulong() const;
00872     int64          to_int64() const;
00873     uint64         to_uint64() const;
00874     float          to_float() const;
00875     double         to_double() const;
00876 
00877 
00878     // explicit conversion to character string
00879 
00880     const std::string to_string() const;
00881     const std::string to_string( sc_numrep ) const;
00882     const std::string to_string( sc_numrep, bool ) const;
00883     const std::string to_string( sc_fmt ) const;
00884     const std::string to_string( sc_numrep, sc_fmt ) const;
00885     const std::string to_string( sc_numrep, bool, sc_fmt ) const;
00886 
00887     const std::string to_dec() const;
00888     const std::string to_bin() const;
00889     const std::string to_oct() const;
00890     const std::string to_hex() const;
00891 
00892 
00893     // query value
00894 
00895     bool is_neg() const;
00896     bool is_zero() const;
00897 
00898     // internal use only;
00899     bool is_normal() const;
00900 
00901     bool quantization_flag() const;
00902     bool overflow_flag() const;
00903 
00904     const sc_fxval value() const;
00905 
00906 
00907     // query parameters
00908 
00909     int       wl() const;
00910     int       iwl() const;
00911     sc_q_mode q_mode() const;
00912     sc_o_mode o_mode() const;
00913     int       n_bits() const;
00914 
00915     const sc_fxtype_params& type_params() const;
00916 
00917     const sc_fxcast_switch& cast_switch() const;
00918 
00919 
00920     // print or dump content
00921 
00922     void print( ::std::ostream& = ::std::cout ) const;
00923     void scan( ::std::istream& = ::std::cin );
00924     void dump( ::std::ostream& = ::std::cout ) const;
00925 
00926 
00927     // internal use only;
00928     void observer_read() const;
00929 
00930 
00931     // internal use only;
00932     bool get_bit( int ) const;
00933 
00934 protected:
00935 
00936     bool set_bit( int, bool );
00937 
00938 
00939     bool get_slice( int, int, sc_bv_base& ) const;
00940     bool set_slice( int, int, const sc_bv_base& );
00941 
00942 
00943     sc_fxnum_observer* lock_observer() const;
00944     void unlock_observer( sc_fxnum_observer* ) const;
00945 
00946 private:
00947 
00948     scfx_rep*                  m_rep;
00949 
00950     scfx_params                m_params;
00951     bool                       m_q_flag;
00952     bool                       m_o_flag;
00953 
00954     mutable sc_fxnum_observer* m_observer;
00955 
00956 private:
00957 
00958     // disabled
00959     sc_fxnum();
00960     sc_fxnum( const sc_fxnum& );
00961 };
00962 
00963 
00964 // ----------------------------------------------------------------------------
00965 //  CLASS : sc_fxnum_fast
00966 //
00967 //  Base class for the fixed-point types; limited precision.
00968 // ----------------------------------------------------------------------------
00969 
00970 class sc_fxnum_fast
00971 {
00972     friend class sc_fxval_fast;
00973 
00974     friend class sc_fxnum_bitref;
00975     friend class sc_fxnum_subref;
00976     friend class sc_fxnum_fast_bitref;
00977     friend class sc_fxnum_fast_subref;
00978 
00979     friend class sc_core::vcd_sc_fxnum_fast_trace;
00980     friend class sc_core::wif_sc_fxnum_fast_trace;
00981 
00982 protected:
00983 
00984     sc_fxnum_fast_observer* observer() const;
00985 
00986 
00987     void cast();
00988 
00989 
00990     // constructors
00991 
00992     sc_fxnum_fast( const sc_fxtype_params&,
00993            sc_enc,
00994            const sc_fxcast_switch&,
00995            sc_fxnum_fast_observer* );
00996 
00997 #define DECL_CTOR_T(tp)                                                       \
00998     sc_fxnum_fast( tp,                                                        \
00999                const sc_fxtype_params&,                                   \
01000                sc_enc,                                                    \
01001                const sc_fxcast_switch&,                                   \
01002                sc_fxnum_fast_observer* );
01003 
01004     DECL_CTOR_T(int)
01005     DECL_CTOR_T(unsigned int)
01006     DECL_CTOR_T(long)
01007     DECL_CTOR_T(unsigned long)
01008     DECL_CTOR_T(double)
01009     DECL_CTOR_T(const char*)
01010     DECL_CTOR_T(const sc_fxval&)
01011     DECL_CTOR_T(const sc_fxval_fast&)
01012     DECL_CTOR_T(const sc_fxnum&)
01013     DECL_CTOR_T(const sc_fxnum_fast&)
01014 #ifndef SC_FX_EXCLUDE_OTHER
01015     DECL_CTOR_T(int64)
01016     DECL_CTOR_T(uint64)
01017     DECL_CTOR_T(const sc_int_base&)
01018     DECL_CTOR_T(const sc_uint_base&)
01019     DECL_CTOR_T(const sc_signed&)
01020     DECL_CTOR_T(const sc_unsigned&)
01021 #endif
01022 
01023 #undef DECL_CTOR_T
01024 
01025     ~sc_fxnum_fast();
01026 
01027 
01028     // internal use only;
01029     double get_val() const;
01030 
01031 public:
01032 
01033     // unary operators
01034 
01035     const sc_fxval_fast operator - () const;
01036     const sc_fxval_fast operator + () const;
01037 
01038 
01039     // unary functions
01040 
01041     friend void neg( sc_fxval_fast&, const sc_fxnum_fast& );
01042     friend void neg( sc_fxnum_fast&, const sc_fxnum_fast& );
01043 
01044 
01045     // binary operators
01046 
01047 #define DECL_BIN_OP_T(op,tp)                                                  \
01048     friend const sc_fxval_fast operator op ( const sc_fxnum_fast&, tp );      \
01049     friend const sc_fxval_fast operator op ( tp, const sc_fxnum_fast& );
01050 
01051 #ifndef SC_FX_EXCLUDE_OTHER
01052 #define DECL_BIN_OP_OTHER(op)                                                 \
01053     DECL_BIN_OP_T(op,int64)                                                   \
01054     DECL_BIN_OP_T(op,uint64)                                                  \
01055     DECL_BIN_OP_T(op,const sc_int_base&)                                      \
01056     DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
01057     DECL_BIN_OP_T(op,const sc_signed&)                                        \
01058     DECL_BIN_OP_T(op,const sc_unsigned&)
01059 #else
01060 #define DECL_BIN_OP_OTHER(op)
01061 #endif
01062 
01063 #define DECL_BIN_OP(op,dummy)                                                 \
01064     friend const sc_fxval_fast operator op ( const sc_fxnum_fast&,            \
01065                          const sc_fxnum_fast& );          \
01066     DECL_BIN_OP_T(op,int)                                                     \
01067     DECL_BIN_OP_T(op,unsigned int)                                            \
01068     DECL_BIN_OP_T(op,long)                                                    \
01069     DECL_BIN_OP_T(op,unsigned long)                                           \
01070     DECL_BIN_OP_T(op,double)                                                  \
01071     DECL_BIN_OP_T(op,const char*)                                             \
01072     DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
01073     DECL_BIN_OP_OTHER(op)
01074 
01075     DECL_BIN_OP(*,mult)
01076     DECL_BIN_OP(+,add)
01077     DECL_BIN_OP(-,sub)
01078 //    DECL_BIN_OP(/,div)
01079     friend const sc_fxval_fast operator / ( const sc_fxnum_fast&,
01080                          const sc_fxnum_fast& );
01081     DECL_BIN_OP_T(/,int)
01082     DECL_BIN_OP_T(/,unsigned int)
01083     DECL_BIN_OP_T(/,long)
01084     DECL_BIN_OP_T(/,unsigned long)
01085     DECL_BIN_OP_T(/,double)
01086     DECL_BIN_OP_T(/,const char*)
01087     DECL_BIN_OP_T(/,const sc_fxval_fast&)
01088 //    DECL_BIN_OP_OTHER(op)
01089 #ifndef SC_FX_EXCLUDE_OTHER
01090     DECL_BIN_OP_T(/,int64)                                                   \
01091     DECL_BIN_OP_T(/,uint64)                                                  \
01092     DECL_BIN_OP_T(/,const sc_int_base&)                                      \
01093     DECL_BIN_OP_T(/,const sc_uint_base&)                                     \
01094     DECL_BIN_OP_T(/,const sc_signed&)                                        \
01095     DECL_BIN_OP_T(/,const sc_unsigned&)
01096 #endif
01097 
01098 #undef DECL_BIN_OP_T
01099 #undef DECL_BIN_OP_OTHER
01100 #undef DECL_BIN_OP
01101 
01102     friend const sc_fxval_fast operator << ( const sc_fxnum_fast&, int );
01103     friend const sc_fxval_fast operator >> ( const sc_fxnum_fast&, int );
01104 
01105 
01106     // binary functions
01107 
01108 #define DECL_BIN_FNC_T(fnc,tp)                                                \
01109     friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&, tp );             \
01110     friend void fnc ( sc_fxval_fast&, tp, const sc_fxnum_fast& );             \
01111     friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&, tp );             \
01112     friend void fnc ( sc_fxnum_fast&, tp, const sc_fxnum_fast& );
01113 
01114 #ifndef SC_FX_EXCLUDE_OTHER
01115 #define DECL_BIN_FNC_OTHER(fnc)                                               \
01116     DECL_BIN_FNC_T(fnc,int64)                                                 \
01117     DECL_BIN_FNC_T(fnc,uint64)                                                \
01118     DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
01119     DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
01120     DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
01121     DECL_BIN_FNC_T(fnc,const sc_unsigned&)
01122 #else
01123 #define DECL_BIN_FNC_OTHER(fnc)
01124 #endif
01125 
01126 #define DECL_BIN_FNC(fnc)                                                     \
01127     friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&,                   \
01128                               const sc_fxnum_fast& );                 \
01129     friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&,                   \
01130                               const sc_fxnum_fast& );                 \
01131     DECL_BIN_FNC_T(fnc,int)                                                   \
01132     DECL_BIN_FNC_T(fnc,unsigned int)                                          \
01133     DECL_BIN_FNC_T(fnc,long)                                                  \
01134     DECL_BIN_FNC_T(fnc,unsigned long)                                         \
01135     DECL_BIN_FNC_T(fnc,double)                                                \
01136     DECL_BIN_FNC_T(fnc,const char*)                                           \
01137     DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
01138     DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
01139     DECL_BIN_FNC_T(fnc,const sc_fxnum&)                                       \
01140     DECL_BIN_FNC_OTHER(fnc)
01141 
01142     DECL_BIN_FNC(mult)
01143     DECL_BIN_FNC(div)
01144     DECL_BIN_FNC(add)
01145     DECL_BIN_FNC(sub)
01146 
01147 #undef DECL_BIN_FNC_T
01148 #undef DECL_BIN_FNC_OTHER
01149 #undef DECL_BIN_FNC
01150 
01151     friend void lshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
01152     friend void rshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
01153     friend void lshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
01154     friend void rshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
01155 
01156 
01157     // relational (including equality) operators
01158 
01159 #define DECL_REL_OP_T(op,tp)                                                  \
01160     friend bool operator op ( const sc_fxnum_fast&, tp );                     \
01161     friend bool operator op ( tp, const sc_fxnum_fast& );
01162 
01163 #ifndef SC_FX_EXCLUDE_OTHER
01164 #define DECL_REL_OP_OTHER(op)                                                 \
01165     DECL_REL_OP_T(op,int64)                                                   \
01166     DECL_REL_OP_T(op,uint64)                                                  \
01167     DECL_REL_OP_T(op,const sc_int_base&)                                      \
01168     DECL_REL_OP_T(op,const sc_uint_base&)                                     \
01169     DECL_REL_OP_T(op,const sc_signed&)                                        \
01170     DECL_REL_OP_T(op,const sc_unsigned&)
01171 #else
01172 #define DECL_REL_OP_OTHER(op)
01173 #endif
01174 
01175 #define DECL_REL_OP(op)                                                       \
01176     friend bool operator op ( const sc_fxnum_fast&, const sc_fxnum_fast& );   \
01177     DECL_REL_OP_T(op,int)                                                     \
01178     DECL_REL_OP_T(op,unsigned int)                                            \
01179     DECL_REL_OP_T(op,long)                                                    \
01180     DECL_REL_OP_T(op,unsigned long)                                           \
01181     DECL_REL_OP_T(op,double)                                                  \
01182     DECL_REL_OP_T(op,const char*)                                             \
01183     DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
01184     DECL_REL_OP_OTHER(op)
01185 
01186     DECL_REL_OP(<)
01187     DECL_REL_OP(<=)
01188     DECL_REL_OP(>)
01189     DECL_REL_OP(>=)
01190     DECL_REL_OP(==)
01191     DECL_REL_OP(!=)
01192 
01193 #undef DECL_REL_OP_T
01194 #undef DECL_REL_OP_OTHER
01195 #undef DECL_REL_OP
01196 
01197 
01198     // assignment operators
01199 
01200 #define DECL_ASN_OP_T(op,tp)                                                  \
01201     sc_fxnum_fast& operator op( tp );
01202 
01203 #ifndef SC_FX_EXCLUDE_OTHER
01204 #define DECL_ASN_OP_OTHER(op)                                                 \
01205     DECL_ASN_OP_T(op,int64)                                                   \
01206     DECL_ASN_OP_T(op,uint64)                                                  \
01207     DECL_ASN_OP_T(op,const sc_int_base&)                                      \
01208     DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
01209     DECL_ASN_OP_T(op,const sc_signed&)                                        \
01210     DECL_ASN_OP_T(op,const sc_unsigned&)
01211 #else
01212 #define DECL_ASN_OP_OTHER(op)
01213 #endif
01214 
01215 #define DECL_ASN_OP(op)                                                       \
01216     DECL_ASN_OP_T(op,int)                                                     \
01217     DECL_ASN_OP_T(op,unsigned int)                                            \
01218     DECL_ASN_OP_T(op,long)                                                    \
01219     DECL_ASN_OP_T(op,unsigned long)                                           \
01220     DECL_ASN_OP_T(op,double)                                                  \
01221     DECL_ASN_OP_T(op,const char*)                                             \
01222     DECL_ASN_OP_T(op,const sc_fxval&)                                         \
01223     DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
01224     DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
01225     DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
01226     DECL_ASN_OP_OTHER(op)
01227 
01228     DECL_ASN_OP(=)
01229 
01230     DECL_ASN_OP(*=)
01231     DECL_ASN_OP(/=)
01232     DECL_ASN_OP(+=)
01233     DECL_ASN_OP(-=)
01234 
01235     DECL_ASN_OP_T(<<=,int)
01236     DECL_ASN_OP_T(>>=,int)
01237 
01238 #undef DECL_ASN_OP_T
01239 #undef DECL_ASN_OP_OTHER
01240 #undef DECL_ASN_OP
01241 
01242 
01243     // auto-increment and auto-decrement
01244 
01245     const sc_fxval_fast operator ++ ( int );
01246     const sc_fxval_fast operator -- ( int );
01247 
01248     sc_fxnum_fast& operator ++ ();
01249     sc_fxnum_fast& operator -- ();
01250 
01251 
01252     // bit selection
01253 
01254     const sc_fxnum_fast_bitref operator [] ( int ) const;
01255     sc_fxnum_fast_bitref       operator [] ( int );
01256 
01257     const sc_fxnum_fast_bitref bit( int ) const;
01258     sc_fxnum_fast_bitref       bit( int );
01259 
01260 
01261     // part selection
01262 
01263     const sc_fxnum_fast_subref operator () ( int, int ) const;
01264     sc_fxnum_fast_subref       operator () ( int, int );
01265 
01266     const sc_fxnum_fast_subref range( int, int ) const;
01267     sc_fxnum_fast_subref       range( int, int );
01268 
01269 
01270     const sc_fxnum_fast_subref operator () () const;
01271     sc_fxnum_fast_subref       operator () ();
01272 
01273     const sc_fxnum_fast_subref range() const;
01274     sc_fxnum_fast_subref       range();
01275 
01276 
01277     // implicit conversion
01278 
01279     operator double() const;        // necessary evil!
01280 
01281 
01282     // explicit conversion to primitive types
01283 
01284     short          to_short() const;
01285     unsigned short to_ushort() const;
01286     int            to_int() const;
01287     unsigned int   to_uint() const;
01288     long           to_long() const;
01289     unsigned long  to_ulong() const;
01290     int64          to_int64() const;
01291     uint64         to_uint64() const;
01292     float          to_float() const;
01293     double         to_double() const;
01294 
01295 
01296     // explicit conversion to character string
01297 
01298     const std::string to_string() const;
01299     const std::string to_string( sc_numrep ) const;
01300     const std::string to_string( sc_numrep, bool ) const;
01301     const std::string to_string( sc_fmt ) const;
01302     const std::string to_string( sc_numrep, sc_fmt ) const;
01303     const std::string to_string( sc_numrep, bool, sc_fmt ) const;
01304 
01305     const std::string to_dec() const;
01306     const std::string to_bin() const;
01307     const std::string to_oct() const;
01308     const std::string to_hex() const;
01309 
01310 
01311     // query value
01312 
01313     bool is_neg() const;
01314     bool is_zero() const;
01315 
01316     // internal use only;
01317     bool is_normal() const;
01318 
01319     bool quantization_flag() const;
01320     bool overflow_flag() const;
01321 
01322     const sc_fxval_fast value() const;
01323 
01324 
01325     // query parameters
01326 
01327     int       wl() const;
01328     int       iwl() const;
01329     sc_q_mode q_mode() const;
01330     sc_o_mode o_mode() const;
01331     int       n_bits() const;
01332 
01333     const sc_fxtype_params& type_params() const;
01334 
01335     const sc_fxcast_switch& cast_switch() const;
01336 
01337 
01338     // print or dump content
01339 
01340     void print( ::std::ostream& = ::std::cout ) const;
01341     void scan( ::std::istream& = ::std::cin );
01342     void dump( ::std::ostream& = ::std::cout ) const;
01343 
01344 
01345     // internal use only;
01346     void observer_read() const;
01347 
01348 
01349     // internal use only;
01350     bool get_bit( int ) const;
01351 
01352 protected:
01353 
01354     bool set_bit( int, bool );
01355 
01356 
01357     bool get_slice( int, int, sc_bv_base& ) const;
01358     bool set_slice( int, int, const sc_bv_base& );
01359 
01360 
01361     sc_fxnum_fast_observer* lock_observer() const;
01362     void unlock_observer( sc_fxnum_fast_observer* ) const;
01363 
01364 private:
01365 
01366     double                          m_val;
01367 
01368     scfx_params                     m_params;
01369     bool                            m_q_flag;
01370     bool                            m_o_flag;
01371 
01372     mutable sc_fxnum_fast_observer* m_observer;
01373 
01374 private:
01375 
01376     // disabled
01377     sc_fxnum_fast();
01378     sc_fxnum_fast( const sc_fxnum_fast& );
01379 };
01380 
01381 
01382 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
01383 
01384 // ----------------------------------------------------------------------------
01385 //  CLASS : sc_fxnum_bitref
01386 //
01387 //  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
01388 // ----------------------------------------------------------------------------
01389 
01390 // constructor
01391 
01392 inline
01393 sc_fxnum_bitref::sc_fxnum_bitref( sc_fxnum& num_, int idx_ )
01394     : m_num( num_ ), m_idx( idx_ )
01395 {}
01396 
01397 
01398 // copy constructor
01399 
01400 inline
01401 sc_fxnum_bitref::sc_fxnum_bitref( const sc_fxnum_bitref& a )
01402     : m_num( a.m_num ), m_idx( a.m_idx )
01403 {}
01404 
01405 
01406 // assignment operators
01407 
01408 inline
01409 sc_fxnum_bitref&
01410 sc_fxnum_bitref::operator = ( const sc_fxnum_bitref& a )
01411 {
01412     if( &a != this )
01413     {
01414     SC_FXNUM_OBSERVER_READ_( a.m_num )
01415     set( a.get() );
01416     SC_FXNUM_OBSERVER_WRITE_( m_num )
01417     }
01418     return *this;
01419 }
01420 
01421 inline
01422 sc_fxnum_bitref&
01423 sc_fxnum_bitref::operator = ( const sc_fxnum_fast_bitref& a )
01424 {
01425     SC_FXNUM_FAST_OBSERVER_READ_( a.m_num )
01426     set( a.get() );
01427     SC_FXNUM_OBSERVER_WRITE_( m_num )
01428     return *this;
01429 }
01430 
01431 inline
01432 sc_fxnum_bitref&
01433 sc_fxnum_bitref::operator = ( const sc_bit& a )
01434 {
01435     set( static_cast<bool>( a ) );
01436     SC_FXNUM_OBSERVER_WRITE_( m_num )
01437     return *this;
01438 }
01439 
01440 inline
01441 sc_fxnum_bitref&
01442 sc_fxnum_bitref::operator = ( bool a )
01443 {
01444     set( a );
01445     SC_FXNUM_OBSERVER_WRITE_( m_num )
01446     return *this;
01447 }
01448 
01449 
01450 inline
01451 sc_fxnum_bitref&
01452 sc_fxnum_bitref::operator &= ( const sc_fxnum_bitref& b )
01453 {
01454     SC_FXNUM_OBSERVER_READ_( m_num )
01455     SC_FXNUM_OBSERVER_READ_( b.m_num )
01456     set( get() && b.get() );
01457     SC_FXNUM_OBSERVER_WRITE_( m_num )
01458     return *this;
01459 }
01460 
01461 inline
01462 sc_fxnum_bitref&
01463 sc_fxnum_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
01464 {
01465     SC_FXNUM_OBSERVER_READ_( m_num )
01466     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01467     set( get() && b.get() );
01468     SC_FXNUM_OBSERVER_WRITE_( m_num )
01469     return *this;
01470 }
01471 
01472 inline
01473 sc_fxnum_bitref&
01474 sc_fxnum_bitref::operator &= ( const sc_bit& b )
01475 {
01476     SC_FXNUM_OBSERVER_READ_( m_num )
01477     set( get() && static_cast<bool>( b ) );
01478     SC_FXNUM_OBSERVER_WRITE_( m_num )
01479     return *this;
01480 }
01481 
01482 inline
01483 sc_fxnum_bitref&
01484 sc_fxnum_bitref::operator &= ( bool b )
01485 {
01486     SC_FXNUM_OBSERVER_READ_( m_num )
01487     set( get() && b );
01488     SC_FXNUM_OBSERVER_WRITE_( m_num )
01489     return *this;
01490 }
01491 
01492 
01493 inline
01494 sc_fxnum_bitref&
01495 sc_fxnum_bitref::operator |= ( const sc_fxnum_bitref& b )
01496 {
01497     SC_FXNUM_OBSERVER_READ_( m_num )
01498     SC_FXNUM_OBSERVER_READ_( b.m_num )
01499     set( get() || b.get() );
01500     SC_FXNUM_OBSERVER_WRITE_( m_num )
01501     return *this;
01502 }
01503 
01504 inline
01505 sc_fxnum_bitref&
01506 sc_fxnum_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
01507 {
01508     SC_FXNUM_OBSERVER_READ_( m_num )
01509     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01510     set( get() || b.get() );
01511     SC_FXNUM_OBSERVER_WRITE_( m_num )
01512     return *this;
01513 }
01514 
01515 inline
01516 sc_fxnum_bitref&
01517 sc_fxnum_bitref::operator |= ( const sc_bit& b )
01518 {
01519     SC_FXNUM_OBSERVER_READ_( m_num )
01520     set( get() || static_cast<bool>( b ) );
01521     SC_FXNUM_OBSERVER_WRITE_( m_num )
01522     return *this;
01523 }
01524 
01525 inline
01526 sc_fxnum_bitref&
01527 sc_fxnum_bitref::operator |= ( bool b )
01528 {
01529     SC_FXNUM_OBSERVER_READ_( m_num )
01530     set( get() || b );
01531     SC_FXNUM_OBSERVER_WRITE_( m_num )
01532     return *this;
01533 }
01534 
01535 
01536 inline
01537 sc_fxnum_bitref&
01538 sc_fxnum_bitref::operator ^= ( const sc_fxnum_bitref& b )
01539 {
01540     SC_FXNUM_OBSERVER_READ_( m_num )
01541     SC_FXNUM_OBSERVER_READ_( b.m_num )
01542     set( get() != b.get() );
01543     SC_FXNUM_OBSERVER_WRITE_( m_num )
01544     return *this;
01545 }
01546 
01547 inline
01548 sc_fxnum_bitref&
01549 sc_fxnum_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
01550 {
01551     SC_FXNUM_OBSERVER_READ_( m_num )
01552     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01553     set( get() != b.get() );
01554     SC_FXNUM_OBSERVER_WRITE_( m_num )
01555     return *this;
01556 }
01557 
01558 inline
01559 sc_fxnum_bitref&
01560 sc_fxnum_bitref::operator ^= ( const sc_bit& b )
01561 {
01562     SC_FXNUM_OBSERVER_READ_( m_num )
01563     set( get() != static_cast<bool>( b ) );
01564     SC_FXNUM_OBSERVER_WRITE_( m_num )
01565     return *this;
01566 }
01567 
01568 inline
01569 sc_fxnum_bitref&
01570 sc_fxnum_bitref::operator ^= ( bool b )
01571 {
01572     SC_FXNUM_OBSERVER_READ_( m_num )
01573     set( get() != b );
01574     SC_FXNUM_OBSERVER_WRITE_( m_num )
01575     return *this;
01576 }
01577 
01578 
01579 // implicit conversion
01580 
01581 inline
01582 sc_fxnum_bitref::operator bool() const
01583 {
01584     SC_FXNUM_OBSERVER_READ_( m_num )
01585     return get();
01586 }
01587 
01588 
01589 inline
01590 ::std::ostream&
01591 operator << ( ::std::ostream& os, const sc_fxnum_bitref& a )
01592 {
01593     a.print( os );
01594     return os;
01595 }
01596 
01597 inline
01598 ::std::istream&
01599 operator >> ( ::std::istream& is, sc_fxnum_bitref& a )
01600 {
01601     a.scan( is );
01602     return is;
01603 }
01604 
01605 
01606 // ----------------------------------------------------------------------------
01607 //  CLASS : sc_fxnum_fast_bitref
01608 //
01609 //  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
01610 // ----------------------------------------------------------------------------
01611 
01612 // constructor
01613 
01614 inline
01615 sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( sc_fxnum_fast& num_, int idx_ )
01616     : m_num( num_ ), m_idx( idx_ )
01617 {}
01618 
01619 
01620 // copy constructor
01621 
01622 inline
01623 sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& a )
01624     : m_num( a.m_num ), m_idx( a.m_idx )
01625 {}
01626 
01627 
01628 // assignment operators
01629 
01630 inline
01631 sc_fxnum_fast_bitref&
01632 sc_fxnum_fast_bitref::operator = ( const sc_fxnum_bitref& a )
01633 {
01634     SC_FXNUM_OBSERVER_READ_( a.m_num )
01635     set( a.get() );
01636     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01637     return *this;
01638 }
01639 
01640 inline
01641 sc_fxnum_fast_bitref&
01642 sc_fxnum_fast_bitref::operator = ( const sc_fxnum_fast_bitref& a )
01643 {
01644     if( &a != this )
01645     {
01646     SC_FXNUM_FAST_OBSERVER_READ_( a.m_num )
01647     set( a.get() );
01648     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01649     }
01650     return *this;
01651 }
01652 
01653 inline
01654 sc_fxnum_fast_bitref&
01655 sc_fxnum_fast_bitref::operator = ( const sc_bit& a )
01656 {
01657     set( static_cast<bool>( a ) );
01658     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01659     return *this;
01660 }
01661 
01662 inline
01663 sc_fxnum_fast_bitref&
01664 sc_fxnum_fast_bitref::operator = ( bool a )
01665 {
01666     set( a );
01667     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01668     return *this;
01669 }
01670 
01671 
01672 inline
01673 sc_fxnum_fast_bitref&
01674 sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_bitref& b )
01675 {
01676     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01677     SC_FXNUM_OBSERVER_READ_( b.m_num )
01678     set( get() && b.get() );
01679     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01680     return *this;
01681 }
01682 
01683 inline
01684 sc_fxnum_fast_bitref&
01685 sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
01686 {
01687     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01688     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01689     set( get() && b.get() );
01690     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01691     return *this;
01692 }
01693 
01694 inline
01695 sc_fxnum_fast_bitref&
01696 sc_fxnum_fast_bitref::operator &= ( const sc_bit& b )
01697 {
01698     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01699     set( get() && static_cast<bool>( b ) );
01700     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01701     return *this;
01702 }
01703 
01704 inline
01705 sc_fxnum_fast_bitref&
01706 sc_fxnum_fast_bitref::operator &= ( bool b )
01707 {
01708     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01709     set( get() && b );
01710     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01711     return *this;
01712 }
01713 
01714 
01715 inline
01716 sc_fxnum_fast_bitref&
01717 sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_bitref& b )
01718 {
01719     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01720     SC_FXNUM_OBSERVER_READ_( b.m_num )
01721     set( get() || b.get() );
01722     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01723     return *this;
01724 }
01725 
01726 inline
01727 sc_fxnum_fast_bitref&
01728 sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
01729 {
01730     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01731     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01732     set( get() || b.get() );
01733     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01734     return *this;
01735 }
01736 
01737 inline
01738 sc_fxnum_fast_bitref&
01739 sc_fxnum_fast_bitref::operator |= ( const sc_bit& b )
01740 {
01741     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01742     set( get() || static_cast<bool>( b ) );
01743     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01744     return *this;
01745 }
01746 
01747 inline
01748 sc_fxnum_fast_bitref&
01749 sc_fxnum_fast_bitref::operator |= ( bool b )
01750 {
01751     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01752     set( get() || b );
01753     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01754     return *this;
01755 }
01756 
01757 
01758 inline
01759 sc_fxnum_fast_bitref&
01760 sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_bitref& b )
01761 {
01762     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01763     SC_FXNUM_OBSERVER_READ_( b.m_num )
01764     set( get() != b.get() );
01765     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01766     return *this;
01767 }
01768 
01769 inline
01770 sc_fxnum_fast_bitref&
01771 sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
01772 {
01773     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01774     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01775     set( get() != b.get() );
01776     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01777     return *this;
01778 }
01779 
01780 inline
01781 sc_fxnum_fast_bitref&
01782 sc_fxnum_fast_bitref::operator ^= ( const sc_bit& b )
01783 {
01784     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01785     set( get() != static_cast<bool>( b ) );
01786     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01787     return *this;
01788 }
01789 
01790 inline
01791 sc_fxnum_fast_bitref&
01792 sc_fxnum_fast_bitref::operator ^= ( bool b )
01793 {
01794     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01795     set( get() != b );
01796     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01797     return *this;
01798 }
01799 
01800 
01801 // implicit conversion
01802 
01803 inline
01804 sc_fxnum_fast_bitref::operator bool() const
01805 {
01806     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01807     return get();
01808 }
01809 
01810 
01811 inline
01812 ::std::ostream&
01813 operator << ( ::std::ostream& os, const sc_fxnum_fast_bitref& a )
01814 {
01815     a.print( os );
01816     return os;
01817 }
01818 
01819 inline
01820 ::std::istream&
01821 operator >> ( ::std::istream& is, sc_fxnum_fast_bitref& a )
01822 {
01823     a.scan( is );
01824     return is;
01825 }
01826 
01827 
01828 // ----------------------------------------------------------------------------
01829 //  CLASS : sc_fxnum_subref
01830 //
01831 //  Proxy class for part-selection in class sc_fxnum,
01832 //  behaves like sc_bv_base.
01833 // ----------------------------------------------------------------------------
01834 
01835 // constructor
01836 
01837 inline
01838 sc_fxnum_subref::sc_fxnum_subref( sc_fxnum& num_, int from_, int to_ )
01839     : m_num( num_ ), m_from( from_ ), m_to( to_ ),
01840       m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
01841                  sc_min( m_from, m_to ) + 1 ) )
01842 {}
01843 
01844 
01845 // copy constructor
01846 
01847 inline
01848 sc_fxnum_subref::sc_fxnum_subref( const sc_fxnum_subref& a )
01849     : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
01850       m_bv( *new sc_bv_base( a.m_bv ) )
01851 {}
01852 
01853 
01854 // destructor
01855 
01856 inline
01857 sc_fxnum_subref::~sc_fxnum_subref()
01858 {
01859     delete &m_bv;
01860 }
01861 
01862 
01863 // assignment operators
01864 
01865 inline
01866 sc_fxnum_subref&
01867 sc_fxnum_subref::operator = ( const sc_fxnum_subref& a )
01868 {
01869     if( &a != this )
01870     {
01871     m_bv = static_cast<sc_bv_base>( a );
01872     set();
01873     SC_FXNUM_OBSERVER_WRITE_( m_num )
01874     }
01875     return *this;
01876 }
01877 
01878 inline
01879 sc_fxnum_subref&
01880 sc_fxnum_subref::operator = ( const sc_fxnum_fast_subref& a )
01881 {
01882     m_bv = static_cast<sc_bv_base>( a );
01883     set();
01884     SC_FXNUM_OBSERVER_WRITE_( m_num )
01885     return *this;
01886 }
01887 
01888 #define DEFN_ASN_OP_T(tp)                                                     \
01889 inline                                                                        \
01890 sc_fxnum_subref&                                                              \
01891 sc_fxnum_subref::operator = ( tp a )                                          \
01892 {                                                                             \
01893     m_bv = a;                                                                 \
01894     set();                                                                    \
01895     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01896     return *this;                                                             \
01897 }
01898 
01899 DEFN_ASN_OP_T(const sc_bv_base&)
01900 DEFN_ASN_OP_T(const sc_lv_base&)
01901 DEFN_ASN_OP_T(const char*)
01902 DEFN_ASN_OP_T(const bool*)
01903 DEFN_ASN_OP_T(const sc_signed&)
01904 DEFN_ASN_OP_T(const sc_unsigned&)
01905 DEFN_ASN_OP_T(const sc_int_base&)
01906 DEFN_ASN_OP_T(const sc_uint_base&)
01907 DEFN_ASN_OP_T(int64)
01908 DEFN_ASN_OP_T(uint64)
01909 DEFN_ASN_OP_T(int)
01910 DEFN_ASN_OP_T(unsigned int)
01911 DEFN_ASN_OP_T(long)
01912 DEFN_ASN_OP_T(unsigned long)
01913 DEFN_ASN_OP_T(char)
01914 
01915 #undef DEFN_ASN_OP_T
01916 
01917 
01918 #define DEFN_ASN_OP_T(op,tp)                                                  \
01919 inline                                                                        \
01920 sc_fxnum_subref&                                                              \
01921 sc_fxnum_subref::operator op ## = ( tp a )                                    \
01922 {                                                                             \
01923     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
01924     get();                                                                    \
01925     m_bv = m_bv op a;                                                         \
01926     set();                                                                    \
01927     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01928     return *this;                                                             \
01929 }
01930 
01931 #define DEFN_ASN_OP(op)                                                       \
01932 inline                                                                        \
01933 sc_fxnum_subref&                                                              \
01934 sc_fxnum_subref::operator op ## = ( const sc_fxnum_subref& a )                \
01935 {                                                                             \
01936     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
01937     get();                                                                    \
01938     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
01939     set();                                                                    \
01940     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01941     return *this;                                                             \
01942 }                                                                             \
01943                                                                               \
01944 inline                                                                        \
01945 sc_fxnum_subref&                                                              \
01946 sc_fxnum_subref::operator op ## = ( const sc_fxnum_fast_subref& a )           \
01947 {                                                                             \
01948     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
01949     get();                                                                    \
01950     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
01951     set();                                                                    \
01952     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01953     return *this;                                                             \
01954 }                                                                             \
01955                                                                               \
01956 DEFN_ASN_OP_T(op,const sc_bv_base&)                                           \
01957 DEFN_ASN_OP_T(op,const sc_lv_base&)
01958 
01959 DEFN_ASN_OP(&)
01960 DEFN_ASN_OP(|)
01961 DEFN_ASN_OP(^)
01962 
01963 #undef DEFN_ASN_OP_T
01964 #undef DEFN_ASN_OP
01965 
01966 
01967 // relational operators
01968 
01969 #define DEFN_REL_OP_T(op,tp)                                                  \
01970 inline                                                                        \
01971 bool                                                                          \
01972 operator op ( const sc_fxnum_subref& a, tp b )                                \
01973 {                                                                             \
01974     return ( static_cast<sc_bv_base>( a ) op b );                             \
01975 }                                                                             \
01976                                                                               \
01977 inline                                                                        \
01978 bool                                                                          \
01979 operator op ( tp a, const sc_fxnum_subref& b )                                \
01980 {                                                                             \
01981     return ( static_cast<sc_bv_base>( b ) op a );                             \
01982 }
01983 
01984 #define DEFN_REL_OP(op)                                                       \
01985 inline                                                                        \
01986 bool                                                                          \
01987 operator op ( const sc_fxnum_subref& a, const sc_fxnum_subref& b )            \
01988 {                                                                             \
01989     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
01990 }                                                                             \
01991                                                                               \
01992 inline                                                                        \
01993 bool                                                                          \
01994 operator op ( const sc_fxnum_subref& a, const sc_fxnum_fast_subref& b )       \
01995 {                                                                             \
01996     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
01997 }                                                                             \
01998                                                                               \
01999 DEFN_REL_OP_T(op,const sc_bv_base&)                                           \
02000 DEFN_REL_OP_T(op,const sc_lv_base&)                                           \
02001 DEFN_REL_OP_T(op,const char*)                                                 \
02002 DEFN_REL_OP_T(op,const bool*)                                                 \
02003 DEFN_REL_OP_T(op,const sc_signed&)                                            \
02004 DEFN_REL_OP_T(op,const sc_unsigned&)                                          \
02005 DEFN_REL_OP_T(op,int)                                                         \
02006 DEFN_REL_OP_T(op,unsigned int)                                                \
02007 DEFN_REL_OP_T(op,long)                                                        \
02008 DEFN_REL_OP_T(op,unsigned long)
02009 
02010 DEFN_REL_OP(==)
02011 DEFN_REL_OP(!=)
02012 
02013 #undef DEFN_REL_OP_T
02014 #undef DEFN_REL_OP
02015 
02016 
02017 // reduce functions
02018 
02019 #define DEFN_RED_FNC(fnc)                                                     \
02020 inline                                                                        \
02021 bool                                                                          \
02022 sc_fxnum_subref::fnc() const                                                  \
02023 {                                                                             \
02024     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
02025     get();                                                                    \
02026     return static_cast<bool>( m_bv.fnc() );                                   \
02027 }
02028 
02029 DEFN_RED_FNC(and_reduce)
02030 DEFN_RED_FNC(nand_reduce)
02031 DEFN_RED_FNC(or_reduce)
02032 DEFN_RED_FNC(nor_reduce)
02033 DEFN_RED_FNC(xor_reduce)
02034 DEFN_RED_FNC(xnor_reduce)
02035 
02036 #undef DEFN_RED_FNC
02037 
02038 
02039 // query parameter
02040 
02041 inline
02042 int
02043 sc_fxnum_subref::length() const
02044 {
02045     return m_bv.length();
02046 }
02047 
02048 
02049 // explicit conversions
02050 
02051 inline
02052 int
02053 sc_fxnum_subref::to_int() const
02054 {
02055     SC_FXNUM_OBSERVER_READ_( m_num )
02056     get();
02057     return m_bv.to_int();
02058 }
02059 
02060 inline
02061 int64
02062 sc_fxnum_subref::to_int64() const
02063 {
02064     SC_FXNUM_OBSERVER_READ_( m_num )
02065     get();
02066     return m_bv.to_int64();
02067 }
02068 
02069 inline
02070 unsigned int
02071 sc_fxnum_subref::to_uint() const
02072 {
02073     SC_FXNUM_OBSERVER_READ_( m_num )
02074     get();
02075     return m_bv.to_uint();
02076 }
02077 
02078 inline
02079 uint64
02080 sc_fxnum_subref::to_uint64() const
02081 {
02082     SC_FXNUM_OBSERVER_READ_( m_num )
02083     get();
02084     return m_bv.to_uint64();
02085 }
02086 
02087 inline
02088 long
02089 sc_fxnum_subref::to_long() const
02090 {
02091     SC_FXNUM_OBSERVER_READ_( m_num )
02092     get();
02093     return m_bv.to_long();
02094 }
02095 
02096 inline
02097 unsigned long
02098 sc_fxnum_subref::to_ulong() const
02099 {
02100     SC_FXNUM_OBSERVER_READ_( m_num )
02101     get();
02102     return m_bv.to_ulong();
02103 }
02104 
02105 
02106 #ifdef SC_DT_DEPRECATED
02107 
02108 inline
02109 int
02110 sc_fxnum_subref::to_signed() const
02111 {
02112     return to_int();
02113 }
02114 
02115 inline
02116 unsigned int
02117 sc_fxnum_subref::to_unsigned() const
02118 {
02119     return to_uint();
02120 }
02121 
02122 #endif
02123 
02124 
02125 inline
02126 const std::string
02127 sc_fxnum_subref::to_string() const
02128 {
02129     get();
02130     return m_bv.to_string();
02131 }
02132 
02133 inline
02134 const std::string
02135 sc_fxnum_subref::to_string( sc_numrep numrep ) const
02136 {
02137     get();
02138     return m_bv.to_string( numrep );
02139 }
02140 
02141 inline
02142 const std::string
02143 sc_fxnum_subref::to_string( sc_numrep numrep, bool w_prefix ) const
02144 {
02145     get();
02146     return m_bv.to_string( numrep, w_prefix );
02147 }
02148 
02149 
02150 // implicit conversion
02151 
02152 inline
02153 sc_fxnum_subref::operator sc_bv_base () const
02154 {
02155     SC_FXNUM_OBSERVER_READ_( m_num )
02156     get();
02157     return m_bv;
02158 }
02159 
02160 
02161 inline
02162 ::std::ostream&
02163 operator << ( ::std::ostream& os, const sc_fxnum_subref& a )
02164 {
02165     a.print( os );
02166     return os;
02167 }
02168 
02169 inline
02170 ::std::istream&
02171 operator >> ( ::std::istream& is, sc_fxnum_subref& a )
02172 {
02173     a.scan( is );
02174     return is;
02175 }
02176 
02177 
02178 // ----------------------------------------------------------------------------
02179 //  CLASS : sc_fxnum_fast_subref
02180 //
02181 //  Proxy class for part-selection in class sc_fxnum_fast,
02182 //  behaves like sc_bv_base.
02183 // ----------------------------------------------------------------------------
02184 
02185 // constructor
02186 
02187 inline
02188 sc_fxnum_fast_subref::sc_fxnum_fast_subref( sc_fxnum_fast& num_,
02189                         int from_, int to_ )
02190     : m_num( num_ ), m_from( from_ ), m_to( to_ ),
02191       m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
02192                  sc_min( m_from, m_to ) + 1 ) )
02193 {}
02194 
02195 
02196 // copy constructor
02197 
02198 inline
02199 sc_fxnum_fast_subref::sc_fxnum_fast_subref( const sc_fxnum_fast_subref& a )
02200     : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
02201       m_bv( *new sc_bv_base( a.m_bv ) )
02202 {}
02203 
02204 
02205 // destructor
02206 
02207 inline
02208 sc_fxnum_fast_subref::~sc_fxnum_fast_subref()
02209 {
02210     delete &m_bv;
02211 }
02212 
02213 
02214 // assignment operators
02215 
02216 inline
02217 sc_fxnum_fast_subref&
02218 sc_fxnum_fast_subref::operator = ( const sc_fxnum_subref& a )
02219 {
02220     m_bv = static_cast<sc_bv_base>( a );
02221     set();
02222     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
02223     return *this;
02224 }
02225 
02226 inline
02227 sc_fxnum_fast_subref&
02228 sc_fxnum_fast_subref::operator = ( const sc_fxnum_fast_subref& a )
02229 {
02230     if( &a != this )
02231     {
02232     m_bv = static_cast<sc_bv_base>( a );
02233     set();
02234     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
02235     }
02236     return *this;
02237 }
02238 
02239 #define DEFN_ASN_OP_T(tp)                                                     \
02240 inline                                                                        \
02241 sc_fxnum_fast_subref&                                                         \
02242 sc_fxnum_fast_subref::operator = ( tp a )                                     \
02243 {                                                                             \
02244     m_bv = a;                                                                 \
02245     set();                                                                    \
02246     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02247     return *this;                                                             \
02248 }
02249 
02250 DEFN_ASN_OP_T(const sc_bv_base&)
02251 DEFN_ASN_OP_T(const sc_lv_base&)
02252 DEFN_ASN_OP_T(const char*)
02253 DEFN_ASN_OP_T(const bool*)
02254 DEFN_ASN_OP_T(const sc_signed&)
02255 DEFN_ASN_OP_T(const sc_unsigned&)
02256 DEFN_ASN_OP_T(const sc_int_base&)
02257 DEFN_ASN_OP_T(const sc_uint_base&)
02258 DEFN_ASN_OP_T(int64)
02259 DEFN_ASN_OP_T(uint64)
02260 DEFN_ASN_OP_T(int)
02261 DEFN_ASN_OP_T(unsigned int)
02262 DEFN_ASN_OP_T(long)
02263 DEFN_ASN_OP_T(unsigned long)
02264 DEFN_ASN_OP_T(char)
02265 
02266 #undef DEFN_ASN_OP_T
02267 
02268 
02269 #define DEFN_ASN_OP_T(op,tp)                                                  \
02270 inline                                                                        \
02271 sc_fxnum_fast_subref&                                                         \
02272 sc_fxnum_fast_subref::operator op ## = ( tp a )                               \
02273 {                                                                             \
02274     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02275     get();                                                                    \
02276     m_bv = m_bv op a;                                                         \
02277     set();                                                                    \
02278     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02279     return *this;                                                             \
02280 }
02281 
02282 #define DEFN_ASN_OP(op)                                                       \
02283 inline                                                                        \
02284 sc_fxnum_fast_subref&                                                         \
02285 sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_subref& a )           \
02286 {                                                                             \
02287     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02288     get();                                                                    \
02289     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
02290     set();                                                                    \
02291     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02292     return *this;                                                             \
02293 }                                                                             \
02294                                                                               \
02295 inline                                                                        \
02296 sc_fxnum_fast_subref&                                                         \
02297 sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_fast_subref& a )      \
02298 {                                                                             \
02299     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02300     get();                                                                    \
02301     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
02302     set();                                                                    \
02303     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02304     return *this;                                                             \
02305 }                                                                             \
02306                                                                               \
02307 DEFN_ASN_OP_T(op,const sc_bv_base&)                                           \
02308 DEFN_ASN_OP_T(op,const sc_lv_base&)
02309 
02310 DEFN_ASN_OP(&)
02311 DEFN_ASN_OP(|)
02312 DEFN_ASN_OP(^)
02313 
02314 #undef DEFN_ASN_OP_T
02315 #undef DEFN_ASN_OP
02316 
02317 
02318 // relational operators
02319 
02320 #define DEFN_REL_OP_T(op,tp)                                                  \
02321 inline                                                                        \
02322 bool                                                                          \
02323 operator op ( const sc_fxnum_fast_subref& a, tp b )                           \
02324 {                                                                             \
02325     return ( static_cast<sc_bv_base>( a ) op b );                             \
02326 }                                                                             \
02327                                                                               \
02328 inline                                                                        \
02329 bool                                                                          \
02330 operator op ( tp a, const sc_fxnum_fast_subref& b )                           \
02331 {                                                                             \
02332     return ( static_cast<sc_bv_base>( b ) op a );                             \
02333 }
02334 
02335 #define DEFN_REL_OP(op)                                                       \
02336 inline                                                                        \
02337 bool                                                                          \
02338 operator op ( const sc_fxnum_fast_subref& a, const sc_fxnum_fast_subref& b )  \
02339 {                                                                             \
02340     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
02341 }                                                                             \
02342                                                                               \
02343 inline                                                                        \
02344 bool                                                                          \
02345 operator op ( const sc_fxnum_fast_subref& a, const sc_fxnum_subref& b )       \
02346 {                                                                             \
02347     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
02348 }                                                                             \
02349                                                                               \
02350 DEFN_REL_OP_T(op,const sc_bv_base&)                                           \
02351 DEFN_REL_OP_T(op,const sc_lv_base&)                                           \
02352 DEFN_REL_OP_T(op,const char*)                                                 \
02353 DEFN_REL_OP_T(op,const bool*)                                                 \
02354 DEFN_REL_OP_T(op,const sc_signed&)                                            \
02355 DEFN_REL_OP_T(op,const sc_unsigned&)                                          \
02356 DEFN_REL_OP_T(op,int)                                                         \
02357 DEFN_REL_OP_T(op,unsigned int)                                                \
02358 DEFN_REL_OP_T(op,long)                                                        \
02359 DEFN_REL_OP_T(op,unsigned long)
02360 
02361 DEFN_REL_OP(==)
02362 DEFN_REL_OP(!=)
02363 
02364 #undef DEFN_REL_OP_T
02365 #undef DEFN_REL_OP
02366 
02367 
02368 // reduce functions
02369 
02370 #define DEFN_RED_FNC(fnc)                                                     \
02371 inline                                                                        \
02372 bool                                                                          \
02373 sc_fxnum_fast_subref::fnc() const                                             \
02374 {                                                                             \
02375     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02376     get();                                                                    \
02377     return static_cast<bool>( m_bv.fnc() );                                   \
02378 }
02379 
02380 DEFN_RED_FNC(and_reduce)
02381 DEFN_RED_FNC(nand_reduce)
02382 DEFN_RED_FNC(or_reduce)
02383 DEFN_RED_FNC(nor_reduce)
02384 DEFN_RED_FNC(xor_reduce)
02385 DEFN_RED_FNC(xnor_reduce)
02386 
02387 #undef DEFN_RED_FNC
02388 
02389 
02390 // query parameter
02391 
02392 inline
02393 int
02394 sc_fxnum_fast_subref::length() const
02395 {
02396     return m_bv.length();
02397 }
02398 
02399 
02400 // explicit conversions
02401 
02402 inline
02403 int
02404 sc_fxnum_fast_subref::to_int() const
02405 {
02406     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02407     get();
02408     return m_bv.to_int();
02409 }
02410 
02411 inline
02412 int64
02413 sc_fxnum_fast_subref::to_int64() const
02414 {
02415     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02416     get();
02417     return m_bv.to_int64();
02418 }
02419 
02420 inline
02421 unsigned int
02422 sc_fxnum_fast_subref::to_uint() const
02423 {
02424     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02425     get();
02426     return m_bv.to_uint();
02427 }
02428 
02429 inline
02430 uint64
02431 sc_fxnum_fast_subref::to_uint64() const
02432 {
02433     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02434     get();
02435     return m_bv.to_uint64();
02436 }
02437 
02438 inline
02439 long
02440 sc_fxnum_fast_subref::to_long() const
02441 {
02442     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02443     get();
02444     return m_bv.to_long();
02445 }
02446 
02447 inline
02448 unsigned long
02449 sc_fxnum_fast_subref::to_ulong() const
02450 {
02451     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02452     get();
02453     return m_bv.to_ulong();
02454 }
02455 
02456 
02457 #ifdef SC_DT_DEPRECATED
02458 
02459 inline
02460 int
02461 sc_fxnum_fast_subref::to_signed() const
02462 {
02463     return to_int();
02464 }
02465 
02466 inline
02467 unsigned int
02468 sc_fxnum_fast_subref::to_unsigned() const
02469 {
02470     return to_uint();
02471 }
02472 
02473 #endif
02474 
02475 
02476 inline
02477 const std::string
02478 sc_fxnum_fast_subref::to_string() const
02479 {
02480     get();
02481     return m_bv.to_string();
02482 }
02483 
02484 inline
02485 const std::string
02486 sc_fxnum_fast_subref::to_string( sc_numrep numrep ) const
02487 {
02488     get();
02489     return m_bv.to_string( numrep );
02490 }
02491 
02492 inline
02493 const std::string
02494 sc_fxnum_fast_subref::to_string( sc_numrep numrep, bool w_prefix ) const
02495 {
02496     get();
02497     return m_bv.to_string( numrep, w_prefix );
02498 }
02499 
02500 
02501 // implicit conversion
02502 
02503 inline
02504 sc_fxnum_fast_subref::operator sc_bv_base () const
02505 {
02506     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02507     get();
02508     return m_bv;
02509 }
02510 
02511 
02512 inline
02513 ::std::ostream&
02514 operator << ( ::std::ostream& os, const sc_fxnum_fast_subref& a )
02515 {
02516     a.print( os );
02517     return os;
02518 }
02519 
02520 inline
02521 ::std::istream&
02522 operator >> ( ::std::istream& is, sc_fxnum_fast_subref& a )
02523 {
02524     a.scan( is );
02525     return is;
02526 }
02527 
02528 
02529 // ----------------------------------------------------------------------------
02530 //  CLASS : sc_fxnum
02531 //
02532 //  Base class for the fixed-point types; arbitrary precision.
02533 // ----------------------------------------------------------------------------
02534 
02535 inline
02536 sc_fxnum_observer*
02537 sc_fxnum::observer() const
02538 {
02539     return m_observer;
02540 }
02541 
02542 
02543 inline
02544 void
02545 sc_fxnum::cast()
02546 {
02547     SC_ERROR_IF_( ! m_rep->is_normal(), sc_core::SC_ID_INVALID_FX_VALUE_ );
02548 
02549     if( m_params.cast_switch() == SC_ON )
02550     m_rep->cast( m_params, m_q_flag, m_o_flag );
02551 }
02552 
02553 
02554 // constructors
02555 
02556 inline
02557 sc_fxnum::sc_fxnum( const sc_fxtype_params& type_params_,
02558             sc_enc enc_,
02559             const sc_fxcast_switch& cast_sw,
02560             sc_fxnum_observer* observer_ )
02561 : m_rep( new scfx_rep ),
02562   m_params( type_params_, enc_, cast_sw ),
02563   m_q_flag( false ),
02564   m_o_flag( false ),
02565   m_observer( observer_ )
02566 {
02567     SC_FXNUM_OBSERVER_DEFAULT_
02568     SC_FXNUM_OBSERVER_CONSTRUCT_( *this )
02569 }
02570 
02571 #define DEFN_CTOR_T(tp,arg)                                                   \
02572 inline                                                                        \
02573 sc_fxnum::sc_fxnum( tp a,                                                     \
02574             const sc_fxtype_params& type_params_,                     \
02575             sc_enc enc_,                                              \
02576             const sc_fxcast_switch& cast_sw,                          \
02577             sc_fxnum_observer* observer_ )                            \
02578 : m_rep( new scfx_rep( arg ) ),                                               \
02579   m_params( type_params_, enc_, cast_sw ),                                    \
02580   m_q_flag( false ),                                                          \
02581   m_o_flag( false ),                                                          \
02582   m_observer( observer_ )                                                     \
02583 {                                                                             \
02584     SC_FXNUM_OBSERVER_DEFAULT_                                                \
02585     cast();                                                                   \
02586     SC_FXNUM_OBSERVER_CONSTRUCT_( *this )                                     \
02587     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
02588 }
02589 
02590 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)
02591 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,*a.m_rep)
02592 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
02593 #define DEFN_CTOR_T_D(tp) DEFN_CTOR_T(tp,a.value())
02594 
02595 DEFN_CTOR_T_A(int)
02596 DEFN_CTOR_T_A(unsigned int)
02597 DEFN_CTOR_T_A(long)
02598 DEFN_CTOR_T_A(unsigned long)
02599 DEFN_CTOR_T_A(double)
02600 DEFN_CTOR_T_A(const char*)
02601 DEFN_CTOR_T_B(const sc_fxval&)
02602 DEFN_CTOR_T_C(const sc_fxval_fast&)
02603 DEFN_CTOR_T_B(const sc_fxnum&)
02604 DEFN_CTOR_T_C(const sc_fxnum_fast&)
02605 #ifndef SC_FX_EXCLUDE_OTHER
02606 DEFN_CTOR_T_A(int64)
02607 DEFN_CTOR_T_A(uint64)
02608 DEFN_CTOR_T_D(const sc_int_base&)
02609 DEFN_CTOR_T_D(const sc_uint_base&)
02610 DEFN_CTOR_T_A(const sc_signed&)
02611 DEFN_CTOR_T_A(const sc_unsigned&)
02612 #endif
02613 
02614 #undef DEFN_CTOR_T
02615 #undef DEFN_CTOR_T_A
02616 #undef DEFN_CTOR_T_B
02617 #undef DEFN_CTOR_T_C
02618 #undef DEFN_CTOR_T_D
02619 
02620 
02621 inline
02622 sc_fxnum::~sc_fxnum()
02623 {
02624     SC_FXNUM_OBSERVER_DESTRUCT_( *this )
02625     delete m_rep;
02626 }
02627 
02628 
02629 // internal use only;
02630 inline
02631 const scfx_rep*
02632 sc_fxnum::get_rep() const
02633 {
02634     SC_FXNUM_OBSERVER_READ_( *this )
02635     return m_rep;
02636 }
02637 
02638 
02639 // unary operators
02640 
02641 inline
02642 const sc_fxval
02643 sc_fxnum::operator - () const
02644 {
02645     SC_FXNUM_OBSERVER_READ_( *this )
02646     return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );
02647 }
02648 
02649 inline
02650 const sc_fxval
02651 sc_fxnum::operator + () const
02652 {
02653     SC_FXNUM_OBSERVER_READ_( *this )
02654     return sc_fxval( new scfx_rep( *m_rep ) );
02655 }
02656 
02657 
02658 // unary functions
02659 
02660 inline
02661 void
02662 neg( sc_fxval& c, const sc_fxnum& a )
02663 {
02664     SC_FXNUM_OBSERVER_READ_( a )
02665     c.set_rep( sc_dt::neg_scfx_rep( *a.m_rep ) );
02666 }
02667 
02668 inline
02669 void
02670 neg( sc_fxnum& c, const sc_fxnum& a )
02671 {
02672     SC_FXNUM_OBSERVER_READ_( a )
02673     delete c.m_rep;
02674     c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );
02675     c.cast();
02676     SC_FXNUM_OBSERVER_WRITE_( c )
02677 }
02678 
02679 
02680 // binary operators
02681 
02682 #define DEFN_BIN_OP_T(op,fnc,tp)                                              \
02683 inline                                                                        \
02684 const sc_fxval                                                                \
02685 operator op ( const sc_fxnum& a, tp b )                                       \
02686 {                                                                             \
02687     SC_FXNUM_OBSERVER_READ_( a )                                              \
02688     sc_fxval tmp( b );                                                        \
02689     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) );  \
02690 }                                                                             \
02691                                                                               \
02692 inline                                                                        \
02693 const sc_fxval                                                                \
02694 operator op ( tp a, const sc_fxnum& b )                                       \
02695 {                                                                             \
02696     SC_FXNUM_OBSERVER_READ_( b )                                              \
02697     sc_fxval tmp( a );                                                        \
02698     return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) );  \
02699 }
02700 
02701 #ifndef SC_FX_EXCLUDE_OTHER
02702 #define DEFN_BIN_OP_OTHER(op,fnc)                                             \
02703 DEFN_BIN_OP_T(op,fnc,int64)                                                   \
02704 DEFN_BIN_OP_T(op,fnc,uint64)                                                  \
02705 DEFN_BIN_OP_T(op,fnc,const sc_int_base&)                                      \
02706 DEFN_BIN_OP_T(op,fnc,const sc_uint_base&)                                     \
02707 DEFN_BIN_OP_T(op,fnc,const sc_signed&)                                        \
02708 DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)
02709 #else
02710 #define DEFN_BIN_OP_OTHER(op,fnc)
02711 #endif
02712 
02713 #define DEFN_BIN_OP(op,fnc)                                                   \
02714 inline                                                                        \
02715 const sc_fxval                                                                \
02716 operator op ( const sc_fxnum& a, const sc_fxnum& b )                          \
02717 {                                                                             \
02718     SC_FXNUM_OBSERVER_READ_( a )                                              \
02719     SC_FXNUM_OBSERVER_READ_( b )                                              \
02720     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );        \
02721 }                                                                             \
02722                                                                               \
02723 inline                                                                        \
02724 const sc_fxval                                                                \
02725 operator op ( const sc_fxnum& a, const sc_fxval& b )                          \
02726 {                                                                             \
02727     SC_FXNUM_OBSERVER_READ_( a )                                              \
02728     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) );    \
02729 }                                                                             \
02730                                                                               \
02731 inline                                                                        \
02732 const sc_fxval                                                                \
02733 operator op ( const sc_fxval& a, const sc_fxnum& b )                          \
02734 {                                                                             \
02735     SC_FXNUM_OBSERVER_READ_( b )                                              \
02736     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) );    \
02737 }                                                                             \
02738                                                                               \
02739 DEFN_BIN_OP_T(op,fnc,int)                                                     \
02740 DEFN_BIN_OP_T(op,fnc,unsigned int)                                            \
02741 DEFN_BIN_OP_T(op,fnc,long)                                                    \
02742 DEFN_BIN_OP_T(op,fnc,unsigned long)                                           \
02743 DEFN_BIN_OP_T(op,fnc,double)                                                  \
02744 DEFN_BIN_OP_T(op,fnc,const char*)                                             \
02745 DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
02746 DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)                                    \
02747 DEFN_BIN_OP_OTHER(op,fnc)
02748 
02749 DEFN_BIN_OP(*,mult)
02750 DEFN_BIN_OP(+,add)
02751 DEFN_BIN_OP(-,sub)
02752 // don't use macros
02753 //DEFN_BIN_OP(/,div)
02754 inline
02755 const sc_fxval
02756 operator / ( const sc_fxnum& a, const sc_fxnum& b )
02757 {
02758     SC_FXNUM_OBSERVER_READ_( a )
02759     SC_FXNUM_OBSERVER_READ_( b )
02760     return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );
02761 }
02762 
02763 inline
02764 const sc_fxval
02765 operator / ( const sc_fxnum& a, const sc_fxval& b )
02766 {
02767     SC_FXNUM_OBSERVER_READ_( a )
02768     return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.get_rep() ) );
02769 }
02770 
02771 inline
02772 const sc_fxval
02773 operator / ( const sc_fxval& a, const sc_fxnum& b )
02774 {
02775     SC_FXNUM_OBSERVER_READ_( b )
02776     return sc_fxval( sc_dt::div_scfx_rep( *a.get_rep(), *b.m_rep ) );
02777 }
02778 
02779 DEFN_BIN_OP_T(/,div,int)
02780 DEFN_BIN_OP_T(/,div,unsigned int)
02781 DEFN_BIN_OP_T(/,div,long)
02782 DEFN_BIN_OP_T(/,div,unsigned long)
02783 DEFN_BIN_OP_T(/,div,double)
02784 DEFN_BIN_OP_T(/,div,const char*)
02785 DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)
02786 DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
02787 //DEFN_BIN_OP_OTHER(/,div)
02788 #ifndef SC_FX_EXCLUDE_OTHER
02789 DEFN_BIN_OP_T(/,div,int64)
02790 DEFN_BIN_OP_T(/,div,uint64)
02791 DEFN_BIN_OP_T(/,div,const sc_int_base&)
02792 DEFN_BIN_OP_T(/,div,const sc_uint_base&)
02793 DEFN_BIN_OP_T(/,div,const sc_signed&)
02794 DEFN_BIN_OP_T(/,div,const sc_unsigned&)
02795 #endif
02796 
02797 #undef DEFN_BIN_OP_T
02798 #undef DEFN_BIN_OP_OTHER
02799 #undef DEFN_BIN_OP
02800 
02801 
02802 inline
02803 const sc_fxval
02804 operator << ( const sc_fxnum& a, int b )
02805 {
02806     SC_FXNUM_OBSERVER_READ_( a )
02807     return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
02808 }
02809 
02810 inline
02811 const sc_fxval
02812 operator >> ( const sc_fxnum& a, int b )
02813 {
02814     SC_FXNUM_OBSERVER_READ_( a )
02815     return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
02816 }
02817 
02818 
02819 // binary functions
02820 
02821 #define DEFN_BIN_FNC_T(fnc,tp)                                                \
02822 inline                                                                        \
02823 void                                                                          \
02824 fnc ( sc_fxval& c, const sc_fxnum& a, tp b )                                  \
02825 {                                                                             \
02826     SC_FXNUM_OBSERVER_READ_( a )                                              \
02827     sc_fxval tmp( b );                                                        \
02828     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) );        \
02829 }                                                                             \
02830                                                                               \
02831 inline                                                                        \
02832 void                                                                          \
02833 fnc ( sc_fxval& c, tp a, const sc_fxnum& b )                                  \
02834 {                                                                             \
02835     SC_FXNUM_OBSERVER_READ_( b )                                              \
02836     sc_fxval tmp( a );                                                        \
02837     c.set_rep( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) );        \
02838 }                                                                             \
02839                                                                               \
02840 inline                                                                        \
02841 void                                                                          \
02842 fnc ( sc_fxnum& c, const sc_fxnum& a, tp b )                                  \
02843 {                                                                             \
02844     SC_FXNUM_OBSERVER_READ_( a )                                              \
02845     sc_fxval tmp( b );                                                        \
02846     delete c.m_rep;                                                           \
02847     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() );           \
02848     c.cast();                                                                 \
02849     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02850 }                                                                             \
02851                                                                               \
02852 inline                                                                        \
02853 void                                                                          \
02854 fnc ( sc_fxnum& c, tp a, const sc_fxnum& b )                                  \
02855 {                                                                             \
02856     SC_FXNUM_OBSERVER_READ_( b )                                              \
02857     sc_fxval tmp( a );                                                        \
02858     delete c.m_rep;                                                           \
02859     c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep );           \
02860     c.cast();                                                                 \
02861     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02862 }
02863 
02864 #ifndef SC_FX_EXCLUDE_OTHER
02865 #define DEFN_BIN_FNC_OTHER(fnc)                                               \
02866 DEFN_BIN_FNC_T(fnc,int64)                                                     \
02867 DEFN_BIN_FNC_T(fnc,uint64)                                                    \
02868 DEFN_BIN_FNC_T(fnc,const sc_int_base&)                                        \
02869 DEFN_BIN_FNC_T(fnc,const sc_uint_base&)                                       \
02870 DEFN_BIN_FNC_T(fnc,const sc_signed&)                                          \
02871 DEFN_BIN_FNC_T(fnc,const sc_unsigned&)
02872 #else
02873 #define DEFN_BIN_FNC_OTHER(fnc)
02874 #endif
02875 
02876 #define DEFN_BIN_FNC(fnc)                                                     \
02877 inline                                                                        \
02878 void                                                                          \
02879 fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxnum& b )                     \
02880 {                                                                             \
02881     SC_FXNUM_OBSERVER_READ_( a )                                              \
02882     SC_FXNUM_OBSERVER_READ_( b )                                              \
02883     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );              \
02884 }                                                                             \
02885                                                                               \
02886 inline                                                                        \
02887 void                                                                          \
02888 fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxnum& b )                     \
02889 {                                                                             \
02890     SC_FXNUM_OBSERVER_READ_( a )                                              \
02891     SC_FXNUM_OBSERVER_READ_( b )                                              \
02892     delete c.m_rep;                                                           \
02893     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep );                 \
02894     c.cast();                                                                 \
02895     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02896 }                                                                             \
02897                                                                               \
02898 inline                                                                        \
02899 void                                                                          \
02900 fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxval& b )                     \
02901 {                                                                             \
02902     SC_FXNUM_OBSERVER_READ_( a )                                              \
02903     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) );          \
02904 }                                                                             \
02905                                                                               \
02906 inline                                                                        \
02907 void                                                                          \
02908 fnc ( sc_fxval& c, const sc_fxval& a, const sc_fxnum& b )                     \
02909 {                                                                             \
02910     SC_FXNUM_OBSERVER_READ_( b )                                              \
02911     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) );          \
02912 }                                                                             \
02913                                                                               \
02914 inline                                                                        \
02915 void                                                                          \
02916 fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxval& b )                     \
02917 {                                                                             \
02918     SC_FXNUM_OBSERVER_READ_( a )                                              \
02919     delete c.m_rep;                                                           \
02920     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() );             \
02921     c.cast();                                                                 \
02922     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02923 }                                                                             \
02924                                                                               \
02925 inline                                                                        \
02926 void                                                                          \
02927 fnc ( sc_fxnum& c, const sc_fxval& a, const sc_fxnum& b )                     \
02928 {                                                                             \
02929     SC_FXNUM_OBSERVER_READ_( b )                                              \
02930     delete c.m_rep;                                                           \
02931     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep );             \
02932     c.cast();                                                                 \
02933     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02934 }                                                                             \
02935                                                                               \
02936 DEFN_BIN_FNC_T(fnc,int)                                                       \
02937 DEFN_BIN_FNC_T(fnc,unsigned int)                                              \
02938 DEFN_BIN_FNC_T(fnc,long)                                                      \
02939 DEFN_BIN_FNC_T(fnc,unsigned long)                                             \
02940 DEFN_BIN_FNC_T(fnc,double)                                                    \
02941 DEFN_BIN_FNC_T(fnc,const char*)                                               \
02942 DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&)                                      \
02943 DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                      \
02944 DEFN_BIN_FNC_OTHER(fnc)
02945 
02946 DEFN_BIN_FNC(mult)
02947 DEFN_BIN_FNC(div)
02948 DEFN_BIN_FNC(add)
02949 DEFN_BIN_FNC(sub)
02950 
02951 #undef DEFN_BIN_FNC_T
02952 #undef DEFN_BIN_FNC_OTHER
02953 #undef DEFN_BIN_FNC
02954 
02955 
02956 inline
02957 void
02958 lshift( sc_fxval& c, const sc_fxnum& a, int b )
02959 {
02960     SC_FXNUM_OBSERVER_READ_( a )
02961     c.set_rep( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
02962 }
02963 
02964 inline
02965 void
02966 rshift( sc_fxval& c, const sc_fxnum& a, int b )
02967 {
02968     SC_FXNUM_OBSERVER_READ_( a )
02969     c.set_rep( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
02970 }
02971 
02972 inline
02973 void
02974 lshift( sc_fxnum& c, const sc_fxnum& a, int b )
02975 {
02976     SC_FXNUM_OBSERVER_READ_( a )
02977     delete c.m_rep;
02978     c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );
02979     c.cast();
02980     SC_FXNUM_OBSERVER_WRITE_( c )
02981 }
02982 
02983 inline
02984 void
02985 rshift( sc_fxnum& c, const sc_fxnum& a, int b )
02986 {
02987     SC_FXNUM_OBSERVER_READ_( a )
02988     delete c.m_rep;
02989     c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );
02990     c.cast();
02991     SC_FXNUM_OBSERVER_WRITE_( c )
02992 }
02993 
02994 
02995 // relational (including equality) operators
02996 
02997 #define DEFN_REL_OP_T(op,ret,tp)                                              \
02998 inline                                                                        \
02999 bool                                                                          \
03000 operator op ( const sc_fxnum& a, tp b )                                       \
03001 {                                                                             \
03002     SC_FXNUM_OBSERVER_READ_( a )                                              \
03003     sc_fxval tmp( b );                                                        \
03004     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.get_rep() );            \
03005     return ( ret );                                                           \
03006 }                                                                             \
03007                                                                               \
03008 inline                                                                        \
03009 bool                                                                          \
03010 operator op ( tp a, const sc_fxnum& b )                                       \
03011 {                                                                             \
03012     SC_FXNUM_OBSERVER_READ_( b )                                              \
03013     sc_fxval tmp( a );                                                        \
03014     int result = sc_dt::cmp_scfx_rep( *tmp.get_rep(), *b.m_rep );            \
03015     return ( ret );                                                           \
03016 }
03017 
03018 #ifndef SC_FX_EXCLUDE_OTHER
03019 #define DEFN_REL_OP_OTHER(op,ret)                                             \
03020 DEFN_REL_OP_T(op,ret,int64)                                                   \
03021 DEFN_REL_OP_T(op,ret,uint64)                                                  \
03022 DEFN_REL_OP_T(op,ret,const sc_int_base&)                                      \
03023 DEFN_REL_OP_T(op,ret,const sc_uint_base&)                                     \
03024 DEFN_REL_OP_T(op,ret,const sc_signed&)                                        \
03025 DEFN_REL_OP_T(op,ret,const sc_unsigned&)
03026 #else
03027 #define DEFN_REL_OP_OTHER(op,ret)
03028 #endif
03029 
03030 #define DEFN_REL_OP(op,ret)                                                   \
03031 inline                                                                        \
03032 bool                                                                          \
03033 operator op ( const sc_fxnum& a, const sc_fxnum& b )                          \
03034 {                                                                             \
03035     SC_FXNUM_OBSERVER_READ_( a )                                              \
03036     SC_FXNUM_OBSERVER_READ_( b )                                              \
03037     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep );                  \
03038     return ( ret );                                                           \
03039 }                                                                             \
03040                                                                               \
03041 inline                                                                        \
03042 bool                                                                          \
03043 operator op ( const sc_fxnum& a, const sc_fxval& b )                          \
03044 {                                                                             \
03045     SC_FXNUM_OBSERVER_READ_( a )                                              \
03046     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.get_rep() );              \
03047     return ( ret );                                                           \
03048 }                                                                             \
03049                                                                               \
03050 inline                                                                        \
03051 bool                                                                          \
03052 operator op ( const sc_fxval& a, const sc_fxnum& b )                          \
03053 {                                                                             \
03054     SC_FXNUM_OBSERVER_READ_( b )                                              \
03055     int result = sc_dt::cmp_scfx_rep( *a.get_rep(), *b.m_rep );              \
03056     return ( ret );                                                           \
03057 }                                                                             \
03058                                                                               \
03059 DEFN_REL_OP_T(op,ret,int)                                                     \
03060 DEFN_REL_OP_T(op,ret,unsigned int)                                            \
03061 DEFN_REL_OP_T(op,ret,long)                                                    \
03062 DEFN_REL_OP_T(op,ret,unsigned long)                                           \
03063 DEFN_REL_OP_T(op,ret,double)                                                  \
03064 DEFN_REL_OP_T(op,ret,const char*)                                             \
03065 DEFN_REL_OP_T(op,ret,const sc_fxval_fast&)                                    \
03066 DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)                                    \
03067 DEFN_REL_OP_OTHER(op,ret)
03068 
03069 DEFN_REL_OP(<,result < 0)
03070 DEFN_REL_OP(<=,result <= 0)
03071 DEFN_REL_OP(>,result > 0 && result != 2)
03072 DEFN_REL_OP(>=,result >= 0 && result != 2)
03073 DEFN_REL_OP(==,result == 0)
03074 DEFN_REL_OP(!=,result != 0)
03075 
03076 #undef DEFN_REL_OP_T
03077 #undef DEFN_REL_OP_OTHER
03078 #undef DEFN_REL_OP
03079 
03080 
03081 // assignment operators
03082 
03083 inline
03084 sc_fxnum&
03085 sc_fxnum::operator = ( const sc_fxnum& a )
03086 {
03087     if( &a != this )
03088     {
03089         SC_FXNUM_OBSERVER_READ_( a )
03090     *m_rep = *a.m_rep;
03091     cast();
03092     SC_FXNUM_OBSERVER_WRITE_( *this )
03093     }
03094     return *this;
03095 }
03096 
03097 inline
03098 sc_fxnum&
03099 sc_fxnum::operator = ( const sc_fxval& a )
03100 {
03101     *m_rep = *a.get_rep();
03102     cast();
03103     SC_FXNUM_OBSERVER_WRITE_( *this )
03104     return *this;
03105 }
03106 
03107 #define DEFN_ASN_OP_T(tp)                                                     \
03108 inline                                                                        \
03109 sc_fxnum&                                                                     \
03110 sc_fxnum::operator = ( tp a )                                                 \
03111 {                                                                             \
03112     sc_fxval tmp( a );                                                        \
03113     *m_rep = *tmp.get_rep();                                                  \
03114     cast();                                                                   \
03115     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03116     return *this;                                                             \
03117 }
03118 
03119 DEFN_ASN_OP_T(int)
03120 DEFN_ASN_OP_T(unsigned int)
03121 DEFN_ASN_OP_T(long)
03122 DEFN_ASN_OP_T(unsigned long)
03123 DEFN_ASN_OP_T(double)
03124 DEFN_ASN_OP_T(const char*)
03125 DEFN_ASN_OP_T(const sc_fxval_fast&)
03126 DEFN_ASN_OP_T(const sc_fxnum_fast&)
03127 #ifndef SC_FX_EXCLUDE_OTHER
03128 DEFN_ASN_OP_T(int64)
03129 DEFN_ASN_OP_T(uint64)
03130 DEFN_ASN_OP_T(const sc_int_base&)
03131 DEFN_ASN_OP_T(const sc_uint_base&)
03132 DEFN_ASN_OP_T(const sc_signed&)
03133 DEFN_ASN_OP_T(const sc_unsigned&)
03134 #endif
03135 
03136 #undef DEFN_ASN_OP_T
03137 
03138 
03139 #define DEFN_ASN_OP_T(op,fnc,tp)                                              \
03140 inline                                                                        \
03141 sc_fxnum&                                                                     \
03142 sc_fxnum::operator op ( tp b )                                                \
03143 {                                                                             \
03144     SC_FXNUM_OBSERVER_READ_( *this )                                          \
03145     sc_fxval tmp( b );                                                        \
03146     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.get_rep() );   \
03147     delete m_rep;                                                             \
03148     m_rep = new_rep;                                                          \
03149     cast();                                                                   \
03150     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03151     return *this;                                                             \
03152 }
03153 
03154 #ifndef SC_FX_EXCLUDE_OTHER
03155 #define DEFN_ASN_OP_OTHER(op,fnc)                                             \
03156 DEFN_ASN_OP_T(op,fnc,int64)                                                   \
03157 DEFN_ASN_OP_T(op,fnc,uint64)                                                  \
03158 DEFN_ASN_OP_T(op,fnc,const sc_int_base&)                                      \
03159 DEFN_ASN_OP_T(op,fnc,const sc_uint_base&)                                     \
03160 DEFN_ASN_OP_T(op,fnc,const sc_signed&)                                        \
03161 DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)
03162 #else
03163 #define DEFN_ASN_OP_OTHER(op,fnc)
03164 #endif
03165 
03166 #define DEFN_ASN_OP(op,fnc)                                                   \
03167 inline                                                                        \
03168 sc_fxnum&                                                                     \
03169 sc_fxnum::operator op ( const sc_fxnum& b )                                   \
03170 {                                                                             \
03171     SC_FXNUM_OBSERVER_READ_( *this )                                          \
03172     SC_FXNUM_OBSERVER_READ_( b )                                              \
03173     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep );         \
03174     delete m_rep;                                                             \
03175     m_rep = new_rep;                                                          \
03176     cast();                                                                   \
03177     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03178     return *this;                                                             \
03179 }                                                                             \
03180                                                                               \
03181 inline                                                                        \
03182 sc_fxnum&                                                                     \
03183 sc_fxnum::operator op ( const sc_fxval& b )                                   \
03184 {                                                                             \
03185     SC_FXNUM_OBSERVER_READ_( *this )                                          \
03186     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() );     \
03187     delete m_rep;                                                             \
03188     m_rep = new_rep;                                                          \
03189     cast();                                                                   \
03190     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03191     return *this;                                                             \
03192 }                                                                             \
03193                                                                               \
03194 DEFN_ASN_OP_T(op,fnc,int)                                                     \
03195 DEFN_ASN_OP_T(op,fnc,unsigned int)                                            \
03196 DEFN_ASN_OP_T(op,fnc,long)                                                    \
03197 DEFN_ASN_OP_T(op,fnc,unsigned long)                                           \
03198 DEFN_ASN_OP_T(op,fnc,double)                                                  \
03199 DEFN_ASN_OP_T(op,fnc,const char*)                                             \
03200 DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
03201 DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)                                    \
03202 DEFN_ASN_OP_OTHER(op,fnc)
03203 
03204 DEFN_ASN_OP(*=,mult)
03205 DEFN_ASN_OP(/=,div)
03206 DEFN_ASN_OP(+=,add)
03207 DEFN_ASN_OP(-=,sub)
03208 
03209 #undef DEFN_ASN_OP_T
03210 #undef DEFN_ASN_OP_OTHER
03211 #undef DEFN_ASN_OP
03212 
03213 
03214 inline
03215 sc_fxnum&
03216 sc_fxnum::operator <<= ( int b )
03217 {
03218     SC_FXNUM_OBSERVER_READ_( *this )
03219     m_rep->lshift( b );
03220     cast();
03221     SC_FXNUM_OBSERVER_WRITE_( *this )
03222     return *this;
03223 }
03224 
03225 inline
03226 sc_fxnum&
03227 sc_fxnum::operator >>= ( int b )
03228 {
03229     SC_FXNUM_OBSERVER_READ_( *this )
03230     m_rep->rshift( b );
03231     cast();
03232     SC_FXNUM_OBSERVER_WRITE_( *this )
03233     return *this;
03234 }
03235 
03236 
03237 // auto-increment and auto-decrement
03238 
03239 inline
03240 const sc_fxval
03241 sc_fxnum::operator ++ ( int )
03242 {
03243     sc_fxval c( *this );
03244     (*this) += 1;
03245     return c;
03246 }
03247 
03248 inline
03249 const sc_fxval
03250 sc_fxnum::operator -- ( int )
03251 {
03252     sc_fxval c( *this );
03253     (*this) -= 1;
03254     return c;
03255 }
03256 
03257 inline
03258 sc_fxnum&
03259 sc_fxnum::operator ++ ()
03260 {
03261     (*this) += 1;
03262     return *this;
03263 }
03264 
03265 inline
03266 sc_fxnum&
03267 sc_fxnum::operator -- ()
03268 {
03269     (*this) -= 1;
03270     return *this;
03271 }
03272 
03273 
03274 // bit selection
03275 
03276 inline
03277 const sc_fxnum_bitref
03278 sc_fxnum::operator [] ( int i ) const
03279 {
03280     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03281     return sc_fxnum_bitref( const_cast<sc_fxnum&>( *this ),
03282                 i - m_params.fwl() );
03283 }
03284 
03285 inline
03286 sc_fxnum_bitref
03287 sc_fxnum::operator [] ( int i )
03288 {
03289     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03290     return sc_fxnum_bitref( *this, i - m_params.fwl() );
03291 }
03292 
03293 inline
03294 const sc_fxnum_bitref
03295 sc_fxnum::bit( int i ) const
03296 {
03297     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03298     return sc_fxnum_bitref( const_cast<sc_fxnum&>( *this ),
03299                 i - m_params.fwl() );
03300 }
03301 
03302 inline
03303 sc_fxnum_bitref
03304 sc_fxnum::bit( int i )
03305 {
03306     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03307     return sc_fxnum_bitref( *this, i - m_params.fwl() );
03308 }
03309 
03310 
03311 // part selection
03312 
03313 inline
03314 const sc_fxnum_subref
03315 sc_fxnum::operator () ( int i, int j ) const
03316 {
03317     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03318     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03319 
03320     return sc_fxnum_subref( const_cast<sc_fxnum&>( *this ),
03321                 i - m_params.fwl(), j - m_params.fwl() );
03322 }
03323 
03324 inline
03325 sc_fxnum_subref
03326 sc_fxnum::operator () ( int i, int j )
03327 {
03328     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03329     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03330 
03331     return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
03332 }
03333 
03334 inline
03335 const sc_fxnum_subref
03336 sc_fxnum::range( int i, int j ) const
03337 {
03338     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03339     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03340 
03341     return sc_fxnum_subref( const_cast<sc_fxnum&>( *this ),
03342                 i - m_params.fwl(), j - m_params.fwl() );
03343 }
03344 
03345 inline
03346 sc_fxnum_subref
03347 sc_fxnum::range( int i, int j )
03348 {
03349     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03350     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03351 
03352     return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
03353 }
03354 
03355 
03356 inline
03357 const sc_fxnum_subref
03358 sc_fxnum::operator () () const
03359 {
03360     return this->operator () ( m_params.wl() - 1, 0 );
03361 }
03362 
03363 inline
03364 sc_fxnum_subref
03365 sc_fxnum::operator () ()
03366 {
03367     return this->operator () ( m_params.wl() - 1, 0 );
03368 }
03369 
03370 inline
03371 const sc_fxnum_subref
03372 sc_fxnum::range() const
03373 {
03374     return this->range( m_params.wl() - 1, 0 );
03375 }
03376 
03377 inline
03378 sc_fxnum_subref
03379 sc_fxnum::range()
03380 {
03381     return this->range( m_params.wl() - 1, 0 );
03382 }
03383 
03384 
03385 // implicit conversion
03386 
03387 inline
03388 sc_fxnum::operator double() const
03389 {
03390     SC_FXNUM_OBSERVER_READ_( *this )
03391     return m_rep->to_double();
03392 }
03393 
03394 
03395 // explicit conversion to primitive types
03396 
03397 inline
03398 short
03399 sc_fxnum::to_short() const
03400 {
03401     SC_FXNUM_OBSERVER_READ_( *this )
03402     return static_cast<short>( m_rep->to_double() );
03403 }
03404 
03405 inline
03406 unsigned short
03407 sc_fxnum::to_ushort() const
03408 {
03409     SC_FXNUM_OBSERVER_READ_( *this )
03410     return static_cast<unsigned short>( m_rep->to_double() );
03411 }
03412 
03413 inline
03414 int
03415 sc_fxnum::to_int() const
03416 {
03417     SC_FXNUM_OBSERVER_READ_( *this )
03418     return static_cast<int>( m_rep->to_double() );
03419 }
03420 
03421 inline
03422 int64
03423 sc_fxnum::to_int64() const
03424 {
03425     SC_FXNUM_OBSERVER_READ_( *this )
03426     return static_cast<int64>( m_rep->to_double() );
03427 }
03428 
03429 inline
03430 unsigned int
03431 sc_fxnum::to_uint() const
03432 {
03433     SC_FXNUM_OBSERVER_READ_( *this )
03434     return static_cast<unsigned int>( m_rep->to_double() );
03435 }
03436 
03437 inline
03438 uint64
03439 sc_fxnum::to_uint64() const
03440 {
03441     SC_FXNUM_OBSERVER_READ_( *this )
03442     return static_cast<uint64>( m_rep->to_double() );
03443 }
03444 
03445 inline
03446 long
03447 sc_fxnum::to_long() const
03448 {
03449     SC_FXNUM_OBSERVER_READ_( *this )
03450     return static_cast<long>( m_rep->to_double() );
03451 }
03452 
03453 inline
03454 unsigned long
03455 sc_fxnum::to_ulong() const
03456 {
03457     SC_FXNUM_OBSERVER_READ_( *this )
03458     return static_cast<unsigned long>( m_rep->to_double() );
03459 }
03460 
03461 inline
03462 float
03463 sc_fxnum::to_float() const
03464 {
03465     SC_FXNUM_OBSERVER_READ_( *this )
03466     return static_cast<float>( m_rep->to_double() );
03467 }
03468 
03469 inline
03470 double
03471 sc_fxnum::to_double() const
03472 {
03473     SC_FXNUM_OBSERVER_READ_( *this )
03474     return m_rep->to_double();
03475 }
03476 
03477 
03478 // query value
03479 
03480 inline
03481 bool
03482 sc_fxnum::is_neg() const
03483 {
03484     SC_FXNUM_OBSERVER_READ_( *this )
03485     return m_rep->is_neg();
03486 }
03487 
03488 inline
03489 bool
03490 sc_fxnum::is_zero() const
03491 {
03492     SC_FXNUM_OBSERVER_READ_( *this )
03493     return m_rep->is_zero();
03494 }
03495 
03496 // internal use only;
03497 inline
03498 bool
03499 sc_fxnum::is_normal() const
03500 {
03501     SC_FXNUM_OBSERVER_READ_( *this )
03502     return m_rep->is_normal();
03503 }
03504 
03505 inline
03506 bool
03507 sc_fxnum::quantization_flag() const
03508 {
03509     return m_q_flag;
03510 }
03511 
03512 inline
03513 bool
03514 sc_fxnum::overflow_flag() const
03515 {
03516     return m_o_flag;
03517 }
03518 
03519 
03520 inline
03521 const sc_fxval
03522 sc_fxnum::value() const
03523 {
03524     SC_FXNUM_OBSERVER_READ_( *this )
03525     return sc_fxval( new scfx_rep( *m_rep ) );
03526 }
03527 
03528 
03529 // query parameters
03530 
03531 inline
03532 int
03533 sc_fxnum::wl() const
03534 {
03535     return m_params.wl();
03536 }
03537 
03538 inline
03539 int
03540 sc_fxnum::iwl() const
03541 {
03542     return m_params.iwl();
03543 }
03544 
03545 inline
03546 sc_q_mode
03547 sc_fxnum::q_mode() const
03548 {
03549     return m_params.q_mode();
03550 }
03551 
03552 inline
03553 sc_o_mode
03554 sc_fxnum::o_mode() const
03555 {
03556     return m_params.o_mode();
03557 }
03558 
03559 inline
03560 int
03561 sc_fxnum::n_bits() const
03562 {
03563     return m_params.n_bits();
03564 }
03565 
03566 
03567 inline
03568 const sc_fxtype_params&
03569 sc_fxnum::type_params() const
03570 {
03571     return m_params.type_params();
03572 }
03573 
03574 
03575 inline
03576 const sc_fxcast_switch&
03577 sc_fxnum::cast_switch() const
03578 {
03579     return m_params.cast_switch();
03580 }
03581 
03582 
03583 // internal use only;
03584 inline
03585 void
03586 sc_fxnum::observer_read() const
03587 {
03588     SC_FXNUM_OBSERVER_READ_( *this );
03589 }
03590 
03591 
03592 // internal use only;
03593 inline
03594 bool
03595 sc_fxnum::get_bit( int i ) const
03596 {
03597     return m_rep->get_bit( i );
03598 }
03599 
03600 
03601 // protected methods and friend functions
03602 
03603 inline
03604 bool
03605 sc_fxnum::set_bit( int i, bool high )
03606 {
03607     if( high )
03608         return m_rep->set( i, m_params );
03609     else
03610         return m_rep->clear( i, m_params );
03611 }
03612 
03613 
03614 inline
03615 bool
03616 sc_fxnum::get_slice( int i, int j, sc_bv_base& bv ) const
03617 {
03618     return m_rep->get_slice( i, j, m_params, bv );
03619 }
03620 
03621 inline
03622 bool
03623 sc_fxnum::set_slice( int i, int j, const sc_bv_base& bv )
03624 {
03625     return m_rep->set_slice( i, j, m_params, bv );
03626 }
03627 
03628 
03629 inline
03630 ::std::ostream&
03631 operator << ( ::std::ostream& os, const sc_fxnum& a )
03632 {
03633     a.print( os );
03634     return os;
03635 }
03636 
03637 inline
03638 ::std::istream&
03639 operator >> ( ::std::istream& is, sc_fxnum& a )
03640 {
03641     a.scan( is );
03642     return is;
03643 }
03644 
03645 
03646 // ----------------------------------------------------------------------------
03647 //  CLASS : sc_fxnum_fast
03648 //
03649 //  Base class for the fixed-point types; limited precision.
03650 // ----------------------------------------------------------------------------
03651 
03652 inline
03653 sc_fxnum_fast_observer*
03654 sc_fxnum_fast::observer() const
03655 {
03656     return m_observer;
03657 }
03658 
03659 
03660 // constructors
03661 
03662 inline
03663 sc_fxnum_fast::sc_fxnum_fast( const sc_fxtype_params& type_params_,
03664                   sc_enc enc_,
03665                   const sc_fxcast_switch& cast_sw,
03666                   sc_fxnum_fast_observer* observer_ )
03667 : m_val( 0.0 ),
03668   m_params( type_params_, enc_, cast_sw ),
03669   m_q_flag( false ),
03670   m_o_flag( false ),
03671   m_observer( observer_ )
03672 {
03673     SC_FXNUM_FAST_OBSERVER_DEFAULT_
03674     SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this)
03675 }
03676 
03677 inline
03678 sc_fxnum_fast::sc_fxnum_fast( const sc_fxnum_fast& a,
03679                   const sc_fxtype_params& type_params_,
03680                   sc_enc enc_,
03681                   const sc_fxcast_switch& cast_sw,
03682                   sc_fxnum_fast_observer* observer_ )
03683 : m_val( a.m_val ),
03684   m_params( type_params_, enc_, cast_sw ),
03685   m_q_flag( false ),
03686   m_o_flag( false ),
03687   m_observer( observer_ )
03688 {
03689     SC_FXNUM_FAST_OBSERVER_DEFAULT_
03690     SC_FXNUM_FAST_OBSERVER_READ_( a )
03691     cast();
03692     SC_FXNUM_FAST_OBSERVER_CONSTRUCT_( *this )
03693     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
03694 }
03695 
03696 #define DEFN_CTOR_T(tp,arg)                                                   \
03697 inline                                                                        \
03698 sc_fxnum_fast::sc_fxnum_fast( tp a,                                           \
03699                       const sc_fxtype_params& type_params_,           \
03700                       sc_enc enc_,                                    \
03701                       const sc_fxcast_switch& cast_sw,                \
03702                       sc_fxnum_fast_observer* observer_ )             \
03703 : m_val( arg ),                                                               \
03704   m_params( type_params_, enc_, cast_sw ),                                    \
03705   m_q_flag( false ),                                                          \
03706   m_o_flag( false ),                                                          \
03707   m_observer( observer_ )                                                     \
03708 {                                                                             \
03709     SC_FXNUM_FAST_OBSERVER_DEFAULT_                                           \
03710     cast();                                                                   \
03711     SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this)                                  \
03712     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
03713 }
03714 
03715 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))
03716 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,sc_fxval_fast::from_string( a ))
03717 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
03718 
03719 DEFN_CTOR_T_A(int)
03720 DEFN_CTOR_T_A(unsigned int)
03721 DEFN_CTOR_T_A(long)
03722 DEFN_CTOR_T_A(unsigned long)
03723 DEFN_CTOR_T_A(double)
03724 DEFN_CTOR_T_B(const char*)
03725 DEFN_CTOR_T_C(const sc_fxval&)
03726 DEFN_CTOR_T_C(const sc_fxval_fast&)
03727 DEFN_CTOR_T_C(const sc_fxnum&)
03728 #ifndef SC_FX_EXCLUDE_OTHER
03729 DEFN_CTOR_T_A(int64)
03730 DEFN_CTOR_T_A(uint64)
03731 DEFN_CTOR_T_C(const sc_int_base&)
03732 DEFN_CTOR_T_C(const sc_uint_base&)
03733 DEFN_CTOR_T_C(const sc_signed&)
03734 DEFN_CTOR_T_C(const sc_unsigned&)
03735 #endif
03736 
03737 #undef DEFN_CTOR_T
03738 #undef DEFN_CTOR_T_A
03739 #undef DEFN_CTOR_T_B
03740 #undef DEFN_CTOR_T_C
03741 #undef DEFN_CTOR_T_D
03742 #undef DEFN_CTOR_T_E
03743 
03744 
03745 inline
03746 sc_fxnum_fast::~sc_fxnum_fast()
03747 {
03748     SC_FXNUM_FAST_OBSERVER_DESTRUCT_( *this )
03749 }
03750 
03751 
03752 // internal use only;
03753 inline
03754 double
03755 sc_fxnum_fast::get_val() const
03756 {
03757     SC_FXNUM_FAST_OBSERVER_READ_( *this )
03758     return m_val;
03759 }
03760 
03761 
03762 // unary operators
03763 
03764 inline
03765 const sc_fxval_fast
03766 sc_fxnum_fast::operator - () const
03767 {
03768     SC_FXNUM_FAST_OBSERVER_READ_( *this )
03769     return sc_fxval_fast( - m_val );
03770 }
03771 
03772 inline
03773 const sc_fxval_fast
03774 sc_fxnum_fast::operator + () const
03775 {
03776     SC_FXNUM_FAST_OBSERVER_READ_( *this )
03777     return sc_fxval_fast( m_val );
03778 }
03779 
03780 
03781 // unary functions
03782 
03783 inline
03784 void
03785 neg( sc_fxval_fast& c, const sc_fxnum_fast& a )
03786 {
03787     SC_FXNUM_FAST_OBSERVER_READ_( a )
03788     c.set_val( - a.m_val );
03789 }
03790 
03791 inline
03792 void
03793 neg( sc_fxnum_fast& c, const sc_fxnum_fast& a )
03794 {
03795     SC_FXNUM_FAST_OBSERVER_READ_( a )
03796     c.m_val = - a.m_val;
03797     c.cast();
03798     SC_FXNUM_FAST_OBSERVER_WRITE_( c )
03799 }
03800 
03801 
03802 // binary operators
03803 
03804 #define DEFN_BIN_OP_T(op,tp)                                                  \
03805 inline                                                                        \
03806 const sc_fxval_fast                                                           \
03807 operator op ( const sc_fxnum_fast& a, tp b )                                  \
03808 {                                                                             \
03809     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03810     sc_fxval_fast tmp( b );                                                   \
03811     return sc_fxval_fast( a.m_val op tmp.get_val() );                         \
03812 }                                                                             \
03813                                                                               \
03814 inline                                                                        \
03815 const sc_fxval_fast                                                           \
03816 operator op ( tp a, const sc_fxnum_fast& b )                                  \
03817 {                                                                             \
03818     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03819     sc_fxval_fast tmp( a );                                                   \
03820     return sc_fxval_fast( tmp.get_val() op b.m_val );                         \
03821 }
03822 
03823 #ifndef SC_FX_EXCLUDE_OTHER
03824 #define DEFN_BIN_OP_OTHER(op)                                                 \
03825 DEFN_BIN_OP_T(op,int64)                                                       \
03826 DEFN_BIN_OP_T(op,uint64)                                                      \
03827 DEFN_BIN_OP_T(op,const sc_int_base&)                                          \
03828 DEFN_BIN_OP_T(op,const sc_uint_base&)                                         \
03829 DEFN_BIN_OP_T(op,const sc_signed&)                                            \
03830 DEFN_BIN_OP_T(op,const sc_unsigned&)
03831 #else
03832 #define DEFN_BIN_OP_OTHER(op)
03833 #endif
03834 
03835 #define DEFN_BIN_OP(op,dummy)                                                 \
03836 inline                                                                        \
03837 const sc_fxval_fast                                                           \
03838 operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )                \
03839 {                                                                             \
03840     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03841     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03842     return sc_fxval_fast( a.m_val op b.m_val );                               \
03843 }                                                                             \
03844                                                                               \
03845 inline                                                                        \
03846 const sc_fxval_fast                                                           \
03847 operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b )                \
03848 {                                                                             \
03849     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03850     return sc_fxval_fast( a.m_val op b.get_val() );                           \
03851 }                                                                             \
03852                                                                               \
03853 inline                                                                        \
03854 const sc_fxval_fast                                                           \
03855 operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b )                \
03856 {                                                                             \
03857     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03858     return sc_fxval_fast( a.get_val() op b.m_val );                           \
03859 }                                                                             \
03860                                                                               \
03861 DEFN_BIN_OP_T(op,int)                                                         \
03862 DEFN_BIN_OP_T(op,unsigned int)                                                \
03863 DEFN_BIN_OP_T(op,long)                                                        \
03864 DEFN_BIN_OP_T(op,unsigned long)                                               \
03865 DEFN_BIN_OP_T(op,double)                                                      \
03866 DEFN_BIN_OP_T(op,const char*)                                                 \
03867 DEFN_BIN_OP_OTHER(op)
03868 
03869 DEFN_BIN_OP(*,mult)
03870 DEFN_BIN_OP(+,add)
03871 DEFN_BIN_OP(-,sub)
03872 //DEFN_BIN_OP(/,div)
03873 inline
03874 const sc_fxval_fast
03875 operator / ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )
03876 {
03877     SC_FXNUM_FAST_OBSERVER_READ_( a )
03878     SC_FXNUM_FAST_OBSERVER_READ_( b )
03879     return sc_fxval_fast( a.m_val / b.m_val );
03880 }
03881 
03882 inline
03883 const sc_fxval_fast
03884 operator / ( const sc_fxnum_fast& a, const sc_fxval_fast& b )
03885 {
03886     SC_FXNUM_FAST_OBSERVER_READ_( a )
03887     return sc_fxval_fast( a.m_val / b.get_val() );
03888 }
03889 
03890 inline
03891 const sc_fxval_fast
03892 operator / ( const sc_fxval_fast& a, const sc_fxnum_fast& b )
03893 {
03894     SC_FXNUM_FAST_OBSERVER_READ_( b )
03895     return sc_fxval_fast( a.get_val() / b.m_val );
03896 }
03897 
03898 DEFN_BIN_OP_T(/,int)
03899 DEFN_BIN_OP_T(/,unsigned int)
03900 DEFN_BIN_OP_T(/,long)
03901 DEFN_BIN_OP_T(/,unsigned long)
03902 DEFN_BIN_OP_T(/,double)
03903 DEFN_BIN_OP_T(/,const char*)
03904 //DEFN_BIN_OP_OTHER(/)
03905 #ifndef SC_FX_EXCLUDE_OTHER
03906 DEFN_BIN_OP_T(/,int64)
03907 DEFN_BIN_OP_T(/,uint64)
03908 DEFN_BIN_OP_T(/,const sc_int_base&)
03909 DEFN_BIN_OP_T(/,const sc_uint_base&)
03910 DEFN_BIN_OP_T(/,const sc_signed&)
03911 DEFN_BIN_OP_T(/,const sc_unsigned&)
03912 #endif
03913 
03914 #undef DEFN_BIN_OP_T
03915 #undef DEFN_BIN_OP_OTHER
03916 #undef DEFN_BIN_OP
03917 
03918 
03919 inline
03920 const sc_fxval_fast
03921 operator << ( const sc_fxnum_fast& a, int b )
03922 {
03923     SC_FXNUM_FAST_OBSERVER_READ_( a )
03924     return sc_fxval_fast( a.m_val * scfx_pow2( b ) );
03925 }
03926 
03927 inline
03928 const sc_fxval_fast
03929 operator >> ( const sc_fxnum_fast& a, int b )
03930 {
03931     SC_FXNUM_FAST_OBSERVER_READ_( a )
03932     return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );
03933 }
03934 
03935 
03936 // binary functions
03937 
03938 #define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
03939 inline                                                                        \
03940 void                                                                          \
03941 fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, tp b )                        \
03942 {                                                                             \
03943     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03944     sc_fxval_fast tmp( b );                                                   \
03945     c.set_val( a.m_val op tmp.get_val() );                                    \
03946 }                                                                             \
03947                                                                               \
03948 inline                                                                        \
03949 void                                                                          \
03950 fnc ( sc_fxval_fast& c, tp a, const sc_fxnum_fast& b )                        \
03951 {                                                                             \
03952     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03953     sc_fxval_fast tmp( a );                                                   \
03954     c.set_val( tmp.get_val() op b.m_val );                                    \
03955 }                                                                             \
03956                                                                               \
03957 inline                                                                        \
03958 void                                                                          \
03959 fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, tp b )                        \
03960 {                                                                             \
03961     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03962     sc_fxval_fast tmp( b );                                                   \
03963     c.m_val = a.m_val op tmp.get_val();                                       \
03964     c.cast();                                                                 \
03965     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
03966 }                                                                             \
03967                                                                               \
03968 inline                                                                        \
03969 void                                                                          \
03970 fnc ( sc_fxnum_fast& c, tp a, const sc_fxnum_fast& b )                        \
03971 {                                                                             \
03972     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03973     sc_fxval_fast tmp( a );                                                   \
03974     c.m_val = tmp.get_val() op b.m_val;                                       \
03975     c.cast();                                                                 \
03976     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
03977 }
03978 
03979 #ifndef SC_FX_EXCLUDE_OTHER
03980 #define DEFN_BIN_FNC_OTHER(fnc,op)                                            \
03981 DEFN_BIN_FNC_T(fnc,op,int64)                                                  \
03982 DEFN_BIN_FNC_T(fnc,op,uint64)                                                 \
03983 DEFN_BIN_FNC_T(fnc,op,const sc_int_base&)                                     \
03984 DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&)                                    \
03985 DEFN_BIN_FNC_T(fnc,op,const sc_signed&)                                       \
03986 DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)
03987 #else
03988 #define DEFN_BIN_FNC_OTHER(fnc,op)
03989 #endif
03990 
03991 #define DEFN_BIN_FNC(fnc,op)                                                  \
03992 inline                                                                        \
03993 void                                                                          \
03994 fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b )      \
03995 {                                                                             \
03996     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03997     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03998     c.set_val( a.m_val op b.m_val );                                          \
03999 }                                                                             \
04000                                                                               \
04001 inline                                                                        \
04002 void                                                                          \
04003 fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b )      \
04004 {                                                                             \
04005     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04006     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04007     c.m_val = a.m_val op b.m_val;                                             \
04008     c.cast();                                                                 \
04009     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
04010 }                                                                             \
04011                                                                               \
04012 inline                                                                        \
04013 void                                                                          \
04014 fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b )      \
04015 {                                                                             \
04016     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04017     c.set_val( a.m_val op b.get_val() );                                      \
04018 }                                                                             \
04019                                                                               \
04020 inline                                                                        \
04021 void                                                                          \
04022 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b )      \
04023 {                                                                             \
04024     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04025     c.set_val( a.get_val() op b.m_val );                                      \
04026 }                                                                             \
04027                                                                               \
04028 inline                                                                        \
04029 void                                                                          \
04030 fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b )      \
04031 {                                                                             \
04032     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04033     c.m_val = a.m_val op b.get_val();                                         \
04034     c.cast();                                                                 \
04035     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
04036 }                                                                             \
04037                                                                               \
04038 inline                                                                        \
04039 void                                                                          \
04040 fnc ( sc_fxnum_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b )      \
04041 {                                                                             \
04042     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04043     c.m_val = a.get_val() op b.m_val;                                         \
04044     c.cast();                                                                 \
04045     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
04046 }                                                                             \
04047                                                                               \
04048 DEFN_BIN_FNC_T(fnc,op,int)                                                    \
04049 DEFN_BIN_FNC_T(fnc,op,unsigned int)                                           \
04050 DEFN_BIN_FNC_T(fnc,op,long)                                                   \
04051 DEFN_BIN_FNC_T(fnc,op,unsigned long)                                          \
04052 DEFN_BIN_FNC_T(fnc,op,double)                                                 \
04053 DEFN_BIN_FNC_T(fnc,op,const char*)                                            \
04054 DEFN_BIN_FNC_T(fnc,op,const sc_fxval&)                                        \
04055 DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)                                        \
04056 DEFN_BIN_FNC_OTHER(fnc,op)
04057 
04058 DEFN_BIN_FNC(mult,*)
04059 DEFN_BIN_FNC(div,/)
04060 DEFN_BIN_FNC(add,+)
04061 DEFN_BIN_FNC(sub,-)
04062 
04063 #undef DEFN_BIN_FNC_T
04064 #undef DEFN_BIN_FNC_OTHER
04065 #undef DEFN_BIN_FNC
04066 
04067 
04068 inline
04069 void
04070 lshift( sc_fxval_fast& c, const sc_fxnum_fast& a, int b )
04071 {
04072     SC_FXNUM_FAST_OBSERVER_READ_( a )
04073     c.set_val( a.m_val * scfx_pow2( b ) );
04074 }
04075 
04076 inline
04077 void
04078 rshift( sc_fxval_fast& c, const sc_fxnum_fast& a, int b )
04079 {
04080     SC_FXNUM_FAST_OBSERVER_READ_( a )
04081     c.set_val( a.m_val * scfx_pow2( -b ) );
04082 }
04083 
04084 inline
04085 void
04086 lshift( sc_fxnum_fast& c, const sc_fxnum_fast& a, int b )
04087 {
04088     SC_FXNUM_FAST_OBSERVER_READ_( a )
04089     c.m_val = a.m_val * scfx_pow2( b );
04090     c.cast();
04091     SC_FXNUM_FAST_OBSERVER_WRITE_( c )
04092 }
04093 
04094 inline
04095 void
04096 rshift( sc_fxnum_fast& c, const sc_fxnum_fast& a, int b )
04097 {
04098     SC_FXNUM_FAST_OBSERVER_READ_( a )
04099     c.m_val = a.m_val * scfx_pow2( -b );
04100     c.cast();
04101     SC_FXNUM_FAST_OBSERVER_WRITE_( c )
04102 }
04103 
04104 
04105 // relational (including equality) operators
04106 
04107 #define DEFN_REL_OP_T(op,tp)                                                  \
04108 inline                                                                        \
04109 bool                                                                          \
04110 operator op ( const sc_fxnum_fast& a, tp b )                                  \
04111 {                                                                             \
04112     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04113     sc_fxval_fast tmp( b );                                                   \
04114     return ( a.m_val op tmp.get_val() );                                      \
04115 }                                                                             \
04116                                                                               \
04117 inline                                                                        \
04118 bool                                                                          \
04119 operator op ( tp a, const sc_fxnum_fast& b )                                  \
04120 {                                                                             \
04121     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04122     sc_fxval_fast tmp( a );                                                   \
04123     return ( tmp.get_val() op b.m_val );                                      \
04124 }
04125 
04126 #ifndef SC_FX_EXCLUDE_OTHER
04127 #define DEFN_REL_OP_OTHER(op)                                                 \
04128 DEFN_REL_OP_T(op,int64)                                                       \
04129 DEFN_REL_OP_T(op,uint64)                                                      \
04130 DEFN_REL_OP_T(op,const sc_int_base&)                                          \
04131 DEFN_REL_OP_T(op,const sc_uint_base&)                                         \
04132 DEFN_REL_OP_T(op,const sc_signed&)                                            \
04133 DEFN_REL_OP_T(op,const sc_unsigned&)
04134 #else
04135 #define DEFN_REL_OP_OTHER(op)
04136 #endif
04137 
04138 #define DEFN_REL_OP(op)                                                       \
04139 inline                                                                        \
04140 bool                                                                          \
04141 operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )                \
04142 {                                                                             \
04143     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04144     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04145     return ( a.m_val op b.m_val );                                            \
04146 }                                                                             \
04147                                                                               \
04148 inline                                                                        \
04149 bool                                                                          \
04150 operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b )                \
04151 {                                                                             \
04152     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04153     return ( a.m_val op b.get_val() );                                        \
04154 }                                                                             \
04155                                                                               \
04156 inline                                                                        \
04157 bool                                                                          \
04158 operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b )                \
04159 {                                                                             \
04160     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04161     return ( a.get_val() op b.m_val );                                        \
04162 }                                                                             \
04163                                                                               \
04164 DEFN_REL_OP_T(op,int)                                                         \
04165 DEFN_REL_OP_T(op,unsigned int)                                                \
04166 DEFN_REL_OP_T(op,long)                                                        \
04167 DEFN_REL_OP_T(op,unsigned long)                                               \
04168 DEFN_REL_OP_T(op,double)                                                      \
04169 DEFN_REL_OP_T(op,const char*)                                                 \
04170 DEFN_REL_OP_OTHER(op)
04171 
04172 DEFN_REL_OP(<)
04173 DEFN_REL_OP(<=)
04174 DEFN_REL_OP(>)
04175 DEFN_REL_OP(>=)
04176 DEFN_REL_OP(==)
04177 DEFN_REL_OP(!=)
04178 
04179 #undef DEFN_REL_OP_T
04180 #undef DEFN_REL_OP_OTHER
04181 #undef DEFN_REL_OP
04182 
04183 
04184 // assignment operators
04185 
04186 inline
04187 sc_fxnum_fast&
04188 sc_fxnum_fast::operator = ( const sc_fxnum_fast& a )
04189 {
04190     if( &a != this )
04191     {
04192     SC_FXNUM_FAST_OBSERVER_READ_( a )
04193     m_val = a.m_val;
04194     cast();
04195     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04196     }
04197     return *this;
04198 }
04199 
04200 inline
04201 sc_fxnum_fast&
04202 sc_fxnum_fast::operator = ( const sc_fxval_fast& a )
04203 {
04204     m_val = a.get_val();
04205     cast();
04206     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04207     return *this;
04208 }
04209 
04210 #define DEFN_ASN_OP_T(tp)                                                     \
04211 inline                                                                        \
04212 sc_fxnum_fast&                                                                \
04213 sc_fxnum_fast::operator = ( tp a )                                            \
04214 {                                                                             \
04215     sc_fxval_fast tmp( a );                                                   \
04216     m_val = tmp.get_val();                                                    \
04217     cast();                                                                   \
04218     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04219     return *this;                                                             \
04220 }
04221 
04222 DEFN_ASN_OP_T(int)
04223 DEFN_ASN_OP_T(unsigned int)
04224 DEFN_ASN_OP_T(long)
04225 DEFN_ASN_OP_T(unsigned long)
04226 DEFN_ASN_OP_T(double)
04227 DEFN_ASN_OP_T(const char*)
04228 DEFN_ASN_OP_T(const sc_fxval&)
04229 DEFN_ASN_OP_T(const sc_fxnum&)
04230 #ifndef SC_FX_EXCLUDE_OTHER
04231 DEFN_ASN_OP_T(int64)
04232 DEFN_ASN_OP_T(uint64)
04233 DEFN_ASN_OP_T(const sc_int_base&)
04234 DEFN_ASN_OP_T(const sc_uint_base&)
04235 DEFN_ASN_OP_T(const sc_signed&)
04236 DEFN_ASN_OP_T(const sc_unsigned&)
04237 #endif
04238 
04239 #undef DEFN_ASN_OP_T
04240 
04241 
04242 #define DEFN_ASN_OP_T(op,tp)                                                  \
04243 inline                                                                        \
04244 sc_fxnum_fast&                                                                \
04245 sc_fxnum_fast::operator op ( tp b )                                           \
04246 {                                                                             \
04247     SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
04248     sc_fxval_fast tmp( b );                                                   \
04249     m_val op tmp.get_val();                                                   \
04250     cast();                                                                   \
04251     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04252     return *this;                                                             \
04253 }
04254 
04255 #ifndef SC_FX_EXCLUDE_OTHER
04256 #define DEFN_ASN_OP_OTHER(op)                                                 \
04257 DEFN_ASN_OP_T(op,int64)                                                       \
04258 DEFN_ASN_OP_T(op,uint64)                                                      \
04259 DEFN_ASN_OP_T(op,const sc_int_base&)                                          \
04260 DEFN_ASN_OP_T(op,const sc_uint_base&)                                         \
04261 DEFN_ASN_OP_T(op,const sc_signed&)                                            \
04262 DEFN_ASN_OP_T(op,const sc_unsigned&)
04263 #else
04264 #define DEFN_ASN_OP_OTHER(op)
04265 #endif
04266 
04267 #define DEFN_ASN_OP(op)                                                       \
04268 inline                                                                        \
04269 sc_fxnum_fast&                                                                \
04270 sc_fxnum_fast::operator op ( const sc_fxnum_fast& b )                         \
04271 {                                                                             \
04272     SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
04273     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04274     m_val op b.m_val;                                                         \
04275     cast();                                                                   \
04276     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04277     return *this;                                                             \
04278 }                                                                             \
04279                                                                               \
04280 inline                                                                        \
04281 sc_fxnum_fast&                                                                \
04282 sc_fxnum_fast::operator op ( const sc_fxval_fast& b )                         \
04283 {                                                                             \
04284     SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
04285     m_val op b.get_val();                                                     \
04286     cast();                                                                   \
04287     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04288     return *this;                                                             \
04289 }                                                                             \
04290                                                                               \
04291 DEFN_ASN_OP_T(op,int)                                                         \
04292 DEFN_ASN_OP_T(op,unsigned int)                                                \
04293 DEFN_ASN_OP_T(op,long)                                                        \
04294 DEFN_ASN_OP_T(op,unsigned long)                                               \
04295 DEFN_ASN_OP_T(op,double)                                                      \
04296 DEFN_ASN_OP_T(op,const char*)                                                 \
04297 DEFN_ASN_OP_T(op,const sc_fxval&)                                             \
04298 DEFN_ASN_OP_T(op,const sc_fxnum&)                                             \
04299 DEFN_ASN_OP_OTHER(op)
04300 
04301 DEFN_ASN_OP(*=)
04302 DEFN_ASN_OP(/=)
04303 DEFN_ASN_OP(+=)
04304 DEFN_ASN_OP(-=)
04305 
04306 #undef DEFN_ASN_OP_T
04307 #undef DEFN_ASN_OP_OTHER
04308 #undef DEFN_ASN_OP
04309 
04310 
04311 inline
04312 sc_fxnum_fast&
04313 sc_fxnum_fast::operator <<= ( int b )
04314 {
04315     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04316     m_val *= scfx_pow2( b );
04317     cast();
04318     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04319     return *this;
04320 }
04321 
04322 inline
04323 sc_fxnum_fast&
04324 sc_fxnum_fast::operator >>= ( int b )
04325 {
04326     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04327     m_val *= scfx_pow2( -b );
04328     cast();
04329     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04330     return *this;
04331 }
04332 
04333 
04334 // auto-increment and auto-decrement
04335 
04336 inline
04337 const sc_fxval_fast
04338 sc_fxnum_fast::operator ++ ( int )
04339 {
04340     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04341     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04342     double c = m_val;
04343     m_val = m_val + 1;
04344     cast();
04345     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04346     return sc_fxval_fast( c );
04347 }
04348 
04349 inline
04350 const sc_fxval_fast
04351 sc_fxnum_fast::operator -- ( int )
04352 {
04353     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04354     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04355     double c = m_val;
04356     m_val = m_val - 1;
04357     cast();
04358     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04359     return sc_fxval_fast( c );
04360 }
04361 
04362 inline
04363 sc_fxnum_fast&
04364 sc_fxnum_fast::operator ++ ()
04365 {
04366     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04367     m_val = m_val + 1;
04368     cast();
04369     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04370     return *this;
04371 }
04372 
04373 inline
04374 sc_fxnum_fast&
04375 sc_fxnum_fast::operator -- ()
04376 {
04377     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04378     m_val = m_val - 1;
04379     cast();
04380     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04381     return *this;
04382 }
04383 
04384 
04385 // bit selection
04386 
04387 inline
04388 const sc_fxnum_fast_bitref
04389 sc_fxnum_fast::operator [] ( int i ) const
04390 {
04391     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04392     return sc_fxnum_fast_bitref( const_cast<sc_fxnum_fast&>( *this ),
04393                  i - m_params.fwl() );
04394 }
04395 
04396 inline
04397 sc_fxnum_fast_bitref
04398 sc_fxnum_fast::operator [] ( int i )
04399 {
04400     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04401     return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
04402 }
04403 
04404 inline
04405 const sc_fxnum_fast_bitref
04406 sc_fxnum_fast::bit( int i ) const
04407 {
04408     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04409     return sc_fxnum_fast_bitref( const_cast<sc_fxnum_fast&>( *this ),
04410                  i - m_params.fwl() );
04411 }
04412 
04413 inline
04414 sc_fxnum_fast_bitref
04415 sc_fxnum_fast::bit( int i )
04416 {
04417     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04418     return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
04419 }
04420 
04421 
04422 // part selection
04423 
04424 inline
04425 const sc_fxnum_fast_subref
04426 sc_fxnum_fast::operator () ( int i, int j ) const
04427 {
04428     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04429     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04430 
04431     return sc_fxnum_fast_subref( const_cast<sc_fxnum_fast&>( *this ),
04432                  i - m_params.fwl(), j - m_params.fwl() );
04433 }
04434 
04435 inline
04436 sc_fxnum_fast_subref
04437 sc_fxnum_fast::operator () ( int i, int j )
04438 {
04439     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04440     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04441 
04442     return sc_fxnum_fast_subref( *this,
04443                  i - m_params.fwl(), j - m_params.fwl() );
04444 }
04445 
04446 inline
04447 const sc_fxnum_fast_subref
04448 sc_fxnum_fast::range( int i, int j ) const
04449 {
04450     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04451     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04452 
04453     return sc_fxnum_fast_subref( const_cast<sc_fxnum_fast&>( *this ),
04454                  i - m_params.fwl(), j - m_params.fwl() );
04455 }
04456 
04457 inline
04458 sc_fxnum_fast_subref
04459 sc_fxnum_fast::range( int i, int j )
04460 {
04461     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04462     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04463 
04464     return sc_fxnum_fast_subref( *this,
04465                  i - m_params.fwl(), j - m_params.fwl() );
04466 }
04467 
04468 inline
04469 const sc_fxnum_fast_subref
04470 sc_fxnum_fast::operator () () const
04471 {
04472     return this->operator () ( m_params.wl() - 1, 0 );
04473 }
04474 
04475 inline
04476 sc_fxnum_fast_subref
04477 sc_fxnum_fast::operator () ()
04478 {
04479     return this->operator () ( m_params.wl() - 1, 0 );
04480 }
04481 
04482 inline
04483 const sc_fxnum_fast_subref
04484 sc_fxnum_fast::range() const
04485 {
04486     return this->range( m_params.wl() - 1, 0 );
04487 }
04488 
04489 inline
04490 sc_fxnum_fast_subref
04491 sc_fxnum_fast::range()
04492 {
04493     return this->range( m_params.wl() - 1, 0 );
04494 }
04495 
04496 
04497 // implicit conversion
04498 
04499 inline
04500 sc_fxnum_fast::operator double() const
04501 {
04502     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04503     return m_val;
04504 }
04505 
04506 
04507 // explicit conversion to primitive types
04508 
04509 inline
04510 short
04511 sc_fxnum_fast::to_short() const
04512 {
04513     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04514     return static_cast<short>( m_val );
04515 }
04516 
04517 inline
04518 unsigned short
04519 sc_fxnum_fast::to_ushort() const
04520 {
04521     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04522     return static_cast<unsigned short>( m_val );
04523 }
04524 
04525 inline
04526 int
04527 sc_fxnum_fast::to_int() const
04528 {
04529     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04530     return static_cast<int>( m_val );
04531 }
04532 
04533 inline
04534 int64
04535 sc_fxnum_fast::to_int64() const
04536 {
04537     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04538     return static_cast<int64>( m_val );
04539 }
04540 
04541 inline
04542 unsigned int
04543 sc_fxnum_fast::to_uint() const
04544 {
04545     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04546     return static_cast<unsigned int>( m_val );
04547 }
04548 
04549 inline
04550 uint64
04551 sc_fxnum_fast::to_uint64() const
04552 {
04553     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04554     return static_cast<uint64>( m_val );
04555 }
04556 
04557 inline
04558 long
04559 sc_fxnum_fast::to_long() const
04560 {
04561     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04562     return static_cast<long>( m_val );
04563 }
04564 
04565 inline
04566 unsigned long
04567 sc_fxnum_fast::to_ulong() const
04568 {
04569     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04570     return static_cast<unsigned long>( m_val );
04571 }
04572 
04573 inline
04574 float
04575 sc_fxnum_fast::to_float() const
04576 {
04577     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04578     return static_cast<float>( m_val );
04579 }
04580 
04581 inline
04582 double
04583 sc_fxnum_fast::to_double() const
04584 {
04585     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04586     return m_val;
04587 }
04588 
04589 
04590 // query value
04591 
04592 inline
04593 bool
04594 sc_fxnum_fast::is_neg() const
04595 {
04596     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04597     scfx_ieee_double id( m_val );
04598     return ( id.negative() != 0 );
04599 }
04600 
04601 inline
04602 bool
04603 sc_fxnum_fast::is_zero() const
04604 {
04605     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04606     scfx_ieee_double id( m_val );
04607     return id.is_zero();
04608 }
04609 
04610 // internal use only;
04611 inline
04612 bool
04613 sc_fxnum_fast::is_normal() const
04614 {
04615     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04616     scfx_ieee_double id( m_val );
04617     return ( id.is_normal() || id.is_subnormal() || id.is_zero() );
04618 }
04619 
04620 
04621 inline
04622 bool
04623 sc_fxnum_fast::quantization_flag() const
04624 {
04625     return m_q_flag;
04626 }
04627 
04628 inline
04629 bool
04630 sc_fxnum_fast::overflow_flag() const
04631 {
04632     return m_o_flag;
04633 }
04634 
04635 
04636 inline
04637 const sc_fxval_fast
04638 sc_fxnum_fast::value() const
04639 {
04640     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04641     return sc_fxval_fast( m_val );
04642 }
04643 
04644 
04645 // query parameters
04646 
04647 inline
04648 int
04649 sc_fxnum_fast::wl() const
04650 {
04651     return m_params.wl();
04652 }
04653 
04654 inline
04655 int
04656 sc_fxnum_fast::iwl() const
04657 {
04658     return m_params.iwl();
04659 }
04660 
04661 inline
04662 sc_q_mode
04663 sc_fxnum_fast::q_mode() const
04664 {
04665     return m_params.q_mode();
04666 }
04667 
04668 inline
04669 sc_o_mode
04670 sc_fxnum_fast::o_mode() const
04671 {
04672     return m_params.o_mode();
04673 }
04674 
04675 inline
04676 int
04677 sc_fxnum_fast::n_bits() const
04678 {
04679     return m_params.n_bits();
04680 }
04681 
04682 
04683 inline
04684 const sc_fxtype_params&
04685 sc_fxnum_fast::type_params() const
04686 {
04687     return m_params.type_params();
04688 }
04689 
04690 
04691 inline
04692 const sc_fxcast_switch&
04693 sc_fxnum_fast::cast_switch() const
04694 {
04695     return m_params.cast_switch();
04696 }
04697 
04698 
04699 // internal use only;
04700 inline
04701 void
04702 sc_fxnum_fast::observer_read() const
04703 {
04704     SC_FXNUM_OBSERVER_READ_( *this );
04705 }
04706 
04707 
04708 inline
04709 ::std::ostream&
04710 operator << ( ::std::ostream& os, const sc_fxnum_fast& a )
04711 {
04712     a.print( os );
04713     return os;
04714 }
04715 
04716 inline
04717 ::std::istream&
04718 operator >> ( ::std::istream& is, sc_fxnum_fast& a )
04719 {
04720     a.scan( is );
04721     return is;
04722 }
04723 
04724 
04725 // ----------------------------------------------------------------------------
04726 //  CLASS : sc_fxval
04727 //
04728 //  Fixed-point value type; arbitrary precision.
04729 // ----------------------------------------------------------------------------
04730 
04731 // public constructors
04732 
04733 inline
04734 sc_fxval::sc_fxval( const sc_fxnum& a,
04735             sc_fxval_observer* observer_ )
04736 : m_rep( new scfx_rep( *a.get_rep() ) ),
04737   m_observer( observer_ )
04738 {
04739     SC_FXVAL_OBSERVER_DEFAULT_
04740     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
04741     SC_FXVAL_OBSERVER_WRITE_( *this )
04742 }
04743 
04744 inline
04745 sc_fxval::sc_fxval( const sc_fxnum_fast& a,
04746             sc_fxval_observer* observer_ )
04747 : m_rep( new scfx_rep( a.to_double() ) ),
04748   m_observer( observer_ )
04749 {
04750     SC_FXVAL_OBSERVER_DEFAULT_
04751     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
04752     SC_FXVAL_OBSERVER_WRITE_( *this )
04753 }
04754 
04755 
04756 // binary operators
04757 
04758 #define DEFN_BIN_OP_T(op,fnc,tp)                                              \
04759 inline                                                                        \
04760 const sc_fxval                                                                \
04761 operator op ( const sc_fxval& a, tp b )                                       \
04762 {                                                                             \
04763     SC_FXVAL_OBSERVER_READ_( a )                                              \
04764     sc_fxval tmp( b );                                                        \
04765     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) );      \
04766 }                                                                             \
04767                                                                               \
04768 inline                                                                        \
04769 const sc_fxval                                                                \
04770 operator op ( tp a, const sc_fxval& b )                                       \
04771 {                                                                             \
04772     SC_FXVAL_OBSERVER_READ_( b )                                              \
04773     sc_fxval tmp( a );                                                        \
04774     return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) );      \
04775 }
04776 
04777 #define DEFN_BIN_OP(op,fnc)                                                   \
04778 DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)
04779 
04780 DEFN_BIN_OP(*,mult)
04781 DEFN_BIN_OP(+,add)
04782 DEFN_BIN_OP(-,sub)
04783 //DEFN_BIN_OP(/,div)
04784 DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
04785 
04786 #undef DEFN_BIN_OP_T
04787 #undef DEFN_BIN_OP
04788 
04789 
04790 // binary functions
04791 
04792 #define DEFN_BIN_FNC_T(fnc,tp)                                                \
04793 inline                                                                        \
04794 void                                                                          \
04795 fnc ( sc_fxval& c, const sc_fxval& a, tp b )                                  \
04796 {                                                                             \
04797     SC_FXVAL_OBSERVER_READ_( a )                                              \
04798     sc_fxval tmp( b );                                                        \
04799     delete c.m_rep;                                                           \
04800     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep );               \
04801     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
04802 }                                                                             \
04803                                                                               \
04804 inline                                                                        \
04805 void                                                                          \
04806 fnc ( sc_fxval& c, tp a, const sc_fxval& b )                                  \
04807 {                                                                             \
04808     SC_FXVAL_OBSERVER_READ_( b )                                              \
04809     sc_fxval tmp( a );                                                        \
04810     delete c.m_rep;                                                           \
04811     c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep );               \
04812     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
04813 }
04814 
04815 #define DEFN_BIN_FNC(fnc)                                                     \
04816 DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)
04817 
04818 DEFN_BIN_FNC(mult)
04819 DEFN_BIN_FNC(div)
04820 DEFN_BIN_FNC(add)
04821 DEFN_BIN_FNC(sub)
04822 
04823 #undef DEFN_BIN_FNC_T
04824 #undef DEFN_BIN_FNC
04825 
04826 
04827 // relational (including equality) operators
04828 
04829 #define DEFN_REL_OP_T(op,ret,tp)                                              \
04830 inline                                                                        \
04831 bool                                                                          \
04832 operator op ( const sc_fxval& a, tp b )                                       \
04833 {                                                                             \
04834     SC_FXVAL_OBSERVER_READ_( a )                                              \
04835     sc_fxval tmp( b );                                                        \
04836     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep );                \
04837     return ( ret );                                                           \
04838 }                                                                             \
04839                                                                               \
04840 inline                                                                        \
04841 bool                                                                          \
04842 operator op ( tp a, const sc_fxval& b )                                       \
04843 {                                                                             \
04844     SC_FXVAL_OBSERVER_READ_( b )                                              \
04845     sc_fxval tmp( a );                                                        \
04846     int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep );                \
04847     return ( ret );                                                           \
04848 }
04849 
04850 
04851 #define DEFN_REL_OP(op,ret)                                                   \
04852 DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)
04853 
04854 DEFN_REL_OP(<,result < 0)
04855 DEFN_REL_OP(<=,result <= 0)
04856 DEFN_REL_OP(>,result > 0 && result != 2)
04857 DEFN_REL_OP(>=,result >= 0 && result != 2)
04858 DEFN_REL_OP(==,result == 0)
04859 DEFN_REL_OP(!=,result != 0)
04860 
04861 #undef DEFN_REL_OP_T
04862 #undef DEFN_REL_OP
04863 
04864 
04865 // assignment operators
04866 
04867 inline
04868 sc_fxval&
04869 sc_fxval::operator = ( const sc_fxnum& a )
04870 {
04871     *m_rep = *a.get_rep();
04872     SC_FXVAL_OBSERVER_WRITE_( *this )
04873     return *this;
04874 }
04875 
04876 #define DEFN_ASN_OP_T(tp)                                                     \
04877 inline                                                                        \
04878 sc_fxval&                                                                     \
04879 sc_fxval::operator = ( tp b )                                                 \
04880 {                                                                             \
04881     sc_fxval tmp( b );                                                        \
04882     *m_rep = *tmp.m_rep;                                                      \
04883     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
04884     return *this;                                                             \
04885 }
04886 
04887 DEFN_ASN_OP_T(const sc_fxnum_fast&)
04888 
04889 #undef DEFN_ASN_OP_T
04890 
04891 
04892 #define DEFN_ASN_OP_T(op,fnc,tp)                                              \
04893 inline                                                                        \
04894 sc_fxval&                                                                     \
04895 sc_fxval::operator op ( tp b )                                                \
04896 {                                                                             \
04897     SC_FXVAL_OBSERVER_READ_( *this )                                          \
04898     sc_fxval tmp( b );                                                        \
04899     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep );       \
04900     delete m_rep;                                                             \
04901     m_rep = new_rep;                                                          \
04902     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
04903     return *this;                                                             \
04904 }
04905 
04906 #define DEFN_ASN_OP(op,fnc)                                                   \
04907 inline                                                                        \
04908 sc_fxval&                                                                     \
04909 sc_fxval::operator op ( const sc_fxnum& b )                                   \
04910 {                                                                             \
04911     SC_FXVAL_OBSERVER_READ_( *this )                                          \
04912     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() );     \
04913     delete m_rep;                                                             \
04914     m_rep = new_rep;                                                          \
04915     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
04916     return *this;                                                             \
04917 }                                                                             \
04918                                                                               \
04919 DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)
04920 
04921 DEFN_ASN_OP(*=,mult)
04922 DEFN_ASN_OP(/=,div)
04923 DEFN_ASN_OP(+=,add)
04924 DEFN_ASN_OP(-=,sub)
04925 
04926 #undef DEFN_ASN_OP_T
04927 #undef DEFN_ASN_OP
04928 
04929 
04930 // ----------------------------------------------------------------------------
04931 //  CLASS : sc_fxval_fast
04932 //
04933 //  Fixed-point value types; limited precision.
04934 // ----------------------------------------------------------------------------
04935 
04936 // public constructors
04937 
04938 inline
04939 sc_fxval_fast::sc_fxval_fast( const sc_fxnum& a,
04940                   sc_fxval_fast_observer* observer_ )
04941 : m_val( a.to_double() ),
04942   m_observer( observer_ )
04943 {
04944     SC_FXVAL_FAST_OBSERVER_DEFAULT_
04945     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
04946     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
04947 }
04948 
04949 inline
04950 sc_fxval_fast::sc_fxval_fast( const sc_fxnum_fast& a,
04951                   sc_fxval_fast_observer* observer_ )
04952 : m_val( a.get_val() ),
04953   m_observer( observer_ )
04954 {
04955     SC_FXVAL_FAST_OBSERVER_DEFAULT_
04956     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
04957     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
04958 }
04959 
04960 
04961 // binary functions
04962 
04963 #define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
04964 inline                                                                        \
04965 void                                                                          \
04966 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b )                        \
04967 {                                                                             \
04968     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
04969     sc_fxval_fast tmp( b );                                                   \
04970     c.m_val = a.m_val op tmp.m_val;                                           \
04971     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
04972 }                                                                             \
04973                                                                               \
04974 inline                                                                        \
04975 void                                                                          \
04976 fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b )                        \
04977 {                                                                             \
04978     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
04979     sc_fxval_fast tmp( a );                                                   \
04980     c.m_val = tmp.m_val op b.m_val;                                           \
04981     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
04982 }
04983 
04984 #define DEFN_BIN_FNC(fnc,op)                                                  \
04985 DEFN_BIN_FNC_T(fnc,op,const sc_fxval&)                                        \
04986 DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)
04987 
04988 DEFN_BIN_FNC(mult,*)
04989 DEFN_BIN_FNC(div,/)
04990 DEFN_BIN_FNC(add,+)
04991 DEFN_BIN_FNC(sub,-)
04992 
04993 #undef DEFN_BIN_FNC_T
04994 #undef DEFN_BIN_FNC
04995 
04996 
04997 // assignment operators
04998 
04999 inline
05000 sc_fxval_fast&
05001 sc_fxval_fast::operator = ( const sc_fxnum_fast& a )
05002 {
05003     m_val = a.get_val();
05004     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
05005     return *this;
05006 }
05007 
05008 #define DEFN_ASN_OP_T(tp)                                                     \
05009 inline                                                                        \
05010 sc_fxval_fast&                                                                \
05011 sc_fxval_fast::operator = ( tp a )                                            \
05012 {                                                                             \
05013     sc_fxval_fast tmp( a );                                                   \
05014     m_val = tmp.m_val;                                                        \
05015     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
05016     return *this;                                                             \
05017 }
05018 
05019 DEFN_ASN_OP_T(const sc_fxnum&)
05020 
05021 #undef DEFN_ASN_OP_T
05022 
05023 
05024 #define DEFN_ASN_OP_T(op,tp)                                                  \
05025 inline                                                                        \
05026 sc_fxval_fast&                                                                \
05027 sc_fxval_fast::operator op ( tp b )                                           \
05028 {                                                                             \
05029     SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
05030     sc_fxval_fast tmp( b );                                                   \
05031     m_val op tmp.m_val;                                                       \
05032     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
05033     return *this;                                                             \
05034 }
05035 
05036 #define DEFN_ASN_OP(op)                                                       \
05037 inline                                                                        \
05038 sc_fxval_fast&                                                                \
05039 sc_fxval_fast::operator op ( const sc_fxnum_fast& b )                         \
05040 {                                                                             \
05041     SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
05042     m_val op b.get_val();                                                     \
05043     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
05044     return *this;                                                             \
05045 }                                                                             \
05046                                                                               \
05047 DEFN_ASN_OP_T(op,const sc_fxnum&)
05048 
05049 DEFN_ASN_OP(*=)
05050 DEFN_ASN_OP(/=)
05051 DEFN_ASN_OP(+=)
05052 DEFN_ASN_OP(-=)
05053 
05054 #undef DEFN_ASN_OP_T
05055 #undef DEFN_ASN_OP
05056 
05057 } // namespace sc_dt
05058 
05059 
05060 #endif
05061 
05062 // Taf!

Generated on Wed Jan 21 15:32:07 2009 for SystemC by  doxygen 1.5.5