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