gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_ufixed.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_ufixed.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_ufixed.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:58 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_UFIXED_HH__
51#define __SYSTEMC_EXT_DT_FX_SC_UFIXED_HH__
52
53#include "sc_ufix.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_ufixed;
61template <int W, int I, sc_q_mode Q, sc_o_mode O, int N>
62class sc_ufixed_fast;
63
64
65// ----------------------------------------------------------------------------
66// TEMPLATE CLASS : sc_ufixed
67//
68// "Constrained" unsigned fixed-point class; arbitrary precision.
69// ----------------------------------------------------------------------------
70
71template <int W, int I,
72 sc_q_mode Q=SC_DEFAULT_Q_MODE_,
73 sc_o_mode O=SC_DEFAULT_O_MODE_, int N=SC_DEFAULT_N_BITS_>
74class sc_ufixed : public sc_ufix
75{
76 public:
77 // constructors
78 explicit sc_ufixed(sc_fxnum_observer * =0);
79 explicit sc_ufixed(const sc_fxcast_switch &, sc_fxnum_observer * =0);
80
81#define DECL_CTORS_T_A(tp) \
82 sc_ufixed(tp, sc_fxnum_observer * =0); \
83 sc_ufixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
84
85#define DECL_CTORS_T_B(tp) \
86 explicit sc_ufixed(tp, sc_fxnum_observer * =0); \
87 sc_ufixed(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0);
88
90 DECL_CTORS_T_A(unsigned int)
91 DECL_CTORS_T_A(long)
92 DECL_CTORS_T_A(unsigned long)
93 DECL_CTORS_T_A(float)
94 DECL_CTORS_T_A(double)
95 DECL_CTORS_T_A(const char *)
97 DECL_CTORS_T_A(const sc_fxval_fast &)
99 DECL_CTORS_T_A(const sc_fxnum_fast &)
100
101 DECL_CTORS_T_B(int64)
102 DECL_CTORS_T_B(uint64)
103 DECL_CTORS_T_B(const sc_int_base &)
104 DECL_CTORS_T_B(const sc_uint_base &)
105 DECL_CTORS_T_B(const sc_signed &)
106 DECL_CTORS_T_B(const sc_unsigned &)
107
108#undef DECL_CTORS_T_A
109#undef DECL_CTORS_T_B
110 // copy constructor
112
113 // assignment operators
115
116#define DECL_ASN_OP_T(op,tp) sc_ufixed &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_ufix &)
151 DECL_ASN_OP_T(&=, const sc_ufix_fast &)
152 DECL_ASN_OP_T(|=, const sc_ufix &)
153 DECL_ASN_OP_T(|=, const sc_ufix_fast &)
154 DECL_ASN_OP_T(^=, const sc_ufix &)
155 DECL_ASN_OP_T(^=, const sc_ufix_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_ufixed_fast
172//
173// "Constrained" unsigned 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_ufixed_fast(const sc_fxcast_switch &,
186
187#define DECL_CTORS_T_A(tp) \
188 sc_ufixed_fast(tp, sc_fxnum_fast_observer * =0); \
189 sc_ufixed_fast(tp, const sc_fxcast_switch &, sc_fxnum_fast_observer * =0);
190
191#define DECL_CTORS_T_B(tp) \
192 explicit sc_ufixed_fast(tp, sc_fxnum_fast_observer * =0); \
193 sc_ufixed_fast(tp, const sc_fxcast_switch &, sc_fxnum_fast_observer * =0);
194
195 DECL_CTORS_T_A(int)
196 DECL_CTORS_T_A(unsigned int)
197 DECL_CTORS_T_A(long)
198 DECL_CTORS_T_A(unsigned long)
199 DECL_CTORS_T_A(float)
200 DECL_CTORS_T_A(double)
201 DECL_CTORS_T_A(const char *)
202 DECL_CTORS_T_A(const sc_fxval &)
204 DECL_CTORS_T_A(const sc_fxnum &)
206
213
214#undef DECL_CTORS_T_A
215#undef DECL_CTORS_T_B
216 // copy constructor
218
219 // assignment operators
221
222#define DECL_ASN_OP_T(op,tp) sc_ufixed_fast &operator op (tp);
223
224#define DECL_ASN_OP_OTHER(op) \
225 DECL_ASN_OP_T(op, int64) \
226 DECL_ASN_OP_T(op, uint64) \
227 DECL_ASN_OP_T(op, const sc_int_base &) \
228 DECL_ASN_OP_T(op, const sc_uint_base &) \
229 DECL_ASN_OP_T(op, const sc_signed &) \
230 DECL_ASN_OP_T(op, const sc_unsigned &)
231
232#define DECL_ASN_OP(op) \
233 DECL_ASN_OP_T(op, int) \
234 DECL_ASN_OP_T(op, unsigned int) \
235 DECL_ASN_OP_T(op, long) \
236 DECL_ASN_OP_T(op, unsigned long) \
237 DECL_ASN_OP_T(op, float) \
238 DECL_ASN_OP_T(op, double) \
239 DECL_ASN_OP_T(op, const char *) \
240 DECL_ASN_OP_T(op, const sc_fxval &) \
241 DECL_ASN_OP_T(op, const sc_fxval_fast &) \
242 DECL_ASN_OP_T(op, const sc_fxnum &) \
243 DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
244 DECL_ASN_OP_OTHER(op)
245
246 DECL_ASN_OP(=)
247
248 DECL_ASN_OP(*=)
249 DECL_ASN_OP(/=)
250 DECL_ASN_OP(+=)
251 DECL_ASN_OP(-=)
252
253 DECL_ASN_OP_T(<<=, int)
254 DECL_ASN_OP_T(>>=, int)
255
256 DECL_ASN_OP_T(&=, const sc_ufix &)
257 DECL_ASN_OP_T(&=, const sc_ufix_fast &)
258 DECL_ASN_OP_T(|=, const sc_ufix &)
259 DECL_ASN_OP_T(|=, const sc_ufix_fast &)
260 DECL_ASN_OP_T(^=, const sc_ufix &)
261 DECL_ASN_OP_T(^=, const sc_ufix_fast &)
262
263#undef DECL_ASN_OP_T
264#undef DECL_ASN_OP_OTHER
265#undef DECL_ASN_OP
266
267 // auto-increment and auto-decrement
268 const sc_fxval_fast operator ++ (int);
269 const sc_fxval_fast operator -- (int);
270
273};
274
275
276// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
277
278// ----------------------------------------------------------------------------
279// TEMPLATE CLASS : sc_ufixed
280//
281// "Constrained" unsigned fixed-point class; arbitrary precision.
282// ----------------------------------------------------------------------------
283
284template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
286 sc_ufix(W, I, Q, O, N, observer_)
287{}
288
289template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
291 sc_fxnum_observer *observer_) :
292 sc_ufix(W, I, Q, O, N, cast_sw, observer_)
293{}
294
295#define DEFN_CTORS_T(tp) \
296template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
297inline sc_ufixed<W, I, Q, O, N>::sc_ufixed( \
298 tp a, sc_fxnum_observer *observer_) :\
299 sc_ufix(a, W, I, Q, O, N, observer_) \
300{} \
301 \
302template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
303inline sc_ufixed<W, I, Q, O, N>::sc_ufixed( \
304 tp a, const sc_fxcast_switch &cast_sw, \
305 sc_fxnum_observer *observer_) : \
306 sc_ufix(a, W, I, Q, O, N, cast_sw, observer_) \
307{}
308
309DEFN_CTORS_T(int)
310DEFN_CTORS_T(unsigned int)
311DEFN_CTORS_T(long)
312DEFN_CTORS_T(unsigned long)
313DEFN_CTORS_T(float)
314DEFN_CTORS_T(double)
315DEFN_CTORS_T(const char *)
316DEFN_CTORS_T(const sc_fxval &)
317DEFN_CTORS_T(const sc_fxval_fast &)
318DEFN_CTORS_T(const sc_fxnum &)
319DEFN_CTORS_T(const sc_fxnum_fast &)
320
321DEFN_CTORS_T(int64)
322DEFN_CTORS_T(uint64)
323DEFN_CTORS_T(const sc_int_base &)
324DEFN_CTORS_T(const sc_uint_base &)
325DEFN_CTORS_T(const sc_signed &)
326DEFN_CTORS_T(const sc_unsigned &)
327
328#undef DEFN_CTORS_T
329
330// copy constructor
331template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
333 sc_ufix(a, W, I, Q, O, N)
334{}
335
336// assignment operators
337template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
344
345#define DEFN_ASN_OP_T(op,tp) \
346template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
347inline sc_ufixed<W, I, Q, O, N> & \
348sc_ufixed<W, I, Q, O, N>::operator op (tp a) \
349{ \
350 sc_ufix::operator op (a); \
351 return *this; \
352}
353
354#define DEFN_ASN_OP_OTHER(op) \
355DEFN_ASN_OP_T(op, int64) \
356DEFN_ASN_OP_T(op, uint64) \
357DEFN_ASN_OP_T(op, const sc_int_base &) \
358DEFN_ASN_OP_T(op, const sc_uint_base &) \
359DEFN_ASN_OP_T(op, const sc_signed &) \
360DEFN_ASN_OP_T(op, const sc_unsigned &)
361
362#define DEFN_ASN_OP(op) \
363DEFN_ASN_OP_T(op, int) \
364DEFN_ASN_OP_T(op, unsigned int) \
365DEFN_ASN_OP_T(op, long) \
366DEFN_ASN_OP_T(op, unsigned long) \
367DEFN_ASN_OP_T(op, float) \
368DEFN_ASN_OP_T(op, double) \
369DEFN_ASN_OP_T(op, const char *) \
370DEFN_ASN_OP_T(op, const sc_fxval &) \
371DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
372DEFN_ASN_OP_T(op, const sc_fxnum &) \
373DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
374DEFN_ASN_OP_OTHER(op)
375
377
378DEFN_ASN_OP(*=)
379DEFN_ASN_OP(/=)
380DEFN_ASN_OP(+=)
381DEFN_ASN_OP(-=)
382
383DEFN_ASN_OP_T(<<=, int)
384DEFN_ASN_OP_T(>>=, int)
385
386DEFN_ASN_OP_T(&=, const sc_ufix &)
387DEFN_ASN_OP_T(&=, const sc_ufix_fast &)
388DEFN_ASN_OP_T(|=, const sc_ufix &)
389DEFN_ASN_OP_T(|=, const sc_ufix_fast &)
390DEFN_ASN_OP_T(^=, const sc_ufix &)
391DEFN_ASN_OP_T(^=, const sc_ufix_fast &)
392
393#undef DEFN_ASN_OP_T
394#undef DEFN_ASN_OP_OTHER
395#undef DEFN_ASN_OP
396
397// auto-increment and auto-decrement
398template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
399inline const sc_fxval
401{
402 return sc_fxval(sc_ufix::operator ++ (0));
403}
404
405template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
406inline const sc_fxval
408{
409 return sc_fxval(sc_ufix::operator -- (0));
410}
411
412template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
419
420template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
427
428
429// ----------------------------------------------------------------------------
430// TEMPLATE CLASS : sc_ufixed_fast
431//
432// "Constrained" unsigned fixed-point class; limited precision.
433// ----------------------------------------------------------------------------
434
435template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
437 sc_fxnum_fast_observer *observer_) :
438 sc_ufix_fast(W, I, Q, O, N, observer_)
439{}
440
441template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
443 const sc_fxcast_switch &cast_sw,
444 sc_fxnum_fast_observer *observer_) :
445 sc_ufix_fast(W, I, Q, O, N, cast_sw, observer_)
446{}
447
448#define DEFN_CTORS_T(tp) \
449template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
450inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast( \
451 tp a, sc_fxnum_fast_observer *observer_ ) : \
452 sc_ufix_fast(a, W, I, Q, O, N, observer_) \
453{} \
454 \
455template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
456inline sc_ufixed_fast<W, I, Q, O, N>::sc_ufixed_fast( \
457 tp a, const sc_fxcast_switch &cast_sw, \
458 sc_fxnum_fast_observer *observer_) : \
459 sc_ufix_fast(a, W, I, Q, O, N, cast_sw, observer_) \
460{}
461
462DEFN_CTORS_T(int)
463DEFN_CTORS_T(unsigned int)
464DEFN_CTORS_T(long)
465DEFN_CTORS_T(unsigned long)
466DEFN_CTORS_T(float)
467DEFN_CTORS_T(double)
468DEFN_CTORS_T(const char *)
469DEFN_CTORS_T(const sc_fxval &)
471DEFN_CTORS_T(const sc_fxnum &)
473
478DEFN_CTORS_T(const sc_signed &)
480
481#undef DEFN_CTORS_T
482
483// copy constructor
484template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
489
490// assignment operators
491template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
499
500#define DEFN_ASN_OP_T(op, tp) \
501template<int W, int I, sc_q_mode Q, sc_o_mode O, int N> \
502inline sc_ufixed_fast<W, I, Q, O, N> & \
503sc_ufixed_fast<W, I, Q, O, N>::operator op (tp a) \
504{ \
505 sc_ufix_fast::operator op (a); \
506 return *this; \
507}
508
509#define DEFN_ASN_OP_OTHER(op) \
510DEFN_ASN_OP_T(op, int64) \
511DEFN_ASN_OP_T(op, uint64) \
512DEFN_ASN_OP_T(op, const sc_int_base &) \
513DEFN_ASN_OP_T(op, const sc_uint_base &) \
514DEFN_ASN_OP_T(op, const sc_signed &) \
515DEFN_ASN_OP_T(op, const sc_unsigned &)
516
517#define DEFN_ASN_OP(op) \
518DEFN_ASN_OP_T(op, int) \
519DEFN_ASN_OP_T(op, unsigned int) \
520DEFN_ASN_OP_T(op, long) \
521DEFN_ASN_OP_T(op, unsigned long) \
522DEFN_ASN_OP_T(op, float) \
523DEFN_ASN_OP_T(op, double) \
524DEFN_ASN_OP_T(op, const char *) \
525DEFN_ASN_OP_T(op, const sc_fxval &) \
526DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
527DEFN_ASN_OP_T(op, const sc_fxnum &) \
528DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
529DEFN_ASN_OP_OTHER(op)
530
532
533DEFN_ASN_OP(*=)
534DEFN_ASN_OP(/=)
535DEFN_ASN_OP(+=)
536DEFN_ASN_OP(-=)
537
538DEFN_ASN_OP_T(<<=, int)
539DEFN_ASN_OP_T(>>=, int)
540
541DEFN_ASN_OP_T(&=, const sc_ufix &)
542DEFN_ASN_OP_T(&=, const sc_ufix_fast &)
543DEFN_ASN_OP_T(|=, const sc_ufix &)
544DEFN_ASN_OP_T(|=, const sc_ufix_fast &)
545DEFN_ASN_OP_T(^=, const sc_ufix &)
546DEFN_ASN_OP_T(^=, const sc_ufix_fast &)
547
548#undef DEFN_ASN_OP_T
549#undef DEFN_ASN_OP_OTHER
550#undef DEFN_ASN_OP
551
552// auto-increment and auto-decrement
553template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
554inline const sc_fxval_fast
556{
557 return sc_fxval_fast( sc_ufix_fast::operator ++ (0));
558}
559
560template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
561inline const sc_fxval_fast
563{
564 return sc_fxval_fast( sc_ufix_fast::operator -- (0));
565}
566
567template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
574
575template<int W, int I, sc_q_mode Q, sc_o_mode O, int N>
582
583} // namespace sc_dt
584
585#endif // __SYSTEMC_EXT_DT_FX_SC_UFIXED_HH__
friend class sc_fxval
Definition sc_fxnum.hh:485
sc_ufix_fast & operator--()
Definition sc_ufix.hh:1346
sc_ufix_fast & operator=(const sc_ufix_fast &)
Definition sc_ufix.hh:1252
sc_ufix_fast & operator++()
Definition sc_ufix.hh:1339
sc_ufix & operator--()
Definition sc_ufix.hh:877
sc_ufix & operator=(const sc_ufix &)
Definition sc_ufix.hh:782
sc_ufix & operator++()
Definition sc_ufix.hh:870
sc_ufixed_fast(sc_fxnum_fast_observer *=0)
Definition sc_ufixed.hh:436
sc_ufixed_fast & operator++()
Definition sc_ufixed.hh:569
sc_ufixed_fast & operator--()
Definition sc_ufixed.hh:577
sc_ufixed_fast & operator=(const sc_ufixed_fast< W, I, Q, O, N > &)
Definition sc_ufixed.hh:493
sc_ufixed(sc_fxnum_observer *=0)
Definition sc_ufixed.hh:285
sc_ufixed & operator++()
Definition sc_ufixed.hh:414
sc_ufixed & operator--()
Definition sc_ufixed.hh:422
sc_ufixed & operator=(const sc_ufixed< W, I, Q, O, N > &)
Definition sc_ufixed.hh:339
#define sc_fxval
Definition sc_fxnum.hh:485
#define sc_ufixed
#define sc_ufix
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