SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_fxdefs.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_fxdefs.h -
21 
22  Original Author: Martin Janssen, Synopsys, Inc.
23 
24  *****************************************************************************/
25 
26 /*****************************************************************************
27 
28  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
29  changes you are making here.
30 
31  Name, Affiliation, Date:
32  Description of Modification:
33 
34  *****************************************************************************/
35 
36 // $Log: sc_fxdefs.h,v $
37 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
38 // SystemC 2.3
39 //
40 // Revision 1.3 2006/01/13 18:53:57 acg
41 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
42 // the source.
43 //
44 
45 #ifndef SC_FXDEFS_H
46 #define SC_FXDEFS_H
47 
48 
49 #include "sysc/utils/sc_machine.h"
52 
53 
54 namespace sc_dt
55 {
56 
57 // ----------------------------------------------------------------------------
58 // ENUM : sc_enc
59 //
60 // Enumeration of sign encodings.
61 // ----------------------------------------------------------------------------
62 
63 enum sc_enc
64 {
65  SC_TC_, // two's complement
66  SC_US_ // unsigned
67 };
68 
69 
70 const std::string to_string( sc_enc );
71 
72 
73 inline
74 ::std::ostream&
75 operator << ( ::std::ostream& os, sc_enc enc )
76 {
77  return os << to_string( enc );
78 }
79 
80 
81 // ----------------------------------------------------------------------------
82 // ENUM : sc_q_mode
83 //
84 // Enumeration of quantization modes.
85 // ----------------------------------------------------------------------------
86 
88 {
89  SC_RND, // rounding to plus infinity
90  SC_RND_ZERO, // rounding to zero
91  SC_RND_MIN_INF, // rounding to minus infinity
92  SC_RND_INF, // rounding to infinity
93  SC_RND_CONV, // convergent rounding
94  SC_TRN, // truncation
95  SC_TRN_ZERO // truncation to zero
96 };
97 
98 
99 const std::string to_string( sc_q_mode );
100 
101 
102 inline
103 ::std::ostream&
104 operator << ( ::std::ostream& os, sc_q_mode q_mode )
105 {
106  return os << to_string( q_mode );
107 }
108 
109 
110 // ----------------------------------------------------------------------------
111 // ENUM : sc_o_mode
112 //
113 // Enumeration of overflow modes.
114 // ----------------------------------------------------------------------------
115 
117 {
118  SC_SAT, // saturation
119  SC_SAT_ZERO, // saturation to zero
120  SC_SAT_SYM, // symmetrical saturation
121  SC_WRAP, // wrap-around (*)
122  SC_WRAP_SM // sign magnitude wrap-around (*)
123 };
124 
125 // (*) uses the number of saturated bits argument, see the documentation.
126 
127 
128 const std::string to_string( sc_o_mode );
129 
130 
131 inline
132 ::std::ostream&
133 operator << ( ::std::ostream& os, sc_o_mode o_mode )
134 {
135  return os << to_string( o_mode );
136 }
137 
138 
139 // ----------------------------------------------------------------------------
140 // ENUM : sc_switch
141 //
142 // Enumeration of switch states.
143 // ----------------------------------------------------------------------------
144 
146 {
149 };
150 
151 
152 const std::string to_string( sc_switch );
153 
154 
155 inline
156 ::std::ostream&
157 operator << ( ::std::ostream& os, sc_switch sw )
158 {
159  return os << to_string( sw );
160 }
161 
162 
163 // ----------------------------------------------------------------------------
164 // ENUM : sc_fmt
165 //
166 // Enumeration of formats for character string conversion.
167 // ----------------------------------------------------------------------------
168 
169 enum sc_fmt
170 {
171  SC_F, // fixed
172  SC_E // scientific
173 };
174 
175 
176 const std::string to_string( sc_fmt );
177 
178 
179 inline
180 ::std::ostream&
181 operator << ( ::std::ostream& os, sc_fmt fmt )
182 {
183  return os << to_string( fmt );
184 }
185 
186 
187 // ----------------------------------------------------------------------------
188 // Built-in & default fixed-point type parameter values.
189 // ----------------------------------------------------------------------------
190 
191 const int SC_BUILTIN_WL_ = 32;
192 const int SC_BUILTIN_IWL_ = 32;
195 const int SC_BUILTIN_N_BITS_ = 0;
196 
197 
203 
204 
205 // ----------------------------------------------------------------------------
206 // Built-in & default fixed-point cast switch parameter values.
207 // ----------------------------------------------------------------------------
208 
210 
211 
213 
214 
215 // ----------------------------------------------------------------------------
216 // Built-in & default fixed-point value type parameter values.
217 // ----------------------------------------------------------------------------
218 
219 const int SC_BUILTIN_DIV_WL_ = 64;
220 const int SC_BUILTIN_CTE_WL_ = 64;
221 const int SC_BUILTIN_MAX_WL_ = 1024;
222 
223 
224 #if defined( SC_FXDIV_WL ) && ( SC_FXDIV_WL > 0 )
225 const int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL;
226 #else
228 #endif
229 
230 #if defined( SC_FXCTE_WL ) && ( SC_FXCTE_WL > 0 )
231 const int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL;
232 #else
234 #endif
235 
236 #if defined( SC_FXMAX_WL ) && ( SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1 )
237 const int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL;
238 #else
240 #endif
241 
242 
243 // ----------------------------------------------------------------------------
244 // Dedicated error reporting and checking.
245 // ----------------------------------------------------------------------------
246 
247 #ifdef DEBUG_SYSTEMC
248 #define SC_ASSERT_(cnd,msg) \
249 { \
250  if( ! (cnd) ) \
251  SC_REPORT_ERROR( sc_core::SC_ID_INTERNAL_ERROR_, msg ); \
252 }
253 #else
254 #define SC_ASSERT_(cnd,msg)
255 #endif
256 
257 #define SC_ERROR_IF_(cnd,id) \
258 { \
259  if( cnd ) \
260  SC_REPORT_ERROR( id, 0 ); \
261 }
262 
263 
264 #define SC_CHECK_WL_(wl) \
265  SC_ERROR_IF_( (wl) <= 0, sc_core::SC_ID_INVALID_WL_ )
266 
267 #define SC_CHECK_N_BITS_(n_bits) \
268  SC_ERROR_IF_( (n_bits) < 0, sc_core::SC_ID_INVALID_N_BITS_ )
269 
270 #define SC_CHECK_DIV_WL_(div_wl) \
271  SC_ERROR_IF_( (div_wl) <= 0, sc_core::SC_ID_INVALID_DIV_WL_ )
272 
273 #define SC_CHECK_CTE_WL_(cte_wl) \
274  SC_ERROR_IF_( (cte_wl) <= 0, sc_core::SC_ID_INVALID_CTE_WL_ )
275 
276 #define SC_CHECK_MAX_WL_(max_wl) \
277  SC_ERROR_IF_( (max_wl) <= 0 && (max_wl) != -1, \
278  sc_core::SC_ID_INVALID_MAX_WL_ )
279 
280 
281 // ----------------------------------------------------------------------------
282 // Generic observer macros.
283 // ----------------------------------------------------------------------------
284 
285 #define SC_OBSERVER_(object,observer_type,event) \
286 { \
287  if( (object).observer() != 0 ) \
288  { \
289  observer_type observer = (object).lock_observer(); \
290  observer->event( (object) ); \
291  (object).unlock_observer( observer ); \
292  } \
293 }
294 
295 #define SC_OBSERVER_DEFAULT_(observer_type) \
296 { \
297  if( m_observer == 0 && observer_type ## ::default_observer != 0 ) \
298  m_observer = (* ## observer_type ## ::default_observer)(); \
299 }
300 
301 } // namespace sc_dt
302 
303 
304 #endif
305 
306 // Taf!
sc_enc
Definition: sc_fxdefs.h:63
const sc_q_mode SC_DEFAULT_Q_MODE_
Definition: sc_fxdefs.h:200
const int SC_DEFAULT_N_BITS_
Definition: sc_fxdefs.h:202
const int SC_DEFAULT_WL_
Definition: sc_fxdefs.h:198
const int SC_BUILTIN_WL_
Definition: sc_fxdefs.h:191
const int SC_BUILTIN_DIV_WL_
Definition: sc_fxdefs.h:219
const int SC_DEFAULT_DIV_WL_
Definition: sc_fxdefs.h:227
const int SC_BUILTIN_IWL_
Definition: sc_fxdefs.h:192
const int SC_BUILTIN_N_BITS_
Definition: sc_fxdefs.h:195
const int SC_DEFAULT_IWL_
Definition: sc_fxdefs.h:199
sc_o_mode
Definition: sc_fxdefs.h:116
const std::string to_string(sc_enc)
const int SC_BUILTIN_MAX_WL_
Definition: sc_fxdefs.h:221
const sc_o_mode SC_DEFAULT_O_MODE_
Definition: sc_fxdefs.h:201
const sc_q_mode SC_BUILTIN_Q_MODE_
Definition: sc_fxdefs.h:193
sc_switch
Definition: sc_fxdefs.h:145
const int SC_BUILTIN_CTE_WL_
Definition: sc_fxdefs.h:220
const int SC_DEFAULT_MAX_WL_
Definition: sc_fxdefs.h:239
sc_q_mode
Definition: sc_fxdefs.h:87
const sc_o_mode SC_BUILTIN_O_MODE_
Definition: sc_fxdefs.h:194
const sc_switch SC_DEFAULT_CAST_SWITCH_
Definition: sc_fxdefs.h:212
const int SC_DEFAULT_CTE_WL_
Definition: sc_fxdefs.h:233
const sc_switch SC_BUILTIN_CAST_SWITCH_
Definition: sc_fxdefs.h:209
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:386