sc_fxdefs.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_fxdefs.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_fxdefs.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:57  acg
00041 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
00042 // the source.
00043 //
00044 
00045 #ifndef SC_FXDEFS_H
00046 #define SC_FXDEFS_H
00047 
00048 
00049 #include "sysc/utils/sc_machine.h"
00050 #include "sysc/datatypes/fx/sc_fx_ids.h"
00051 #include "sysc/datatypes/int/sc_nbutils.h"
00052 #include "sysc/utils/sc_string.h"
00053 
00054 
00055 namespace sc_dt
00056 {
00057 
00058 // ----------------------------------------------------------------------------
00059 //  ENUM : sc_enc
00060 //
00061 //  Enumeration of sign encodings.
00062 // ----------------------------------------------------------------------------
00063 
00064 enum sc_enc
00065 {
00066     SC_TC_, // two's complement
00067     SC_US_  // unsigned
00068 };
00069 
00070 
00071 const std::string to_string( sc_enc );
00072 
00073 
00074 inline
00075 ::std::ostream&
00076 operator << ( ::std::ostream& os, sc_enc enc )
00077 {
00078     return os << to_string( enc );
00079 }
00080 
00081 
00082 // ----------------------------------------------------------------------------
00083 //  ENUM : sc_q_mode
00084 //
00085 //  Enumeration of quantization modes.
00086 // ----------------------------------------------------------------------------
00087 
00088 enum sc_q_mode
00089 {
00090     SC_RND,     // rounding to plus infinity
00091     SC_RND_ZERO,    // rounding to zero
00092     SC_RND_MIN_INF, // rounding to minus infinity
00093     SC_RND_INF,     // rounding to infinity
00094     SC_RND_CONV,    // convergent rounding
00095     SC_TRN,     // truncation
00096     SC_TRN_ZERO     // truncation to zero
00097 };
00098 
00099 
00100 const std::string to_string( sc_q_mode );
00101 
00102 
00103 inline
00104 ::std::ostream&
00105 operator << ( ::std::ostream& os, sc_q_mode q_mode )
00106 {
00107     return os << to_string( q_mode );
00108 }
00109 
00110 
00111 // ----------------------------------------------------------------------------
00112 //  ENUM : sc_o_mode
00113 //
00114 //  Enumeration of overflow modes.
00115 // ----------------------------------------------------------------------------
00116 
00117 enum sc_o_mode
00118 {
00119     SC_SAT,     // saturation
00120     SC_SAT_ZERO,    // saturation to zero
00121     SC_SAT_SYM,     // symmetrical saturation
00122     SC_WRAP,        // wrap-around (*)
00123     SC_WRAP_SM      // sign magnitude wrap-around (*)
00124 };
00125 
00126 // (*) uses the number of saturated bits argument, see the documentation.
00127 
00128 
00129 const std::string to_string( sc_o_mode );
00130 
00131 
00132 inline
00133 ::std::ostream&
00134 operator << ( ::std::ostream& os, sc_o_mode o_mode )
00135 {
00136     return os << to_string( o_mode );
00137 }
00138 
00139 
00140 // ----------------------------------------------------------------------------
00141 //  ENUM : sc_switch
00142 //
00143 //  Enumeration of switch states.
00144 // ----------------------------------------------------------------------------
00145 
00146 enum sc_switch
00147 {
00148     SC_OFF,
00149     SC_ON
00150 };
00151 
00152 
00153 const std::string to_string( sc_switch );
00154 
00155 
00156 inline
00157 ::std::ostream&
00158 operator << ( ::std::ostream& os, sc_switch sw )
00159 {
00160     return os << to_string( sw );
00161 }
00162 
00163 
00164 // ----------------------------------------------------------------------------
00165 //  ENUM : sc_fmt
00166 //
00167 //  Enumeration of formats for character string conversion.
00168 // ----------------------------------------------------------------------------
00169 
00170 enum sc_fmt
00171 {
00172     SC_F,   // fixed
00173     SC_E    // scientific
00174 };
00175 
00176 
00177 const std::string to_string( sc_fmt );
00178 
00179 
00180 inline
00181 ::std::ostream&
00182 operator << ( ::std::ostream& os, sc_fmt fmt )
00183 {
00184     return os << to_string( fmt );
00185 }
00186 
00187 
00188 // ----------------------------------------------------------------------------
00189 //  Built-in & default fixed-point type parameter values.
00190 // ----------------------------------------------------------------------------
00191 
00192 const int       SC_BUILTIN_WL_     = 32;
00193 const int       SC_BUILTIN_IWL_    = 32;
00194 const sc_q_mode SC_BUILTIN_Q_MODE_ = SC_TRN;
00195 const sc_o_mode SC_BUILTIN_O_MODE_ = SC_WRAP;
00196 const int       SC_BUILTIN_N_BITS_ = 0;
00197 
00198 
00199 const int       SC_DEFAULT_WL_     = SC_BUILTIN_WL_;
00200 const int       SC_DEFAULT_IWL_    = SC_BUILTIN_IWL_;
00201 const sc_q_mode SC_DEFAULT_Q_MODE_ = SC_BUILTIN_Q_MODE_;
00202 const sc_o_mode SC_DEFAULT_O_MODE_ = SC_BUILTIN_O_MODE_;
00203 const int       SC_DEFAULT_N_BITS_ = SC_BUILTIN_N_BITS_;
00204 
00205 
00206 // ----------------------------------------------------------------------------
00207 //  Built-in & default fixed-point cast switch parameter values.
00208 // ----------------------------------------------------------------------------
00209 
00210 const sc_switch SC_BUILTIN_CAST_SWITCH_ = SC_ON;
00211 
00212 
00213 const sc_switch SC_DEFAULT_CAST_SWITCH_ = SC_BUILTIN_CAST_SWITCH_;
00214 
00215 
00216 // ----------------------------------------------------------------------------
00217 //  Built-in & default fixed-point value type parameter values.
00218 // ----------------------------------------------------------------------------
00219 
00220 const int SC_BUILTIN_DIV_WL_ = 64;
00221 const int SC_BUILTIN_CTE_WL_ = 64;
00222 const int SC_BUILTIN_MAX_WL_ = 1024;
00223 
00224 
00225 #if defined( SC_FXDIV_WL ) && ( SC_FXDIV_WL > 0 )
00226 const int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL;
00227 #else
00228 const int SC_DEFAULT_DIV_WL_ = SC_BUILTIN_DIV_WL_;
00229 #endif
00230 
00231 #if defined( SC_FXCTE_WL ) && ( SC_FXCTE_WL > 0 )
00232 const int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL;
00233 #else
00234 const int SC_DEFAULT_CTE_WL_ = SC_BUILTIN_CTE_WL_;
00235 #endif
00236 
00237 #if defined( SC_FXMAX_WL ) && ( SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1 )
00238 const int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL;
00239 #else
00240 const int SC_DEFAULT_MAX_WL_ = SC_BUILTIN_MAX_WL_;
00241 #endif
00242 
00243 
00244 // ----------------------------------------------------------------------------
00245 //  Dedicated error reporting and checking.
00246 // ----------------------------------------------------------------------------
00247 
00248 #ifdef DEBUG_SYSTEMC
00249 #define SC_ASSERT_(cnd,msg)                                                   \
00250 {                                                                             \
00251     if( ! (cnd) )                                                             \
00252         SC_REPORT_ERROR( sc_core::SC_ID_INTERNAL_ERROR_, msg );                        \
00253 }
00254 #else
00255 #define SC_ASSERT_(cnd,msg)
00256 #endif
00257 
00258 #define SC_ERROR_IF_(cnd,id)                                                  \
00259 {                                                                             \
00260     if( cnd )                                                                 \
00261         SC_REPORT_ERROR( id, 0 );                                             \
00262 }
00263 
00264 
00265 #define SC_CHECK_WL_(wl)                                                      \
00266     SC_ERROR_IF_( (wl) <= 0, sc_core::SC_ID_INVALID_WL_ )
00267 
00268 #define SC_CHECK_N_BITS_(n_bits)                                              \
00269     SC_ERROR_IF_( (n_bits) < 0, sc_core::SC_ID_INVALID_N_BITS_ )
00270 
00271 #define SC_CHECK_DIV_WL_(div_wl)                                              \
00272     SC_ERROR_IF_( (div_wl) <= 0, sc_core::SC_ID_INVALID_DIV_WL_ )
00273 
00274 #define SC_CHECK_CTE_WL_(cte_wl)                                              \
00275     SC_ERROR_IF_( (cte_wl) <= 0, sc_core::SC_ID_INVALID_CTE_WL_ )
00276 
00277 #define SC_CHECK_MAX_WL_(max_wl)                                              \
00278     SC_ERROR_IF_( (max_wl) <= 0 && (max_wl) != -1,                            \
00279         sc_core::SC_ID_INVALID_MAX_WL_ )
00280 
00281 
00282 // ----------------------------------------------------------------------------
00283 //  Generic observer macros.
00284 // ----------------------------------------------------------------------------
00285 
00286 #define SC_OBSERVER_(object,observer_type,event)                              \
00287 {                                                                             \
00288     if( (object).observer() != 0 )                                            \
00289     {                                                                         \
00290     observer_type observer = (object).lock_observer();                    \
00291     observer->event( (object) );                                          \
00292     (object).unlock_observer( observer );                                 \
00293     }                                                                         \
00294 }
00295 
00296 #define SC_OBSERVER_DEFAULT_(observer_type)                                   \
00297 {                                                                             \
00298     if( m_observer == 0 && observer_type ## ::default_observer != 0 )         \
00299         m_observer = (* ## observer_type ## ::default_observer)();            \
00300 }
00301 
00302 } // namespace sc_dt
00303 
00304 
00305 #endif
00306 
00307 // Taf!

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