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