gem5  v22.1.0.0
sc_fix.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_fix.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_fix.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_FIX_HH__
51 #define __SYSTEMC_EXT_DT_FX_SC_FIX_HH__
52 
53 #include "sc_fxnum.hh"
54 
55 namespace sc_dt
56 {
57 
58 // classes defined in this module
59 class sc_fix;
60 class sc_fix_fast;
61 
62 
63 // ----------------------------------------------------------------------------
64 // CLASS : sc_fix
65 //
66 // "Unconstrained" signed fixed-point class; arbitrary precision.
67 // ----------------------------------------------------------------------------
68 
69 class sc_fix : public sc_fxnum
70 {
71  public:
72  // constructors
73  explicit sc_fix(sc_fxnum_observer * =0);
74  sc_fix(int, int, sc_fxnum_observer * =0);
77  sc_fix(int, int, sc_q_mode, sc_o_mode, sc_fxnum_observer * =0);
78  sc_fix(int, int, sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0);
79  explicit sc_fix(const sc_fxcast_switch &, sc_fxnum_observer * =0);
80  sc_fix(int, int, const sc_fxcast_switch &, sc_fxnum_observer * =0);
82  sc_fxnum_observer * =0);
84  sc_fxnum_observer * =0);
85  sc_fix(int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &,
86  sc_fxnum_observer * =0);
87  sc_fix(int, int, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &,
88  sc_fxnum_observer * =0);
89  explicit sc_fix(const sc_fxtype_params &, sc_fxnum_observer * =0);
90  sc_fix(const sc_fxtype_params &, const sc_fxcast_switch &,
91  sc_fxnum_observer * =0);
92 
93 #define DECL_CTORS_T(tp) \
94  sc_fix(tp, int, int, sc_fxnum_observer * =0); \
95  sc_fix(tp, sc_q_mode, sc_o_mode, sc_fxnum_observer * =0); \
96  sc_fix(tp, sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0); \
97  sc_fix(tp, int, int, sc_q_mode, sc_o_mode, sc_fxnum_observer * =0); \
98  sc_fix(tp, int, int, sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0); \
99  sc_fix(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0); \
100  sc_fix(tp, int, int, const sc_fxcast_switch &, sc_fxnum_observer * =0); \
101  sc_fix(tp, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
102  sc_fxnum_observer * =0); \
103  sc_fix(tp, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &, \
104  sc_fxnum_observer * =0); \
105  sc_fix(tp, int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
106  sc_fxnum_observer * =0); \
107  sc_fix(tp, int, int, sc_q_mode, sc_o_mode, int, \
108  const sc_fxcast_switch &, sc_fxnum_observer * =0); \
109  sc_fix(tp, const sc_fxtype_params &, sc_fxnum_observer * =0); \
110  sc_fix(tp, const sc_fxtype_params &, const sc_fxcast_switch &, \
111  sc_fxnum_observer * =0);
112 
113 #define DECL_CTORS_T_A(tp) \
114  sc_fix(tp, sc_fxnum_observer * =0); \
115  DECL_CTORS_T(tp)
116 
117 #define DECL_CTORS_T_B(tp) \
118  explicit sc_fix(tp, sc_fxnum_observer * =0); \
119  DECL_CTORS_T(tp)
120 
121  DECL_CTORS_T_A(int)
122  DECL_CTORS_T_A(unsigned int)
123  DECL_CTORS_T_A(long)
124  DECL_CTORS_T_A(unsigned long)
125  DECL_CTORS_T_A(float)
126  DECL_CTORS_T_A(double)
127  DECL_CTORS_T_A(const char *)
128  DECL_CTORS_T_A(const sc_fxval &)
130  DECL_CTORS_T_A(const sc_fxnum &)
132 
135  DECL_CTORS_T_B(const sc_int_base &)
137  DECL_CTORS_T_B(const sc_signed &)
138  DECL_CTORS_T_B(const sc_unsigned &)
139 
140 #undef DECL_CTORS_T
141 #undef DECL_CTORS_T_A
142 #undef DECL_CTORS_T_B
143 
144  // copy constructor
145  sc_fix(const sc_fix &);
146 
147  // unary bitwise operators
148  const sc_fix operator ~ () const;
149 
150  // unary bitwise functions
151  friend void b_not(sc_fix &, const sc_fix &);
152 
153  // binary bitwise operators
154  friend const sc_fix operator & (const sc_fix &, const sc_fix &);
155  friend const sc_fix operator & (const sc_fix &, const sc_fix_fast &);
156  friend const sc_fix operator & (const sc_fix_fast &, const sc_fix &);
157  friend const sc_fix operator | (const sc_fix &, const sc_fix &);
158  friend const sc_fix operator | (const sc_fix &, const sc_fix_fast &);
159  friend const sc_fix operator | (const sc_fix_fast &, const sc_fix &);
160  friend const sc_fix operator ^ (const sc_fix &, const sc_fix &);
161  friend const sc_fix operator ^ (const sc_fix &, const sc_fix_fast &);
162  friend const sc_fix operator ^ (const sc_fix_fast&, const sc_fix &);
163 
164  // binary bitwise functions
165  friend void b_and(sc_fix &, const sc_fix &, const sc_fix &);
166  friend void b_and(sc_fix &, const sc_fix &, const sc_fix_fast &);
167  friend void b_and(sc_fix &, const sc_fix_fast &, const sc_fix &);
168  friend void b_or(sc_fix &, const sc_fix &, const sc_fix &);
169  friend void b_or(sc_fix &, const sc_fix &, const sc_fix_fast &);
170  friend void b_or(sc_fix &, const sc_fix_fast &, const sc_fix &);
171  friend void b_xor(sc_fix &, const sc_fix &, const sc_fix &);
172  friend void b_xor(sc_fix &, const sc_fix &, const sc_fix_fast &);
173  friend void b_xor(sc_fix &, const sc_fix_fast &, const sc_fix &);
174 
175  // assignment operators
176  sc_fix &operator = (const sc_fix &);
177 
178 #define DECL_ASN_OP_T(op, tp) sc_fix &operator op (tp);
179 
180 #define DECL_ASN_OP_OTHER(op) \
181  DECL_ASN_OP_T(op, int64) \
182  DECL_ASN_OP_T(op, uint64) \
183  DECL_ASN_OP_T(op, const sc_int_base &) \
184  DECL_ASN_OP_T(op, const sc_uint_base &) \
185  DECL_ASN_OP_T(op, const sc_signed &) \
186  DECL_ASN_OP_T(op, const sc_unsigned &)
187 
188 #define DECL_ASN_OP(op) \
189  DECL_ASN_OP_T(op, int) \
190  DECL_ASN_OP_T(op, unsigned int) \
191  DECL_ASN_OP_T(op, long) \
192  DECL_ASN_OP_T(op, unsigned long) \
193  DECL_ASN_OP_T(op, float) \
194  DECL_ASN_OP_T(op, double) \
195  DECL_ASN_OP_T(op, const char *) \
196  DECL_ASN_OP_T(op, const sc_fxval &) \
197  DECL_ASN_OP_T(op, const sc_fxval_fast &) \
198  DECL_ASN_OP_T(op, const sc_fxnum &) \
199  DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
200  DECL_ASN_OP_OTHER(op)
201 
202  DECL_ASN_OP(=)
203 
204  DECL_ASN_OP(*=)
205  DECL_ASN_OP(/=)
206  DECL_ASN_OP(+=)
207  DECL_ASN_OP(-=)
208 
209  DECL_ASN_OP_T(<<=, int)
210  DECL_ASN_OP_T(>>=, int)
211 
212  DECL_ASN_OP_T(&=, const sc_fix &)
213  DECL_ASN_OP_T(&=, const sc_fix_fast &)
214  DECL_ASN_OP_T(|=, const sc_fix &)
215  DECL_ASN_OP_T(|=, const sc_fix_fast &)
216  DECL_ASN_OP_T(^=, const sc_fix &)
217  DECL_ASN_OP_T(^=, const sc_fix_fast &)
218 
219 #undef DECL_ASN_OP_T
220 #undef DECL_ASN_OP_OTHER
221 #undef DECL_ASN_OP
222 
223  // auto-increment and auto-decrement
224  const sc_fxval operator ++ (int);
225  const sc_fxval operator -- (int);
226 
227  sc_fix& operator ++ ();
228  sc_fix& operator -- ();
229 };
230 
231 
232 // ----------------------------------------------------------------------------
233 // CLASS : sc_fix_fast
234 //
235 // "Unconstrained" signed fixed-point class; limited precision.
236 // ----------------------------------------------------------------------------
237 
239 {
240  public:
241  // constructors
242  explicit sc_fix_fast(sc_fxnum_fast_observer * =0);
243  sc_fix_fast(int, int, sc_fxnum_fast_observer * =0);
247  sc_fix_fast(int, int, sc_q_mode, sc_o_mode, int,
249  explicit sc_fix_fast(const sc_fxcast_switch &,
251  sc_fix_fast(int, int, const sc_fxcast_switch &,
257  sc_fix_fast(int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &,
259  sc_fix_fast(int, int, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &,
261  explicit sc_fix_fast(const sc_fxtype_params &,
265 
266 #define DECL_CTORS_T(tp) \
267  sc_fix_fast(tp, int, int, sc_fxnum_fast_observer * = 0); \
268  sc_fix_fast(tp, sc_q_mode, sc_o_mode, sc_fxnum_fast_observer * = 0); \
269  sc_fix_fast(tp, sc_q_mode, sc_o_mode, int, sc_fxnum_fast_observer * = 0); \
270  sc_fix_fast(tp, int, int, sc_q_mode, sc_o_mode, \
271  sc_fxnum_fast_observer * = 0); \
272  sc_fix_fast(tp, int, int, sc_q_mode, sc_o_mode, int, \
273  sc_fxnum_fast_observer * = 0); \
274  sc_fix_fast(tp, const sc_fxcast_switch &, sc_fxnum_fast_observer * = 0); \
275  sc_fix_fast(tp, int, int, const sc_fxcast_switch &, \
276  sc_fxnum_fast_observer * = 0); \
277  sc_fix_fast(tp, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
278  sc_fxnum_fast_observer * = 0); \
279  sc_fix_fast(tp, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &, \
280  sc_fxnum_fast_observer * = 0); \
281  sc_fix_fast(tp, int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
282  sc_fxnum_fast_observer * = 0); \
283  sc_fix_fast(tp, int, int, sc_q_mode, sc_o_mode, int, \
284  const sc_fxcast_switch &, sc_fxnum_fast_observer * = 0); \
285  sc_fix_fast(tp, const sc_fxtype_params &, sc_fxnum_fast_observer * = 0); \
286  sc_fix_fast(tp, const sc_fxtype_params &, const sc_fxcast_switch &, \
287  sc_fxnum_fast_observer * = 0);
288 
289 #define DECL_CTORS_T_A(tp) \
290  sc_fix_fast(tp, sc_fxnum_fast_observer * =0); \
291  DECL_CTORS_T(tp)
292 
293 #define DECL_CTORS_T_B(tp) \
294  explicit sc_fix_fast(tp, sc_fxnum_fast_observer * =0); \
295  DECL_CTORS_T(tp)
296 
297  DECL_CTORS_T_A(int)
298  DECL_CTORS_T_A(unsigned int)
299  DECL_CTORS_T_A(long)
300  DECL_CTORS_T_A(unsigned long)
301  DECL_CTORS_T_A(float)
302  DECL_CTORS_T_A(double)
303  DECL_CTORS_T_A(const char *)
304  DECL_CTORS_T_A(const sc_fxval &)
306  DECL_CTORS_T_A(const sc_fxnum &)
308 
311  DECL_CTORS_T_B(const sc_int_base &)
312  DECL_CTORS_T_B(const sc_uint_base &)
313  DECL_CTORS_T_B(const sc_signed &)
314  DECL_CTORS_T_B(const sc_unsigned &)
315 
316 #undef DECL_CTORS_T
317 #undef DECL_CTORS_T_A
318 #undef DECL_CTORS_T_B
319 
320  // copy constructor
321  sc_fix_fast(const sc_fix_fast &);
322 
323  // unary bitwise operators
324  const sc_fix_fast operator ~ () const;
325 
326  // unary bitwise functions
327  friend void b_not(sc_fix_fast &, const sc_fix_fast &);
328 
329  // binary bitwise operators
330  friend const sc_fix_fast operator & (
331  const sc_fix_fast &, const sc_fix_fast &);
332  friend const sc_fix_fast operator ^ (
333  const sc_fix_fast &, const sc_fix_fast &);
334  friend const sc_fix_fast operator | (
335  const sc_fix_fast &, const sc_fix_fast &);
336 
337  // binary bitwise functions
338  friend void b_and(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &);
339  friend void b_or(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &);
340  friend void b_xor(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &);
341 
342  // assignment operators
344 
345 #define DECL_ASN_OP_T(op,tp) sc_fix_fast &operator op (tp);
346 
347 #define DECL_ASN_OP_OTHER(op) \
348  DECL_ASN_OP_T(op, int64) \
349  DECL_ASN_OP_T(op, uint64) \
350  DECL_ASN_OP_T(op, const sc_int_base &) \
351  DECL_ASN_OP_T(op, const sc_uint_base &) \
352  DECL_ASN_OP_T(op, const sc_signed &) \
353  DECL_ASN_OP_T(op, const sc_unsigned &)
354 
355 #define DECL_ASN_OP(op) \
356  DECL_ASN_OP_T(op, int) \
357  DECL_ASN_OP_T(op, unsigned int) \
358  DECL_ASN_OP_T(op, long) \
359  DECL_ASN_OP_T(op, unsigned long) \
360  DECL_ASN_OP_T(op, float) \
361  DECL_ASN_OP_T(op, double) \
362  DECL_ASN_OP_T(op, const char *) \
363  DECL_ASN_OP_T(op, const sc_fxval &) \
364  DECL_ASN_OP_T(op, const sc_fxval_fast &) \
365  DECL_ASN_OP_T(op, const sc_fxnum &) \
366  DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
367  DECL_ASN_OP_OTHER(op)
368 
369  DECL_ASN_OP(=)
370 
371  DECL_ASN_OP(*=)
372  DECL_ASN_OP(/=)
373  DECL_ASN_OP(+=)
374  DECL_ASN_OP(-=)
375 
376  DECL_ASN_OP_T(<<=, int)
377  DECL_ASN_OP_T(>>=, int)
378 
379  DECL_ASN_OP_T(&=, const sc_fix &)
380  DECL_ASN_OP_T(&=, const sc_fix_fast &)
381  DECL_ASN_OP_T(|=, const sc_fix &)
382  DECL_ASN_OP_T(|=, const sc_fix_fast &)
383  DECL_ASN_OP_T(^=, const sc_fix &)
384  DECL_ASN_OP_T(^=, const sc_fix_fast &)
385 
386 #undef DECL_ASN_OP_T
387 #undef DECL_ASN_OP_OTHER
388 #undef DECL_ASN_OP
389 
390  // auto-increment and auto-decrement
391  const sc_fxval_fast operator ++ (int);
392  const sc_fxval_fast operator -- (int);
393 
396 };
397 
398 
399 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
400 
401 // ----------------------------------------------------------------------------
402 // CLASS : sc_fix
403 //
404 // "Unconstrained" signed fixed-point class; arbitrary precision.
405 // ----------------------------------------------------------------------------
406 
407 // constructors
408 inline sc_fix::sc_fix(sc_fxnum_observer *observer_) :
410 {}
411 
412 inline sc_fix::sc_fix(int wl_, int iwl_, sc_fxnum_observer *observer_) :
414  observer_)
415 {}
416 
418  sc_fxnum_observer *observer_) :
420  observer_ )
421 {}
422 
423 inline sc_fix::sc_fix(sc_q_mode qm, sc_o_mode om, int nb,
424  sc_fxnum_observer *observer_) :
426  observer_)
427 {}
428 
429 inline sc_fix::sc_fix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
430  sc_fxnum_observer *observer_) :
431  sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_,
432  sc_fxcast_switch(), observer_)
433 {}
434 
435 inline sc_fix::sc_fix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
436  sc_fxnum_observer* observer_) :
437  sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_,
438  sc_fxcast_switch(), observer_)
439 {}
440 
441 inline sc_fix::sc_fix(const sc_fxcast_switch &cast_sw,
442  sc_fxnum_observer *observer_) :
443  sc_fxnum(sc_fxtype_params(), SC_TC_, cast_sw, observer_)
444 {}
445 
446 inline sc_fix::sc_fix(int wl_, int iwl_, const sc_fxcast_switch &cast_sw,
447  sc_fxnum_observer *observer_) :
448  sc_fxnum(sc_fxtype_params(wl_, iwl_), SC_TC_, cast_sw, observer_)
449 {}
450 
452  const sc_fxcast_switch &cast_sw,
453  sc_fxnum_observer *observer_) :
454  sc_fxnum(sc_fxtype_params(qm, om), SC_TC_, cast_sw, observer_)
455 {}
456 
457 inline sc_fix::sc_fix(sc_q_mode qm, sc_o_mode om, int nb,
458  const sc_fxcast_switch &cast_sw,
459  sc_fxnum_observer *observer_) :
460  sc_fxnum(sc_fxtype_params(qm, om, nb), SC_TC_, cast_sw, observer_)
461 {}
462 
463 inline sc_fix::sc_fix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
464  const sc_fxcast_switch &cast_sw,
465  sc_fxnum_observer *observer_) :
466  sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, cast_sw,
467  observer_)
468 {}
469 
470 inline sc_fix::sc_fix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
471  const sc_fxcast_switch &cast_sw,
472  sc_fxnum_observer *observer_) :
473  sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, cast_sw,
474  observer_)
475 {}
476 
477 inline sc_fix::sc_fix(const sc_fxtype_params &type_params_,
478  sc_fxnum_observer *observer_) :
479  sc_fxnum( type_params_, SC_TC_, sc_fxcast_switch(), observer_)
480 {}
481 
482 inline sc_fix::sc_fix(const sc_fxtype_params &type_params_,
483  const sc_fxcast_switch &cast_sw,
484  sc_fxnum_observer *observer_) :
485  sc_fxnum(type_params_, SC_TC_, cast_sw, observer_)
486 {}
487 
488 #define DEFN_CTORS_T_A(tp) \
489 inline sc_fix::sc_fix(tp a, sc_fxnum_observer *observer_) : \
490  sc_fxnum(a, sc_fxtype_params(), SC_TC_, sc_fxcast_switch(), \
491  observer_) \
492 {} \
493  \
494 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, \
495  sc_fxnum_observer *observer_) : \
496  sc_fxnum(a, sc_fxtype_params(wl_, iwl_), SC_TC_, sc_fxcast_switch(), \
497  observer_) \
498 {} \
499  \
500 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, \
501  sc_fxnum_observer *observer_) : \
502  sc_fxnum(a, sc_fxtype_params(qm, om), SC_TC_, sc_fxcast_switch(), \
503  observer_) \
504 {} \
505  \
506 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
507  sc_fxnum_observer *observer_) : \
508  sc_fxnum(a, sc_fxtype_params(qm, om, nb), SC_TC_, \
509  sc_fxcast_switch(), observer_) \
510 {} \
511  \
512 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
513  sc_fxnum_observer *observer_) : \
514  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, \
515  sc_fxcast_switch(), observer_) \
516 {} \
517  \
518 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
519  int nb, sc_fxnum_observer *observer_) : \
520  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, \
521  sc_fxcast_switch(), observer_) \
522 {} \
523  \
524 inline sc_fix::sc_fix(tp a, const sc_fxcast_switch &cast_sw, \
525  sc_fxnum_observer *observer_) : \
526  sc_fxnum(a, sc_fxtype_params(), SC_TC_, cast_sw, observer_) \
527 {} \
528  \
529 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, \
530  const sc_fxcast_switch &cast_sw, \
531  sc_fxnum_observer *observer_) : \
532  sc_fxnum(a, sc_fxtype_params(wl_, iwl_), SC_TC_, cast_sw, observer_) \
533 {} \
534  \
535 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, \
536  const sc_fxcast_switch &cast_sw, \
537  sc_fxnum_observer *observer_) : \
538  sc_fxnum(a, sc_fxtype_params(qm, om), SC_TC_, cast_sw, observer_) \
539 {} \
540  \
541 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
542  const sc_fxcast_switch &cast_sw, \
543  sc_fxnum_observer *observer_) : \
544  sc_fxnum(a, sc_fxtype_params(qm, om, nb), SC_TC_, cast_sw, observer_) \
545 {} \
546  \
547 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
548  const sc_fxcast_switch &cast_sw, \
549  sc_fxnum_observer *observer_) : \
550  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, cast_sw, \
551  observer_) \
552 {} \
553  \
554 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
555  int nb, const sc_fxcast_switch &cast_sw, \
556  sc_fxnum_observer *observer_) : \
557  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, cast_sw, \
558  observer_) \
559 {} \
560  \
561 inline sc_fix::sc_fix(tp a, const sc_fxtype_params &type_params_, \
562  sc_fxnum_observer *observer_) : \
563  sc_fxnum(a, type_params_, SC_TC_, sc_fxcast_switch(), observer_) \
564 {} \
565  \
566 inline sc_fix::sc_fix(tp a, const sc_fxtype_params &type_params_, \
567  const sc_fxcast_switch &cast_sw, \
568  sc_fxnum_observer *observer_) : \
569  sc_fxnum(a, type_params_, SC_TC_, cast_sw, observer_) \
570 {}
571 
572 #define DEFN_CTORS_T_B(tp) \
573 inline sc_fix::sc_fix(tp a, sc_fxnum_observer *observer_) : \
574  sc_fxnum(a, a.type_params(), SC_TC_, sc_fxcast_switch(), observer_) \
575 {} \
576  \
577 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, \
578  sc_fxnum_observer *observer_) : \
579  sc_fxnum(a, sc_fxtype_params(a.type_params(), wl_, iwl_), SC_TC_, \
580  sc_fxcast_switch(), observer_) \
581 {} \
582  \
583 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, \
584  sc_fxnum_observer *observer_) : \
585  sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om), SC_TC_, \
586  sc_fxcast_switch(), observer_) \
587 {} \
588  \
589 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
590  sc_fxnum_observer *observer_) : \
591  sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om, nb), SC_TC_, \
592  sc_fxcast_switch(), observer_) \
593 {} \
594  \
595 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
596  sc_fxnum_observer *observer_) : \
597  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, \
598  sc_fxcast_switch(), observer_) \
599 {} \
600  \
601 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
602  int nb, sc_fxnum_observer *observer_) : \
603  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, \
604  sc_fxcast_switch(), observer_) \
605 {} \
606  \
607 inline sc_fix::sc_fix(tp a, const sc_fxcast_switch &cast_sw, \
608  sc_fxnum_observer *observer_) : \
609  sc_fxnum(a, a.type_params(), SC_TC_, cast_sw, observer_) \
610 {} \
611  \
612 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, \
613  const sc_fxcast_switch &cast_sw, \
614  sc_fxnum_observer *observer_) : \
615  sc_fxnum(a, sc_fxtype_params(a.type_params(), wl_, iwl_), SC_TC_, \
616  cast_sw, observer_) \
617 {} \
618  \
619 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, \
620  const sc_fxcast_switch &cast_sw, \
621  sc_fxnum_observer *observer_) : \
622  sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om), SC_TC_, \
623  cast_sw, observer_) \
624 {} \
625  \
626 inline sc_fix::sc_fix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
627  const sc_fxcast_switch &cast_sw, \
628  sc_fxnum_observer *observer_) : \
629  sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om, nb), SC_TC_, \
630  cast_sw, observer_) \
631 {} \
632  \
633 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
634  const sc_fxcast_switch &cast_sw, \
635  sc_fxnum_observer *observer_) : \
636  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, cast_sw, \
637  observer_) \
638 {} \
639  \
640 inline sc_fix::sc_fix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
641  int nb, const sc_fxcast_switch &cast_sw, \
642  sc_fxnum_observer *observer_) : \
643  sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, cast_sw, \
644  observer_) \
645 {} \
646  \
647 inline sc_fix::sc_fix(tp a, const sc_fxtype_params &type_params_, \
648  sc_fxnum_observer *observer_) : \
649  sc_fxnum(a, type_params_, SC_TC_, sc_fxcast_switch(), observer_) \
650 {} \
651  \
652 inline sc_fix::sc_fix(tp a, const sc_fxtype_params &type_params_, \
653  const sc_fxcast_switch &cast_sw, \
654  sc_fxnum_observer *observer_) : \
655  sc_fxnum(a, type_params_, SC_TC_, cast_sw, observer_) \
656 {}
657 
658 DEFN_CTORS_T_A(int)
659 DEFN_CTORS_T_A(unsigned int)
660 DEFN_CTORS_T_A(long)
661 DEFN_CTORS_T_A(unsigned long)
662 DEFN_CTORS_T_A(float)
663 DEFN_CTORS_T_A(double)
664 DEFN_CTORS_T_A(const char *)
665 DEFN_CTORS_T_A(const sc_fxval &)
667 DEFN_CTORS_T_B(const sc_fxnum &)
669 
674 DEFN_CTORS_T_A(const sc_signed &)
676 
677 #undef DEFN_CTORS_T_A
678 #undef DEFN_CTORS_T_B
679 
680 // copy constructor
681 inline sc_fix::sc_fix(const sc_fix &a) :
682  sc_fxnum(a, a.type_params(), SC_TC_, sc_fxcast_switch(), 0)
683 {}
684 
685 // unary bitwise operators
686 inline const sc_fix sc_fix::operator ~ () const
687 {
689  int iwl_c = iwl();
690  int wl_c = wl();
691  sc_fix c(wl_c, iwl_c);
692  for (int i = iwl_c - wl_c; i < iwl_c; ++i)
693  c.set_bit(i, !get_bit(i));
694  return sc_fix(c, wl_c, iwl_c);
695 }
696 
697 // unary bitwise functions
698 inline void
699 b_not(sc_fix &c, const sc_fix &a)
700 {
702  int iwl_c = c.iwl();
703  for (int i = iwl_c - c.wl(); i < iwl_c; ++i)
704  c.set_bit(i, !a.get_bit(i));
705  c.cast();
707 }
708 
709 // binary bitwise operators
710 #define DEFN_BIN_OP_T(op, op2, tp1, tp2) \
711 inline const sc_fix \
712 operator op (const tp1 &a, const tp2 &b) \
713 { \
714  a.observer_read(); \
715  b.observer_read(); \
716  int iwl_a = a.iwl(); \
717  int iwl_b = b.iwl(); \
718  int iwl_c = sc_max(iwl_a, iwl_b); \
719  int fwl_c = sc_max(a.wl() - iwl_a, b.wl() - iwl_b); \
720  sc_fix c(iwl_c + fwl_c, iwl_c); \
721  for (int i = -fwl_c; i < iwl_c; ++ i) \
722  c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
723  return sc_fix(c, iwl_c + fwl_c, iwl_c); \
724 }
725 
726 DEFN_BIN_OP_T(&, &&, sc_fix, sc_fix)
729 
730 DEFN_BIN_OP_T(|, ||, sc_fix, sc_fix)
733 
734 DEFN_BIN_OP_T(^, !=, sc_fix, sc_fix)
737 
738 #undef DEFN_BIN_OP_T
739 
740 // binary bitwise functions
741 #define DEFN_BIN_FNC_T(fnc, op2, tp1, tp2) \
742 inline void \
743 fnc (sc_fix &c, const tp1 &a, const tp2 &b) \
744 { \
745  a.observer_read(); \
746  b.observer_read(); \
747  int iwl_c = c.iwl(); \
748  for (int i = iwl_c - c.wl(); i < iwl_c; ++i) \
749  c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
750  c.cast(); \
751  SC_FXNUM_OBSERVER_WRITE_(c) \
752 }
753 
757 
761 
765 
766 #undef DEFN_BIN_FNC_T
767 
768 // assignment operators
769 inline
770 sc_fix &
772 {
773  sc_fxnum::operator = (a);
774  return *this;
775 }
776 
777 #define DEFN_ASN_OP_T(op, tp) \
778 inline sc_fix & \
779 sc_fix::operator op (tp a) \
780 { \
781  sc_fxnum::operator op(a); \
782  return *this; \
783 }
784 
785 #define DEFN_ASN_OP_OTHER(op) \
786 DEFN_ASN_OP_T(op, int64) \
787 DEFN_ASN_OP_T(op, uint64) \
788 DEFN_ASN_OP_T(op, const sc_int_base &) \
789 DEFN_ASN_OP_T(op, const sc_uint_base &) \
790 DEFN_ASN_OP_T(op, const sc_signed &) \
791 DEFN_ASN_OP_T(op, const sc_unsigned &)
792 
793 #define DEFN_ASN_OP(op) \
794 DEFN_ASN_OP_T(op, int) \
795 DEFN_ASN_OP_T(op, unsigned int) \
796 DEFN_ASN_OP_T(op, long) \
797 DEFN_ASN_OP_T(op, unsigned long) \
798 DEFN_ASN_OP_T(op, float) \
799 DEFN_ASN_OP_T(op, double) \
800 DEFN_ASN_OP_T(op, const char *) \
801 DEFN_ASN_OP_T(op, const sc_fxval &) \
802 DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
803 DEFN_ASN_OP_T(op, const sc_fxnum &) \
804 DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
805 DEFN_ASN_OP_OTHER(op)
806 
807 DEFN_ASN_OP(=)
808 
809 DEFN_ASN_OP(*=)
810 DEFN_ASN_OP(/=)
811 DEFN_ASN_OP(+=)
812 DEFN_ASN_OP(-=)
813 
814 DEFN_ASN_OP_T(<<=, int)
815 DEFN_ASN_OP_T(>>=, int)
816 
817 #undef DEFN_ASN_OP_T
818 #undef DEFN_ASN_OP_OTHER
819 #undef DEFN_ASN_OP
820 
821 #define DEFN_ASN_OP_T(op, op2, tp) \
822 inline sc_fix & \
823 sc_fix::operator op (const tp &b) \
824 { \
825  SC_FXNUM_OBSERVER_READ_(*this) \
826  b.observer_read(); \
827  int iwl_c = iwl(); \
828  for (int i = iwl_c - wl(); i < iwl_c; ++i) \
829  set_bit(i, get_bit(i) op2 b.get_bit(i)); \
830  cast(); \
831  SC_FXNUM_OBSERVER_WRITE_(*this) \
832  return *this; \
833 }
834 
835 DEFN_ASN_OP_T(&=, &&, sc_fix)
836 DEFN_ASN_OP_T(&=, &&, sc_fix_fast)
837 DEFN_ASN_OP_T(|=, ||, sc_fix)
838 DEFN_ASN_OP_T(|=, ||, sc_fix_fast)
839 DEFN_ASN_OP_T(^=, !=, sc_fix)
840 DEFN_ASN_OP_T(^=, !=, sc_fix_fast)
841 
842 #undef DEFN_ASN_OP_T
843 
844 // auto-increment and auto-decrement
845 inline const sc_fxval
847 {
848  return sc_fxval(sc_fxnum::operator ++ (0));
849 }
850 
851 inline const sc_fxval
853 {
854  return sc_fxval(sc_fxnum::operator -- (0));
855 }
856 
857 inline sc_fix &
859 {
861  return *this;
862 }
863 
864 inline sc_fix &
866 {
868  return *this;
869 }
870 
871 
872 // ----------------------------------------------------------------------------
873 // CLASS : sc_fix_fast
874 //
875 // "Unconstrained" signed fixed-point class; limited precision.
876 // ----------------------------------------------------------------------------
877 
878 // constructors
881  observer_)
882 {}
883 
884 inline sc_fix_fast::sc_fix_fast(int wl_, int iwl_,
885  sc_fxnum_fast_observer *observer_) :
887  observer_ )
888 {}
889 
891  sc_fxnum_fast_observer *observer_) :
893  observer_ )
894 {}
895 
897  sc_fxnum_fast_observer *observer_) :
899  observer_ )
900 {}
901 
902 inline sc_fix_fast::sc_fix_fast(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
903  sc_fxnum_fast_observer *observer_) :
904  sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_,
905  sc_fxcast_switch(), observer_)
906 {}
907 
908 inline sc_fix_fast::sc_fix_fast(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
909  int nb, sc_fxnum_fast_observer *observer_) :
910  sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_,
911  sc_fxcast_switch(), observer_)
912 {}
913 
915  sc_fxnum_fast_observer *observer_) :
916  sc_fxnum_fast(sc_fxtype_params(), SC_TC_, cast_sw, observer_)
917 {}
918 
919 inline sc_fix_fast::sc_fix_fast(int wl_, int iwl_,
920  const sc_fxcast_switch &cast_sw,
921  sc_fxnum_fast_observer *observer_) :
922  sc_fxnum_fast(sc_fxtype_params(wl_, iwl_), SC_TC_, cast_sw, observer_)
923 {}
924 
926  const sc_fxcast_switch &cast_sw,
927  sc_fxnum_fast_observer *observer_) :
928  sc_fxnum_fast(sc_fxtype_params(qm, om), SC_TC_, cast_sw, observer_)
929 {}
930 
932  const sc_fxcast_switch &cast_sw,
933  sc_fxnum_fast_observer *observer_) :
934  sc_fxnum_fast(sc_fxtype_params(qm, om, nb), SC_TC_, cast_sw, observer_)
935 {}
936 
937 inline sc_fix_fast::sc_fix_fast(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
938  const sc_fxcast_switch &cast_sw,
939  sc_fxnum_fast_observer *observer_) :
940  sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, cast_sw,
941  observer_)
942 {}
943 
944 inline sc_fix_fast::sc_fix_fast(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
945  int nb, const sc_fxcast_switch &cast_sw,
946  sc_fxnum_fast_observer *observer_) :
947  sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, cast_sw,
948  observer_)
949 {}
950 
951 inline sc_fix_fast::sc_fix_fast(const sc_fxtype_params &type_params_,
952  sc_fxnum_fast_observer *observer_) :
953  sc_fxnum_fast(type_params_, SC_TC_, sc_fxcast_switch(), observer_)
954 {}
955 
956 inline sc_fix_fast::sc_fix_fast(const sc_fxtype_params &type_params_,
957  const sc_fxcast_switch &cast_sw,
958  sc_fxnum_fast_observer *observer_) :
959  sc_fxnum_fast(type_params_, SC_TC_, cast_sw, observer_)
960 {}
961 
962 #define DEFN_CTORS_T_A(tp) \
963 inline sc_fix_fast::sc_fix_fast(tp a, sc_fxnum_fast_observer *observer_ ) : \
964  sc_fxnum_fast(a, sc_fxtype_params(), SC_TC_, sc_fxcast_switch(), \
965  observer_ ) \
966 {} \
967  \
968 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, \
969  sc_fxnum_fast_observer *observer_) : \
970  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_), SC_TC_, \
971  sc_fxcast_switch(), observer_) \
972 {} \
973  \
974 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
975  sc_fxnum_fast_observer *observer_) : \
976  sc_fxnum_fast(a, sc_fxtype_params(qm, om), SC_TC_, \
977  sc_fxcast_switch(), observer_) \
978 {} \
979  \
980 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
981  sc_fxnum_fast_observer *observer_ ) : \
982  sc_fxnum_fast(a, sc_fxtype_params(qm, om, nb), SC_TC_, \
983  sc_fxcast_switch(), observer_) \
984 {} \
985  \
986 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
987  sc_o_mode om, \
988  sc_fxnum_fast_observer *observer_) : \
989  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, \
990  sc_fxcast_switch(), observer_) \
991 {} \
992  \
993 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
994  sc_o_mode om, int nb, \
995  sc_fxnum_fast_observer *observer_) : \
996  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, \
997  sc_fxcast_switch(), observer_) \
998 {} \
999  \
1000 inline sc_fix_fast::sc_fix_fast(tp a, const sc_fxcast_switch &cast_sw, \
1001  sc_fxnum_fast_observer *observer_) : \
1002  sc_fxnum_fast(a, sc_fxtype_params(), SC_TC_, cast_sw, observer_) \
1003 {} \
1004  \
1005 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, \
1006  const sc_fxcast_switch &cast_sw, \
1007  sc_fxnum_fast_observer *observer_) : \
1008  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_), SC_TC_, cast_sw, \
1009  observer_ ) \
1010 {} \
1011  \
1012 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
1013  const sc_fxcast_switch &cast_sw, \
1014  sc_fxnum_fast_observer *observer_) : \
1015  sc_fxnum_fast(a, sc_fxtype_params(qm, om), SC_TC_, cast_sw, \
1016  observer_) \
1017 {} \
1018  \
1019 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
1020  const sc_fxcast_switch &cast_sw, \
1021  sc_fxnum_fast_observer *observer_) : \
1022  sc_fxnum_fast(a, sc_fxtype_params(qm, om, nb), SC_TC_, cast_sw, \
1023  observer_ ) \
1024 {} \
1025  \
1026 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
1027  sc_o_mode om, \
1028  const sc_fxcast_switch &cast_sw, \
1029  sc_fxnum_fast_observer *observer_) : \
1030  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, \
1031  cast_sw, observer_) \
1032 {} \
1033  \
1034 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
1035  sc_o_mode om, int nb, \
1036  const sc_fxcast_switch &cast_sw, \
1037  sc_fxnum_fast_observer *observer_) : \
1038  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, \
1039  cast_sw, observer_) \
1040 {} \
1041  \
1042 inline sc_fix_fast::sc_fix_fast(tp a, const sc_fxtype_params &type_params_, \
1043  sc_fxnum_fast_observer *observer_) : \
1044  sc_fxnum_fast(a, type_params_, SC_TC_, sc_fxcast_switch(), observer_) \
1045 {} \
1046  \
1047 inline sc_fix_fast::sc_fix_fast(tp a, const sc_fxtype_params &type_params_, \
1048  const sc_fxcast_switch &cast_sw, \
1049  sc_fxnum_fast_observer *observer_) : \
1050  sc_fxnum_fast(a, type_params_, SC_TC_, cast_sw, observer_) \
1051 {}
1052 
1053 #define DEFN_CTORS_T_B(tp) \
1054 inline sc_fix_fast::sc_fix_fast(tp a, sc_fxnum_fast_observer *observer_) : \
1055  sc_fxnum_fast(a, a.type_params(), SC_TC_, sc_fxcast_switch(), \
1056  observer_ ) \
1057 {} \
1058  \
1059 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, \
1060  sc_fxnum_fast_observer *observer_) : \
1061  sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), wl_, iwl_), \
1062  SC_TC_, sc_fxcast_switch(), observer_) \
1063 {} \
1064  \
1065 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
1066  sc_fxnum_fast_observer *observer_) : \
1067  sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om), SC_TC_, \
1068  sc_fxcast_switch(), observer_) \
1069 {} \
1070  \
1071 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
1072  sc_fxnum_fast_observer *observer_) : \
1073  sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om, nb), \
1074  SC_TC_, sc_fxcast_switch(), observer_) \
1075 {} \
1076  \
1077 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
1078  sc_o_mode om, \
1079  sc_fxnum_fast_observer *observer_) : \
1080  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, \
1081  sc_fxcast_switch(), observer_) \
1082 {} \
1083  \
1084 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
1085  sc_o_mode om, int nb, \
1086  sc_fxnum_fast_observer *observer_) : \
1087  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, \
1088  sc_fxcast_switch(), observer_) \
1089 {} \
1090  \
1091 inline sc_fix_fast::sc_fix_fast(tp a, const sc_fxcast_switch &cast_sw, \
1092  sc_fxnum_fast_observer *observer_) : \
1093  sc_fxnum_fast(a, a.type_params(), SC_TC_, cast_sw, observer_) \
1094 {} \
1095  \
1096 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, \
1097  const sc_fxcast_switch &cast_sw, \
1098  sc_fxnum_fast_observer *observer_) : \
1099  sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), wl_, iwl_), \
1100  SC_TC_, cast_sw, observer_) \
1101 {} \
1102  \
1103 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
1104  const sc_fxcast_switch &cast_sw, \
1105  sc_fxnum_fast_observer *observer_) : \
1106  sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om), SC_TC_, \
1107  cast_sw, observer_) \
1108 {} \
1109  \
1110 inline sc_fix_fast::sc_fix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
1111  const sc_fxcast_switch &cast_sw, \
1112  sc_fxnum_fast_observer *observer_) : \
1113  sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om, nb), \
1114  SC_TC_, cast_sw, observer_) \
1115 {} \
1116  \
1117 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
1118  sc_o_mode om, \
1119  const sc_fxcast_switch &cast_sw, \
1120  sc_fxnum_fast_observer *observer_) : \
1121  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_TC_, \
1122  cast_sw, observer_) \
1123 {} \
1124  \
1125 inline sc_fix_fast::sc_fix_fast(tp a, int wl_, int iwl_, sc_q_mode qm, \
1126  sc_o_mode om, int nb, \
1127  const sc_fxcast_switch &cast_sw, \
1128  sc_fxnum_fast_observer *observer_) : \
1129  sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_TC_, \
1130  cast_sw, observer_) \
1131 {} \
1132  \
1133 inline sc_fix_fast::sc_fix_fast(tp a, const sc_fxtype_params &type_params_, \
1134  sc_fxnum_fast_observer *observer_) : \
1135  sc_fxnum_fast(a, type_params_, SC_TC_, sc_fxcast_switch(), observer_) \
1136 {} \
1137  \
1138 inline sc_fix_fast::sc_fix_fast(tp a, const sc_fxtype_params &type_params_, \
1139  const sc_fxcast_switch &cast_sw, \
1140  sc_fxnum_fast_observer *observer_) : \
1141  sc_fxnum_fast(a, type_params_, SC_TC_, cast_sw, observer_ ) \
1142 {}
1143 
1144 DEFN_CTORS_T_A(int)
1145 DEFN_CTORS_T_A(unsigned int)
1146 DEFN_CTORS_T_A(long)
1147 DEFN_CTORS_T_A(unsigned long)
1148 DEFN_CTORS_T_A(float)
1149 DEFN_CTORS_T_A(double)
1150 DEFN_CTORS_T_A(const char *)
1151 DEFN_CTORS_T_A(const sc_fxval &)
1152 DEFN_CTORS_T_A(const sc_fxval_fast &)
1153 DEFN_CTORS_T_B(const sc_fxnum &)
1154 DEFN_CTORS_T_B(const sc_fxnum_fast &)
1155 
1158 DEFN_CTORS_T_A(const sc_int_base &)
1159 DEFN_CTORS_T_A(const sc_uint_base &)
1160 DEFN_CTORS_T_A(const sc_signed &)
1161 DEFN_CTORS_T_A(const sc_unsigned &)
1162 
1163 #undef DEFN_CTORS_T_A
1164 #undef DEFN_CTORS_T_B
1165 
1166 // copy constructor
1168  sc_fxnum_fast(a, a.type_params(), SC_TC_, sc_fxcast_switch(), 0)
1169 {}
1170 
1171 // unary bitwise operators
1172 inline const sc_fix_fast
1174 {
1176  int iwl_c = iwl();
1177  int wl_c = wl();
1178  sc_fix_fast c(wl_c, iwl_c);
1179  for (int i = iwl_c - wl_c; i < iwl_c; ++i)
1180  c.set_bit(i, !get_bit(i));
1181  return sc_fix_fast(c, wl_c, iwl_c);
1182 }
1183 
1184 // unary bitwise functions
1185 inline void
1187 {
1189  int iwl_c = c.iwl();
1190  for (int i = iwl_c - c.wl(); i < iwl_c; ++i)
1191  c.set_bit(i, !a.get_bit(i));
1192  c.cast();
1194 }
1195 
1196 // binary bitwise operators
1197 #define DEFN_BIN_OP_T(op, op2, tp1, tp2) \
1198 inline const sc_fix_fast \
1199 operator op (const tp1 &a, const tp2 &b) \
1200 { \
1201  a.observer_read(); \
1202  b.observer_read(); \
1203  int iwl_a = a.iwl(); \
1204  int iwl_b = b.iwl(); \
1205  int iwl_c = sc_max(iwl_a, iwl_b); \
1206  int fwl_c = sc_max(a.wl() - iwl_a, b.wl() - iwl_b); \
1207  sc_fix_fast c(iwl_c + fwl_c, iwl_c); \
1208  for (int i = -fwl_c; i < iwl_c; ++i) \
1209  c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
1210  return sc_fix_fast(c, iwl_c + fwl_c, iwl_c); \
1211 }
1212 
1213 DEFN_BIN_OP_T(&, &&, sc_fix_fast, sc_fix_fast)
1214 DEFN_BIN_OP_T(|, ||, sc_fix_fast, sc_fix_fast)
1215 DEFN_BIN_OP_T(^, !=, sc_fix_fast, sc_fix_fast)
1216 
1217 #undef DEFN_BIN_OP_T
1218 
1219 // binary bitwise functions
1220 #define DEFN_BIN_FNC_T(fnc, op2, tp1, tp2) \
1221 inline void \
1222 fnc(sc_fix_fast &c, const tp1 &a, const tp2 &b) \
1223 { \
1224  a.observer_read(); \
1225  b.observer_read(); \
1226  int iwl_c = c.iwl(); \
1227  for (int i = iwl_c - c.wl(); i < iwl_c; ++i) \
1228  c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
1229  c.cast(); \
1230  SC_FXNUM_FAST_OBSERVER_WRITE_(c) \
1231 }
1232 
1233 DEFN_BIN_FNC_T(b_and, &&, sc_fix_fast, sc_fix_fast)
1234 DEFN_BIN_FNC_T(b_or, ||, sc_fix_fast, sc_fix_fast)
1235 DEFN_BIN_FNC_T(b_xor, !=, sc_fix_fast, sc_fix_fast)
1236 
1237 #undef DEFN_BIN_FNC_T
1238 
1239 // assignment operators
1240 inline sc_fix_fast &
1242 {
1243  sc_fxnum_fast::operator = (a);
1244  return *this;
1245 }
1246 
1247 #define DEFN_ASN_OP_T(op, tp) \
1248 inline sc_fix_fast & \
1249 sc_fix_fast::operator op (tp a) \
1250 { \
1251  sc_fxnum_fast::operator op(a); \
1252  return *this; \
1253 }
1254 
1255 #define DEFN_ASN_OP_OTHER(op) \
1256 DEFN_ASN_OP_T(op, int64) \
1257 DEFN_ASN_OP_T(op, uint64) \
1258 DEFN_ASN_OP_T(op, const sc_int_base &) \
1259 DEFN_ASN_OP_T(op, const sc_uint_base &) \
1260 DEFN_ASN_OP_T(op, const sc_signed &) \
1261 DEFN_ASN_OP_T(op, const sc_unsigned &)
1262 
1263 #define DEFN_ASN_OP(op) \
1264 DEFN_ASN_OP_T(op, int) \
1265 DEFN_ASN_OP_T(op, unsigned int) \
1266 DEFN_ASN_OP_T(op, long) \
1267 DEFN_ASN_OP_T(op, unsigned long) \
1268 DEFN_ASN_OP_T(op, float) \
1269 DEFN_ASN_OP_T(op, double) \
1270 DEFN_ASN_OP_T(op, const char *) \
1271 DEFN_ASN_OP_T(op, const sc_fxval &) \
1272 DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
1273 DEFN_ASN_OP_T(op, const sc_fxnum &) \
1274 DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
1275 DEFN_ASN_OP_OTHER(op)
1276 
1277 DEFN_ASN_OP(=)
1278 
1279 DEFN_ASN_OP(*=)
1280 DEFN_ASN_OP(/=)
1281 DEFN_ASN_OP(+=)
1282 DEFN_ASN_OP(-=)
1283 
1284 DEFN_ASN_OP_T(<<=, int)
1285 DEFN_ASN_OP_T(>>=, int)
1286 
1287 #undef DEFN_ASN_OP_T
1288 #undef DEFN_ASN_OP_OTHER
1289 #undef DEFN_ASN_OP
1290 
1291 #define DEFN_ASN_OP_T(op, op2, tp) \
1292 inline sc_fix_fast & \
1293 sc_fix_fast::operator op (const tp &b) \
1294 { \
1295  SC_FXNUM_FAST_OBSERVER_READ_(*this) \
1296  b.observer_read(); \
1297  int iwl_c = iwl(); \
1298  for (int i = iwl_c - wl(); i < iwl_c; ++i) \
1299  set_bit(i, get_bit(i) op2 b.get_bit(i)); \
1300  cast(); \
1301  SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \
1302  return *this; \
1303 }
1304 
1305 DEFN_ASN_OP_T(&=, &&, sc_fix)
1306 DEFN_ASN_OP_T(&=, &&, sc_fix_fast)
1307 DEFN_ASN_OP_T(|=, ||, sc_fix)
1308 DEFN_ASN_OP_T(|=, ||, sc_fix_fast)
1309 DEFN_ASN_OP_T(^=, !=, sc_fix)
1310 DEFN_ASN_OP_T(^=, !=, sc_fix_fast)
1311 
1312 #undef DEFN_ASN_OP_T
1313 
1314 // auto-increment and auto-decrement
1315 inline const sc_fxval_fast
1317 {
1318  return sc_fxval_fast(sc_fxnum_fast::operator ++ (0));
1319 }
1320 
1321 inline const sc_fxval_fast
1323 {
1324  return sc_fxval_fast(sc_fxnum_fast::operator -- (0));
1325 }
1326 
1327 inline sc_fix_fast &
1329 {
1331  return *this;
1332 }
1333 
1334 inline sc_fix_fast &
1336 {
1338  return *this;
1339 }
1340 
1341 } // namespace sc_dt
1342 
1343 #endif // __SYSTEMC_EXT_DT_FX_SC_FIX_HH__
friend void b_or(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &)
friend const sc_fix_fast operator|(const sc_fix_fast &, const sc_fix_fast &)
sc_fix_fast & operator--()
Definition: sc_fix.hh:1335
friend void b_and(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &)
friend void b_xor(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &)
friend const sc_fix_fast operator&(const sc_fix_fast &, const sc_fix_fast &)
sc_fix_fast(sc_fxnum_fast_observer *=0)
Definition: sc_fix.hh:879
const sc_fix_fast operator~() const
Definition: sc_fix.hh:1173
sc_fix_fast & operator++()
Definition: sc_fix.hh:1328
friend void b_not(sc_fix_fast &, const sc_fix_fast &)
Definition: sc_fix.hh:1186
sc_fix_fast & operator=(const sc_fix_fast &)
Definition: sc_fix.hh:1241
friend const sc_fix_fast operator^(const sc_fix_fast &, const sc_fix_fast &)
friend void b_or(sc_fix &, const sc_fix &, const sc_fix &)
friend void b_xor(sc_fix &, const sc_fix &, const sc_fix &)
friend const sc_fix operator^(const sc_fix &, const sc_fix &)
friend void b_not(sc_fix &, const sc_fix &)
Definition: sc_fix.hh:699
friend void b_or(sc_fix &, const sc_fix &, const sc_fix_fast &)
friend void b_and(sc_fix &, const sc_fix &, const sc_fix_fast &)
friend const sc_fix operator|(const sc_fix &, const sc_fix &)
const sc_fix operator~() const
Definition: sc_fix.hh:686
friend void b_and(sc_fix &, const sc_fix_fast &, const sc_fix &)
friend void b_and(sc_fix &, const sc_fix &, const sc_fix &)
sc_fix & operator=(const sc_fix &)
Definition: sc_fix.hh:771
friend void b_xor(sc_fix &, const sc_fix &, const sc_fix_fast &)
friend const sc_fix operator&(const sc_fix &, const sc_fix &)
friend void b_xor(sc_fix &, const sc_fix_fast &, const sc_fix &)
sc_fix & operator--()
Definition: sc_fix.hh:865
friend void b_or(sc_fix &, const sc_fix_fast &, const sc_fix &)
sc_fix & operator++()
Definition: sc_fix.hh:858
sc_fix(sc_fxnum_observer *=0)
Definition: sc_fix.hh:408
sc_fxnum_fast & operator--()
Definition: sc_fxnum.hh:3764
sc_fxnum_fast & operator++()
Definition: sc_fxnum.hh:3754
friend class sc_fxval_fast
Definition: sc_fxnum.hh:846
bool get_bit(int) const
Definition: sc_fxnum.cc:706
int iwl() const
Definition: sc_fxnum.hh:3043
bool get_bit(int) const
Definition: sc_fxnum.hh:3087
int wl() const
Definition: sc_fxnum.hh:3037
friend class sc_fxval
Definition: sc_fxnum.hh:485
sc_fxnum & operator--()
Definition: sc_fxnum.hh:2812
sc_fxnum & operator++()
Definition: sc_fxnum.hh:2805
#define sc_fxval
#define sc_fix
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 8 > a
Definition: misc_types.hh:66
Bitfield< 2 > c
Definition: pagetable.hh:63
Definition: sc_bit.cc:68
@ SC_TC_
Definition: sc_fxdefs.hh:72
uint64_t uint64
Definition: sc_nbdefs.hh:172
sc_q_mode
Definition: sc_fxdefs.hh:92
const sc_bit b_xor(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:330
const sc_bit b_and(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:328
const sc_bit b_not(const sc_bit &a)
Definition: sc_bit.hh:298
int64_t int64
Definition: sc_nbdefs.hh:171
const sc_bit b_or(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.hh:329
#define DECL_CTORS_T_A(tp)
Definition: sc_fix.hh:289
#define DEFN_CTORS_T_B(tp)
Definition: sc_fix.hh:1053
#define DECL_CTORS_T_B(tp)
Definition: sc_fix.hh:293
#define DEFN_CTORS_T_A(tp)
Definition: sc_fix.hh:962
#define DEFN_BIN_OP_T(op, op2, tp1, tp2)
Definition: sc_fix.hh:1197
#define DEFN_ASN_OP(op)
Definition: sc_fix.hh:1263
#define DEFN_BIN_FNC_T(fnc, op2, tp1, tp2)
Definition: sc_fix.hh:1220
#define DEFN_ASN_OP_T(op, tp)
Definition: sc_fix.hh:1291
#define DECL_ASN_OP_T(op, tp)
Definition: sc_fix.hh:345
#define DECL_ASN_OP(op)
Definition: sc_fix.hh:355
#define SC_FXNUM_OBSERVER_WRITE_(object)
#define SC_FXNUM_OBSERVER_READ_(object)
#define SC_FXNUM_FAST_OBSERVER_WRITE_(object)
#define SC_FXNUM_FAST_OBSERVER_READ_(object)

Generated on Wed Dec 21 2022 10:22:41 for gem5 by doxygen 1.9.1