SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_fxdefs.h
Go to the documentation of this file.
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
55
56
57namespace sc_dt
58{
59
60// ----------------------------------------------------------------------------
61// ENUM : sc_enc
62//
63// Enumeration of sign encodings.
64// ----------------------------------------------------------------------------
65
67{
68 SC_TC_, // two's complement
69 SC_US_ // unsigned
70};
71
72
73SC_API std::string to_string( sc_enc );
74
75
76inline
77::std::ostream&
78operator << ( ::std::ostream& os, sc_enc enc )
79{
80 return os << to_string( enc );
81}
82
83
84// ----------------------------------------------------------------------------
85// ENUM : sc_q_mode
86//
87// Enumeration of quantization modes.
88// ----------------------------------------------------------------------------
89
91{
92 SC_RND, // rounding to plus infinity
93 SC_RND_ZERO, // rounding to zero
94 SC_RND_MIN_INF, // rounding to minus infinity
95 SC_RND_INF, // rounding to infinity
96 SC_RND_CONV, // convergent rounding
97 SC_TRN, // truncation
98 SC_TRN_ZERO // truncation to zero
99};
100
101
103
104
105inline
106::std::ostream&
107operator << ( ::std::ostream& os, sc_q_mode q_mode )
108{
109 return os << to_string( q_mode );
110}
111
112
113// ----------------------------------------------------------------------------
114// ENUM : sc_o_mode
115//
116// Enumeration of overflow modes.
117// ----------------------------------------------------------------------------
118
120{
121 SC_SAT, // saturation
122 SC_SAT_ZERO, // saturation to zero
123 SC_SAT_SYM, // symmetrical saturation
124 SC_WRAP, // wrap-around (*)
125 SC_WRAP_SM // sign magnitude wrap-around (*)
127
128// (*) uses the number of saturated bits argument, see the documentation.
129
130
132
133
134inline
135::std::ostream&
136operator << ( ::std::ostream& os, sc_o_mode o_mode )
137{
138 return os << to_string( o_mode );
139}
140
141
142// ----------------------------------------------------------------------------
143// ENUM : sc_switch
144//
145// Enumeration of switch states.
146// ----------------------------------------------------------------------------
147
149{
151 SC_ON
153
154
156
157
158inline
159::std::ostream&
160operator << ( ::std::ostream& os, sc_switch sw )
161{
162 return os << to_string( sw );
163}
164
165
166// ----------------------------------------------------------------------------
167// ENUM : sc_fmt
168//
169// Enumeration of formats for character string conversion.
170// ----------------------------------------------------------------------------
171
173{
174 SC_F, // fixed
175 SC_E // scientific
177
178
179SC_API std::string to_string( sc_fmt );
180
181
182inline
183::std::ostream&
184operator << ( ::std::ostream& os, sc_fmt fmt )
185{
186 return os << to_string( fmt );
187}
188
189
190// ----------------------------------------------------------------------------
191// Built-in & default fixed-point type parameter values.
192// ----------------------------------------------------------------------------
193
194const int SC_BUILTIN_WL_ = 32;
195const int SC_BUILTIN_IWL_ = 32;
198const int SC_BUILTIN_N_BITS_ = 0;
199
200
206
207
208// ----------------------------------------------------------------------------
209// Built-in & default fixed-point cast switch parameter values.
210// ----------------------------------------------------------------------------
211
213
214
216
217
218// ----------------------------------------------------------------------------
219// Built-in & default fixed-point value type parameter values.
220// ----------------------------------------------------------------------------
221
222const int SC_BUILTIN_DIV_WL_ = 64;
223const int SC_BUILTIN_CTE_WL_ = 64;
224const int SC_BUILTIN_MAX_WL_ = 1024;
225
226
227#if defined( SC_FXDIV_WL ) && ( SC_FXDIV_WL > 0 )
228const int SC_DEFAULT_DIV_WL_ = SC_FXDIV_WL;
229#else
231#endif
232
233#if defined( SC_FXCTE_WL ) && ( SC_FXCTE_WL > 0 )
234const int SC_DEFAULT_CTE_WL_ = SC_FXCTE_WL;
235#else
237#endif
238
239#if defined( SC_FXMAX_WL ) && ( SC_FXMAX_WL > 0 || SC_FXMAX_WL == -1 )
240const int SC_DEFAULT_MAX_WL_ = SC_FXMAX_WL;
241#else
243#endif
244
245
246// ----------------------------------------------------------------------------
247// Dedicated error reporting and checking.
248// ----------------------------------------------------------------------------
249
250#define SC_ERROR_IF_IMPL_(cnd,id,msg) \
251 do { \
252 if( cnd ) { \
253 SC_REPORT_ERROR( id, msg ); \
254 sc_core::sc_abort(); /* can't recover from here */ \
255 } \
256 } while( false )
257
258#ifdef DEBUG_SYSTEMC
259# define SC_ASSERT_(cnd,msg) \
260 SC_ERROR_IF_IMPL_(!(cnd), sc_core::SC_ID_INTERNAL_ERROR_, msg )
261#else
262# define SC_ASSERT_(cnd,msg) (void(0))
263#endif
264
265#define SC_ERROR_IF_(cnd,id) \
266 SC_ERROR_IF_IMPL_( cnd, id, 0 )
267
268#define SC_CHECK_WL_(wl) \
269 SC_ERROR_IF_( (wl) <= 0, sc_core::SC_ID_INVALID_WL_ )
270
271#define SC_CHECK_N_BITS_(n_bits) \
272 SC_ERROR_IF_( (n_bits) < 0, sc_core::SC_ID_INVALID_N_BITS_ )
273
274#define SC_CHECK_DIV_WL_(div_wl) \
275 SC_ERROR_IF_( (div_wl) <= 0, sc_core::SC_ID_INVALID_DIV_WL_ )
276
277#define SC_CHECK_CTE_WL_(cte_wl) \
278 SC_ERROR_IF_( (cte_wl) <= 0, sc_core::SC_ID_INVALID_CTE_WL_ )
279
280#define SC_CHECK_MAX_WL_(max_wl) \
281 SC_ERROR_IF_( (max_wl) <= 0 && (max_wl) != -1, \
282 sc_core::SC_ID_INVALID_MAX_WL_ )
283
284
285// ----------------------------------------------------------------------------
286// Generic observer macros.
287// ----------------------------------------------------------------------------
288
289#define SC_OBSERVER_(object,observer_type,event) \
290{ \
291 if( (object).observer() != 0 ) \
292 { \
293 observer_type observer = (object).lock_observer(); \
294 observer->event( (object) ); \
295 (object).unlock_observer( observer ); \
296 } \
297}
298
299#define SC_OBSERVER_DEFAULT_(observer_type) \
300{ \
301 if( m_observer == 0 && observer_type::default_observer != 0 ) \
302 m_observer = (*observer_type::default_observer)(); \
303}
304
305} // namespace sc_dt
306
307
308#endif
309
310// Taf!
#define SC_API
Definition: sc_cmnhdr.h:148
const int SC_DEFAULT_DIV_WL_
Definition: sc_fxdefs.h:230
sc_enc
Definition: sc_fxdefs.h:67
@ SC_US_
Definition: sc_fxdefs.h:69
@ SC_TC_
Definition: sc_fxdefs.h:68
const int SC_DEFAULT_WL_
Definition: sc_fxdefs.h:201
const sc_o_mode SC_BUILTIN_O_MODE_
Definition: sc_fxdefs.h:197
sc_q_mode
Definition: sc_fxdefs.h:91
@ SC_RND_CONV
Definition: sc_fxdefs.h:96
@ SC_RND
Definition: sc_fxdefs.h:92
@ SC_RND_MIN_INF
Definition: sc_fxdefs.h:94
@ SC_TRN_ZERO
Definition: sc_fxdefs.h:98
@ SC_TRN
Definition: sc_fxdefs.h:97
@ SC_RND_ZERO
Definition: sc_fxdefs.h:93
@ SC_RND_INF
Definition: sc_fxdefs.h:95
const sc_q_mode SC_BUILTIN_Q_MODE_
Definition: sc_fxdefs.h:196
const int SC_BUILTIN_CTE_WL_
Definition: sc_fxdefs.h:223
const sc_switch SC_DEFAULT_CAST_SWITCH_
Definition: sc_fxdefs.h:215
const int SC_BUILTIN_IWL_
Definition: sc_fxdefs.h:195
const sc_q_mode SC_DEFAULT_Q_MODE_
Definition: sc_fxdefs.h:203
const int SC_BUILTIN_WL_
Definition: sc_fxdefs.h:194
const int SC_BUILTIN_MAX_WL_
Definition: sc_fxdefs.h:224
const int SC_DEFAULT_IWL_
Definition: sc_fxdefs.h:202
@ SC_F
Definition: sc_fxdefs.h:174
@ SC_E
Definition: sc_fxdefs.h:175
SC_API std::string to_string(sc_enc)
const int SC_DEFAULT_MAX_WL_
Definition: sc_fxdefs.h:242
const sc_o_mode SC_DEFAULT_O_MODE_
Definition: sc_fxdefs.h:204
const int SC_BUILTIN_N_BITS_
Definition: sc_fxdefs.h:198
sc_switch
Definition: sc_fxdefs.h:149
@ SC_OFF
Definition: sc_fxdefs.h:150
@ SC_ON
Definition: sc_fxdefs.h:151
const sc_switch SC_BUILTIN_CAST_SWITCH_
Definition: sc_fxdefs.h:212
const int SC_DEFAULT_CTE_WL_
Definition: sc_fxdefs.h:236
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:388
const int SC_BUILTIN_DIV_WL_
Definition: sc_fxdefs.h:222
sc_o_mode
Definition: sc_fxdefs.h:120
@ SC_WRAP
Definition: sc_fxdefs.h:124
@ SC_WRAP_SM
Definition: sc_fxdefs.h:125
@ SC_SAT_SYM
Definition: sc_fxdefs.h:123
@ SC_SAT_ZERO
Definition: sc_fxdefs.h:122
@ SC_SAT
Definition: sc_fxdefs.h:121
const int SC_DEFAULT_N_BITS_
Definition: sc_fxdefs.h:205