SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_fix.h
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 SC_FIX_H
51#define SC_FIX_H
52
53
55
56
57namespace sc_dt
58{
59
60// classes defined in this module
61class sc_fix;
62class sc_fix_fast;
63
64
65// ----------------------------------------------------------------------------
66// CLASS : sc_fix
67//
68// "Unconstrained" signed fixed-point class; arbitrary precision.
69// ----------------------------------------------------------------------------
70
71class SC_API sc_fix : public sc_fxnum
72{
73
74public:
75
76 // constructors
77
78 explicit sc_fix( sc_fxnum_observer* = 0 );
79 sc_fix( int, int,
80 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,
86 sc_fxnum_observer* = 0 );
87 sc_fix( int, int, sc_q_mode, sc_o_mode, int,
88 sc_fxnum_observer* = 0 );
89 explicit sc_fix( const sc_fxcast_switch&,
90 sc_fxnum_observer* = 0 );
91 sc_fix( int, int,
92 const sc_fxcast_switch&,
93 sc_fxnum_observer* = 0 );
95 const sc_fxcast_switch&,
96 sc_fxnum_observer* = 0 );
98 const sc_fxcast_switch&,
99 sc_fxnum_observer* = 0 );
100 sc_fix( int, int, sc_q_mode, sc_o_mode,
101 const sc_fxcast_switch&,
102 sc_fxnum_observer* = 0 );
103 sc_fix( int, int, sc_q_mode, sc_o_mode, int,
104 const sc_fxcast_switch&,
105 sc_fxnum_observer* = 0 );
106 explicit sc_fix( const sc_fxtype_params&,
107 sc_fxnum_observer* = 0 );
108 sc_fix( const sc_fxtype_params&,
109 const sc_fxcast_switch&,
110 sc_fxnum_observer* = 0 );
111
112#define DECL_CTORS_T(tp) \
113 sc_fix( tp, \
114 int, int, \
115 sc_fxnum_observer* = 0 ); \
116 sc_fix( tp, \
117 sc_q_mode, sc_o_mode, \
118 sc_fxnum_observer* = 0 ); \
119 sc_fix( tp, \
120 sc_q_mode, sc_o_mode, int, \
121 sc_fxnum_observer* = 0 ); \
122 sc_fix( tp, \
123 int, int, sc_q_mode, sc_o_mode, \
124 sc_fxnum_observer* = 0 ); \
125 sc_fix( tp, \
126 int, int, sc_q_mode, sc_o_mode, int, \
127 sc_fxnum_observer* = 0 ); \
128 sc_fix( tp, \
129 const sc_fxcast_switch&, \
130 sc_fxnum_observer* = 0 ); \
131 sc_fix( tp, \
132 int, int, \
133 const sc_fxcast_switch&, \
134 sc_fxnum_observer* = 0 ); \
135 sc_fix( tp, \
136 sc_q_mode, sc_o_mode, \
137 const sc_fxcast_switch&, \
138 sc_fxnum_observer* = 0 ); \
139 sc_fix( tp, \
140 sc_q_mode, sc_o_mode, int, \
141 const sc_fxcast_switch&, \
142 sc_fxnum_observer* = 0 ); \
143 sc_fix( tp, \
144 int, int, sc_q_mode, sc_o_mode, \
145 const sc_fxcast_switch&, \
146 sc_fxnum_observer* = 0 ); \
147 sc_fix( tp, \
148 int, int, sc_q_mode, sc_o_mode, int, \
149 const sc_fxcast_switch&, \
150 sc_fxnum_observer* = 0 ); \
151 sc_fix( tp, \
152 const sc_fxtype_params&, \
153 sc_fxnum_observer* = 0 ); \
154 sc_fix( tp, \
155 const sc_fxtype_params&, \
156 const sc_fxcast_switch&, \
157 sc_fxnum_observer* = 0 );
158
159#define DECL_CTORS_T_A(tp) \
160 sc_fix( tp, \
161 sc_fxnum_observer* = 0 ); \
162 DECL_CTORS_T(tp)
163
164#define DECL_CTORS_T_B(tp) \
165 explicit sc_fix( tp, \
166 sc_fxnum_observer* = 0 ); \
167 DECL_CTORS_T(tp)
168
169 DECL_CTORS_T_A(int)
170 DECL_CTORS_T_A(unsigned int)
171 DECL_CTORS_T_A(long)
172 DECL_CTORS_T_A(unsigned long)
173 DECL_CTORS_T_A(float)
174 DECL_CTORS_T_A(double)
175 DECL_CTORS_T_A(const char*)
186
187#undef DECL_CTORS_T
188#undef DECL_CTORS_T_A
189#undef DECL_CTORS_T_B
190
191 // copy constructor
192
193 sc_fix( const sc_fix& );
194
195
196 // unary bitwise operators
197
198 sc_fix operator ~ () const;
199
200
201 // unary bitwise functions
202
203 friend void b_not( sc_fix&, const sc_fix& );
204
205
206 // binary bitwise operators
207
208 friend sc_fix operator & ( const sc_fix&, const sc_fix& );
209 friend sc_fix operator & ( const sc_fix&, const sc_fix_fast& );
210 friend sc_fix operator & ( const sc_fix_fast&, const sc_fix& );
211 friend sc_fix operator | ( const sc_fix&, const sc_fix& );
212 friend sc_fix operator | ( const sc_fix&, const sc_fix_fast& );
213 friend sc_fix operator | ( const sc_fix_fast&, const sc_fix& );
214 friend sc_fix operator ^ ( const sc_fix&, const sc_fix& );
215 friend sc_fix operator ^ ( const sc_fix&, const sc_fix_fast& );
216 friend sc_fix operator ^ ( const sc_fix_fast&, const sc_fix& );
217
218
219 // binary bitwise functions
220
221 friend void b_and( sc_fix&, const sc_fix&, const sc_fix& );
222 friend void b_and( sc_fix&, const sc_fix&, const sc_fix_fast& );
223 friend void b_and( sc_fix&, const sc_fix_fast&, const sc_fix& );
224 friend void b_or ( sc_fix&, const sc_fix&, const sc_fix& );
225 friend void b_or ( sc_fix&, const sc_fix&, const sc_fix_fast& );
226 friend void b_or ( sc_fix&, const sc_fix_fast&, const sc_fix& );
227 friend void b_xor( sc_fix&, const sc_fix&, const sc_fix& );
228 friend void b_xor( sc_fix&, const sc_fix&, const sc_fix_fast& );
229 friend void b_xor( sc_fix&, const sc_fix_fast&, const sc_fix& );
230
231
232 // assignment operators
233
234 sc_fix& operator = ( const sc_fix& );
235
236#define DECL_ASN_OP_T(op,tp) \
237 sc_fix& operator op ( tp );
238
239#define DECL_ASN_OP_OTHER(op) \
240 DECL_ASN_OP_T(op,int64) \
241 DECL_ASN_OP_T(op,uint64) \
242 DECL_ASN_OP_T(op,const sc_int_base&) \
243 DECL_ASN_OP_T(op,const sc_uint_base&) \
244 DECL_ASN_OP_T(op,const sc_signed&) \
245 DECL_ASN_OP_T(op,const sc_unsigned&)
246
247#define DECL_ASN_OP(op) \
248 DECL_ASN_OP_T(op,int) \
249 DECL_ASN_OP_T(op,unsigned int) \
250 DECL_ASN_OP_T(op,long) \
251 DECL_ASN_OP_T(op,unsigned long) \
252 DECL_ASN_OP_T(op,float) \
253 DECL_ASN_OP_T(op,double) \
254 DECL_ASN_OP_T(op,const char*) \
255 DECL_ASN_OP_T(op,const sc_fxval&) \
256 DECL_ASN_OP_T(op,const sc_fxval_fast&) \
257 DECL_ASN_OP_T(op,const sc_fxnum&) \
258 DECL_ASN_OP_T(op,const sc_fxnum_fast&) \
259 DECL_ASN_OP_OTHER(op)
260
261 DECL_ASN_OP(=)
262
263 DECL_ASN_OP(*=)
264 DECL_ASN_OP(/=)
265 DECL_ASN_OP(+=)
266 DECL_ASN_OP(-=)
267
268 DECL_ASN_OP_T(<<=,int)
269 DECL_ASN_OP_T(>>=,int)
270
271 DECL_ASN_OP_T(&=,const sc_fix&)
272 DECL_ASN_OP_T(&=,const sc_fix_fast&)
273 DECL_ASN_OP_T(|=,const sc_fix&)
274 DECL_ASN_OP_T(|=,const sc_fix_fast&)
275 DECL_ASN_OP_T(^=,const sc_fix&)
276 DECL_ASN_OP_T(^=,const sc_fix_fast&)
277
278#undef DECL_ASN_OP_T
279#undef DECL_ASN_OP_OTHER
280#undef DECL_ASN_OP
281
282
283 // auto-increment and auto-decrement
284
285 sc_fxval operator ++ ( int );
286 sc_fxval operator -- ( int );
287
288 sc_fix& operator ++ ();
289 sc_fix& operator -- ();
290
291};
292
293
294// ----------------------------------------------------------------------------
295// CLASS : sc_fix_fast
296//
297// "Unconstrained" signed fixed-point class; limited precision.
298// ----------------------------------------------------------------------------
299
301{
302
303public:
304
305 // constructors
306
307 explicit sc_fix_fast( sc_fxnum_fast_observer* = 0 );
308 sc_fix_fast( int, int,
314 sc_fix_fast( int, int, sc_q_mode, sc_o_mode,
316 sc_fix_fast( int, int, sc_q_mode, sc_o_mode, int,
318 explicit sc_fix_fast( const sc_fxcast_switch&,
320 sc_fix_fast( int, int,
321 const sc_fxcast_switch&,
324 const sc_fxcast_switch&,
327 const sc_fxcast_switch&,
329 sc_fix_fast( int, int, sc_q_mode, sc_o_mode,
330 const sc_fxcast_switch&,
332 sc_fix_fast( int, int, sc_q_mode, sc_o_mode, int,
333 const sc_fxcast_switch&,
335 explicit sc_fix_fast( const sc_fxtype_params&,
338 const sc_fxcast_switch&,
340
341#define DECL_CTORS_T(tp) \
342 sc_fix_fast( tp, \
343 int, int, \
344 sc_fxnum_fast_observer* = 0 ); \
345 sc_fix_fast( tp, \
346 sc_q_mode, sc_o_mode, \
347 sc_fxnum_fast_observer* = 0 ); \
348 sc_fix_fast( tp, \
349 sc_q_mode, sc_o_mode, int, \
350 sc_fxnum_fast_observer* = 0 ); \
351 sc_fix_fast( tp, \
352 int, int, sc_q_mode, sc_o_mode, \
353 sc_fxnum_fast_observer* = 0 ); \
354 sc_fix_fast( tp, \
355 int, int, sc_q_mode, sc_o_mode, int, \
356 sc_fxnum_fast_observer* = 0 ); \
357 sc_fix_fast( tp, \
358 const sc_fxcast_switch&, \
359 sc_fxnum_fast_observer* = 0 ); \
360 sc_fix_fast( tp, \
361 int, int, \
362 const sc_fxcast_switch&, \
363 sc_fxnum_fast_observer* = 0 ); \
364 sc_fix_fast( tp, \
365 sc_q_mode, sc_o_mode, \
366 const sc_fxcast_switch&, \
367 sc_fxnum_fast_observer* = 0 ); \
368 sc_fix_fast( tp, \
369 sc_q_mode, sc_o_mode, int, \
370 const sc_fxcast_switch&, \
371 sc_fxnum_fast_observer* = 0 ); \
372 sc_fix_fast( tp, \
373 int, int, sc_q_mode, sc_o_mode, \
374 const sc_fxcast_switch&, \
375 sc_fxnum_fast_observer* = 0 ); \
376 sc_fix_fast( tp, \
377 int, int, sc_q_mode, sc_o_mode, int, \
378 const sc_fxcast_switch&, \
379 sc_fxnum_fast_observer* = 0 ); \
380 sc_fix_fast( tp, \
381 const sc_fxtype_params&, \
382 sc_fxnum_fast_observer* = 0 ); \
383 sc_fix_fast( tp, \
384 const sc_fxtype_params&, \
385 const sc_fxcast_switch&, \
386 sc_fxnum_fast_observer* = 0 );
387
388#define DECL_CTORS_T_A(tp) \
389 sc_fix_fast( tp, \
390 sc_fxnum_fast_observer* = 0 ); \
391 DECL_CTORS_T(tp)
392
393#define DECL_CTORS_T_B(tp) \
394 explicit sc_fix_fast( tp, \
395 sc_fxnum_fast_observer* = 0 ); \
396 DECL_CTORS_T(tp)
397
398 DECL_CTORS_T_A(int)
399 DECL_CTORS_T_A(unsigned int)
400 DECL_CTORS_T_A(long)
401 DECL_CTORS_T_A(unsigned long)
402 DECL_CTORS_T_A(float)
403 DECL_CTORS_T_A(double)
404 DECL_CTORS_T_A(const char*)
405 DECL_CTORS_T_A(const sc_fxval&)
406 DECL_CTORS_T_A(const sc_fxval_fast&)
407 DECL_CTORS_T_A(const sc_fxnum&)
408 DECL_CTORS_T_A(const sc_fxnum_fast&)
411 DECL_CTORS_T_B(const sc_int_base&)
412 DECL_CTORS_T_B(const sc_uint_base&)
413 DECL_CTORS_T_B(const sc_signed&)
414 DECL_CTORS_T_B(const sc_unsigned&)
415
416#undef DECL_CTORS_T
417#undef DECL_CTORS_T_A
418#undef DECL_CTORS_T_B
419
420 // copy constructor
421
422 sc_fix_fast( const sc_fix_fast& );
423
424
425 // unary bitwise operators
426
427 sc_fix_fast operator ~ () const;
428
429
430 // unary bitwise functions
431
432 friend void b_not( sc_fix_fast&, const sc_fix_fast& );
433
434
435 // binary bitwise operators
436
438 const sc_fix_fast& );
440 const sc_fix_fast& );
442 const sc_fix_fast& );
443
444
445 // binary bitwise functions
446
447 friend void b_and( sc_fix_fast&, const sc_fix_fast&, const sc_fix_fast& );
448 friend void b_or ( sc_fix_fast&, const sc_fix_fast&, const sc_fix_fast& );
449 friend void b_xor( sc_fix_fast&, const sc_fix_fast&, const sc_fix_fast& );
450
451
452 // assignment operators
453
454 sc_fix_fast& operator = ( const sc_fix_fast& );
455
456#define DECL_ASN_OP_T(op,tp) \
457 sc_fix_fast& operator op ( tp );
458
459#define DECL_ASN_OP_OTHER(op) \
460 DECL_ASN_OP_T(op,int64) \
461 DECL_ASN_OP_T(op,uint64) \
462 DECL_ASN_OP_T(op,const sc_int_base&) \
463 DECL_ASN_OP_T(op,const sc_uint_base&) \
464 DECL_ASN_OP_T(op,const sc_signed&) \
465 DECL_ASN_OP_T(op,const sc_unsigned&)
466
467#define DECL_ASN_OP(op) \
468 DECL_ASN_OP_T(op,int) \
469 DECL_ASN_OP_T(op,unsigned int) \
470 DECL_ASN_OP_T(op,long) \
471 DECL_ASN_OP_T(op,unsigned long) \
472 DECL_ASN_OP_T(op,float) \
473 DECL_ASN_OP_T(op,double) \
474 DECL_ASN_OP_T(op,const char*) \
475 DECL_ASN_OP_T(op,const sc_fxval&) \
476 DECL_ASN_OP_T(op,const sc_fxval_fast&) \
477 DECL_ASN_OP_T(op,const sc_fxnum&) \
478 DECL_ASN_OP_T(op,const sc_fxnum_fast&) \
479 DECL_ASN_OP_OTHER(op)
480
481 DECL_ASN_OP(=)
482
483 DECL_ASN_OP(*=)
484 DECL_ASN_OP(/=)
485 DECL_ASN_OP(+=)
486 DECL_ASN_OP(-=)
487
488 DECL_ASN_OP_T(<<=,int)
489 DECL_ASN_OP_T(>>=,int)
490
491 DECL_ASN_OP_T(&=,const sc_fix&)
492 DECL_ASN_OP_T(&=,const sc_fix_fast&)
493 DECL_ASN_OP_T(|=,const sc_fix&)
494 DECL_ASN_OP_T(|=,const sc_fix_fast&)
495 DECL_ASN_OP_T(^=,const sc_fix&)
496 DECL_ASN_OP_T(^=,const sc_fix_fast&)
497
498#undef DECL_ASN_OP_T
499#undef DECL_ASN_OP_OTHER
500#undef DECL_ASN_OP
501
502
503 // auto-increment and auto-decrement
504
505 sc_fxval_fast operator ++ ( int );
506 sc_fxval_fast operator -- ( int );
507
508 sc_fix_fast& operator ++ ();
509 sc_fix_fast& operator -- ();
510
511};
512
513
514// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
515
516// ----------------------------------------------------------------------------
517// CLASS : sc_fix
518//
519// "Unconstrained" signed fixed-point class; arbitrary precision.
520// ----------------------------------------------------------------------------
521
522// constructors
523
524inline
527 SC_TC_,
529 observer_ )
530{}
531
532inline
533sc_fix::sc_fix( int wl_, int iwl_,
534 sc_fxnum_observer* observer_ )
535: sc_fxnum( sc_fxtype_params( wl_, iwl_ ),
536 SC_TC_,
538 observer_ )
539{}
540
541inline
543 sc_fxnum_observer* observer_ )
544: sc_fxnum( sc_fxtype_params( qm, om ),
545 SC_TC_,
547 observer_ )
548{}
549
550inline
552 sc_fxnum_observer* observer_ )
553: sc_fxnum( sc_fxtype_params( qm, om, nb ),
554 SC_TC_,
556 observer_ )
557{}
558
559inline
560sc_fix::sc_fix( int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
561 sc_fxnum_observer* observer_ )
562: sc_fxnum( sc_fxtype_params( wl_, iwl_, qm, om ),
563 SC_TC_,
565 observer_ )
566{}
567
568inline
569sc_fix::sc_fix( int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
570 sc_fxnum_observer* observer_ )
571: sc_fxnum( sc_fxtype_params( wl_, iwl_, qm, om, nb ),
572 SC_TC_,
574 observer_ )
575{}
576
577inline
579 sc_fxnum_observer* observer_ )
581 SC_TC_,
582 cast_sw,
583 observer_ )
584{}
585
586inline
587sc_fix::sc_fix( int wl_, int iwl_,
588 const sc_fxcast_switch& cast_sw,
589 sc_fxnum_observer* observer_ )
590: sc_fxnum( sc_fxtype_params( wl_, iwl_ ),
591 SC_TC_,
592 cast_sw,
593 observer_ )
594{}
595
596inline
598 const sc_fxcast_switch& cast_sw,
599 sc_fxnum_observer* observer_ )
600: sc_fxnum( sc_fxtype_params( qm, om ),
601 SC_TC_,
602 cast_sw,
603 observer_ )
604{}
605
606inline
608 const sc_fxcast_switch& cast_sw,
609 sc_fxnum_observer* observer_ )
610: sc_fxnum( sc_fxtype_params( qm, om, nb ),
611 SC_TC_,
612 cast_sw,
613 observer_ )
614{}
615
616inline
617sc_fix::sc_fix( int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
618 const sc_fxcast_switch& cast_sw,
619 sc_fxnum_observer* observer_ )
620: sc_fxnum( sc_fxtype_params( wl_, iwl_, qm, om ),
621 SC_TC_,
622 cast_sw,
623 observer_ )
624{}
625
626inline
627sc_fix::sc_fix( int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
628 const sc_fxcast_switch& cast_sw,
629 sc_fxnum_observer* observer_ )
630: sc_fxnum( sc_fxtype_params( wl_, iwl_, qm, om, nb ),
631 SC_TC_,
632 cast_sw,
633 observer_ )
634{}
635
636inline
637sc_fix::sc_fix( const sc_fxtype_params& type_params_,
638 sc_fxnum_observer* observer_ )
639: sc_fxnum( type_params_,
640 SC_TC_,
642 observer_ )
643{}
644
645inline
646sc_fix::sc_fix( const sc_fxtype_params& type_params_,
647 const sc_fxcast_switch& cast_sw,
648 sc_fxnum_observer* observer_ )
649: sc_fxnum( type_params_,
650 SC_TC_,
651 cast_sw,
652 observer_ )
653{}
654
655#define DEFN_CTORS_T_A(tp) \
656inline \
657sc_fix::sc_fix( tp a, \
658 sc_fxnum_observer* observer_ ) \
659: sc_fxnum( a, \
660 sc_fxtype_params(), \
661 SC_TC_, \
662 sc_fxcast_switch(), \
663 observer_ ) \
664{} \
665 \
666inline \
667sc_fix::sc_fix( tp a, \
668 int wl_, int iwl_, \
669 sc_fxnum_observer* observer_ ) \
670: sc_fxnum( a, \
671 sc_fxtype_params( wl_, iwl_ ), \
672 SC_TC_, \
673 sc_fxcast_switch(), \
674 observer_ ) \
675{} \
676 \
677inline \
678sc_fix::sc_fix( tp a, \
679 sc_q_mode qm, sc_o_mode om, \
680 sc_fxnum_observer* observer_ ) \
681: sc_fxnum( a, \
682 sc_fxtype_params( qm, om ), \
683 SC_TC_, \
684 sc_fxcast_switch(), \
685 observer_ ) \
686{} \
687 \
688inline \
689sc_fix::sc_fix( tp a, \
690 sc_q_mode qm, sc_o_mode om, int nb, \
691 sc_fxnum_observer* observer_ ) \
692: sc_fxnum( a, \
693 sc_fxtype_params( qm, om, nb ), \
694 SC_TC_, \
695 sc_fxcast_switch(), \
696 observer_ ) \
697{} \
698 \
699inline \
700sc_fix::sc_fix( tp a, \
701 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
702 sc_fxnum_observer* observer_ ) \
703: sc_fxnum( a, \
704 sc_fxtype_params( wl_, iwl_, qm, om ), \
705 SC_TC_, \
706 sc_fxcast_switch(), \
707 observer_ ) \
708{} \
709 \
710inline \
711sc_fix::sc_fix( tp a, \
712 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
713 sc_fxnum_observer* observer_ ) \
714: sc_fxnum( a, \
715 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
716 SC_TC_, \
717 sc_fxcast_switch(), \
718 observer_ ) \
719{} \
720 \
721inline \
722sc_fix::sc_fix( tp a, \
723 const sc_fxcast_switch& cast_sw, \
724 sc_fxnum_observer* observer_ ) \
725: sc_fxnum( a, \
726 sc_fxtype_params(), \
727 SC_TC_, \
728 cast_sw, \
729 observer_ ) \
730{} \
731 \
732inline \
733sc_fix::sc_fix( tp a, \
734 int wl_, int iwl_, \
735 const sc_fxcast_switch& cast_sw, \
736 sc_fxnum_observer* observer_ ) \
737: sc_fxnum( a, \
738 sc_fxtype_params( wl_, iwl_ ), \
739 SC_TC_, \
740 cast_sw, \
741 observer_ ) \
742{} \
743 \
744inline \
745sc_fix::sc_fix( tp a, \
746 sc_q_mode qm, sc_o_mode om, \
747 const sc_fxcast_switch& cast_sw, \
748 sc_fxnum_observer* observer_ ) \
749: sc_fxnum( a, \
750 sc_fxtype_params( qm, om ), \
751 SC_TC_, \
752 cast_sw, \
753 observer_ ) \
754{} \
755 \
756inline \
757sc_fix::sc_fix( tp a, \
758 sc_q_mode qm, sc_o_mode om, int nb, \
759 const sc_fxcast_switch& cast_sw, \
760 sc_fxnum_observer* observer_ ) \
761: sc_fxnum( a, \
762 sc_fxtype_params( qm, om, nb ), \
763 SC_TC_, \
764 cast_sw, \
765 observer_ ) \
766{} \
767 \
768inline \
769sc_fix::sc_fix( tp a, \
770 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
771 const sc_fxcast_switch& cast_sw, \
772 sc_fxnum_observer* observer_ ) \
773: sc_fxnum( a, \
774 sc_fxtype_params( wl_, iwl_, qm, om ), \
775 SC_TC_, \
776 cast_sw, \
777 observer_ ) \
778{} \
779 \
780inline \
781sc_fix::sc_fix( tp a, \
782 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
783 const sc_fxcast_switch& cast_sw, \
784 sc_fxnum_observer* observer_ ) \
785: sc_fxnum( a, \
786 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
787 SC_TC_, \
788 cast_sw, \
789 observer_ ) \
790{} \
791 \
792inline \
793sc_fix::sc_fix( tp a, \
794 const sc_fxtype_params& type_params_, \
795 sc_fxnum_observer* observer_ ) \
796: sc_fxnum( a, \
797 type_params_, \
798 SC_TC_, \
799 sc_fxcast_switch(), \
800 observer_ ) \
801{} \
802 \
803inline \
804sc_fix::sc_fix( tp a, \
805 const sc_fxtype_params& type_params_, \
806 const sc_fxcast_switch& cast_sw, \
807 sc_fxnum_observer* observer_ ) \
808: sc_fxnum( a, \
809 type_params_, \
810 SC_TC_, \
811 cast_sw, \
812 observer_ ) \
813{}
814
815#define DEFN_CTORS_T_B(tp) \
816inline \
817sc_fix::sc_fix( tp a, \
818 sc_fxnum_observer* observer_ ) \
819: sc_fxnum( a, \
820 a.type_params(), \
821 SC_TC_, \
822 sc_fxcast_switch(), \
823 observer_ ) \
824{} \
825 \
826inline \
827sc_fix::sc_fix( tp a, \
828 int wl_, int iwl_, \
829 sc_fxnum_observer* observer_ ) \
830: sc_fxnum( a, \
831 sc_fxtype_params( a.type_params(), wl_, iwl_ ), \
832 SC_TC_, \
833 sc_fxcast_switch(), \
834 observer_ ) \
835{} \
836 \
837inline \
838sc_fix::sc_fix( tp a, \
839 sc_q_mode qm, sc_o_mode om, \
840 sc_fxnum_observer* observer_ ) \
841: sc_fxnum( a, \
842 sc_fxtype_params( a.type_params(), qm, om ), \
843 SC_TC_, \
844 sc_fxcast_switch(), \
845 observer_ ) \
846{} \
847 \
848inline \
849sc_fix::sc_fix( tp a, \
850 sc_q_mode qm, sc_o_mode om, int nb, \
851 sc_fxnum_observer* observer_ ) \
852: sc_fxnum( a, \
853 sc_fxtype_params( a.type_params(), qm, om, nb ), \
854 SC_TC_, \
855 sc_fxcast_switch(), \
856 observer_ ) \
857{} \
858 \
859inline \
860sc_fix::sc_fix( tp a, \
861 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
862 sc_fxnum_observer* observer_ ) \
863: sc_fxnum( a, \
864 sc_fxtype_params( wl_, iwl_, qm, om ), \
865 SC_TC_, \
866 sc_fxcast_switch(), \
867 observer_ ) \
868{} \
869 \
870inline \
871sc_fix::sc_fix( tp a, \
872 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
873 sc_fxnum_observer* observer_ ) \
874: sc_fxnum( a, \
875 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
876 SC_TC_, \
877 sc_fxcast_switch(), \
878 observer_ ) \
879{} \
880 \
881inline \
882sc_fix::sc_fix( tp a, \
883 const sc_fxcast_switch& cast_sw, \
884 sc_fxnum_observer* observer_ ) \
885: sc_fxnum( a, \
886 a.type_params(), \
887 SC_TC_, \
888 cast_sw, \
889 observer_ ) \
890{} \
891 \
892inline \
893sc_fix::sc_fix( tp a, \
894 int wl_, int iwl_, \
895 const sc_fxcast_switch& cast_sw, \
896 sc_fxnum_observer* observer_ ) \
897: sc_fxnum( a, \
898 sc_fxtype_params( a.type_params(), wl_, iwl_ ), \
899 SC_TC_, \
900 cast_sw, \
901 observer_ ) \
902{} \
903 \
904inline \
905sc_fix::sc_fix( tp a, \
906 sc_q_mode qm, sc_o_mode om, \
907 const sc_fxcast_switch& cast_sw, \
908 sc_fxnum_observer* observer_ ) \
909: sc_fxnum( a, \
910 sc_fxtype_params( a.type_params(), qm, om ), \
911 SC_TC_, \
912 cast_sw, \
913 observer_ ) \
914{} \
915 \
916inline \
917sc_fix::sc_fix( tp a, \
918 sc_q_mode qm, sc_o_mode om, int nb, \
919 const sc_fxcast_switch& cast_sw, \
920 sc_fxnum_observer* observer_ ) \
921: sc_fxnum( a, \
922 sc_fxtype_params( a.type_params(), qm, om, nb ), \
923 SC_TC_, \
924 cast_sw, \
925 observer_ ) \
926{} \
927 \
928inline \
929sc_fix::sc_fix( tp a, \
930 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
931 const sc_fxcast_switch& cast_sw, \
932 sc_fxnum_observer* observer_ ) \
933: sc_fxnum( a, \
934 sc_fxtype_params( wl_, iwl_, qm, om ), \
935 SC_TC_, \
936 cast_sw, \
937 observer_ ) \
938{} \
939 \
940inline \
941sc_fix::sc_fix( tp a, \
942 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
943 const sc_fxcast_switch& cast_sw, \
944 sc_fxnum_observer* observer_ ) \
945: sc_fxnum( a, \
946 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
947 SC_TC_, \
948 cast_sw, \
949 observer_ ) \
950{} \
951 \
952inline \
953sc_fix::sc_fix( tp a, \
954 const sc_fxtype_params& type_params_, \
955 sc_fxnum_observer* observer_ ) \
956: sc_fxnum( a, \
957 type_params_, \
958 SC_TC_, \
959 sc_fxcast_switch(), \
960 observer_ ) \
961{} \
962 \
963inline \
964sc_fix::sc_fix( tp a, \
965 const sc_fxtype_params& type_params_, \
966 const sc_fxcast_switch& cast_sw, \
967 sc_fxnum_observer* observer_ ) \
968: sc_fxnum( a, \
969 type_params_, \
970 SC_TC_, \
971 cast_sw, \
972 observer_ ) \
973{}
974
976DEFN_CTORS_T_A(unsigned int)
977DEFN_CTORS_T_A(long)
978DEFN_CTORS_T_A(unsigned long)
979DEFN_CTORS_T_A(float)
980DEFN_CTORS_T_A(double)
981DEFN_CTORS_T_A(const char*)
992
993#undef DEFN_CTORS_T_A
994#undef DEFN_CTORS_T_B
995
996// copy constructor
997
998inline
1000: sc_fxnum( a,
1001 a.type_params(),
1002 SC_TC_,
1004 0 )
1005{}
1006
1007
1008// unary bitwise operators
1009
1010inline
1011sc_fix
1013{
1015 int iwl_c = iwl();
1016 int wl_c = wl();
1017 sc_fix c( wl_c, iwl_c );
1018 for( int i = iwl_c - wl_c; i < iwl_c; ++ i )
1019 c.set_bit( i, ! get_bit( i ) );
1020 return sc_fix( c, wl_c, iwl_c );
1021}
1022
1023
1024// unary bitwise functions
1025
1026inline
1027void
1028b_not( sc_fix& c, const sc_fix& a )
1029{
1031 int iwl_c = c.iwl();
1032 for( int i = iwl_c - c.wl(); i < iwl_c; ++ i )
1033 c.set_bit( i, ! a.get_bit( i ) );
1034 c.cast();
1036}
1037
1038
1039// binary bitwise operators
1040
1041#define DEFN_BIN_OP_T(op,op2,tp1,tp2) \
1042inline \
1043sc_fix \
1044operator op ( const tp1& a, const tp2& b ) \
1045{ \
1046 a.observer_read(); \
1047 b.observer_read(); \
1048 int iwl_a = a.iwl(); \
1049 int iwl_b = b.iwl(); \
1050 int iwl_c = sc_max( iwl_a, iwl_b ); \
1051 int fwl_c = sc_max( a.wl() - iwl_a, b.wl() - iwl_b ); \
1052 sc_fix c( iwl_c + fwl_c, iwl_c ); \
1053 for( int i = -fwl_c; i < iwl_c; ++ i ) \
1054 c.set_bit( i, a.get_bit( i ) op2 b.get_bit( i ) ); \
1055 return sc_fix( c, iwl_c + fwl_c, iwl_c ); \
1056}
1057
1061
1065
1069
1070#undef DEFN_BIN_OP_T
1071
1072
1073// binary bitwise functions
1074
1075#define DEFN_BIN_FNC_T(fnc,op2,tp1,tp2) \
1076inline \
1077void \
1078fnc ( sc_fix& c, const tp1& a, const tp2& b ) \
1079{ \
1080 a.observer_read(); \
1081 b.observer_read(); \
1082 int iwl_c = c.iwl(); \
1083 for( int i = iwl_c - c.wl(); i < iwl_c; ++ i ) \
1084 c.set_bit( i, a.get_bit( i ) op2 b.get_bit( i ) ); \
1085 c.cast(); \
1086 SC_FXNUM_OBSERVER_WRITE_( c ) \
1087}
1088
1092
1096
1100
1101#undef DEFN_BIN_FNC_T
1102
1103
1104// assignment operators
1105
1106inline
1107sc_fix&
1109{
1110 sc_fxnum::operator = ( a );
1111 return *this;
1112}
1113
1114#define DEFN_ASN_OP_T(op,tp) \
1115inline \
1116sc_fix& \
1117sc_fix::operator op ( tp a ) \
1118{ \
1119 sc_fxnum::operator op( a ); \
1120 return *this; \
1121}
1122
1123#define DEFN_ASN_OP_OTHER(op) \
1124DEFN_ASN_OP_T(op,int64) \
1125DEFN_ASN_OP_T(op,uint64) \
1126DEFN_ASN_OP_T(op,const sc_int_base&) \
1127DEFN_ASN_OP_T(op,const sc_uint_base&) \
1128DEFN_ASN_OP_T(op,const sc_signed&) \
1129DEFN_ASN_OP_T(op,const sc_unsigned&)
1130
1131#define DEFN_ASN_OP(op) \
1132DEFN_ASN_OP_T(op,int) \
1133DEFN_ASN_OP_T(op,unsigned int) \
1134DEFN_ASN_OP_T(op,long) \
1135DEFN_ASN_OP_T(op,unsigned long) \
1136DEFN_ASN_OP_T(op,float) \
1137DEFN_ASN_OP_T(op,double) \
1138DEFN_ASN_OP_T(op,const char*) \
1139DEFN_ASN_OP_T(op,const sc_fxval&) \
1140DEFN_ASN_OP_T(op,const sc_fxval_fast&) \
1141DEFN_ASN_OP_T(op,const sc_fxnum&) \
1142DEFN_ASN_OP_T(op,const sc_fxnum_fast&) \
1143DEFN_ASN_OP_OTHER(op)
1144
1145DEFN_ASN_OP(=)
1146
1147DEFN_ASN_OP(*=)
1148DEFN_ASN_OP(/=)
1149DEFN_ASN_OP(+=)
1150DEFN_ASN_OP(-=)
1151
1152DEFN_ASN_OP_T(<<=,int)
1153DEFN_ASN_OP_T(>>=,int)
1154
1155#undef DEFN_ASN_OP_T
1156#undef DEFN_ASN_OP_OTHER
1157#undef DEFN_ASN_OP
1158
1159
1160#define DEFN_ASN_OP_T(op,op2,tp) \
1161inline \
1162sc_fix& \
1163sc_fix::operator op ( const tp& b ) \
1164{ \
1165 SC_FXNUM_OBSERVER_READ_( *this ) \
1166 b.observer_read(); \
1167 int iwl_c = iwl(); \
1168 for( int i = iwl_c - wl(); i < iwl_c; ++ i ) \
1169 set_bit( i, get_bit( i ) op2 b.get_bit( i ) ); \
1170 cast(); \
1171 SC_FXNUM_OBSERVER_WRITE_( *this ) \
1172 return *this; \
1173}
1174
1175DEFN_ASN_OP_T(&=,&&,sc_fix)
1177DEFN_ASN_OP_T(|=,||,sc_fix)
1179DEFN_ASN_OP_T(^=,!=,sc_fix)
1181
1182#undef DEFN_ASN_OP_T
1183
1184
1185// auto-increment and auto-decrement
1186
1187inline
1190{
1191 return sc_fxval( sc_fxnum::operator ++ ( 0 ) );
1192}
1193
1194inline
1197{
1198 return sc_fxval( sc_fxnum::operator -- ( 0 ) );
1199}
1200
1201inline
1202sc_fix&
1204{
1206 return *this;
1207}
1208
1209inline
1210sc_fix&
1212{
1214 return *this;
1215}
1216
1217
1218// ----------------------------------------------------------------------------
1219// CLASS : sc_fix_fast
1220//
1221// "Unconstrained" signed fixed-point class; limited precision.
1222// ----------------------------------------------------------------------------
1223
1224// constructors
1225
1226inline
1229 SC_TC_,
1231 observer_ )
1232{}
1233
1234inline
1235sc_fix_fast::sc_fix_fast( int wl_, int iwl_,
1236 sc_fxnum_fast_observer* observer_ )
1237: sc_fxnum_fast( sc_fxtype_params( wl_, iwl_ ),
1238 SC_TC_,
1240 observer_ )
1241{}
1242
1243inline
1245 sc_fxnum_fast_observer* observer_ )
1246: sc_fxnum_fast( sc_fxtype_params( qm, om ),
1247 SC_TC_,
1249 observer_ )
1250{}
1251
1252inline
1254 sc_fxnum_fast_observer* observer_ )
1255: sc_fxnum_fast( sc_fxtype_params( qm, om, nb ),
1256 SC_TC_,
1258 observer_ )
1259{}
1260
1261inline
1263 sc_fxnum_fast_observer* observer_ )
1264: sc_fxnum_fast( sc_fxtype_params( wl_, iwl_, qm, om ),
1265 SC_TC_,
1267 observer_ )
1268{}
1269
1270inline
1271sc_fix_fast::sc_fix_fast( int wl_, int iwl_,
1272 sc_q_mode qm, sc_o_mode om, int nb,
1273 sc_fxnum_fast_observer* observer_ )
1274: sc_fxnum_fast( sc_fxtype_params( wl_, iwl_, qm, om, nb ),
1275 SC_TC_,
1277 observer_ )
1278{}
1279
1280inline
1282 sc_fxnum_fast_observer* observer_ )
1284 SC_TC_,
1285 cast_sw,
1286 observer_ )
1287{}
1288
1289inline
1290sc_fix_fast::sc_fix_fast( int wl_, int iwl_,
1291 const sc_fxcast_switch& cast_sw,
1292 sc_fxnum_fast_observer* observer_ )
1293: sc_fxnum_fast( sc_fxtype_params( wl_, iwl_ ),
1294 SC_TC_,
1295 cast_sw,
1296 observer_ )
1297{}
1298
1299inline
1301 const sc_fxcast_switch& cast_sw,
1302 sc_fxnum_fast_observer* observer_ )
1303: sc_fxnum_fast( sc_fxtype_params( qm, om ),
1304 SC_TC_,
1305 cast_sw,
1306 observer_ )
1307{}
1308
1309inline
1311 const sc_fxcast_switch& cast_sw,
1312 sc_fxnum_fast_observer* observer_ )
1313: sc_fxnum_fast( sc_fxtype_params( qm, om, nb ),
1314 SC_TC_,
1315 cast_sw,
1316 observer_ )
1317{}
1318
1319inline
1321 const sc_fxcast_switch& cast_sw,
1322 sc_fxnum_fast_observer* observer_ )
1323: sc_fxnum_fast( sc_fxtype_params( wl_, iwl_, qm, om ),
1324 SC_TC_,
1325 cast_sw,
1326 observer_ )
1327{}
1328
1329inline
1330sc_fix_fast::sc_fix_fast( int wl_, int iwl_,
1331 sc_q_mode qm, sc_o_mode om, int nb,
1332 const sc_fxcast_switch& cast_sw,
1333 sc_fxnum_fast_observer* observer_ )
1334: sc_fxnum_fast( sc_fxtype_params( wl_, iwl_, qm, om, nb ),
1335 SC_TC_,
1336 cast_sw,
1337 observer_ )
1338{}
1339
1340inline
1342 sc_fxnum_fast_observer* observer_ )
1343: sc_fxnum_fast( type_params_,
1344 SC_TC_,
1346 observer_ )
1347{}
1348
1349inline
1351 const sc_fxcast_switch& cast_sw,
1352 sc_fxnum_fast_observer* observer_ )
1353: sc_fxnum_fast( type_params_,
1354 SC_TC_,
1355 cast_sw,
1356 observer_ )
1357{}
1358
1359#define DEFN_CTORS_T_A(tp) \
1360inline \
1361sc_fix_fast::sc_fix_fast( tp a, \
1362 sc_fxnum_fast_observer* observer_ ) \
1363: sc_fxnum_fast( a, \
1364 sc_fxtype_params(), \
1365 SC_TC_, \
1366 sc_fxcast_switch(), \
1367 observer_ ) \
1368{} \
1369 \
1370inline \
1371sc_fix_fast::sc_fix_fast( tp a, \
1372 int wl_, int iwl_, \
1373 sc_fxnum_fast_observer* observer_ ) \
1374: sc_fxnum_fast( a, \
1375 sc_fxtype_params( wl_, iwl_ ), \
1376 SC_TC_, \
1377 sc_fxcast_switch(), \
1378 observer_ ) \
1379{} \
1380 \
1381inline \
1382sc_fix_fast::sc_fix_fast( tp a, \
1383 sc_q_mode qm, sc_o_mode om, \
1384 sc_fxnum_fast_observer* observer_ ) \
1385: sc_fxnum_fast( a, \
1386 sc_fxtype_params( qm, om ), \
1387 SC_TC_, \
1388 sc_fxcast_switch(), \
1389 observer_ ) \
1390{} \
1391 \
1392inline \
1393sc_fix_fast::sc_fix_fast( tp a, \
1394 sc_q_mode qm, sc_o_mode om, int nb, \
1395 sc_fxnum_fast_observer* observer_ ) \
1396: sc_fxnum_fast( a, \
1397 sc_fxtype_params( qm, om, nb ), \
1398 SC_TC_, \
1399 sc_fxcast_switch(), \
1400 observer_ ) \
1401{} \
1402 \
1403inline \
1404sc_fix_fast::sc_fix_fast( tp a, \
1405 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1406 sc_fxnum_fast_observer* observer_ ) \
1407: sc_fxnum_fast( a, \
1408 sc_fxtype_params( wl_, iwl_, qm, om ), \
1409 SC_TC_, \
1410 sc_fxcast_switch(), \
1411 observer_ ) \
1412{} \
1413 \
1414inline \
1415sc_fix_fast::sc_fix_fast( tp a, \
1416 int wl_, int iwl_, \
1417 sc_q_mode qm, sc_o_mode om, int nb, \
1418 sc_fxnum_fast_observer* observer_ ) \
1419: sc_fxnum_fast( a, \
1420 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
1421 SC_TC_, \
1422 sc_fxcast_switch(), \
1423 observer_ ) \
1424{} \
1425 \
1426inline \
1427sc_fix_fast::sc_fix_fast( tp a, \
1428 const sc_fxcast_switch& cast_sw, \
1429 sc_fxnum_fast_observer* observer_ ) \
1430: sc_fxnum_fast( a, \
1431 sc_fxtype_params(), \
1432 SC_TC_, \
1433 cast_sw, \
1434 observer_ ) \
1435{} \
1436 \
1437inline \
1438sc_fix_fast::sc_fix_fast( tp a, \
1439 int wl_, int iwl_, \
1440 const sc_fxcast_switch& cast_sw, \
1441 sc_fxnum_fast_observer* observer_ ) \
1442: sc_fxnum_fast( a, \
1443 sc_fxtype_params( wl_, iwl_ ), \
1444 SC_TC_, \
1445 cast_sw, \
1446 observer_ ) \
1447{} \
1448 \
1449inline \
1450sc_fix_fast::sc_fix_fast( tp a, \
1451 sc_q_mode qm, sc_o_mode om, \
1452 const sc_fxcast_switch& cast_sw, \
1453 sc_fxnum_fast_observer* observer_ ) \
1454: sc_fxnum_fast( a, \
1455 sc_fxtype_params( qm, om ), \
1456 SC_TC_, \
1457 cast_sw, \
1458 observer_ ) \
1459{} \
1460 \
1461inline \
1462sc_fix_fast::sc_fix_fast( tp a, \
1463 sc_q_mode qm, sc_o_mode om, int nb, \
1464 const sc_fxcast_switch& cast_sw, \
1465 sc_fxnum_fast_observer* observer_ ) \
1466: sc_fxnum_fast( a, \
1467 sc_fxtype_params( qm, om, nb ), \
1468 SC_TC_, \
1469 cast_sw, \
1470 observer_ ) \
1471{} \
1472 \
1473inline \
1474sc_fix_fast::sc_fix_fast( tp a, \
1475 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1476 const sc_fxcast_switch& cast_sw, \
1477 sc_fxnum_fast_observer* observer_ ) \
1478: sc_fxnum_fast( a, \
1479 sc_fxtype_params( wl_, iwl_, qm, om ), \
1480 SC_TC_, \
1481 cast_sw, \
1482 observer_ ) \
1483{} \
1484 \
1485inline \
1486sc_fix_fast::sc_fix_fast( tp a, \
1487 int wl_, int iwl_, \
1488 sc_q_mode qm, sc_o_mode om, int nb, \
1489 const sc_fxcast_switch& cast_sw, \
1490 sc_fxnum_fast_observer* observer_ ) \
1491: sc_fxnum_fast( a, \
1492 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
1493 SC_TC_, \
1494 cast_sw, \
1495 observer_ ) \
1496{} \
1497 \
1498inline \
1499sc_fix_fast::sc_fix_fast( tp a, \
1500 const sc_fxtype_params& type_params_, \
1501 sc_fxnum_fast_observer* observer_ ) \
1502: sc_fxnum_fast( a, \
1503 type_params_, \
1504 SC_TC_, \
1505 sc_fxcast_switch(), \
1506 observer_ ) \
1507{} \
1508 \
1509inline \
1510sc_fix_fast::sc_fix_fast( tp a, \
1511 const sc_fxtype_params& type_params_, \
1512 const sc_fxcast_switch& cast_sw, \
1513 sc_fxnum_fast_observer* observer_ ) \
1514: sc_fxnum_fast( a, \
1515 type_params_, \
1516 SC_TC_, \
1517 cast_sw, \
1518 observer_ ) \
1519{}
1520
1521#define DEFN_CTORS_T_B(tp) \
1522inline \
1523sc_fix_fast::sc_fix_fast( tp a, \
1524 sc_fxnum_fast_observer* observer_ ) \
1525: sc_fxnum_fast( a, \
1526 a.type_params(), \
1527 SC_TC_, \
1528 sc_fxcast_switch(), \
1529 observer_ ) \
1530{} \
1531 \
1532inline \
1533sc_fix_fast::sc_fix_fast( tp a, \
1534 int wl_, int iwl_, \
1535 sc_fxnum_fast_observer* observer_ ) \
1536: sc_fxnum_fast( a, \
1537 sc_fxtype_params( a.type_params(), wl_, iwl_ ), \
1538 SC_TC_, \
1539 sc_fxcast_switch(), \
1540 observer_ ) \
1541{} \
1542 \
1543inline \
1544sc_fix_fast::sc_fix_fast( tp a, \
1545 sc_q_mode qm, sc_o_mode om, \
1546 sc_fxnum_fast_observer* observer_ ) \
1547: sc_fxnum_fast( a, \
1548 sc_fxtype_params( a.type_params(), qm, om ), \
1549 SC_TC_, \
1550 sc_fxcast_switch(), \
1551 observer_ ) \
1552{} \
1553 \
1554inline \
1555sc_fix_fast::sc_fix_fast( tp a, \
1556 sc_q_mode qm, sc_o_mode om, int nb, \
1557 sc_fxnum_fast_observer* observer_ ) \
1558: sc_fxnum_fast( a, \
1559 sc_fxtype_params( a.type_params(), qm, om, nb ), \
1560 SC_TC_, \
1561 sc_fxcast_switch(), \
1562 observer_ ) \
1563{} \
1564 \
1565inline \
1566sc_fix_fast::sc_fix_fast( tp a, \
1567 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1568 sc_fxnum_fast_observer* observer_ ) \
1569: sc_fxnum_fast( a, \
1570 sc_fxtype_params( wl_, iwl_, qm, om ), \
1571 SC_TC_, \
1572 sc_fxcast_switch(), \
1573 observer_ ) \
1574{} \
1575 \
1576inline \
1577sc_fix_fast::sc_fix_fast( tp a, \
1578 int wl_, int iwl_, \
1579 sc_q_mode qm, sc_o_mode om, int nb, \
1580 sc_fxnum_fast_observer* observer_ ) \
1581: sc_fxnum_fast( a, \
1582 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
1583 SC_TC_, \
1584 sc_fxcast_switch(), \
1585 observer_ ) \
1586{} \
1587 \
1588inline \
1589sc_fix_fast::sc_fix_fast( tp a, \
1590 const sc_fxcast_switch& cast_sw, \
1591 sc_fxnum_fast_observer* observer_ ) \
1592: sc_fxnum_fast( a, \
1593 a.type_params(), \
1594 SC_TC_, \
1595 cast_sw, \
1596 observer_ ) \
1597{} \
1598 \
1599inline \
1600sc_fix_fast::sc_fix_fast( tp a, \
1601 int wl_, int iwl_, \
1602 const sc_fxcast_switch& cast_sw, \
1603 sc_fxnum_fast_observer* observer_ ) \
1604: sc_fxnum_fast( a, \
1605 sc_fxtype_params( a.type_params(), wl_, iwl_ ), \
1606 SC_TC_, \
1607 cast_sw, \
1608 observer_ ) \
1609{} \
1610 \
1611inline \
1612sc_fix_fast::sc_fix_fast( tp a, \
1613 sc_q_mode qm, sc_o_mode om, \
1614 const sc_fxcast_switch& cast_sw, \
1615 sc_fxnum_fast_observer* observer_ ) \
1616: sc_fxnum_fast( a, \
1617 sc_fxtype_params( a.type_params(), qm, om ), \
1618 SC_TC_, \
1619 cast_sw, \
1620 observer_ ) \
1621{} \
1622 \
1623inline \
1624sc_fix_fast::sc_fix_fast( tp a, \
1625 sc_q_mode qm, sc_o_mode om, int nb, \
1626 const sc_fxcast_switch& cast_sw, \
1627 sc_fxnum_fast_observer* observer_ ) \
1628: sc_fxnum_fast( a, \
1629 sc_fxtype_params( a.type_params(), qm, om, nb ), \
1630 SC_TC_, \
1631 cast_sw, \
1632 observer_ ) \
1633{} \
1634 \
1635inline \
1636sc_fix_fast::sc_fix_fast( tp a, \
1637 int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1638 const sc_fxcast_switch& cast_sw, \
1639 sc_fxnum_fast_observer* observer_ ) \
1640: sc_fxnum_fast( a, \
1641 sc_fxtype_params( wl_, iwl_, qm, om ), \
1642 SC_TC_, \
1643 cast_sw, \
1644 observer_ ) \
1645{} \
1646 \
1647inline \
1648sc_fix_fast::sc_fix_fast( tp a, \
1649 int wl_, int iwl_, \
1650 sc_q_mode qm, sc_o_mode om, int nb, \
1651 const sc_fxcast_switch& cast_sw, \
1652 sc_fxnum_fast_observer* observer_ ) \
1653: sc_fxnum_fast( a, \
1654 sc_fxtype_params( wl_, iwl_, qm, om, nb ), \
1655 SC_TC_, \
1656 cast_sw, \
1657 observer_ ) \
1658{} \
1659 \
1660inline \
1661sc_fix_fast::sc_fix_fast( tp a, \
1662 const sc_fxtype_params& type_params_, \
1663 sc_fxnum_fast_observer* observer_ ) \
1664: sc_fxnum_fast( a, \
1665 type_params_, \
1666 SC_TC_, \
1667 sc_fxcast_switch(), \
1668 observer_ ) \
1669{} \
1670 \
1671inline \
1672sc_fix_fast::sc_fix_fast( tp a, \
1673 const sc_fxtype_params& type_params_, \
1674 const sc_fxcast_switch& cast_sw, \
1675 sc_fxnum_fast_observer* observer_ ) \
1676: sc_fxnum_fast( a, \
1677 type_params_, \
1678 SC_TC_, \
1679 cast_sw, \
1680 observer_ ) \
1681{}
1682
1683DEFN_CTORS_T_A(int)
1684DEFN_CTORS_T_A(unsigned int)
1685DEFN_CTORS_T_A(long)
1686DEFN_CTORS_T_A(unsigned long)
1687DEFN_CTORS_T_A(float)
1688DEFN_CTORS_T_A(double)
1689DEFN_CTORS_T_A(const char*)
1690DEFN_CTORS_T_A(const sc_fxval&)
1691DEFN_CTORS_T_A(const sc_fxval_fast&)
1692DEFN_CTORS_T_B(const sc_fxnum&)
1693DEFN_CTORS_T_B(const sc_fxnum_fast&)
1696DEFN_CTORS_T_A(const sc_int_base&)
1697DEFN_CTORS_T_A(const sc_uint_base&)
1698DEFN_CTORS_T_A(const sc_signed&)
1699DEFN_CTORS_T_A(const sc_unsigned&)
1700
1701#undef DEFN_CTORS_T_A
1702#undef DEFN_CTORS_T_B
1703
1704// copy constructor
1705
1706inline
1708: sc_fxnum_fast( a,
1709 a.type_params(),
1710 SC_TC_,
1712 0 )
1713{}
1714
1715
1716// unary bitwise operators
1717
1718inline
1721{
1723 int iwl_c = iwl();
1724 int wl_c = wl();
1725 sc_fix_fast c( wl_c, iwl_c );
1726 for( int i = iwl_c - wl_c; i < iwl_c; ++ i )
1727 c.set_bit( i, ! get_bit( i ) );
1728 return sc_fix_fast( c, wl_c, iwl_c );
1729}
1730
1731
1732// unary bitwise functions
1733
1734inline
1735void
1737{
1739 int iwl_c = c.iwl();
1740 for( int i = iwl_c - c.wl(); i < iwl_c; ++ i )
1741 c.set_bit( i, ! a.get_bit( i ) );
1742 c.cast();
1744}
1745
1746
1747// binary bitwise operators
1748
1749#define DEFN_BIN_OP_T(op,op2,tp1,tp2) \
1750inline \
1751sc_fix_fast \
1752operator op ( const tp1& a, const tp2& b ) \
1753{ \
1754 a.observer_read(); \
1755 b.observer_read(); \
1756 int iwl_a = a.iwl(); \
1757 int iwl_b = b.iwl(); \
1758 int iwl_c = sc_max( iwl_a, iwl_b ); \
1759 int fwl_c = sc_max( a.wl() - iwl_a, b.wl() - iwl_b ); \
1760 sc_fix_fast c( iwl_c + fwl_c, iwl_c ); \
1761 for( int i = -fwl_c; i < iwl_c; ++ i ) \
1762 c.set_bit( i, a.get_bit( i ) op2 b.get_bit( i ) ); \
1763 return sc_fix_fast( c, iwl_c + fwl_c, iwl_c ); \
1764}
1765
1766DEFN_BIN_OP_T(&,&&,sc_fix_fast,sc_fix_fast)
1767DEFN_BIN_OP_T(|,||,sc_fix_fast,sc_fix_fast)
1768DEFN_BIN_OP_T(^,!=,sc_fix_fast,sc_fix_fast)
1769
1770#undef DEFN_BIN_OP_T
1771
1772
1773// binary bitwise functions
1774
1775#define DEFN_BIN_FNC_T(fnc,op2,tp1,tp2) \
1776inline \
1777void \
1778fnc ( sc_fix_fast& c, const tp1& a, const tp2& b ) \
1779{ \
1780 a.observer_read(); \
1781 b.observer_read(); \
1782 int iwl_c = c.iwl(); \
1783 for( int i = iwl_c - c.wl(); i < iwl_c; ++ i ) \
1784 c.set_bit( i, a.get_bit( i ) op2 b.get_bit( i ) ); \
1785 c.cast(); \
1786 SC_FXNUM_FAST_OBSERVER_WRITE_( c ) \
1787}
1788
1789DEFN_BIN_FNC_T(b_and,&&,sc_fix_fast,sc_fix_fast)
1790DEFN_BIN_FNC_T(b_or,||,sc_fix_fast,sc_fix_fast)
1791DEFN_BIN_FNC_T(b_xor,!=,sc_fix_fast,sc_fix_fast)
1792
1793#undef DEFN_BIN_FNC_T
1794
1795
1796// assignment operators
1797
1798inline
1799sc_fix_fast&
1801{
1802 sc_fxnum_fast::operator = ( a );
1803 return *this;
1804}
1805
1806#define DEFN_ASN_OP_T(op,tp) \
1807inline \
1808sc_fix_fast& \
1809sc_fix_fast::operator op ( tp a ) \
1810{ \
1811 sc_fxnum_fast::operator op( a ); \
1812 return *this; \
1813}
1814
1815#define DEFN_ASN_OP_OTHER(op) \
1816DEFN_ASN_OP_T(op,int64) \
1817DEFN_ASN_OP_T(op,uint64) \
1818DEFN_ASN_OP_T(op,const sc_int_base&) \
1819DEFN_ASN_OP_T(op,const sc_uint_base&) \
1820DEFN_ASN_OP_T(op,const sc_signed&) \
1821DEFN_ASN_OP_T(op,const sc_unsigned&)
1822
1823#define DEFN_ASN_OP(op) \
1824DEFN_ASN_OP_T(op,int) \
1825DEFN_ASN_OP_T(op,unsigned int) \
1826DEFN_ASN_OP_T(op,long) \
1827DEFN_ASN_OP_T(op,unsigned long) \
1828DEFN_ASN_OP_T(op,float) \
1829DEFN_ASN_OP_T(op,double) \
1830DEFN_ASN_OP_T(op,const char*) \
1831DEFN_ASN_OP_T(op,const sc_fxval&) \
1832DEFN_ASN_OP_T(op,const sc_fxval_fast&) \
1833DEFN_ASN_OP_T(op,const sc_fxnum&) \
1834DEFN_ASN_OP_T(op,const sc_fxnum_fast&) \
1835DEFN_ASN_OP_OTHER(op)
1836
1837DEFN_ASN_OP(=)
1838
1839DEFN_ASN_OP(*=)
1840DEFN_ASN_OP(/=)
1841DEFN_ASN_OP(+=)
1842DEFN_ASN_OP(-=)
1843
1844DEFN_ASN_OP_T(<<=,int)
1845DEFN_ASN_OP_T(>>=,int)
1846
1847#undef DEFN_ASN_OP_T
1848#undef DEFN_ASN_OP_OTHER
1849#undef DEFN_ASN_OP
1850
1851
1852#define DEFN_ASN_OP_T(op,op2,tp) \
1853inline \
1854sc_fix_fast& \
1855sc_fix_fast::operator op ( const tp& b ) \
1856{ \
1857 SC_FXNUM_FAST_OBSERVER_READ_( *this ) \
1858 b.observer_read(); \
1859 int iwl_c = iwl(); \
1860 for( int i = iwl_c - wl(); i < iwl_c; ++ i ) \
1861 set_bit( i, get_bit( i ) op2 b.get_bit( i ) ); \
1862 cast(); \
1863 SC_FXNUM_FAST_OBSERVER_WRITE_( *this ) \
1864 return *this; \
1865}
1866
1867DEFN_ASN_OP_T(&=,&&,sc_fix)
1868DEFN_ASN_OP_T(&=,&&,sc_fix_fast)
1869DEFN_ASN_OP_T(|=,||,sc_fix)
1870DEFN_ASN_OP_T(|=,||,sc_fix_fast)
1871DEFN_ASN_OP_T(^=,!=,sc_fix)
1872DEFN_ASN_OP_T(^=,!=,sc_fix_fast)
1873
1874#undef DEFN_ASN_OP_T
1875
1876
1877// auto-increment and auto-decrement
1878
1879inline
1880sc_fxval_fast
1882{
1883 return sc_fxval_fast( sc_fxnum_fast::operator ++ ( 0 ) );
1884}
1885
1886inline
1889{
1890 return sc_fxval_fast( sc_fxnum_fast::operator -- ( 0 ) );
1891}
1892
1893inline
1896{
1898 return *this;
1899}
1900
1901inline
1904{
1906 return *this;
1907}
1908
1909} // namespace sc_dt
1910
1911
1912#endif
1913
1914// Taf!
#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)
#define DECL_CTORS_T_A(tp)
Definition: sc_fix.h:388
#define DEFN_CTORS_T_B(tp)
Definition: sc_fix.h:1521
#define DECL_CTORS_T_B(tp)
Definition: sc_fix.h:393
#define DEFN_CTORS_T_A(tp)
Definition: sc_fix.h:1359
#define DEFN_ASN_OP(op)
Definition: sc_fix.h:1823
#define DEFN_BIN_FNC_T(fnc, op2, tp1, tp2)
Definition: sc_fix.h:1775
#define DEFN_ASN_OP_T(op, tp)
Definition: sc_fix.h:1852
#define DECL_ASN_OP_T(op, tp)
Definition: sc_fix.h:456
#define DECL_ASN_OP(op)
Definition: sc_fix.h:467
#define SC_API
Definition: sc_cmnhdr.h:148
@ SC_TC_
Definition: sc_fxdefs.h:68
sc_bit b_and(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:346
sc_q_mode
Definition: sc_fxdefs.h:91
sc_bit operator&(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:331
sc_bit operator^(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:337
sc_bit b_or(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:349
unsigned long long uint64
Definition: sc_nbdefs.h:216
sc_bit b_not(const sc_bit &a)
Definition: sc_bit.h:318
DEFN_BIN_OP_T(/, div, int64) DEFN_BIN_OP_T(/
sc_bit b_xor(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:352
sc_bit operator~(const sc_bit &a)
Definition: sc_bit.h:312
sc_bit operator|(const sc_bit &a, const sc_bit &b)
Definition: sc_bit.h:334
long long int64
Definition: sc_nbdefs.h:215
sc_o_mode
Definition: sc_fxdefs.h:120
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 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 void b_and(sc_fix &, const sc_fix_fast &, const sc_fix &)
sc_fix operator~() const
Definition: sc_fix.h:1012
friend void b_and(sc_fix &, const sc_fix &, const sc_fix &)
sc_fix & operator=(const sc_fix &)
Definition: sc_fix.h:1108
friend void b_xor(sc_fix &, const sc_fix &, const sc_fix_fast &)
friend void b_xor(sc_fix &, const sc_fix_fast &, const sc_fix &)
sc_fix & operator--()
Definition: sc_fix.h:1211
friend void b_or(sc_fix &, const sc_fix_fast &, const sc_fix &)
sc_fix & operator++()
Definition: sc_fix.h:1203
sc_fix(sc_fxnum_observer *=0)
Definition: sc_fix.h:525
friend void b_or(sc_fix_fast &, const sc_fix_fast &, const sc_fix_fast &)
sc_fix_fast & operator--()
Definition: sc_fix.h:1903
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 &)
sc_fix_fast operator~() const
Definition: sc_fix.h:1720
sc_fix_fast(sc_fxnum_fast_observer *=0)
Definition: sc_fix.h:1227
sc_fix_fast & operator++()
Definition: sc_fix.h:1895
sc_fix_fast & operator=(const sc_fix_fast &)
Definition: sc_fix.h:1800
int iwl() const
Definition: sc_fxnum.h:3622
bool get_bit(int) const
Definition: sc_fxnum.h:3677
int wl() const
Definition: sc_fxnum.h:3615
bool set_bit(int, bool)
Definition: sc_fxnum.h:3687
friend class sc_fxval
Definition: sc_fxnum.h:618
sc_fxnum & operator--()
Definition: sc_fxnum.h:3349
sc_fxnum & operator++()
Definition: sc_fxnum.h:3341
sc_fxnum_fast & operator--()
Definition: sc_fxnum.h:4442
sc_fxnum_fast & operator++()
Definition: sc_fxnum.h:4431
int iwl() const
Definition: sc_fxnum.h:4740
friend class sc_fxval_fast
Definition: sc_fxnum.h:1027
int wl() const
Definition: sc_fxnum.h:4733
bool get_bit(int) const
bool set_bit(int, bool)