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