gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_fixed.hh
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_fixed.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_fixed.h,v $
39// Revision 1.2 2011/01/19 18:57:40 acg
40// Andy Goodrich: changes for IEEE_1666_2011.
41//
42// Revision 1.1.1.1 2006/12/15 20:20:04 acg
43// SystemC 2.3
44//
45// Revision 1.3 2006/01/13 18:53:57 acg
46// Andy Goodrich: added $Log command so that CVS comments are reproduced in
47// the source.
48//
49
50#ifndef __SYSTEMC_EXT_DT_FX_SC_FIXED_HH__
51#define __SYSTEMC_EXT_DT_FX_SC_FIXED_HH__
52
53#include "sc_fix.hh"
54
55namespace sc_dt
56{
57
58// classes defined in this module
59template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
60class sc_fixed;
61template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
62class sc_fixed_fast;
63
64// ----------------------------------------------------------------------------
65// TEMPLATE CLASS : sc_fixed
66//
67// "Constrained" signed fixed-point class; arbitrary precision.
68// ----------------------------------------------------------------------------
69
70template <int W, int I,
71 sc_q_mode Q=SC_DEFAULT_Q_MODE_,
72 sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
73class sc_fixed : public sc_fix
74{
75 public:
76 // constructors
77 explicit sc_fixed(sc_fxnum_observer * =0);
78 explicit sc_fixed(const sc_fxcast_switch &, sc_fxnum_observer * =0);
79
80#define DECL_CTORS_T_A(tp) \
81 sc_fixed(tp, sc_fxnum_observer * =0); \
82 sc_fixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
83
84#define DECL_CTORS_T_B(tp) \
85 explicit sc_fixed(tp, sc_fxnum_observer * =0); \
86 sc_fixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
87
89 DECL_CTORS_T_A(unsigned int)
90 DECL_CTORS_T_A(long)
91 DECL_CTORS_T_A(unsigned long)
92 DECL_CTORS_T_A(float)
93 DECL_CTORS_T_A(double)
94 DECL_CTORS_T_A(const char *)
96 DECL_CTORS_T_A(const sc_fxval_fast &)
98 DECL_CTORS_T_A(const sc_fxnum_fast &)
99
100 DECL_CTORS_T_B(int64)
101 DECL_CTORS_T_B(uint64)
102 DECL_CTORS_T_B(const sc_int_base&)
103 DECL_CTORS_T_B(const sc_uint_base&)
104 DECL_CTORS_T_B(const sc_signed&)
105 DECL_CTORS_T_B(const sc_unsigned&)
106
107#undef DECL_CTORS_T_A
108#undef DECL_CTORS_T_B
109
110 // copy constructor
112
113 // assignment operators
115
116#define DECL_ASN_OP_T(op, tp) sc_fixed &operator op (tp);
117
118#define DECL_ASN_OP_OTHER(op) \
119 DECL_ASN_OP_T(op, int64) \
120 DECL_ASN_OP_T(op, uint64) \
121 DECL_ASN_OP_T(op, const sc_int_base&) \
122 DECL_ASN_OP_T(op, const sc_uint_base&) \
123 DECL_ASN_OP_T(op, const sc_signed&) \
124 DECL_ASN_OP_T(op, const sc_unsigned&)
125
126#define DECL_ASN_OP(op) \
127 DECL_ASN_OP_T(op, int) \
128 DECL_ASN_OP_T(op, unsigned int) \
129 DECL_ASN_OP_T(op, long) \
130 DECL_ASN_OP_T(op, unsigned long) \
131 DECL_ASN_OP_T(op, float) \
132 DECL_ASN_OP_T(op, double) \
133 DECL_ASN_OP_T(op, const char *) \
134 DECL_ASN_OP_T(op, const sc_fxval &) \
135 DECL_ASN_OP_T(op, const sc_fxval_fast &) \
136 DECL_ASN_OP_T(op, const sc_fxnum &) \
137 DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
138 DECL_ASN_OP_OTHER(op)
139
140 DECL_ASN_OP(=)
141
142 DECL_ASN_OP(*=)
143 DECL_ASN_OP(/=)
144 DECL_ASN_OP(+=)
145 DECL_ASN_OP(-=)
146
147 DECL_ASN_OP_T(<<=, int)
148 DECL_ASN_OP_T(>>=, int)
149
150 DECL_ASN_OP_T(&=, const sc_fix &)
151 DECL_ASN_OP_T(&=, const sc_fix_fast &)
152 DECL_ASN_OP_T(|=, const sc_fix &)
153 DECL_ASN_OP_T(|=, const sc_fix_fast &)
154 DECL_ASN_OP_T(^=, const sc_fix &)
155 DECL_ASN_OP_T(^=, const sc_fix_fast &)
156
157#undef DECL_ASN_OP_T
158#undef DECL_ASN_OP_OTHER
159#undef DECL_ASN_OP
160
161 // auto-increment and auto-decrement
162 const sc_fxval operator ++ (int);
163 const sc_fxval operator -- (int);
164
167};
168
169
170// ----------------------------------------------------------------------------
171// TEMPLATE CLASS : sc_fixed_fast
172//
173// "Constrained" signed fixed-point class; limited precision.
174// ----------------------------------------------------------------------------
175
176template <int W, int I,
177 sc_q_mode Q=SC_DEFAULT_Q_MODE_,
178 sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
180{
181 public:
182 // constructors
184 explicit sc_fixed_fast(const sc_fxcast_switch &,
186
187#define DECL_CTORS_T_A(tp) \
188 sc_fixed_fast(tp, sc_fxnum_fast_observer * =0); \
189 sc_fixed_fast(tp, const sc_fxcast_switch &, \
190 sc_fxnum_fast_observer * =0);
191
192#define DECL_CTORS_T_B(tp) \
193 explicit sc_fixed_fast(tp, sc_fxnum_fast_observer * =0); \
194 sc_fixed_fast(tp, const sc_fxcast_switch &, \
195 sc_fxnum_fast_observer * =0);
196
197 DECL_CTORS_T_A(int)
198 DECL_CTORS_T_A(unsigned int)
199 DECL_CTORS_T_A(long)
200 DECL_CTORS_T_A(unsigned long)
201 DECL_CTORS_T_A(float)
202 DECL_CTORS_T_A(double)
203 DECL_CTORS_T_A(const char *)
204 DECL_CTORS_T_A(const sc_fxval &)
206 DECL_CTORS_T_A(const sc_fxnum &)
208
215
216#undef DECL_CTORS_T_A
217#undef DECL_CTORS_T_B
218
219 // copy constructor
221
222 // assignment operators
224
225#define DECL_ASN_OP_T(op, tp) sc_fixed_fast &operator op (tp);
226
227#define DECL_ASN_OP_OTHER(op) \
228 DECL_ASN_OP_T(op, int64) \
229 DECL_ASN_OP_T(op, uint64) \
230 DECL_ASN_OP_T(op, const sc_int_base &) \
231 DECL_ASN_OP_T(op, const sc_uint_base &) \
232 DECL_ASN_OP_T(op, const sc_signed &) \
233 DECL_ASN_OP_T(op, const sc_unsigned &)
234
235#define DECL_ASN_OP(op) \
236 DECL_ASN_OP_T(op, int) \
237 DECL_ASN_OP_T(op, unsigned int) \
238 DECL_ASN_OP_T(op, long) \
239 DECL_ASN_OP_T(op, unsigned long) \
240 DECL_ASN_OP_T(op, float) \
241 DECL_ASN_OP_T(op, double) \
242 DECL_ASN_OP_T(op, const char *) \
243 DECL_ASN_OP_T(op, const sc_fxval &) \
244 DECL_ASN_OP_T(op, const sc_fxval_fast &) \
245 DECL_ASN_OP_T(op, const sc_fxnum &) \
246 DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
247 DECL_ASN_OP_OTHER(op)
248
249 DECL_ASN_OP(=)
250
251 DECL_ASN_OP(*=)
252 DECL_ASN_OP(/=)
253 DECL_ASN_OP(+=)
254 DECL_ASN_OP(-=)
255
256 DECL_ASN_OP_T(<<=, int)
257 DECL_ASN_OP_T(>>=, int)
258
259 DECL_ASN_OP_T(&=, const sc_fix &)
260 DECL_ASN_OP_T(&=, const sc_fix_fast &)
261 DECL_ASN_OP_T(|=, const sc_fix &)
262 DECL_ASN_OP_T(|=, const sc_fix_fast &)
263 DECL_ASN_OP_T(^=, const sc_fix &)
264 DECL_ASN_OP_T(^=, const sc_fix_fast &)
265
266#undef DECL_ASN_OP_T
267#undef DECL_ASN_OP_OTHER
268#undef DECL_ASN_OP
269
270 // auto-increment and auto-decrement
271 const sc_fxval_fast operator ++ (int);
272 const sc_fxval_fast operator -- (int);
273
276};
277
278
279// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
280
281// ----------------------------------------------------------------------------
282// TEMPLATE CLASS : sc_fixed
283//
284// "Constrained" signed fixed-point class; arbitrary precision.
285// ----------------------------------------------------------------------------
286
287template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
289 sc_fix(W, I, Q, O, N, observer_)
290{}
291
292template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
294 const sc_fxcast_switch &cast_sw, sc_fxnum_observer *observer_) :
295 sc_fix(W, I, Q, O, N, cast_sw, observer_)
296{}
297
298#define DEFN_CTORS_T(tp) \
299template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
300inline sc_fixed<W, I, Q, O, N>::sc_fixed( \
301 tp a, sc_fxnum_observer* observer_) : \
302 sc_fix(a, W, I, Q, O, N, observer_) \
303{} \
304 \
305template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
306inline sc_fixed<W, I, Q, O, N>::sc_fixed( \
307 tp a, const sc_fxcast_switch &cast_sw, \
308 sc_fxnum_observer *observer_) : \
309 sc_fix(a, W, I, Q, O, N, cast_sw, observer_) \
310{}
311
312DEFN_CTORS_T(int)
313DEFN_CTORS_T(unsigned int)
314DEFN_CTORS_T(long)
315DEFN_CTORS_T(unsigned long)
316DEFN_CTORS_T(float)
317DEFN_CTORS_T(double)
318DEFN_CTORS_T(const char *)
319DEFN_CTORS_T(const sc_fxval &)
320DEFN_CTORS_T(const sc_fxval_fast &)
321DEFN_CTORS_T(const sc_fxnum &)
322DEFN_CTORS_T(const sc_fxnum_fast &)
323
324DEFN_CTORS_T(int64)
325DEFN_CTORS_T(uint64)
326DEFN_CTORS_T(const sc_int_base &)
327DEFN_CTORS_T(const sc_uint_base &)
328DEFN_CTORS_T(const sc_signed &)
329DEFN_CTORS_T(const sc_unsigned &)
330
331#undef DEFN_CTORS_T
332
333// copy constructor
334template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
336 sc_fix(a, W, I, Q, O, N)
337{}
338
339// assignment operators
340template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
347
348#define DEFN_ASN_OP_T(op, tp) \
349template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
350inline sc_fixed<W, I, Q, O, N> & \
351sc_fixed<W, I, Q, O, N>::operator op (tp a) \
352{ \
353 sc_fix::operator op (a); \
354 return *this; \
355}
356
357#define DEFN_ASN_OP_OTHER(op) \
358DEFN_ASN_OP_T(op, int64) \
359DEFN_ASN_OP_T(op, uint64) \
360DEFN_ASN_OP_T(op, const sc_int_base &) \
361DEFN_ASN_OP_T(op, const sc_uint_base &) \
362DEFN_ASN_OP_T(op, const sc_signed &) \
363DEFN_ASN_OP_T(op, const sc_unsigned &)
364
365#define DEFN_ASN_OP(op) \
366DEFN_ASN_OP_T(op, int) \
367DEFN_ASN_OP_T(op, unsigned int) \
368DEFN_ASN_OP_T(op, long) \
369DEFN_ASN_OP_T(op, unsigned long) \
370DEFN_ASN_OP_T(op, float) \
371DEFN_ASN_OP_T(op, double) \
372DEFN_ASN_OP_T(op, const char *) \
373DEFN_ASN_OP_T(op, const sc_fxval &) \
374DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
375DEFN_ASN_OP_T(op, const sc_fxnum &) \
376DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
377DEFN_ASN_OP_OTHER(op)
378
380
381DEFN_ASN_OP(*=)
382DEFN_ASN_OP(/=)
383DEFN_ASN_OP(+=)
384DEFN_ASN_OP(-=)
385
386DEFN_ASN_OP_T(<<=, int)
387DEFN_ASN_OP_T(>>=, int)
388
389DEFN_ASN_OP_T(&=, const sc_fix &)
390DEFN_ASN_OP_T(&=, const sc_fix_fast &)
391DEFN_ASN_OP_T(|=, const sc_fix &)
392DEFN_ASN_OP_T(|=, const sc_fix_fast &)
393DEFN_ASN_OP_T(^=, const sc_fix &)
394DEFN_ASN_OP_T(^=, const sc_fix_fast &)
395
396#undef DEFN_ASN_OP_T
397#undef DEFN_ASN_OP_OTHER
398#undef DEFN_ASN_OP
399
400// auto-increment and auto-decrement
401template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
402inline const sc_fxval
404{
405 return sc_fxval(sc_fix::operator ++ (0));
406}
407
408template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
409inline const sc_fxval
411{
412 return sc_fxval(sc_fix::operator -- (0));
413}
414
415template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
422
423template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
430
431
432// ----------------------------------------------------------------------------
433// TEMPLATE CLASS : sc_fixed_fast
434//
435// "Constrained" signed fixed-point class; limited precision.
436// ----------------------------------------------------------------------------
437
438template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
440 sc_fxnum_fast_observer *observer_) :
441 sc_fix_fast(W, I, Q, O, N, observer_)
442{}
443
444template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
446 const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) :
447 sc_fix_fast(W, I, Q, O, N, cast_sw, observer_)
448{}
449
450#define DEFN_CTORS_T(tp) \
451template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
452inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast( \
453 tp a, sc_fxnum_fast_observer *observer_) : \
454 sc_fix_fast(a, W, I, Q, O, N, observer_) \
455{} \
456 \
457template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
458inline sc_fixed_fast<W, I, Q, O, N>::sc_fixed_fast( \
459 tp a, const sc_fxcast_switch &cast_sw, \
460 sc_fxnum_fast_observer *observer_) : \
461 sc_fix_fast(a, W, I, Q, O, N, cast_sw, observer_) \
462{}
463
464DEFN_CTORS_T(int)
465DEFN_CTORS_T(unsigned int)
466DEFN_CTORS_T(long)
467DEFN_CTORS_T(unsigned long)
468DEFN_CTORS_T(float)
469DEFN_CTORS_T(double)
470DEFN_CTORS_T(const char *)
471DEFN_CTORS_T(const sc_fxval &)
473DEFN_CTORS_T(const sc_fxnum &)
475
480DEFN_CTORS_T(const sc_signed &)
482
483#undef DEFN_CTORS_T
484
485// copy constructor
486template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
490
491// assignment operators
492template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
500
501#define DEFN_ASN_OP_T(op, tp) \
502template <int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
503inline sc_fixed_fast<W, I, Q, O, N> & \
504sc_fixed_fast<W, I, Q, O, N>::operator op (tp a) \
505{ \
506 sc_fix_fast::operator op (a); \
507 return *this; \
508}
509
510#define DEFN_ASN_OP_OTHER(op) \
511DEFN_ASN_OP_T(op, int64) \
512DEFN_ASN_OP_T(op, uint64) \
513DEFN_ASN_OP_T(op, const sc_int_base &) \
514DEFN_ASN_OP_T(op, const sc_uint_base &) \
515DEFN_ASN_OP_T(op, const sc_signed &) \
516DEFN_ASN_OP_T(op, const sc_unsigned &)
517
518#define DEFN_ASN_OP(op) \
519DEFN_ASN_OP_T(op, int) \
520DEFN_ASN_OP_T(op, unsigned int) \
521DEFN_ASN_OP_T(op, long) \
522DEFN_ASN_OP_T(op, unsigned long) \
523DEFN_ASN_OP_T(op, float) \
524DEFN_ASN_OP_T(op, double) \
525DEFN_ASN_OP_T(op, const char *) \
526DEFN_ASN_OP_T(op, const sc_fxval &) \
527DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
528DEFN_ASN_OP_T(op, const sc_fxnum &) \
529DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
530DEFN_ASN_OP_OTHER(op)
531
533
534DEFN_ASN_OP(*=)
535DEFN_ASN_OP(/=)
536DEFN_ASN_OP(+=)
537DEFN_ASN_OP(-=)
538
539DEFN_ASN_OP_T(<<=, int)
540DEFN_ASN_OP_T(>>=, int)
541
542DEFN_ASN_OP_T(&=, const sc_fix &)
543DEFN_ASN_OP_T(&=, const sc_fix_fast &)
544DEFN_ASN_OP_T(|=, const sc_fix &)
545DEFN_ASN_OP_T(|=, const sc_fix_fast &)
546DEFN_ASN_OP_T(^=, const sc_fix &)
547DEFN_ASN_OP_T(^=, const sc_fix_fast &)
548
549#undef DEFN_ASN_OP_T
550#undef DEFN_ASN_OP_OTHER
551#undef DEFN_ASN_OP
552
553// auto-increment and auto-decrement
554template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
555inline const sc_fxval_fast
557{
558 return sc_fxval_fast(sc_fix_fast::operator ++ (0));
559}
560
561template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
562inline const sc_fxval_fast
564{
565 return sc_fxval_fast(sc_fix_fast::operator -- (0));
566}
567
568template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
575
576template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
583
584} // namespace sc_dt
585
586#endif // __SYSTEMC_EXT_DT_FX_SC_FIXED_HH__
sc_fix_fast & operator--()
Definition sc_fix.hh:1335
sc_fix_fast & operator++()
Definition sc_fix.hh:1328
sc_fix_fast & operator=(const sc_fix_fast &)
Definition sc_fix.hh:1241
sc_fix & operator=(const sc_fix &)
Definition sc_fix.hh:771
sc_fix & operator--()
Definition sc_fix.hh:865
sc_fix & operator++()
Definition sc_fix.hh:858
sc_fixed_fast(sc_fxnum_fast_observer *=0)
Definition sc_fixed.hh:439
sc_fixed_fast & operator--()
Definition sc_fixed.hh:578
sc_fixed_fast & operator=(const sc_fixed_fast< W, I, Q, O, N > &)
Definition sc_fixed.hh:494
sc_fixed_fast & operator++()
Definition sc_fixed.hh:570
sc_fixed & operator--()
Definition sc_fixed.hh:425
sc_fixed(sc_fxnum_observer *=0)
Definition sc_fixed.hh:288
sc_fixed & operator=(const sc_fixed< W, I, Q, O, N > &)
Definition sc_fixed.hh:342
sc_fixed & operator++()
Definition sc_fixed.hh:417
friend class sc_fxval
Definition sc_fxnum.hh:485
#define sc_fixed
#define sc_fxval
Definition sc_fxnum.hh:485
#define sc_fix
SwitchingFiber a
uint64_t uint64
Definition sc_nbdefs.hh:172
const sc_q_mode SC_DEFAULT_Q_MODE_
Definition sc_fxdefs.hh:191
int64_t int64
Definition sc_nbdefs.hh:171
const sc_o_mode SC_DEFAULT_O_MODE_
Definition sc_fxdefs.hh:192
const int SC_DEFAULT_N_BITS_
Definition sc_fxdefs.hh:193
#define DEFN_ASN_OP(op)
Definition sc_bit.hh:164
#define DEFN_ASN_OP_T(op, tp)
Definition sc_bit.hh:162
#define DECL_CTORS_T_A(tp)
Definition sc_fix.hh:113
#define DECL_CTORS_T_B(tp)
Definition sc_fix.hh:117
#define DECL_ASN_OP_T(op, tp)
Definition sc_fix.hh:178
#define DECL_ASN_OP(op)
Definition sc_fix.hh:188
#define DEFN_CTORS_T(tp)
Definition sc_fixed.hh:298

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0