SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_fxnum.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_fxnum.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_fxnum.h,v $
39// Revision 1.5 2011/08/29 18:04:32 acg
40// Philipp A. Hartmann: miscellaneous clean ups.
41//
42// Revision 1.4 2011/08/24 22:05:43 acg
43// Torsten Maehne: initialization changes to remove warnings.
44//
45// Revision 1.3 2011/01/19 18:57:40 acg
46// Andy Goodrich: changes for IEEE_1666_2011.
47//
48// Revision 1.2 2009/03/09 17:26:46 acg
49// Andy Goodrich: removed ; from namespace { }
50//
51// Revision 1.1.1.1 2006/12/15 20:20:04 acg
52// SystemC 2.3
53//
54// Revision 1.3 2006/01/13 18:53:58 acg
55// Andy Goodrich: added $Log command so that CVS comments are reproduced in
56// the source.
57//
58
59#ifndef SC_FXNUM_H
60#define SC_FXNUM_H
61
62
68
69
70namespace sc_core {
71 class vcd_sc_fxnum_trace;
72 class vcd_sc_fxnum_fast_trace;
73 class wif_sc_fxnum_trace;
74 class wif_sc_fxnum_fast_trace;
75}
76
77
78namespace sc_dt
79{
80
81// classes defined in this module
82class sc_fxnum_bitref_r;
83class sc_fxnum_fast_bitref_r;
84class sc_fxnum_bitref;
85class sc_fxnum_fast_bitref;
86class sc_fxnum_subref_r;
87class sc_fxnum_fast_subref_r;
88class sc_fxnum_subref;
89class sc_fxnum_fast_subref;
90class sc_fxnum;
91class sc_fxnum_fast;
92
93
94// ----------------------------------------------------------------------------
95// CLASS : sc_fxnum_bitref_r
96//
97// Read-only proxy class for bit-selection in class sc_fxnum
98// ----------------------------------------------------------------------------
100 friend class sc_fxnum;
102
103protected:
104
105 bool get() const;
107
108public:
109
111
112 operator bool() const;
113
114 // print or dump content
115 void print( ::std::ostream& = ::std::cout ) const;
116 void dump( ::std::ostream& = ::std::cout ) const;
117
118protected:
119
121 int m_idx;
122};
123
124
125// ----------------------------------------------------------------------------
126// CLASS : sc_fxnum_bitref
127//
128// Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
129// ----------------------------------------------------------------------------
130
132{
133 friend class sc_fxnum;
134
135 void set( bool );
136
137 // constructor
138
139 sc_fxnum_bitref( sc_fxnum&, int );
140
141public:
142
143 // copy constructor
144
146
147
148 // assignment operators
149
150#define DECL_ASN_OP_T(op,tp) \
151 sc_fxnum_bitref& operator op ( tp );
152
153#define DECL_ASN_OP(op) \
154 DECL_ASN_OP_T(op,const sc_fxnum_bitref&) \
155 DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&) \
156 DECL_ASN_OP_T(op,const sc_bit&) \
157 DECL_ASN_OP_T(op,bool)
158
159 DECL_ASN_OP(=)
160
161 DECL_ASN_OP(&=)
162 DECL_ASN_OP(|=)
163 DECL_ASN_OP(^=)
164
165#undef DECL_ASN_OP_T
166#undef DECL_ASN_OP
167
168
169 void scan( ::std::istream& = ::std::cin );
170
171};
172
173// ----------------------------------------------------------------------------
174// CLASS : sc_fxnum_fast_bitref_r
175//
176// Read-only proxy class for bit-selection in class sc_fxnum_fast
177// ----------------------------------------------------------------------------
178
180{
181 friend class sc_fxnum_fast;
182 friend class sc_fxnum_bitref;
183
184protected:
185 bool get() const;
187
188public:
189
190 // copy constructor
191
193
194 operator bool() const;
195
196 void print( ::std::ostream& = ::std::cout ) const;
197 void dump( ::std::ostream& = ::std::cout ) const;
198
199protected:
200
202 int m_idx;
203};
204
205
206// ----------------------------------------------------------------------------
207// CLASS : sc_fxnum_fast_bitref
208//
209// Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
210// ----------------------------------------------------------------------------
211
213{
214 friend class sc_fxnum_fast;
215
216 void set( bool );
217
219
220public:
221
223
224 // assignment operators
225
226#define DECL_ASN_OP_T(op,tp) \
227 sc_fxnum_fast_bitref& operator op ( tp );
228
229#define DECL_ASN_OP(op) \
230 DECL_ASN_OP_T(op,const sc_fxnum_bitref&) \
231 DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&) \
232 DECL_ASN_OP_T(op,const sc_bit&) \
233 DECL_ASN_OP_T(op,bool)
234
235 DECL_ASN_OP(=)
236
237 DECL_ASN_OP(&=)
238 DECL_ASN_OP(|=)
239 DECL_ASN_OP(^=)
240
241#undef DECL_ASN_OP_T
242#undef DECL_ASN_OP
243
244 void scan( ::std::istream& = ::std::cin );
245};
246
247
248// ----------------------------------------------------------------------------
249// CLASS : sc_fxnum_subref_r
250//
251// Read-only proxy class for part-selection in class sc_fxnum,
252// behaves like sc_bv_base.
253// ----------------------------------------------------------------------------
254
256{
257 friend class sc_fxnum;
258
259protected:
260
261 bool get() const;
262
263 sc_fxnum_subref_r( sc_fxnum&, int, int );
264
265public:
266
267 // copy constructor
268
270
271
272 // destructor
273
275
276 // relational operators
277
278#define DECL_REL_OP_T(op,tp) \
279 friend bool operator op ( const sc_fxnum_subref_r&, tp ); \
280 friend bool operator op ( tp, const sc_fxnum_subref_r& );
281
282#define DECL_REL_OP(op) \
283 friend bool operator op ( const sc_fxnum_subref_r&, \
284 const sc_fxnum_subref_r& ); \
285 friend bool operator op ( const sc_fxnum_subref_r&, \
286 const sc_fxnum_fast_subref_r& ); \
287 DECL_REL_OP_T(op,const sc_bv_base&) \
288 DECL_REL_OP_T(op,const sc_lv_base&) \
289 DECL_REL_OP_T(op,const char*) \
290 DECL_REL_OP_T(op,const bool*) \
291 DECL_REL_OP_T(op,const sc_signed&) \
292 DECL_REL_OP_T(op,const sc_unsigned&) \
293 DECL_REL_OP_T(op,int) \
294 DECL_REL_OP_T(op,unsigned int) \
295 DECL_REL_OP_T(op,long) \
296 DECL_REL_OP_T(op,unsigned long)
297
298 DECL_REL_OP(==)
299 DECL_REL_OP(!=)
300
301#undef DECL_REL_OP_T
302#undef DECL_REL_OP
303
304
305 // reduce functions
306
307 bool and_reduce() const;
308 bool nand_reduce() const;
309 bool or_reduce() const;
310 bool nor_reduce() const;
311 bool xor_reduce() const;
312 bool xnor_reduce() const;
313
314
315 // query parameter
316
317 int length() const;
318
319
320 // explicit conversions
321
322 int to_int() const;
323 unsigned int to_uint() const;
324 long to_long() const;
325 unsigned long to_ulong() const;
326 int64 to_int64() const;
327 uint64 to_uint64() const;
328
329#ifdef SC_DT_DEPRECATED
330 int to_signed() const;
331 unsigned int to_unsigned() const;
332#endif
333
334 std::string to_string() const;
335 std::string to_string( sc_numrep ) const;
336 std::string to_string( sc_numrep, bool ) const;
337
338
339 // implicit conversion
340
341 operator sc_bv_base() const;
342
343
344 // print or dump content
345
346 void print( ::std::ostream& = ::std::cout ) const;
347 void dump( ::std::ostream& = ::std::cout ) const;
348
349protected:
350
353 int m_to;
354
356};
357
358
359// ----------------------------------------------------------------------------
360// CLASS : sc_fxnum_subref
361//
362// Proxy class for part-selection in class sc_fxnum,
363// behaves like sc_bv_base.
364// ----------------------------------------------------------------------------
365
367{
368 friend class sc_fxnum;
370
371 bool set();
372
373 // constructor
374
375 sc_fxnum_subref( sc_fxnum&, int, int );
376
377public:
378
379 // copy constructor
380
382
383 // assignment operators
384
385#define DECL_ASN_OP_T(tp) \
386 sc_fxnum_subref& operator = ( tp );
387
392 DECL_ASN_OP_T(const char*)
393 DECL_ASN_OP_T(const bool*)
400 DECL_ASN_OP_T(int)
401 DECL_ASN_OP_T(unsigned int)
402 DECL_ASN_OP_T(long)
403 DECL_ASN_OP_T(unsigned long)
404 DECL_ASN_OP_T(char)
405
406#undef DECL_ASN_OP_T
407
408#define DECL_ASN_OP_T_A(op,tp) \
409 sc_fxnum_subref& operator op ## = ( tp );
410
411#define DECL_ASN_OP_A(op) \
412 DECL_ASN_OP_T_A(op,const sc_fxnum_subref&) \
413 DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&) \
414 DECL_ASN_OP_T_A(op,const sc_bv_base&) \
415 DECL_ASN_OP_T_A(op,const sc_lv_base&)
416
420
421#undef DECL_ASN_OP_T_A
422#undef DECL_ASN_OP_A
423
424 void scan( ::std::istream& = ::std::cin );
425
426};
427
428
429// ----------------------------------------------------------------------------
430// CLASS : sc_fxnum_fast_subref_r
431//
432// Read-only proxy class for part-selection in class sc_fxnum_fast,
433// behaves like sc_bv_base.
434// ----------------------------------------------------------------------------
435
437{
438 friend class sc_fxnum_fast;
439
440protected:
441
442 bool get() const;
443
445
446public:
447
448 // copy constructor
449
451
452 // destructor
453
455
456 // relational operators
457
458#define DECL_REL_OP_T(op,tp) \
459 friend bool operator op ( const sc_fxnum_fast_subref_r&, tp ); \
460 friend bool operator op ( tp, const sc_fxnum_fast_subref_r& );
461
462#define DECL_REL_OP(op) \
463 friend bool operator op ( const sc_fxnum_fast_subref_r&, \
464 const sc_fxnum_fast_subref_r& ); \
465 friend bool operator op ( const sc_fxnum_fast_subref_r&, \
466 const sc_fxnum_subref_r& ); \
467 DECL_REL_OP_T(op,const sc_bv_base&) \
468 DECL_REL_OP_T(op,const sc_lv_base&) \
469 DECL_REL_OP_T(op,const char*) \
470 DECL_REL_OP_T(op,const bool*) \
471 DECL_REL_OP_T(op,const sc_signed&) \
472 DECL_REL_OP_T(op,const sc_unsigned&) \
473 DECL_REL_OP_T(op,int) \
474 DECL_REL_OP_T(op,unsigned int) \
475 DECL_REL_OP_T(op,long) \
476 DECL_REL_OP_T(op,unsigned long)
477
478 DECL_REL_OP(==)
479 DECL_REL_OP(!=)
480
481#undef DECL_REL_OP_T
482#undef DECL_REL_OP
483
484
485 // reduce functions
486
487 bool and_reduce() const;
488 bool nand_reduce() const;
489 bool or_reduce() const;
490 bool nor_reduce() const;
491 bool xor_reduce() const;
492 bool xnor_reduce() const;
493
494
495 // query parameter
496
497 int length() const;
498
499
500 // explicit conversions
501
502 int to_int() const;
503 unsigned int to_uint() const;
504 long to_long() const;
505 unsigned long to_ulong() const;
506 int64 to_int64() const;
507 uint64 to_uint64() const;
508
509#ifdef SC_DT_DEPRECATED
510 int to_signed() const;
511 unsigned int to_unsigned() const;
512#endif
513
514 std::string to_string() const;
515 std::string to_string( sc_numrep ) const;
516 std::string to_string( sc_numrep, bool ) const;
517
518
519 // implicit conversion
520
521 operator sc_bv_base() const;
522
523
524 // print or dump content
525
526 void print( ::std::ostream& = ::std::cout ) const;
527 void dump( ::std::ostream& = ::std::cout ) const;
528
529protected:
530
533 int m_to;
534
536};
537
538
539
540// ----------------------------------------------------------------------------
541// CLASS : sc_fxnum_fast_subref
542//
543// Proxy class for part-selection in class sc_fxnum_fast,
544// behaves like sc_bv_base.
545// ----------------------------------------------------------------------------
546
548{
549 friend class sc_fxnum_fast;
550 friend class sc_fxnum_subref;
551
552 bool set();
553
554 // constructor
555
557
558public:
559
560 // copy constructor
561
563
564
565 // assignment operators
566
567#define DECL_ASN_OP_T(tp) \
568 sc_fxnum_fast_subref& operator = ( tp );
569
574 DECL_ASN_OP_T(const char*)
575 DECL_ASN_OP_T(const bool*)
582 DECL_ASN_OP_T(int)
583 DECL_ASN_OP_T(unsigned int)
584 DECL_ASN_OP_T(long)
585 DECL_ASN_OP_T(unsigned long)
586 DECL_ASN_OP_T(char)
587
588#undef DECL_ASN_OP_T
589
590#define DECL_ASN_OP_T_A(op,tp) \
591 sc_fxnum_fast_subref& operator op ## = ( tp );
592
593#define DECL_ASN_OP_A(op) \
594 DECL_ASN_OP_T_A(op,const sc_fxnum_subref&) \
595 DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&) \
596 DECL_ASN_OP_T_A(op,const sc_bv_base&) \
597 DECL_ASN_OP_T_A(op,const sc_lv_base&)
598
602
603#undef DECL_ASN_OP_T_A
604#undef DECL_ASN_OP_A
605
606 void scan( ::std::istream& = ::std::cin );
607};
608
609
610// ----------------------------------------------------------------------------
611// CLASS : sc_fxnum
612//
613// Base class for the fixed-point types; arbitrary precision.
614// ----------------------------------------------------------------------------
615
617{
618 friend class sc_fxval;
619
620 friend class sc_fxnum_bitref;
621 friend class sc_fxnum_bitref_r;
622 friend class sc_fxnum_subref;
623 friend class sc_fxnum_subref_r;
626
627 friend class sc_core::vcd_sc_fxnum_trace;
628 friend class sc_core::wif_sc_fxnum_trace;
629
630protected:
631
632 sc_fxnum_observer* observer() const;
633
634
635 void cast();
636
637
638 // constructors
639
641 sc_enc,
642 const sc_fxcast_switch&,
644
645#define DECL_CTOR_T(tp) \
646 sc_fxnum( tp, \
647 const sc_fxtype_params&, \
648 sc_enc, \
649 const sc_fxcast_switch&, \
650 sc_fxnum_observer* );
651
652 DECL_CTOR_T(int)
653 DECL_CTOR_T(unsigned int)
654 DECL_CTOR_T(long)
655 DECL_CTOR_T(unsigned long)
656 DECL_CTOR_T(float)
657 DECL_CTOR_T(double)
658 DECL_CTOR_T(const char*)
659 DECL_CTOR_T(const sc_fxval&)
661 DECL_CTOR_T(const sc_fxnum&)
667 DECL_CTOR_T(const sc_signed&)
669
670#undef DECL_CTOR_T
671
672 ~sc_fxnum();
673
674
675 // internal use only;
676 const scfx_rep* get_rep() const;
677
678public:
679
680 // unary operators
681
682 sc_fxval operator - () const;
683 sc_fxval operator + () const;
684
685
686 // unary functions
687
688 friend void neg( sc_fxval&, const sc_fxnum& );
689 friend void neg( sc_fxnum&, const sc_fxnum& );
690
691
692 // binary operators
693
694#define DECL_BIN_OP_T(op,tp) \
695 friend sc_fxval operator op ( const sc_fxnum&, tp ); \
696 friend sc_fxval operator op ( tp, const sc_fxnum& );
697
698#define DECL_BIN_OP_OTHER(op) \
699 DECL_BIN_OP_T(op,int64) \
700 DECL_BIN_OP_T(op,uint64) \
701 DECL_BIN_OP_T(op,const sc_int_base&) \
702 DECL_BIN_OP_T(op,const sc_uint_base&) \
703 DECL_BIN_OP_T(op,const sc_signed&) \
704 DECL_BIN_OP_T(op,const sc_unsigned&)
705
706#define DECL_BIN_OP(op,dummy) \
707 friend sc_fxval operator op ( const sc_fxnum&, const sc_fxnum& ); \
708 DECL_BIN_OP_T(op,int) \
709 DECL_BIN_OP_T(op,unsigned int) \
710 DECL_BIN_OP_T(op,long) \
711 DECL_BIN_OP_T(op,unsigned long) \
712 DECL_BIN_OP_T(op,float) \
713 DECL_BIN_OP_T(op,double) \
714 DECL_BIN_OP_T(op,const char*) \
715 DECL_BIN_OP_T(op,const sc_fxval&) \
716 DECL_BIN_OP_T(op,const sc_fxval_fast&) \
717 DECL_BIN_OP_T(op,const sc_fxnum_fast&) \
718 DECL_BIN_OP_OTHER(op)
719
720 DECL_BIN_OP(*,mult)
721 DECL_BIN_OP(+,add)
722 DECL_BIN_OP(-,sub)
723// don't use macros
724// DECL_BIN_OP(/,div)
725 friend sc_fxval operator / ( const sc_fxnum&, const sc_fxnum& );
726 DECL_BIN_OP_T(/,int)
727 DECL_BIN_OP_T(/,unsigned int)
728 DECL_BIN_OP_T(/,long)
729 DECL_BIN_OP_T(/,unsigned long)
730 DECL_BIN_OP_T(/,float)
731 DECL_BIN_OP_T(/,double)
732 DECL_BIN_OP_T(/,const char*)
733 DECL_BIN_OP_T(/,const sc_fxval&)
736// DECL_BIN_OP_OTHER(op)
739 DECL_BIN_OP_T(/,const sc_int_base&)
741 DECL_BIN_OP_T(/,const sc_signed&)
742 DECL_BIN_OP_T(/,const sc_unsigned&)
743
744#undef DECL_BIN_OP_T
745#undef DECL_BIN_OP_OTHER
746#undef DECL_BIN_OP
747
748 friend sc_fxval operator << ( const sc_fxnum&, int );
749 friend sc_fxval operator >> ( const sc_fxnum&, int );
750
751
752 // binary functions
753
754#define DECL_BIN_FNC_T(fnc,tp) \
755 friend void fnc ( sc_fxval&, const sc_fxnum&, tp ); \
756 friend void fnc ( sc_fxval&, tp, const sc_fxnum& ); \
757 friend void fnc ( sc_fxnum&, const sc_fxnum&, tp ); \
758 friend void fnc ( sc_fxnum&, tp, const sc_fxnum& );
759
760#define DECL_BIN_FNC_OTHER(fnc) \
761 DECL_BIN_FNC_T(fnc,int64) \
762 DECL_BIN_FNC_T(fnc,uint64) \
763 DECL_BIN_FNC_T(fnc,const sc_int_base&) \
764 DECL_BIN_FNC_T(fnc,const sc_uint_base&) \
765 DECL_BIN_FNC_T(fnc,const sc_signed&) \
766 DECL_BIN_FNC_T(fnc,const sc_unsigned&)
767
768#define DECL_BIN_FNC(fnc) \
769 friend void fnc ( sc_fxval&, const sc_fxnum&, const sc_fxnum& ); \
770 friend void fnc ( sc_fxnum&, const sc_fxnum&, const sc_fxnum& ); \
771 DECL_BIN_FNC_T(fnc,int) \
772 DECL_BIN_FNC_T(fnc,unsigned int) \
773 DECL_BIN_FNC_T(fnc,long) \
774 DECL_BIN_FNC_T(fnc,unsigned long) \
775 DECL_BIN_FNC_T(fnc,float) \
776 DECL_BIN_FNC_T(fnc,double) \
777 DECL_BIN_FNC_T(fnc,const char*) \
778 DECL_BIN_FNC_T(fnc,const sc_fxval&) \
779 DECL_BIN_FNC_T(fnc,const sc_fxval_fast&) \
780 DECL_BIN_FNC_T(fnc,const sc_fxnum_fast&) \
781 DECL_BIN_FNC_OTHER(fnc)
782
783 DECL_BIN_FNC(mult)
785 DECL_BIN_FNC(add)
786 DECL_BIN_FNC(sub)
787
788#undef DECL_BIN_FNC_T
789#undef DECL_BIN_FNC_OTHER
790#undef DECL_BIN_FNC
791
792 friend void lshift( sc_fxval&, const sc_fxnum&, int );
793 friend void rshift( sc_fxval&, const sc_fxnum&, int );
794 friend void lshift( sc_fxnum&, const sc_fxnum&, int );
795 friend void rshift( sc_fxnum&, const sc_fxnum&, int );
796
797
798 // relational (including equality) operators
799
800#define DECL_REL_OP_T(op,tp) \
801 friend bool operator op ( const sc_fxnum&, tp ); \
802 friend bool operator op ( tp, const sc_fxnum& );
803
804#define DECL_REL_OP_OTHER(op) \
805 DECL_REL_OP_T(op,int64) \
806 DECL_REL_OP_T(op,uint64) \
807 DECL_REL_OP_T(op,const sc_int_base&) \
808 DECL_REL_OP_T(op,const sc_uint_base&) \
809 DECL_REL_OP_T(op,const sc_signed&) \
810 DECL_REL_OP_T(op,const sc_unsigned&)
811
812#define DECL_REL_OP(op) \
813 friend bool operator op ( const sc_fxnum&, const sc_fxnum& ); \
814 DECL_REL_OP_T(op,int) \
815 DECL_REL_OP_T(op,unsigned int) \
816 DECL_REL_OP_T(op,long) \
817 DECL_REL_OP_T(op,unsigned long) \
818 DECL_REL_OP_T(op,float) \
819 DECL_REL_OP_T(op,double) \
820 DECL_REL_OP_T(op,const char*) \
821 DECL_REL_OP_T(op,const sc_fxval&) \
822 DECL_REL_OP_T(op,const sc_fxval_fast&) \
823 DECL_REL_OP_T(op,const sc_fxnum_fast&) \
824 DECL_REL_OP_OTHER(op)
825
826 DECL_REL_OP(<)
827 DECL_REL_OP(<=)
828 DECL_REL_OP(>)
829 DECL_REL_OP(>=)
830 DECL_REL_OP(==)
831 DECL_REL_OP(!=)
832
833#undef DECL_REL_OP_T
834#undef DECL_REL_OP_OTHER
835#undef DECL_REL_OP
836
837
838 // assignment operators
839
840#define DECL_ASN_OP_T(op,tp) \
841 sc_fxnum& operator op( tp );
842
843#define DECL_ASN_OP_OTHER(op) \
844 DECL_ASN_OP_T(op,int64) \
845 DECL_ASN_OP_T(op,uint64) \
846 DECL_ASN_OP_T(op,const sc_int_base&) \
847 DECL_ASN_OP_T(op,const sc_uint_base&) \
848 DECL_ASN_OP_T(op,const sc_signed&) \
849 DECL_ASN_OP_T(op,const sc_unsigned&)
850
851#define DECL_ASN_OP(op) \
852 DECL_ASN_OP_T(op,int) \
853 DECL_ASN_OP_T(op,unsigned int) \
854 DECL_ASN_OP_T(op,long) \
855 DECL_ASN_OP_T(op,unsigned long) \
856 DECL_ASN_OP_T(op,float) \
857 DECL_ASN_OP_T(op,double) \
858 DECL_ASN_OP_T(op,const char*) \
859 DECL_ASN_OP_T(op,const sc_fxval&) \
860 DECL_ASN_OP_T(op,const sc_fxval_fast&) \
861 DECL_ASN_OP_T(op,const sc_fxnum&) \
862 DECL_ASN_OP_T(op,const sc_fxnum_fast&) \
863 DECL_ASN_OP_OTHER(op)
864
865 DECL_ASN_OP(=)
866
867 DECL_ASN_OP(*=)
868 DECL_ASN_OP(/=)
869 DECL_ASN_OP(+=)
870 DECL_ASN_OP(-=)
871
872 DECL_ASN_OP_T(<<=,int)
873 DECL_ASN_OP_T(>>=,int)
874
875#undef DECL_ASN_OP_T
876#undef DECL_ASN_OP_OTHER
877#undef DECL_ASN_OP
878
879
880 // auto-increment and auto-decrement
881
882 sc_fxval operator ++ ( int );
883 sc_fxval operator -- ( int );
884
885 sc_fxnum& operator ++ ();
886 sc_fxnum& operator -- ();
887
888
889 // bit selection
890
891 sc_fxnum_bitref_r operator [] ( int ) const;
892 sc_fxnum_bitref operator [] ( int );
893
894 sc_fxnum_bitref_r bit( int ) const;
895 sc_fxnum_bitref bit( int );
896
897
898 // part selection
899
900 sc_fxnum_subref_r operator () ( int, int ) const;
901 sc_fxnum_subref operator () ( int, int );
902
903 sc_fxnum_subref_r range( int, int ) const;
904 sc_fxnum_subref range( int, int );
905
906
907 sc_fxnum_subref_r operator () () const;
908 sc_fxnum_subref operator () ();
909
910 sc_fxnum_subref_r range() const;
911 sc_fxnum_subref range();
912
913
914 // implicit conversion
915
916 operator double() const; // necessary evil!
917
918
919 // explicit conversion to primitive types
920
921 short to_short() const;
922 unsigned short to_ushort() const;
923 int to_int() const;
924 unsigned int to_uint() const;
925 long to_long() const;
926 unsigned long to_ulong() const;
927 int64 to_int64() const;
928 uint64 to_uint64() const;
929 float to_float() const;
930 double to_double() const;
931
932
933 // explicit conversion to character string
934
935 std::string to_string() const;
936 std::string to_string( sc_numrep ) const;
937 std::string to_string( sc_numrep, bool ) const;
938 std::string to_string( sc_fmt ) const;
939 std::string to_string( sc_numrep, sc_fmt ) const;
940 std::string to_string( sc_numrep, bool, sc_fmt ) const;
941
942 std::string to_dec() const;
943 std::string to_bin() const;
944 std::string to_oct() const;
945 std::string to_hex() const;
946
947
948 // query value
949
950 bool is_neg() const;
951 bool is_zero() const;
952
953 // internal use only;
954 bool is_normal() const;
955
956 bool quantization_flag() const;
957 bool overflow_flag() const;
958
959 sc_fxval value() const;
960
961
962 // query parameters
963
964 int wl() const;
965 int iwl() const;
966 sc_q_mode q_mode() const;
967 sc_o_mode o_mode() const;
968 int n_bits() const;
969
970 const sc_fxtype_params& type_params() const;
971
972 const sc_fxcast_switch& cast_switch() const;
973
974
975 // print or dump content
976
977 void print( ::std::ostream& = ::std::cout ) const;
978 void scan( ::std::istream& = ::std::cin );
979 void dump( ::std::ostream& = ::std::cout ) const;
980
981
982 // internal use only;
983 void observer_read() const;
984
985
986 // internal use only;
987 bool get_bit( int ) const;
988
989protected:
990
991 bool set_bit( int, bool );
992
993
994 bool get_slice( int, int, sc_bv_base& ) const;
995 bool set_slice( int, int, const sc_bv_base& );
996
997
1000
1001private:
1002
1003 scfx_rep* m_rep;
1004
1005 scfx_params m_params;
1006 bool m_q_flag;
1007 bool m_o_flag;
1008
1009 mutable sc_fxnum_observer* m_observer;
1010
1011private:
1012
1013 // disabled
1014 sc_fxnum();
1015 sc_fxnum( const sc_fxnum& );
1016};
1017
1018
1019// ----------------------------------------------------------------------------
1020// CLASS : sc_fxnum_fast
1021//
1022// Base class for the fixed-point types; limited precision.
1023// ----------------------------------------------------------------------------
1024
1026{
1027 friend class sc_fxval_fast;
1028
1029 friend class sc_fxnum_bitref;
1030 friend class sc_fxnum_subref;
1035
1036 friend class sc_core::vcd_sc_fxnum_fast_trace;
1037 friend class sc_core::wif_sc_fxnum_fast_trace;
1038
1039protected:
1040
1041 sc_fxnum_fast_observer* observer() const;
1042
1043
1044 void cast();
1045
1046
1047 // constructors
1048
1050 sc_enc,
1051 const sc_fxcast_switch&,
1053
1054#define DECL_CTOR_T(tp) \
1055 sc_fxnum_fast( tp, \
1056 const sc_fxtype_params&, \
1057 sc_enc, \
1058 const sc_fxcast_switch&, \
1059 sc_fxnum_fast_observer* );
1060
1061 DECL_CTOR_T(int)
1062 DECL_CTOR_T(unsigned int)
1063 DECL_CTOR_T(long)
1064 DECL_CTOR_T(unsigned long)
1065 DECL_CTOR_T(float)
1066 DECL_CTOR_T(double)
1067 DECL_CTOR_T(const char*)
1068 DECL_CTOR_T(const sc_fxval&)
1069 DECL_CTOR_T(const sc_fxval_fast&)
1070 DECL_CTOR_T(const sc_fxnum&)
1071 DECL_CTOR_T(const sc_fxnum_fast&)
1074 DECL_CTOR_T(const sc_int_base&)
1075 DECL_CTOR_T(const sc_uint_base&)
1076 DECL_CTOR_T(const sc_signed&)
1077 DECL_CTOR_T(const sc_unsigned&)
1078
1079#undef DECL_CTOR_T
1080
1081 ~sc_fxnum_fast();
1082
1083
1084 // internal use only;
1085 double get_val() const;
1086
1087public:
1088
1089 // unary operators
1090
1091 sc_fxval_fast operator - () const;
1092 sc_fxval_fast operator + () const;
1093
1094
1095 // unary functions
1096
1097 friend void neg( sc_fxval_fast&, const sc_fxnum_fast& );
1098 friend void neg( sc_fxnum_fast&, const sc_fxnum_fast& );
1099
1100
1101 // binary operators
1102
1103#define DECL_BIN_OP_T(op,tp) \
1104 friend sc_fxval_fast operator op ( const sc_fxnum_fast&, tp ); \
1105 friend sc_fxval_fast operator op ( tp, const sc_fxnum_fast& );
1106
1107#define DECL_BIN_OP_OTHER(op) \
1108 DECL_BIN_OP_T(op,int64) \
1109 DECL_BIN_OP_T(op,uint64) \
1110 DECL_BIN_OP_T(op,const sc_int_base&) \
1111 DECL_BIN_OP_T(op,const sc_uint_base&) \
1112 DECL_BIN_OP_T(op,const sc_signed&) \
1113 DECL_BIN_OP_T(op,const sc_unsigned&)
1114
1115#define DECL_BIN_OP(op,dummy) \
1116 friend sc_fxval_fast operator op ( const sc_fxnum_fast&, \
1117 const sc_fxnum_fast& ); \
1118 DECL_BIN_OP_T(op,int) \
1119 DECL_BIN_OP_T(op,unsigned int) \
1120 DECL_BIN_OP_T(op,long) \
1121 DECL_BIN_OP_T(op,unsigned long) \
1122 DECL_BIN_OP_T(op,float) \
1123 DECL_BIN_OP_T(op,double) \
1124 DECL_BIN_OP_T(op,const char*) \
1125 DECL_BIN_OP_T(op,const sc_fxval_fast&) \
1126 DECL_BIN_OP_OTHER(op)
1127
1128 DECL_BIN_OP(*,mult)
1129 DECL_BIN_OP(+,add)
1130 DECL_BIN_OP(-,sub)
1131// DECL_BIN_OP(/,div)
1132 friend sc_fxval_fast operator / ( const sc_fxnum_fast&,
1133 const sc_fxnum_fast& );
1134 DECL_BIN_OP_T(/,int)
1135 DECL_BIN_OP_T(/,unsigned int)
1136 DECL_BIN_OP_T(/,long)
1137 DECL_BIN_OP_T(/,unsigned long)
1138 DECL_BIN_OP_T(/,float)
1139 DECL_BIN_OP_T(/,double)
1140 DECL_BIN_OP_T(/,const char*)
1141 DECL_BIN_OP_T(/,const sc_fxval_fast&)
1142// DECL_BIN_OP_OTHER(op)
1146 DECL_BIN_OP_T(/,const sc_uint_base&) \
1148 DECL_BIN_OP_T(/,const sc_unsigned&)
1149
1150#undef DECL_BIN_OP_T
1151#undef DECL_BIN_OP_OTHER
1152#undef DECL_BIN_OP
1153
1155 friend sc_fxval_fast operator >> ( const sc_fxnum_fast&, int );
1156
1157
1158 // binary functions
1159
1160#define DECL_BIN_FNC_T(fnc,tp) \
1161 friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&, tp ); \
1162 friend void fnc ( sc_fxval_fast&, tp, const sc_fxnum_fast& ); \
1163 friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&, tp ); \
1164 friend void fnc ( sc_fxnum_fast&, tp, const sc_fxnum_fast& );
1165
1166#define DECL_BIN_FNC_OTHER(fnc) \
1167 DECL_BIN_FNC_T(fnc,int64) \
1168 DECL_BIN_FNC_T(fnc,uint64) \
1169 DECL_BIN_FNC_T(fnc,const sc_int_base&) \
1170 DECL_BIN_FNC_T(fnc,const sc_uint_base&) \
1171 DECL_BIN_FNC_T(fnc,const sc_signed&) \
1172 DECL_BIN_FNC_T(fnc,const sc_unsigned&)
1173
1174#define DECL_BIN_FNC(fnc) \
1175 friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&, \
1176 const sc_fxnum_fast& ); \
1177 friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&, \
1178 const sc_fxnum_fast& ); \
1179 DECL_BIN_FNC_T(fnc,int) \
1180 DECL_BIN_FNC_T(fnc,unsigned int) \
1181 DECL_BIN_FNC_T(fnc,long) \
1182 DECL_BIN_FNC_T(fnc,unsigned long) \
1183 DECL_BIN_FNC_T(fnc,float) \
1184 DECL_BIN_FNC_T(fnc,double) \
1185 DECL_BIN_FNC_T(fnc,const char*) \
1186 DECL_BIN_FNC_T(fnc,const sc_fxval&) \
1187 DECL_BIN_FNC_T(fnc,const sc_fxval_fast&) \
1188 DECL_BIN_FNC_T(fnc,const sc_fxnum&) \
1189 DECL_BIN_FNC_OTHER(fnc)
1190
1191 DECL_BIN_FNC(mult)
1193 DECL_BIN_FNC(add)
1194 DECL_BIN_FNC(sub)
1195
1196#undef DECL_BIN_FNC_T
1197#undef DECL_BIN_FNC_OTHER
1198#undef DECL_BIN_FNC
1199
1200 friend void lshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
1201 friend void rshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
1202 friend void lshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
1203 friend void rshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
1204
1205
1206 // relational (including equality) operators
1207
1208#define DECL_REL_OP_T(op,tp) \
1209 friend bool operator op ( const sc_fxnum_fast&, tp ); \
1210 friend bool operator op ( tp, const sc_fxnum_fast& );
1211
1212#define DECL_REL_OP_OTHER(op) \
1213 DECL_REL_OP_T(op,int64) \
1214 DECL_REL_OP_T(op,uint64) \
1215 DECL_REL_OP_T(op,const sc_int_base&) \
1216 DECL_REL_OP_T(op,const sc_uint_base&) \
1217 DECL_REL_OP_T(op,const sc_signed&) \
1218 DECL_REL_OP_T(op,const sc_unsigned&)
1219
1220#define DECL_REL_OP(op) \
1221 friend bool operator op ( const sc_fxnum_fast&, const sc_fxnum_fast& ); \
1222 DECL_REL_OP_T(op,int) \
1223 DECL_REL_OP_T(op,unsigned int) \
1224 DECL_REL_OP_T(op,long) \
1225 DECL_REL_OP_T(op,unsigned long) \
1226 DECL_REL_OP_T(op,float) \
1227 DECL_REL_OP_T(op,double) \
1228 DECL_REL_OP_T(op,const char*) \
1229 DECL_REL_OP_T(op,const sc_fxval_fast&) \
1230 DECL_REL_OP_OTHER(op)
1231
1232 DECL_REL_OP(<)
1233 DECL_REL_OP(<=)
1234 DECL_REL_OP(>)
1235 DECL_REL_OP(>=)
1236 DECL_REL_OP(==)
1237 DECL_REL_OP(!=)
1238
1239#undef DECL_REL_OP_T
1240#undef DECL_REL_OP_OTHER
1241#undef DECL_REL_OP
1242
1243
1244 // assignment operators
1245
1246#define DECL_ASN_OP_T(op,tp) \
1247 sc_fxnum_fast& operator op( tp );
1248
1249#define DECL_ASN_OP_OTHER(op) \
1250 DECL_ASN_OP_T(op,int64) \
1251 DECL_ASN_OP_T(op,uint64) \
1252 DECL_ASN_OP_T(op,const sc_int_base&) \
1253 DECL_ASN_OP_T(op,const sc_uint_base&) \
1254 DECL_ASN_OP_T(op,const sc_signed&) \
1255 DECL_ASN_OP_T(op,const sc_unsigned&)
1256
1257#define DECL_ASN_OP(op) \
1258 DECL_ASN_OP_T(op,int) \
1259 DECL_ASN_OP_T(op,unsigned int) \
1260 DECL_ASN_OP_T(op,long) \
1261 DECL_ASN_OP_T(op,unsigned long) \
1262 DECL_ASN_OP_T(op,float) \
1263 DECL_ASN_OP_T(op,double) \
1264 DECL_ASN_OP_T(op,const char*) \
1265 DECL_ASN_OP_T(op,const sc_fxval&) \
1266 DECL_ASN_OP_T(op,const sc_fxval_fast&) \
1267 DECL_ASN_OP_T(op,const sc_fxnum&) \
1268 DECL_ASN_OP_T(op,const sc_fxnum_fast&) \
1269 DECL_ASN_OP_OTHER(op)
1270
1271 DECL_ASN_OP(=)
1272
1273 DECL_ASN_OP(*=)
1274 DECL_ASN_OP(/=)
1275 DECL_ASN_OP(+=)
1276 DECL_ASN_OP(-=)
1277
1278 DECL_ASN_OP_T(<<=,int)
1279 DECL_ASN_OP_T(>>=,int)
1280
1281#undef DECL_ASN_OP_T
1282#undef DECL_ASN_OP_OTHER
1283#undef DECL_ASN_OP
1284
1285
1286 // auto-increment and auto-decrement
1287
1288 sc_fxval_fast operator ++ ( int );
1289 sc_fxval_fast operator -- ( int );
1290
1291 sc_fxnum_fast& operator ++ ();
1292 sc_fxnum_fast& operator -- ();
1293
1294
1295 // bit selection
1296
1297 sc_fxnum_fast_bitref_r operator [] ( int ) const;
1298 sc_fxnum_fast_bitref operator [] ( int );
1299
1300 sc_fxnum_fast_bitref_r bit( int ) const;
1301 sc_fxnum_fast_bitref bit( int );
1302
1303
1304 // part selection
1305
1306 sc_fxnum_fast_subref_r operator () ( int, int ) const;
1307 sc_fxnum_fast_subref operator () ( int, int );
1308
1309 sc_fxnum_fast_subref_r range( int, int ) const;
1310 sc_fxnum_fast_subref range( int, int );
1311
1312
1313 sc_fxnum_fast_subref_r operator () () const;
1314 sc_fxnum_fast_subref operator () ();
1315
1316 sc_fxnum_fast_subref_r range() const;
1317 sc_fxnum_fast_subref range();
1318
1319
1320 // implicit conversion
1321
1322 operator double() const; // necessary evil!
1323
1324
1325 // explicit conversion to primitive types
1326
1327 short to_short() const;
1328 unsigned short to_ushort() const;
1329 int to_int() const;
1330 unsigned int to_uint() const;
1331 long to_long() const;
1332 unsigned long to_ulong() const;
1333 int64 to_int64() const;
1334 uint64 to_uint64() const;
1335 float to_float() const;
1336 double to_double() const;
1337
1338
1339 // explicit conversion to character string
1340
1341 std::string to_string() const;
1342 std::string to_string( sc_numrep ) const;
1343 std::string to_string( sc_numrep, bool ) const;
1344 std::string to_string( sc_fmt ) const;
1345 std::string to_string( sc_numrep, sc_fmt ) const;
1346 std::string to_string( sc_numrep, bool, sc_fmt ) const;
1347
1348 std::string to_dec() const;
1349 std::string to_bin() const;
1350 std::string to_oct() const;
1351 std::string to_hex() const;
1352
1353
1354 // query value
1355
1356 bool is_neg() const;
1357 bool is_zero() const;
1358
1359 // internal use only;
1360 bool is_normal() const;
1361
1362 bool quantization_flag() const;
1363 bool overflow_flag() const;
1364
1365 sc_fxval_fast value() const;
1366
1367
1368 // query parameters
1369
1370 int wl() const;
1371 int iwl() const;
1372 sc_q_mode q_mode() const;
1373 sc_o_mode o_mode() const;
1374 int n_bits() const;
1375
1376 const sc_fxtype_params& type_params() const;
1377
1378 const sc_fxcast_switch& cast_switch() const;
1379
1380
1381 // print or dump content
1382
1383 void print( ::std::ostream& = ::std::cout ) const;
1384 void scan( ::std::istream& = ::std::cin );
1385 void dump( ::std::ostream& = ::std::cout ) const;
1386
1387
1388 // internal use only;
1389 void observer_read() const;
1390
1391
1392 // internal use only;
1393 bool get_bit( int ) const;
1394
1395protected:
1396
1397 bool set_bit( int, bool );
1398
1399
1400 bool get_slice( int, int, sc_bv_base& ) const;
1401 bool set_slice( int, int, const sc_bv_base& );
1402
1403
1406
1407private:
1408
1409 double m_val;
1410
1411 scfx_params m_params;
1412 bool m_q_flag;
1413 bool m_o_flag;
1414
1415 mutable sc_fxnum_fast_observer* m_observer;
1416
1417private:
1418
1419 // disabled
1420 sc_fxnum_fast();
1421 sc_fxnum_fast( const sc_fxnum_fast& );
1422};
1423
1424
1425// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
1426
1427// ----------------------------------------------------------------------------
1428// CLASS : sc_fxnum_bitref_r
1429// ----------------------------------------------------------------------------
1430
1431inline
1433 : m_num(num_) , m_idx(idx_)
1434{ }
1435
1436inline
1438 : m_num( a.m_num ), m_idx ( a.m_idx )
1439{}
1440
1441
1442// implicit conversion
1443
1444inline
1445sc_fxnum_bitref_r::operator bool() const
1446{
1448 return get();
1449}
1450
1451
1452inline
1453::std::ostream&
1454operator << ( ::std::ostream& os, const sc_fxnum_bitref_r& a )
1455{
1456 a.print( os );
1457 return os;
1458}
1459
1460
1461// ----------------------------------------------------------------------------
1462// CLASS : sc_fxnum_bitref
1463//
1464// Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
1465// ----------------------------------------------------------------------------
1466
1467
1468// constructor
1469
1470inline
1471sc_fxnum_bitref::sc_fxnum_bitref( sc_fxnum& num_, int idx_ )
1472 : sc_fxnum_bitref_r ( num_ , idx_ )
1473{}
1474
1475
1476// copy constructor
1477
1478inline
1479sc_fxnum_bitref::sc_fxnum_bitref( const sc_fxnum_bitref& a )
1480 : sc_fxnum_bitref_r( a )
1481{}
1482
1483
1484// assignment operators
1485
1486inline
1488sc_fxnum_bitref::operator = ( const sc_fxnum_bitref& a )
1489{
1490 if( &a != this )
1491 {
1493 set( a.get() );
1495 }
1496 return *this;
1497}
1498
1499inline
1501sc_fxnum_bitref::operator = ( const sc_fxnum_fast_bitref& a )
1502{
1504 set( a.get() );
1506 return *this;
1507}
1508
1509inline
1511sc_fxnum_bitref::operator = ( const sc_bit& a )
1512{
1513 set( static_cast<bool>( a ) );
1515 return *this;
1516}
1517
1518inline
1519sc_fxnum_bitref&
1520sc_fxnum_bitref::operator = ( bool a )
1521{
1522 set( a );
1524 return *this;
1525}
1526
1527
1528inline
1529sc_fxnum_bitref&
1530sc_fxnum_bitref::operator &= ( const sc_fxnum_bitref& b )
1531{
1533 SC_FXNUM_OBSERVER_READ_( b.m_num )
1534 set( get() && b.get() );
1536 return *this;
1537}
1538
1539inline
1540sc_fxnum_bitref&
1541sc_fxnum_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
1542{
1545 set( get() && b.get() );
1547 return *this;
1548}
1549
1550inline
1551sc_fxnum_bitref&
1552sc_fxnum_bitref::operator &= ( const sc_bit& b )
1553{
1555 set( get() && static_cast<bool>( b ) );
1557 return *this;
1558}
1559
1560inline
1561sc_fxnum_bitref&
1563{
1565 set( get() && b );
1567 return *this;
1568}
1569
1570
1571inline
1572sc_fxnum_bitref&
1573sc_fxnum_bitref::operator |= ( const sc_fxnum_bitref& b )
1574{
1576 SC_FXNUM_OBSERVER_READ_( b.m_num )
1577 set( get() || b.get() );
1579 return *this;
1580}
1581
1582inline
1583sc_fxnum_bitref&
1584sc_fxnum_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
1585{
1588 set( get() || b.get() );
1590 return *this;
1591}
1592
1593inline
1594sc_fxnum_bitref&
1595sc_fxnum_bitref::operator |= ( const sc_bit& b )
1596{
1598 set( get() || static_cast<bool>( b ) );
1600 return *this;
1601}
1602
1603inline
1604sc_fxnum_bitref&
1606{
1608 set( get() || b );
1610 return *this;
1611}
1612
1613
1614inline
1615sc_fxnum_bitref&
1616sc_fxnum_bitref::operator ^= ( const sc_fxnum_bitref& b )
1617{
1619 SC_FXNUM_OBSERVER_READ_( b.m_num )
1620 set( get() != b.get() );
1622 return *this;
1623}
1624
1625inline
1626sc_fxnum_bitref&
1627sc_fxnum_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
1628{
1631 set( get() != b.get() );
1633 return *this;
1634}
1635
1636inline
1637sc_fxnum_bitref&
1638sc_fxnum_bitref::operator ^= ( const sc_bit& b )
1639{
1641 set( get() != static_cast<bool>( b ) );
1643 return *this;
1644}
1645
1646inline
1647sc_fxnum_bitref&
1649{
1651 set( get() != b );
1653 return *this;
1654}
1655
1656
1657inline
1658::std::istream&
1659operator >> ( ::std::istream& is, sc_fxnum_bitref& a )
1660{
1661 a.scan( is );
1662 return is;
1663}
1664
1665
1666
1667// ----------------------------------------------------------------------------
1668// CLASS : sc_fxnum_fast_bitref_r
1669// ----------------------------------------------------------------------------
1670
1671inline
1673 : m_num( num_ ), m_idx( idx_ )
1674{}
1675
1676inline
1678 : m_num( a.m_num ), m_idx( a.m_idx )
1679{}
1680
1681inline
1682sc_fxnum_fast_bitref_r::operator bool() const
1683{
1685 return get();
1686}
1687
1688inline
1689::std::ostream&
1690operator << ( ::std::ostream& os, const sc_fxnum_fast_bitref_r& a )
1691{
1692 a.print( os );
1693 return os;
1694}
1695
1696
1697// ----------------------------------------------------------------------------
1698// CLASS : sc_fxnum_fast_bitref
1699//
1700// Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
1701// ----------------------------------------------------------------------------
1702
1703// constructor
1704
1705inline
1706sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( sc_fxnum_fast& num_, int idx_ )
1707 : sc_fxnum_fast_bitref_r( num_ , idx_ )
1708{}
1709
1710
1711// copy constructor
1712
1713inline
1714sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& a )
1716{}
1717
1718
1719// assignment operators
1720
1721inline
1723sc_fxnum_fast_bitref::operator = ( const sc_fxnum_bitref& a )
1724{
1726 set( a.get() );
1728 return *this;
1729}
1730
1731inline
1733sc_fxnum_fast_bitref::operator = ( const sc_fxnum_fast_bitref& a )
1734{
1735 if( &a != this )
1736 {
1738 set( a.get() );
1740 }
1741 return *this;
1742}
1743
1744inline
1746sc_fxnum_fast_bitref::operator = ( const sc_bit& a )
1747{
1748 set( static_cast<bool>( a ) );
1750 return *this;
1751}
1752
1753inline
1754sc_fxnum_fast_bitref&
1755sc_fxnum_fast_bitref::operator = ( bool a )
1756{
1757 set( a );
1759 return *this;
1760}
1761
1762
1763inline
1764sc_fxnum_fast_bitref&
1766{
1768 SC_FXNUM_OBSERVER_READ_( b.m_num )
1769 set( get() && b.get() );
1771 return *this;
1772}
1773
1774inline
1775sc_fxnum_fast_bitref&
1776sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
1777{
1780 set( get() && b.get() );
1782 return *this;
1783}
1784
1785inline
1786sc_fxnum_fast_bitref&
1787sc_fxnum_fast_bitref::operator &= ( const sc_bit& b )
1788{
1790 set( get() && static_cast<bool>( b ) );
1792 return *this;
1793}
1794
1795inline
1796sc_fxnum_fast_bitref&
1798{
1800 set( get() && b );
1802 return *this;
1803}
1804
1805
1806inline
1807sc_fxnum_fast_bitref&
1809{
1811 SC_FXNUM_OBSERVER_READ_( b.m_num )
1812 set( get() || b.get() );
1814 return *this;
1815}
1816
1817inline
1818sc_fxnum_fast_bitref&
1819sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
1820{
1823 set( get() || b.get() );
1825 return *this;
1826}
1827
1828inline
1829sc_fxnum_fast_bitref&
1830sc_fxnum_fast_bitref::operator |= ( const sc_bit& b )
1831{
1833 set( get() || static_cast<bool>( b ) );
1835 return *this;
1836}
1837
1838inline
1839sc_fxnum_fast_bitref&
1841{
1843 set( get() || b );
1845 return *this;
1846}
1847
1848
1849inline
1850sc_fxnum_fast_bitref&
1852{
1854 SC_FXNUM_OBSERVER_READ_( b.m_num )
1855 set( get() != b.get() );
1857 return *this;
1858}
1859
1860inline
1861sc_fxnum_fast_bitref&
1862sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
1863{
1866 set( get() != b.get() );
1868 return *this;
1869}
1870
1871inline
1872sc_fxnum_fast_bitref&
1873sc_fxnum_fast_bitref::operator ^= ( const sc_bit& b )
1874{
1876 set( get() != static_cast<bool>( b ) );
1878 return *this;
1879}
1880
1881inline
1882sc_fxnum_fast_bitref&
1884{
1886 set( get() != b );
1888 return *this;
1889}
1890
1891
1892inline
1893::std::istream&
1894operator >> ( ::std::istream& is, sc_fxnum_fast_bitref& a )
1895{
1896 a.scan( is );
1897 return is;
1898}
1899
1900
1901// ----------------------------------------------------------------------------
1902// CLASS : sc_fxnum_subref_r
1903// ----------------------------------------------------------------------------
1904
1905inline
1907 : m_num( num_ ), m_from( from_ ), m_to( to_ ),
1908 m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
1909 sc_min( m_from, m_to ) + 1 ) )
1910{}
1911
1912
1913inline
1915 : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
1916 m_bv( *new sc_bv_base( a.m_bv ) )
1917{}
1918
1919inline
1921{
1922 delete &m_bv;
1923}
1924
1925// relational operators
1926
1927#define DEFN_REL_OP_T(op,tp) \
1928inline \
1929bool \
1930operator op ( const sc_fxnum_subref_r& a, tp b ) \
1931{ \
1932 return ( static_cast<sc_bv_base>( a ) op b ); \
1933} \
1934 \
1935inline \
1936bool \
1937operator op ( tp a, const sc_fxnum_subref_r& b ) \
1938{ \
1939 return ( static_cast<sc_bv_base>( b ) op a ); \
1940}
1941
1942#define DEFN_REL_OP(op) \
1943inline \
1944bool \
1945operator op ( const sc_fxnum_subref_r& a, const sc_fxnum_subref_r& b ) \
1946{ \
1947 return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) ); \
1948} \
1949 \
1950inline \
1951bool \
1952operator op ( const sc_fxnum_subref_r& a, const sc_fxnum_fast_subref_r& b ) \
1953{ \
1954 return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) ); \
1955} \
1956 \
1957DEFN_REL_OP_T(op,const sc_bv_base&) \
1958DEFN_REL_OP_T(op,const sc_lv_base&) \
1959DEFN_REL_OP_T(op,const char*) \
1960DEFN_REL_OP_T(op,const bool*) \
1961DEFN_REL_OP_T(op,const sc_signed&) \
1962DEFN_REL_OP_T(op,const sc_unsigned&) \
1963DEFN_REL_OP_T(op,int) \
1964DEFN_REL_OP_T(op,unsigned int) \
1965DEFN_REL_OP_T(op,long) \
1966DEFN_REL_OP_T(op,unsigned long)
1967
1968DEFN_REL_OP(==)
1969DEFN_REL_OP(!=)
1970
1971#undef DEFN_REL_OP_T
1972#undef DEFN_REL_OP
1973
1974
1975// reduce functions
1976
1977#define DEFN_RED_FNC(fnc) \
1978inline \
1979bool \
1980sc_fxnum_subref_r::fnc() const \
1981{ \
1982 SC_FXNUM_OBSERVER_READ_( m_num ) \
1983 get(); \
1984 return static_cast<bool>( m_bv.fnc() ); \
1985}
1986
1993
1994#undef DEFN_RED_FNC
1995
1996
1997// query parameter
1998
1999inline
2000int
2002{
2003 return m_bv.length();
2004}
2005
2006
2007// explicit conversions
2008
2009inline
2010int
2012{
2014 get();
2015 return m_bv.to_int();
2016}
2017
2018inline
2019int64
2021{
2023 get();
2024 return m_bv.to_int64();
2025}
2026
2027inline
2028unsigned int
2030{
2032 get();
2033 return m_bv.to_uint();
2034}
2035
2036inline
2037uint64
2039{
2041 get();
2042 return m_bv.to_uint64();
2043}
2044
2045inline
2046long
2048{
2050 get();
2051 return m_bv.to_long();
2052}
2053
2054inline
2055unsigned long
2057{
2059 get();
2060 return m_bv.to_ulong();
2061}
2062
2063
2064#ifdef SC_DT_DEPRECATED
2065
2066inline
2067int
2068sc_fxnum_subref_r::to_signed() const
2069{
2070 return to_int();
2071}
2072
2073inline
2074unsigned int
2075sc_fxnum_subref_r::to_unsigned() const
2076{
2077 return to_uint();
2078}
2079
2080#endif
2081
2082
2083inline
2084std::string
2086{
2087 get();
2088 return m_bv.to_string();
2089}
2090
2091inline
2092std::string
2094{
2095 get();
2096 return m_bv.to_string( numrep );
2097}
2098
2099inline
2100std::string
2101sc_fxnum_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
2102{
2103 get();
2104 return m_bv.to_string( numrep, w_prefix );
2105}
2106
2107// implicit conversion
2108
2109inline
2110sc_fxnum_subref_r::operator sc_bv_base () const
2111{
2113 get();
2114 return m_bv;
2115}
2116
2117
2118// ----------------------------------------------------------------------------
2119// CLASS : sc_fxnum_subref
2120//
2121// Proxy class for part-selection in class sc_fxnum,
2122// behaves like sc_bv_base.
2123// ----------------------------------------------------------------------------
2124
2125// constructor
2126
2127inline
2128sc_fxnum_subref::sc_fxnum_subref( sc_fxnum& num_, int from_, int to_ )
2129 : sc_fxnum_subref_r (num_, from_, to_)
2130{}
2131
2132
2133// copy constructor
2134
2135inline
2136sc_fxnum_subref::sc_fxnum_subref( const sc_fxnum_subref& a )
2137 : sc_fxnum_subref_r( a )
2138{}
2139
2140
2141
2142// assignment operators
2143
2144inline
2146sc_fxnum_subref::operator = ( const sc_fxnum_subref& a )
2147{
2148 if( &a != this )
2149 {
2150 m_bv = static_cast<sc_bv_base>( a );
2151 set();
2153 }
2154 return *this;
2155}
2156
2157inline
2158sc_fxnum_subref&
2159sc_fxnum_subref::operator = ( const sc_fxnum_fast_subref& a )
2160{
2161 m_bv = static_cast<sc_bv_base>( a );
2162 set();
2164 return *this;
2165}
2166
2167#define DEFN_ASN_OP_T(tp) \
2168inline \
2169sc_fxnum_subref& \
2170sc_fxnum_subref::operator = ( tp a ) \
2171{ \
2172 m_bv = a; \
2173 set(); \
2174 SC_FXNUM_OBSERVER_WRITE_( m_num ) \
2175 return *this; \
2176}
2177
2178DEFN_ASN_OP_T(const sc_bv_base&)
2179DEFN_ASN_OP_T(const sc_lv_base&)
2180DEFN_ASN_OP_T(const char*)
2181DEFN_ASN_OP_T(const bool*)
2182DEFN_ASN_OP_T(const sc_signed&)
2183DEFN_ASN_OP_T(const sc_unsigned&)
2184DEFN_ASN_OP_T(const sc_int_base&)
2185DEFN_ASN_OP_T(const sc_uint_base&)
2188DEFN_ASN_OP_T(int)
2189DEFN_ASN_OP_T(unsigned int)
2190DEFN_ASN_OP_T(long)
2191DEFN_ASN_OP_T(unsigned long)
2192DEFN_ASN_OP_T(char)
2193
2194#undef DEFN_ASN_OP_T
2195
2196
2197#define DEFN_ASN_OP_T(op,tp) \
2198inline \
2199sc_fxnum_subref& \
2200sc_fxnum_subref::operator op ## = ( tp a ) \
2201{ \
2202 SC_FXNUM_OBSERVER_READ_( m_num ) \
2203 get(); \
2204 m_bv = m_bv op a; \
2205 set(); \
2206 SC_FXNUM_OBSERVER_WRITE_( m_num ) \
2207 return *this; \
2208}
2209
2210#define DEFN_ASN_OP(op) \
2211inline \
2212sc_fxnum_subref& \
2213sc_fxnum_subref::operator op ## = ( const sc_fxnum_subref& a ) \
2214{ \
2215 SC_FXNUM_OBSERVER_READ_( m_num ) \
2216 get(); \
2217 m_bv = m_bv op static_cast<sc_bv_base>( a ); \
2218 set(); \
2219 SC_FXNUM_OBSERVER_WRITE_( m_num ) \
2220 return *this; \
2221} \
2222 \
2223inline \
2224sc_fxnum_subref& \
2225sc_fxnum_subref::operator op ## = ( const sc_fxnum_fast_subref& a ) \
2226{ \
2227 SC_FXNUM_OBSERVER_READ_( m_num ) \
2228 get(); \
2229 m_bv = m_bv op static_cast<sc_bv_base>( a ); \
2230 set(); \
2231 SC_FXNUM_OBSERVER_WRITE_( m_num ) \
2232 return *this; \
2233} \
2234 \
2235DEFN_ASN_OP_T(op,const sc_bv_base&) \
2236DEFN_ASN_OP_T(op,const sc_lv_base&)
2237
2238DEFN_ASN_OP(&)
2239DEFN_ASN_OP(|)
2240DEFN_ASN_OP(^)
2241
2242#undef DEFN_ASN_OP_T
2243#undef DEFN_ASN_OP
2244
2245
2246inline
2247::std::ostream&
2248operator << ( ::std::ostream& os, const sc_fxnum_subref& a )
2249{
2250 a.print( os );
2251 return os;
2252}
2253
2254inline
2255::std::istream&
2256operator >> ( ::std::istream& is, sc_fxnum_subref& a )
2257{
2258 a.scan( is );
2259 return is;
2260}
2261
2262// ----------------------------------------------------------------------------
2263// CLASS : sc_fxnum_fast_subref_r
2264// ----------------------------------------------------------------------------
2265
2266inline
2268 int from_, int to_)
2269 : m_num(num_), m_from(from_), m_to(to_),
2270 m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
2271 sc_min( m_from, m_to ) + 1 ) )
2272{}
2273
2274inline
2276 : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
2277 m_bv( *new sc_bv_base( a.m_bv ) )
2278
2279{}
2280
2281inline
2283{
2284 delete &m_bv;
2285}
2286
2287// relational operators
2288
2289#define DEFN_REL_OP_T(op,tp) \
2290inline \
2291bool \
2292operator op ( const sc_fxnum_fast_subref_r& a, tp b ) \
2293{ \
2294 return ( static_cast<sc_bv_base>( a ) op b ); \
2295} \
2296 \
2297inline \
2298bool \
2299operator op ( tp a, const sc_fxnum_fast_subref_r& b ) \
2300{ \
2301 return ( static_cast<sc_bv_base>( b ) op a ); \
2302}
2303
2304#define DEFN_REL_OP(op) \
2305inline \
2306bool \
2307operator op ( const sc_fxnum_fast_subref_r& a, \
2308 const sc_fxnum_fast_subref_r& b ) \
2309{ \
2310 return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) ); \
2311} \
2312 \
2313inline \
2314bool \
2315operator op ( const sc_fxnum_fast_subref_r& a, const sc_fxnum_subref_r& b ) \
2316{ \
2317 return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) ); \
2318} \
2319 \
2320DEFN_REL_OP_T(op,const sc_bv_base&) \
2321DEFN_REL_OP_T(op,const sc_lv_base&) \
2322DEFN_REL_OP_T(op,const char*) \
2323DEFN_REL_OP_T(op,const bool*) \
2324DEFN_REL_OP_T(op,const sc_signed&) \
2325DEFN_REL_OP_T(op,const sc_unsigned&) \
2326DEFN_REL_OP_T(op,int) \
2327DEFN_REL_OP_T(op,unsigned int) \
2328DEFN_REL_OP_T(op,long) \
2329DEFN_REL_OP_T(op,unsigned long)
2330
2331DEFN_REL_OP(==)
2332DEFN_REL_OP(!=)
2333
2334#undef DEFN_REL_OP_T
2335#undef DEFN_REL_OP
2336
2337
2338// reduce functions
2339
2340#define DEFN_RED_FNC(fnc) \
2341inline \
2342bool \
2343sc_fxnum_fast_subref_r::fnc() const \
2344{ \
2345 SC_FXNUM_FAST_OBSERVER_READ_( m_num ) \
2346 get(); \
2347 return static_cast<bool>( m_bv.fnc() ); \
2348}
2349
2356
2357#undef DEFN_RED_FNC
2358
2359
2360// query parameter
2361
2362inline
2363int
2365{
2366 return m_bv.length();
2367}
2368
2369
2370// explicit conversions
2371
2372inline
2373int
2375{
2377 get();
2378 return m_bv.to_int();
2379}
2380
2381inline
2382int64
2384{
2386 get();
2387 return m_bv.to_int64();
2388}
2389
2390inline
2391unsigned int
2393{
2395 get();
2396 return m_bv.to_uint();
2397}
2398
2399inline
2400uint64
2402{
2404 get();
2405 return m_bv.to_uint64();
2406}
2407
2408inline
2409long
2411{
2413 get();
2414 return m_bv.to_long();
2415}
2416
2417inline
2418unsigned long
2420{
2422 get();
2423 return m_bv.to_ulong();
2424}
2425
2426
2427#ifdef SC_DT_DEPRECATED
2428
2429inline
2430int
2431sc_fxnum_fast_subref_r::to_signed() const
2432{
2433 return to_int();
2434}
2435
2436inline
2437unsigned int
2438sc_fxnum_fast_subref_r::to_unsigned() const
2439{
2440 return to_uint();
2441}
2442
2443#endif
2444
2445
2446inline
2447std::string
2449{
2450 get();
2451 return m_bv.to_string();
2452}
2453
2454inline
2455std::string
2457{
2458 get();
2459 return m_bv.to_string( numrep );
2460}
2461
2462inline
2463std::string
2464sc_fxnum_fast_subref_r::to_string( sc_numrep numrep, bool w_prefix ) const
2465{
2466 get();
2467 return m_bv.to_string( numrep, w_prefix );
2468}
2469
2470
2471// implicit conversion
2472
2473inline
2474sc_fxnum_fast_subref_r::operator sc_bv_base () const
2475{
2477 get();
2478 return m_bv;
2479}
2480
2481inline
2482::std::ostream&
2483operator << ( ::std::ostream& os, const sc_fxnum_fast_subref_r& a )
2484{
2485 a.print( os );
2486 return os;
2487}
2488
2489// ----------------------------------------------------------------------------
2490// CLASS : sc_fxnum_fast_subref
2491//
2492// Proxy class for part-selection in class sc_fxnum_fast,
2493// behaves like sc_bv_base.
2494// ----------------------------------------------------------------------------
2495
2496// constructor
2497
2498inline
2499sc_fxnum_fast_subref::sc_fxnum_fast_subref( sc_fxnum_fast& num_,
2500 int from_, int to_ )
2501 : sc_fxnum_fast_subref_r( num_ , from_ , to_ )
2502{}
2503
2504
2505// copy constructor
2506
2507inline
2508sc_fxnum_fast_subref::sc_fxnum_fast_subref( const sc_fxnum_fast_subref& a )
2510{}
2511
2512
2513// assignment operators
2514
2515inline
2517sc_fxnum_fast_subref::operator = ( const sc_fxnum_subref& a )
2518{
2519 m_bv = static_cast<sc_bv_base>( a );
2520 set();
2522 return *this;
2523}
2524
2525inline
2526sc_fxnum_fast_subref&
2527sc_fxnum_fast_subref::operator = ( const sc_fxnum_fast_subref& a )
2528{
2529 if( &a != this )
2530 {
2531 m_bv = static_cast<sc_bv_base>( a );
2532 set();
2534 }
2535 return *this;
2536}
2537
2538#define DEFN_ASN_OP_T(tp) \
2539inline \
2540sc_fxnum_fast_subref& \
2541sc_fxnum_fast_subref::operator = ( tp a ) \
2542{ \
2543 m_bv = a; \
2544 set(); \
2545 SC_FXNUM_FAST_OBSERVER_WRITE_( m_num ) \
2546 return *this; \
2547}
2548
2549DEFN_ASN_OP_T(const sc_bv_base&)
2550DEFN_ASN_OP_T(const sc_lv_base&)
2551DEFN_ASN_OP_T(const char*)
2552DEFN_ASN_OP_T(const bool*)
2553DEFN_ASN_OP_T(const sc_signed&)
2554DEFN_ASN_OP_T(const sc_unsigned&)
2555DEFN_ASN_OP_T(const sc_int_base&)
2556DEFN_ASN_OP_T(const sc_uint_base&)
2559DEFN_ASN_OP_T(int)
2560DEFN_ASN_OP_T(unsigned int)
2561DEFN_ASN_OP_T(long)
2562DEFN_ASN_OP_T(unsigned long)
2563DEFN_ASN_OP_T(char)
2564
2565#undef DEFN_ASN_OP_T
2566
2567
2568#define DEFN_ASN_OP_T(op,tp) \
2569inline \
2570sc_fxnum_fast_subref& \
2571sc_fxnum_fast_subref::operator op ## = ( tp a ) \
2572{ \
2573 SC_FXNUM_FAST_OBSERVER_READ_( m_num ) \
2574 get(); \
2575 m_bv = m_bv op a; \
2576 set(); \
2577 SC_FXNUM_FAST_OBSERVER_WRITE_( m_num ) \
2578 return *this; \
2579}
2580
2581#define DEFN_ASN_OP(op) \
2582inline \
2583sc_fxnum_fast_subref& \
2584sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_subref& a ) \
2585{ \
2586 SC_FXNUM_FAST_OBSERVER_READ_( m_num ) \
2587 get(); \
2588 m_bv = m_bv op static_cast<sc_bv_base>( a ); \
2589 set(); \
2590 SC_FXNUM_FAST_OBSERVER_WRITE_( m_num ) \
2591 return *this; \
2592} \
2593 \
2594inline \
2595sc_fxnum_fast_subref& \
2596sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_fast_subref& a ) \
2597{ \
2598 SC_FXNUM_FAST_OBSERVER_READ_( m_num ) \
2599 get(); \
2600 m_bv = m_bv op static_cast<sc_bv_base>( a ); \
2601 set(); \
2602 SC_FXNUM_FAST_OBSERVER_WRITE_( m_num ) \
2603 return *this; \
2604} \
2605 \
2606DEFN_ASN_OP_T(op,const sc_bv_base&) \
2607DEFN_ASN_OP_T(op,const sc_lv_base&)
2608
2609DEFN_ASN_OP(&)
2610DEFN_ASN_OP(|)
2611DEFN_ASN_OP(^)
2612
2613#undef DEFN_ASN_OP_T
2614#undef DEFN_ASN_OP
2615
2616
2617inline
2618::std::istream&
2619operator >> ( ::std::istream& is, sc_fxnum_fast_subref& a )
2620{
2621 a.scan( is );
2622 return is;
2623}
2624
2625
2626// ----------------------------------------------------------------------------
2627// CLASS : sc_fxnum
2628//
2629// Base class for the fixed-point types; arbitrary precision.
2630// ----------------------------------------------------------------------------
2631
2632inline
2633sc_fxnum_observer*
2635{
2636 return m_observer;
2637}
2638
2639
2640inline
2641void
2643{
2645
2646 if( m_params.cast_switch() == SC_ON )
2647 m_rep->cast( m_params, m_q_flag, m_o_flag );
2648}
2649
2650
2651// constructors
2652
2653inline
2654sc_fxnum::sc_fxnum( const sc_fxtype_params& type_params_,
2655 sc_enc enc_,
2656 const sc_fxcast_switch& cast_sw,
2657 sc_fxnum_observer* observer_ )
2658: m_rep( new scfx_rep ),
2659 m_params( type_params_, enc_, cast_sw ),
2660 m_q_flag( false ),
2661 m_o_flag( false ),
2662 m_observer( observer_ )
2663{
2666}
2667
2668#define DEFN_CTOR_T(tp,arg) \
2669inline \
2670sc_fxnum::sc_fxnum( tp a, \
2671 const sc_fxtype_params& type_params_, \
2672 sc_enc enc_, \
2673 const sc_fxcast_switch& cast_sw, \
2674 sc_fxnum_observer* observer_ ) \
2675: m_rep( new scfx_rep( arg ) ), \
2676 m_params( type_params_, enc_, cast_sw ), \
2677 m_q_flag( false ), \
2678 m_o_flag( false ), \
2679 m_observer( observer_ ) \
2680{ \
2681 SC_FXNUM_OBSERVER_DEFAULT_ \
2682 cast(); \
2683 SC_FXNUM_OBSERVER_CONSTRUCT_( *this ) \
2684 SC_FXNUM_OBSERVER_WRITE_( *this ) \
2685}
2686
2687#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)
2688#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,*a.m_rep)
2689#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
2690#define DEFN_CTOR_T_D(tp) DEFN_CTOR_T(tp,a.value())
2691
2692DEFN_CTOR_T_A(int)
2693DEFN_CTOR_T_A(unsigned int)
2694DEFN_CTOR_T_A(long)
2695DEFN_CTOR_T_A(unsigned long)
2696DEFN_CTOR_T_A(float)
2697DEFN_CTOR_T_A(double)
2698DEFN_CTOR_T_A(const char*)
2699DEFN_CTOR_T_B(const sc_fxval&)
2700DEFN_CTOR_T_C(const sc_fxval_fast&)
2701DEFN_CTOR_T_B(const sc_fxnum&)
2702DEFN_CTOR_T_C(const sc_fxnum_fast&)
2705DEFN_CTOR_T_D(const sc_int_base&)
2706DEFN_CTOR_T_D(const sc_uint_base&)
2707DEFN_CTOR_T_A(const sc_signed&)
2708DEFN_CTOR_T_A(const sc_unsigned&)
2709
2710#undef DEFN_CTOR_T
2711#undef DEFN_CTOR_T_A
2712#undef DEFN_CTOR_T_B
2713#undef DEFN_CTOR_T_C
2714#undef DEFN_CTOR_T_D
2715
2716
2717inline
2719{
2721 delete m_rep;
2722}
2723
2724
2725// internal use only;
2726inline
2727const scfx_rep*
2729{
2731 return m_rep;
2732}
2733
2734
2735// unary operators
2736
2737inline
2740{
2742 return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );
2743}
2744
2745inline
2748{
2750 return sc_fxval( new scfx_rep( *m_rep ) );
2751}
2752
2753
2754// unary functions
2755
2756inline
2757void
2758neg( sc_fxval& c, const sc_fxnum& a )
2759{
2761 c.set_rep( sc_dt::neg_scfx_rep( *a.m_rep ) );
2762}
2763
2764inline
2765void
2766neg( sc_fxnum& c, const sc_fxnum& a )
2767{
2769 delete c.m_rep;
2770 c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );
2771 c.cast();
2773}
2774
2775
2776// binary operators
2777
2778#define DEFN_BIN_OP_T(op,fnc,tp) \
2779inline \
2780sc_fxval \
2781operator op ( const sc_fxnum& a, tp b ) \
2782{ \
2783 SC_FXNUM_OBSERVER_READ_( a ) \
2784 sc_fxval tmp( b ); \
2785 return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) ); \
2786} \
2787 \
2788inline \
2789sc_fxval \
2790operator op ( tp a, const sc_fxnum& b ) \
2791{ \
2792 SC_FXNUM_OBSERVER_READ_( b ) \
2793 sc_fxval tmp( a ); \
2794 return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) ); \
2795}
2796
2797#define DEFN_BIN_OP_OTHER(op,fnc) \
2798DEFN_BIN_OP_T(op,fnc,int64) \
2799DEFN_BIN_OP_T(op,fnc,uint64) \
2800DEFN_BIN_OP_T(op,fnc,const sc_int_base&) \
2801DEFN_BIN_OP_T(op,fnc,const sc_uint_base&) \
2802DEFN_BIN_OP_T(op,fnc,const sc_signed&) \
2803DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)
2804
2805#define DEFN_BIN_OP(op,fnc) \
2806inline \
2807sc_fxval \
2808operator op ( const sc_fxnum& a, const sc_fxnum& b ) \
2809{ \
2810 SC_FXNUM_OBSERVER_READ_( a ) \
2811 SC_FXNUM_OBSERVER_READ_( b ) \
2812 return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) ); \
2813} \
2814 \
2815inline \
2816sc_fxval \
2817operator op ( const sc_fxnum& a, const sc_fxval& b ) \
2818{ \
2819 SC_FXNUM_OBSERVER_READ_( a ) \
2820 return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) ); \
2821} \
2822 \
2823inline \
2824sc_fxval \
2825operator op ( const sc_fxval& a, const sc_fxnum& b ) \
2826{ \
2827 SC_FXNUM_OBSERVER_READ_( b ) \
2828 return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) ); \
2829} \
2830 \
2831DEFN_BIN_OP_T(op,fnc,int) \
2832DEFN_BIN_OP_T(op,fnc,unsigned int) \
2833DEFN_BIN_OP_T(op,fnc,long) \
2834DEFN_BIN_OP_T(op,fnc,unsigned long) \
2835DEFN_BIN_OP_T(op,fnc,float) \
2836DEFN_BIN_OP_T(op,fnc,double) \
2837DEFN_BIN_OP_T(op,fnc,const char*) \
2838DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&) \
2839DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&) \
2840DEFN_BIN_OP_OTHER(op,fnc)
2841
2842DEFN_BIN_OP(*,mult)
2843DEFN_BIN_OP(+,add)
2844DEFN_BIN_OP(-,sub)
2845// don't use macros
2846//DEFN_BIN_OP(/,div)
2847inline
2849operator / ( const sc_fxnum& a, const sc_fxnum& b )
2850{
2853 return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );
2854}
2855
2856inline
2858operator / ( const sc_fxnum& a, const sc_fxval& b )
2859{
2861 return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.get_rep() ) );
2862}
2863
2864inline
2865sc_fxval
2866operator / ( const sc_fxval& a, const sc_fxnum& b )
2867{
2869 return sc_fxval( sc_dt::div_scfx_rep( *a.get_rep(), *b.m_rep ) );
2870}
2871
2872DEFN_BIN_OP_T(/,div,int)
2873DEFN_BIN_OP_T(/,div,unsigned int)
2874DEFN_BIN_OP_T(/,div,long)
2875DEFN_BIN_OP_T(/,div,unsigned long)
2876DEFN_BIN_OP_T(/,div,float)
2877DEFN_BIN_OP_T(/,div,double)
2878DEFN_BIN_OP_T(/,div,const char*)
2879DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)
2880DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
2881//DEFN_BIN_OP_OTHER(/,div)
2884DEFN_BIN_OP_T(/,div,const sc_int_base&)
2885DEFN_BIN_OP_T(/,div,const sc_uint_base&)
2886DEFN_BIN_OP_T(/,div,const sc_signed&)
2887DEFN_BIN_OP_T(/,div,const sc_unsigned&)
2888
2889#undef DEFN_BIN_OP_T
2890#undef DEFN_BIN_OP_OTHER
2891#undef DEFN_BIN_OP
2892
2893
2894inline
2896operator << ( const sc_fxnum& a, int b )
2897{
2899 return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
2900}
2901
2902inline
2904operator >> ( const sc_fxnum& a, int b )
2905{
2907 return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
2908}
2909
2910
2911// binary functions
2912
2913#define DEFN_BIN_FNC_T(fnc,tp) \
2914inline \
2915void \
2916fnc ( sc_fxval& c, const sc_fxnum& a, tp b ) \
2917{ \
2918 SC_FXNUM_OBSERVER_READ_( a ) \
2919 sc_fxval tmp( b ); \
2920 c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) ); \
2921} \
2922 \
2923inline \
2924void \
2925fnc ( sc_fxval& c, tp a, const sc_fxnum& b ) \
2926{ \
2927 SC_FXNUM_OBSERVER_READ_( b ) \
2928 sc_fxval tmp( a ); \
2929 c.set_rep( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) ); \
2930} \
2931 \
2932inline \
2933void \
2934fnc ( sc_fxnum& c, const sc_fxnum& a, tp b ) \
2935{ \
2936 SC_FXNUM_OBSERVER_READ_( a ) \
2937 sc_fxval tmp( b ); \
2938 delete c.m_rep; \
2939 c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ); \
2940 c.cast(); \
2941 SC_FXNUM_OBSERVER_WRITE_( c ) \
2942} \
2943 \
2944inline \
2945void \
2946fnc ( sc_fxnum& c, tp a, const sc_fxnum& b ) \
2947{ \
2948 SC_FXNUM_OBSERVER_READ_( b ) \
2949 sc_fxval tmp( a ); \
2950 delete c.m_rep; \
2951 c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ); \
2952 c.cast(); \
2953 SC_FXNUM_OBSERVER_WRITE_( c ) \
2954}
2955
2956#define DEFN_BIN_FNC_OTHER(fnc) \
2957DEFN_BIN_FNC_T(fnc,int64) \
2958DEFN_BIN_FNC_T(fnc,uint64) \
2959DEFN_BIN_FNC_T(fnc,const sc_int_base&) \
2960DEFN_BIN_FNC_T(fnc,const sc_uint_base&) \
2961DEFN_BIN_FNC_T(fnc,const sc_signed&) \
2962DEFN_BIN_FNC_T(fnc,const sc_unsigned&)
2963
2964#define DEFN_BIN_FNC(fnc) \
2965inline \
2966void \
2967fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxnum& b ) \
2968{ \
2969 SC_FXNUM_OBSERVER_READ_( a ) \
2970 SC_FXNUM_OBSERVER_READ_( b ) \
2971 c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) ); \
2972} \
2973 \
2974inline \
2975void \
2976fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxnum& b ) \
2977{ \
2978 SC_FXNUM_OBSERVER_READ_( a ) \
2979 SC_FXNUM_OBSERVER_READ_( b ) \
2980 delete c.m_rep; \
2981 c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ); \
2982 c.cast(); \
2983 SC_FXNUM_OBSERVER_WRITE_( c ) \
2984} \
2985 \
2986inline \
2987void \
2988fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxval& b ) \
2989{ \
2990 SC_FXNUM_OBSERVER_READ_( a ) \
2991 c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) ); \
2992} \
2993 \
2994inline \
2995void \
2996fnc ( sc_fxval& c, const sc_fxval& a, const sc_fxnum& b ) \
2997{ \
2998 SC_FXNUM_OBSERVER_READ_( b ) \
2999 c.set_rep( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) ); \
3000} \
3001 \
3002inline \
3003void \
3004fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxval& b ) \
3005{ \
3006 SC_FXNUM_OBSERVER_READ_( a ) \
3007 delete c.m_rep; \
3008 c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ); \
3009 c.cast(); \
3010 SC_FXNUM_OBSERVER_WRITE_( c ) \
3011} \
3012 \
3013inline \
3014void \
3015fnc ( sc_fxnum& c, const sc_fxval& a, const sc_fxnum& b ) \
3016{ \
3017 SC_FXNUM_OBSERVER_READ_( b ) \
3018 delete c.m_rep; \
3019 c.m_rep = sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ); \
3020 c.cast(); \
3021 SC_FXNUM_OBSERVER_WRITE_( c ) \
3022} \
3023 \
3024DEFN_BIN_FNC_T(fnc,int) \
3025DEFN_BIN_FNC_T(fnc,unsigned int) \
3026DEFN_BIN_FNC_T(fnc,long) \
3027DEFN_BIN_FNC_T(fnc,unsigned long) \
3028DEFN_BIN_FNC_T(fnc,float) \
3029DEFN_BIN_FNC_T(fnc,double) \
3030DEFN_BIN_FNC_T(fnc,const char*) \
3031DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&) \
3032DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&) \
3033DEFN_BIN_FNC_OTHER(fnc)
3034
3035DEFN_BIN_FNC(mult)
3037DEFN_BIN_FNC(add)
3038DEFN_BIN_FNC(sub)
3039
3040#undef DEFN_BIN_FNC_T
3041#undef DEFN_BIN_FNC_OTHER
3042#undef DEFN_BIN_FNC
3043
3044
3045inline
3046void
3047lshift( sc_fxval& c, const sc_fxnum& a, int b )
3048{
3050 c.set_rep( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
3051}
3052
3053inline
3054void
3055rshift( sc_fxval& c, const sc_fxnum& a, int b )
3056{
3058 c.set_rep( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
3059}
3060
3061inline
3062void
3063lshift( sc_fxnum& c, const sc_fxnum& a, int b )
3064{
3066 delete c.m_rep;
3067 c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );
3068 c.cast();
3070}
3071
3072inline
3073void
3074rshift( sc_fxnum& c, const sc_fxnum& a, int b )
3075{
3077 delete c.m_rep;
3078 c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );
3079 c.cast();
3081}
3082
3083
3084// relational (including equality) operators
3085
3086#define DEFN_REL_OP_T(op,ret,tp) \
3087inline \
3088bool \
3089operator op ( const sc_fxnum& a, tp b ) \
3090{ \
3091 SC_FXNUM_OBSERVER_READ_( a ) \
3092 sc_fxval tmp( b ); \
3093 int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.get_rep() ); \
3094 return ( ret ); \
3095} \
3096 \
3097inline \
3098bool \
3099operator op ( tp a, const sc_fxnum& b ) \
3100{ \
3101 SC_FXNUM_OBSERVER_READ_( b ) \
3102 sc_fxval tmp( a ); \
3103 int result = sc_dt::cmp_scfx_rep( *tmp.get_rep(), *b.m_rep ); \
3104 return ( ret ); \
3105}
3106
3107#define DEFN_REL_OP_OTHER(op,ret) \
3108DEFN_REL_OP_T(op,ret,int64) \
3109DEFN_REL_OP_T(op,ret,uint64) \
3110DEFN_REL_OP_T(op,ret,const sc_int_base&) \
3111DEFN_REL_OP_T(op,ret,const sc_uint_base&) \
3112DEFN_REL_OP_T(op,ret,const sc_signed&) \
3113DEFN_REL_OP_T(op,ret,const sc_unsigned&)
3114
3115#define DEFN_REL_OP(op,ret) \
3116inline \
3117bool \
3118operator op ( const sc_fxnum& a, const sc_fxnum& b ) \
3119{ \
3120 SC_FXNUM_OBSERVER_READ_( a ) \
3121 SC_FXNUM_OBSERVER_READ_( b ) \
3122 int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep ); \
3123 return ( ret ); \
3124} \
3125 \
3126inline \
3127bool \
3128operator op ( const sc_fxnum& a, const sc_fxval& b ) \
3129{ \
3130 SC_FXNUM_OBSERVER_READ_( a ) \
3131 int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.get_rep() ); \
3132 return ( ret ); \
3133} \
3134 \
3135inline \
3136bool \
3137operator op ( const sc_fxval& a, const sc_fxnum& b ) \
3138{ \
3139 SC_FXNUM_OBSERVER_READ_( b ) \
3140 int result = sc_dt::cmp_scfx_rep( *a.get_rep(), *b.m_rep ); \
3141 return ( ret ); \
3142} \
3143 \
3144DEFN_REL_OP_T(op,ret,int) \
3145DEFN_REL_OP_T(op,ret,unsigned int) \
3146DEFN_REL_OP_T(op,ret,long) \
3147DEFN_REL_OP_T(op,ret,unsigned long) \
3148DEFN_REL_OP_T(op,ret,float) \
3149DEFN_REL_OP_T(op,ret,double) \
3150DEFN_REL_OP_T(op,ret,const char*) \
3151DEFN_REL_OP_T(op,ret,const sc_fxval_fast&) \
3152DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&) \
3153DEFN_REL_OP_OTHER(op,ret)
3154
3155DEFN_REL_OP(<,result < 0)
3156DEFN_REL_OP(<=,result <= 0)
3157DEFN_REL_OP(>,result > 0 && result != 2)
3158DEFN_REL_OP(>=,result >= 0 && result != 2)
3159DEFN_REL_OP(==,result == 0)
3160DEFN_REL_OP(!=,result != 0)
3161
3162#undef DEFN_REL_OP_T
3163#undef DEFN_REL_OP_OTHER
3164#undef DEFN_REL_OP
3165
3166
3167// assignment operators
3168
3169inline
3170sc_fxnum&
3171sc_fxnum::operator = ( const sc_fxnum& a )
3172{
3173 if( &a != this )
3174 {
3176 *m_rep = *a.m_rep;
3177 cast();
3179 }
3180 return *this;
3181}
3182
3183inline
3184sc_fxnum&
3185sc_fxnum::operator = ( const sc_fxval& a )
3186{
3187 *m_rep = *a.get_rep();
3188 cast();
3190 return *this;
3191}
3192
3193#define DEFN_ASN_OP_T(tp) \
3194inline \
3195sc_fxnum& \
3196sc_fxnum::operator = ( tp a ) \
3197{ \
3198 sc_fxval tmp( a ); \
3199 *m_rep = *tmp.get_rep(); \
3200 cast(); \
3201 SC_FXNUM_OBSERVER_WRITE_( *this ) \
3202 return *this; \
3203}
3204
3205DEFN_ASN_OP_T(int)
3206DEFN_ASN_OP_T(unsigned int)
3207DEFN_ASN_OP_T(long)
3208DEFN_ASN_OP_T(unsigned long)
3209DEFN_ASN_OP_T(float)
3210DEFN_ASN_OP_T(double)
3211DEFN_ASN_OP_T(const char*)
3212DEFN_ASN_OP_T(const sc_fxval_fast&)
3213DEFN_ASN_OP_T(const sc_fxnum_fast&)
3216DEFN_ASN_OP_T(const sc_int_base&)
3217DEFN_ASN_OP_T(const sc_uint_base&)
3218DEFN_ASN_OP_T(const sc_signed&)
3219DEFN_ASN_OP_T(const sc_unsigned&)
3220
3221#undef DEFN_ASN_OP_T
3222
3223
3224#define DEFN_ASN_OP_T(op,fnc,tp) \
3225inline \
3226sc_fxnum& \
3227sc_fxnum::operator op ( tp b ) \
3228{ \
3229 SC_FXNUM_OBSERVER_READ_( *this ) \
3230 sc_fxval tmp( b ); \
3231 scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.get_rep() ); \
3232 delete m_rep; \
3233 m_rep = new_rep; \
3234 cast(); \
3235 SC_FXNUM_OBSERVER_WRITE_( *this ) \
3236 return *this; \
3237}
3238
3239#define DEFN_ASN_OP_OTHER(op,fnc) \
3240DEFN_ASN_OP_T(op,fnc,int64) \
3241DEFN_ASN_OP_T(op,fnc,uint64) \
3242DEFN_ASN_OP_T(op,fnc,const sc_int_base&) \
3243DEFN_ASN_OP_T(op,fnc,const sc_uint_base&) \
3244DEFN_ASN_OP_T(op,fnc,const sc_signed&) \
3245DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)
3246
3247#define DEFN_ASN_OP(op,fnc) \
3248inline \
3249sc_fxnum& \
3250sc_fxnum::operator op ( const sc_fxnum& b ) \
3251{ \
3252 SC_FXNUM_OBSERVER_READ_( *this ) \
3253 SC_FXNUM_OBSERVER_READ_( b ) \
3254 scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep ); \
3255 delete m_rep; \
3256 m_rep = new_rep; \
3257 cast(); \
3258 SC_FXNUM_OBSERVER_WRITE_( *this ) \
3259 return *this; \
3260} \
3261 \
3262inline \
3263sc_fxnum& \
3264sc_fxnum::operator op ( const sc_fxval& b ) \
3265{ \
3266 SC_FXNUM_OBSERVER_READ_( *this ) \
3267 scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() ); \
3268 delete m_rep; \
3269 m_rep = new_rep; \
3270 cast(); \
3271 SC_FXNUM_OBSERVER_WRITE_( *this ) \
3272 return *this; \
3273} \
3274 \
3275DEFN_ASN_OP_T(op,fnc,int) \
3276DEFN_ASN_OP_T(op,fnc,unsigned int) \
3277DEFN_ASN_OP_T(op,fnc,long) \
3278DEFN_ASN_OP_T(op,fnc,unsigned long) \
3279DEFN_ASN_OP_T(op,fnc,float) \
3280DEFN_ASN_OP_T(op,fnc,double) \
3281DEFN_ASN_OP_T(op,fnc,const char*) \
3282DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&) \
3283DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&) \
3284DEFN_ASN_OP_OTHER(op,fnc)
3285
3286DEFN_ASN_OP(*=,mult)
3287DEFN_ASN_OP(/=,div)
3288DEFN_ASN_OP(+=,add)
3289DEFN_ASN_OP(-=,sub)
3290
3291#undef DEFN_ASN_OP_T
3292#undef DEFN_ASN_OP_OTHER
3293#undef DEFN_ASN_OP
3294
3295
3296inline
3297sc_fxnum&
3298sc_fxnum::operator <<= ( int b )
3299{
3301 m_rep->lshift( b );
3302 cast();
3304 return *this;
3305}
3306
3307inline
3308sc_fxnum&
3309sc_fxnum::operator >>= ( int b )
3310{
3312 m_rep->rshift( b );
3313 cast();
3315 return *this;
3316}
3317
3318
3319// auto-increment and auto-decrement
3320
3321inline
3323sc_fxnum::operator ++ ( int )
3324{
3325 sc_fxval c( *this );
3326 (*this) += 1;
3327 return c;
3328}
3329
3330inline
3333{
3334 sc_fxval c( *this );
3335 (*this) -= 1;
3336 return c;
3337}
3338
3339inline
3340sc_fxnum&
3342{
3343 (*this) += 1;
3344 return *this;
3345}
3346
3347inline
3348sc_fxnum&
3350{
3351 (*this) -= 1;
3352 return *this;
3353}
3354
3355
3356// bit selection
3357
3358inline
3361{
3362 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3363 return sc_fxnum_bitref_r( const_cast<sc_fxnum&>( *this ),
3364 i - m_params.fwl() );
3365}
3366
3367inline
3370{
3371 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3372 return sc_fxnum_bitref( *this, i - m_params.fwl() );
3373}
3374
3375inline
3377sc_fxnum::bit( int i ) const
3378{
3379 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3380 return sc_fxnum_bitref_r( const_cast<sc_fxnum&>( *this ),
3381 i - m_params.fwl() );
3382}
3383
3384inline
3387{
3388 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3389 return sc_fxnum_bitref( *this, i - m_params.fwl() );
3390}
3391
3392
3393// part selection
3394
3395inline
3397sc_fxnum::operator () ( int i, int j ) const
3398{
3399 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3400 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3401
3402 return sc_fxnum_subref_r( const_cast<sc_fxnum&>( *this ),
3403 i - m_params.fwl(), j - m_params.fwl() );
3404}
3405
3406inline
3409{
3410 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3411 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3412
3413 return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
3414}
3415
3416inline
3418sc_fxnum::range( int i, int j ) const
3419{
3420 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3421 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3422
3423 return sc_fxnum_subref_r( const_cast<sc_fxnum&>( *this ),
3424 i - m_params.fwl(), j - m_params.fwl() );
3425}
3426
3427inline
3429sc_fxnum::range( int i, int j )
3430{
3431 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3432 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3433
3434 return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
3435}
3436
3437
3438inline
3441{
3442 return this->operator () ( m_params.wl() - 1, 0 );
3443}
3444
3445inline
3448{
3449 return this->operator () ( m_params.wl() - 1, 0 );
3450}
3451
3452inline
3455{
3456 return this->range( m_params.wl() - 1, 0 );
3457}
3458
3459inline
3462{
3463 return this->range( m_params.wl() - 1, 0 );
3464}
3465
3466
3467// implicit conversion
3468
3469inline
3470sc_fxnum::operator double() const
3471{
3473 return m_rep->to_double();
3474}
3475
3476
3477// explicit conversion to primitive types
3478
3479inline
3480short
3482{
3484 return static_cast<short>( m_rep->to_uint64() );
3485}
3486
3487inline
3488unsigned short
3490{
3492 return static_cast<unsigned short>( m_rep->to_uint64() );
3493}
3494
3495inline
3496int
3498{
3500 return static_cast<int>( m_rep->to_uint64() );
3501}
3502
3503inline
3504int64
3506{
3508 return static_cast<int64>( m_rep->to_uint64() );
3509}
3510
3511inline
3512unsigned int
3514{
3516 return static_cast<unsigned int>( m_rep->to_uint64() );
3517}
3518
3519inline
3520uint64
3522{
3524 return m_rep->to_uint64();
3525}
3526
3527inline
3528long
3530{
3532 return static_cast<long>( m_rep->to_uint64() );
3533}
3534
3535inline
3536unsigned long
3538{
3540 return static_cast<unsigned long>( m_rep->to_uint64() );
3541}
3542
3543inline
3544float
3546{
3548 return static_cast<float>( m_rep->to_double() );
3549}
3550
3551inline
3552double
3554{
3556 return m_rep->to_double();
3557}
3558
3559
3560// query value
3561
3562inline
3563bool
3565{
3567 return m_rep->is_neg();
3568}
3569
3570inline
3571bool
3573{
3575 return m_rep->is_zero();
3576}
3577
3578// internal use only;
3579inline
3580bool
3582{
3584 return m_rep->is_normal();
3585}
3586
3587inline
3588bool
3590{
3591 return m_q_flag;
3592}
3593
3594inline
3595bool
3597{
3598 return m_o_flag;
3599}
3600
3601
3602inline
3605{
3607 return sc_fxval( new scfx_rep( *m_rep ) );
3608}
3609
3610
3611// query parameters
3612
3613inline
3614int
3616{
3617 return m_params.wl();
3618}
3619
3620inline
3621int
3623{
3624 return m_params.iwl();
3625}
3626
3627inline
3630{
3631 return m_params.q_mode();
3632}
3633
3634inline
3637{
3638 return m_params.o_mode();
3639}
3640
3641inline
3642int
3644{
3645 return m_params.n_bits();
3646}
3647
3648
3649inline
3650const sc_fxtype_params&
3652{
3653 return m_params.type_params();
3654}
3655
3656
3657inline
3658const sc_fxcast_switch&
3660{
3661 return m_params.cast_switch();
3662}
3663
3664
3665// internal use only;
3666inline
3667void
3669{
3670 SC_FXNUM_OBSERVER_READ_( *this );
3671}
3672
3673
3674// internal use only;
3675inline
3676bool
3677sc_fxnum::get_bit( int i ) const
3678{
3679 return m_rep->get_bit( i );
3680}
3681
3682
3683// protected methods and friend functions
3684
3685inline
3686bool
3687sc_fxnum::set_bit( int i, bool high )
3688{
3689 if( high )
3690 return m_rep->set( i, m_params );
3691 else
3692 return m_rep->clear( i, m_params );
3693}
3694
3695
3696inline
3697bool
3698sc_fxnum::get_slice( int i, int j, sc_bv_base& bv ) const
3699{
3700 return m_rep->get_slice( i, j, m_params, bv );
3701}
3702
3703inline
3704bool
3705sc_fxnum::set_slice( int i, int j, const sc_bv_base& bv )
3706{
3707 return m_rep->set_slice( i, j, m_params, bv );
3708}
3709
3710
3711inline
3712::std::ostream&
3713operator << ( ::std::ostream& os, const sc_fxnum& a )
3714{
3715 a.print( os );
3716 return os;
3717}
3718
3719inline
3720::std::istream&
3721operator >> ( ::std::istream& is, sc_fxnum& a )
3722{
3723 a.scan( is );
3724 return is;
3725}
3726
3727
3728// ----------------------------------------------------------------------------
3729// CLASS : sc_fxnum_fast
3730//
3731// Base class for the fixed-point types; limited precision.
3732// ----------------------------------------------------------------------------
3733
3734inline
3735sc_fxnum_fast_observer*
3737{
3738 return m_observer;
3739}
3740
3741
3742// constructors
3743
3744inline
3745sc_fxnum_fast::sc_fxnum_fast( const sc_fxtype_params& type_params_,
3746 sc_enc enc_,
3747 const sc_fxcast_switch& cast_sw,
3748 sc_fxnum_fast_observer* observer_ )
3749: m_val( 0.0 ),
3750 m_params( type_params_, enc_, cast_sw ),
3751 m_q_flag( false ),
3752 m_o_flag( false ),
3753 m_observer( observer_ )
3754{
3757}
3758
3759inline
3760sc_fxnum_fast::sc_fxnum_fast( const sc_fxnum_fast& a,
3761 const sc_fxtype_params& type_params_,
3762 sc_enc enc_,
3763 const sc_fxcast_switch& cast_sw,
3764 sc_fxnum_fast_observer* observer_ )
3765: m_val( a.m_val ),
3766 m_params( type_params_, enc_, cast_sw ),
3767 m_q_flag( false ),
3768 m_o_flag( false ),
3769 m_observer( observer_ )
3770{
3773 cast();
3776}
3777
3778#define DEFN_CTOR_T(tp,arg) \
3779inline \
3780sc_fxnum_fast::sc_fxnum_fast( tp a, \
3781 const sc_fxtype_params& type_params_, \
3782 sc_enc enc_, \
3783 const sc_fxcast_switch& cast_sw, \
3784 sc_fxnum_fast_observer* observer_ ) \
3785: m_val( arg ), \
3786 m_params( type_params_, enc_, cast_sw ), \
3787 m_q_flag( false ), \
3788 m_o_flag( false ), \
3789 m_observer( observer_ ) \
3790{ \
3791 SC_FXNUM_FAST_OBSERVER_DEFAULT_ \
3792 cast(); \
3793 SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this) \
3794 SC_FXNUM_FAST_OBSERVER_WRITE_( *this ) \
3795}
3796
3797#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))
3798#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,sc_fxval_fast::from_string( a ))
3799#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
3800
3801DEFN_CTOR_T_A(int)
3802DEFN_CTOR_T_A(unsigned int)
3803DEFN_CTOR_T_A(long)
3804DEFN_CTOR_T_A(unsigned long)
3805DEFN_CTOR_T_A(float)
3806DEFN_CTOR_T_A(double)
3807DEFN_CTOR_T_B(const char*)
3808DEFN_CTOR_T_C(const sc_fxval&)
3810DEFN_CTOR_T_C(const sc_fxnum&)
3813DEFN_CTOR_T_C(const sc_int_base&)
3814DEFN_CTOR_T_C(const sc_uint_base&)
3815DEFN_CTOR_T_C(const sc_signed&)
3816DEFN_CTOR_T_C(const sc_unsigned&)
3817
3818#undef DEFN_CTOR_T
3819#undef DEFN_CTOR_T_A
3820#undef DEFN_CTOR_T_B
3821#undef DEFN_CTOR_T_C
3822#undef DEFN_CTOR_T_D
3823#undef DEFN_CTOR_T_E
3824
3825
3826inline
3828{
3830}
3831
3832
3833// internal use only;
3834inline
3835double
3837{
3839 return m_val;
3840}
3841
3842
3843// unary operators
3844
3845inline
3848{
3850 return sc_fxval_fast( - m_val );
3851}
3852
3853inline
3856{
3858 return sc_fxval_fast( m_val );
3859}
3860
3861
3862// unary functions
3863
3864inline
3865void
3867{
3869 c.set_val( - a.m_val );
3870}
3871
3872inline
3873void
3875{
3877 c.m_val = - a.m_val;
3878 c.cast();
3880}
3881
3882
3883// binary operators
3884
3885#define DEFN_BIN_OP_T(op,tp) \
3886inline \
3887sc_fxval_fast \
3888operator op ( const sc_fxnum_fast& a, tp b ) \
3889{ \
3890 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
3891 sc_fxval_fast tmp( b ); \
3892 return sc_fxval_fast( a.m_val op tmp.get_val() ); \
3893} \
3894 \
3895inline \
3896sc_fxval_fast \
3897operator op ( tp a, const sc_fxnum_fast& b ) \
3898{ \
3899 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
3900 sc_fxval_fast tmp( a ); \
3901 return sc_fxval_fast( tmp.get_val() op b.m_val ); \
3902}
3903
3904#define DEFN_BIN_OP_OTHER(op) \
3905DEFN_BIN_OP_T(op,int64) \
3906DEFN_BIN_OP_T(op,uint64) \
3907DEFN_BIN_OP_T(op,const sc_int_base&) \
3908DEFN_BIN_OP_T(op,const sc_uint_base&) \
3909DEFN_BIN_OP_T(op,const sc_signed&) \
3910DEFN_BIN_OP_T(op,const sc_unsigned&)
3911
3912#define DEFN_BIN_OP(op,dummy) \
3913inline \
3914sc_fxval_fast \
3915operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b ) \
3916{ \
3917 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
3918 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
3919 return sc_fxval_fast( a.m_val op b.m_val ); \
3920} \
3921 \
3922inline \
3923sc_fxval_fast \
3924operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b ) \
3925{ \
3926 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
3927 return sc_fxval_fast( a.m_val op b.get_val() ); \
3928} \
3929 \
3930inline \
3931sc_fxval_fast \
3932operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b ) \
3933{ \
3934 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
3935 return sc_fxval_fast( a.get_val() op b.m_val ); \
3936} \
3937 \
3938DEFN_BIN_OP_T(op,int) \
3939DEFN_BIN_OP_T(op,unsigned int) \
3940DEFN_BIN_OP_T(op,long) \
3941DEFN_BIN_OP_T(op,unsigned long) \
3942DEFN_BIN_OP_T(op,float) \
3943DEFN_BIN_OP_T(op,double) \
3944DEFN_BIN_OP_T(op,const char*) \
3945DEFN_BIN_OP_OTHER(op)
3946
3947DEFN_BIN_OP(*,mult)
3948DEFN_BIN_OP(+,add)
3949DEFN_BIN_OP(-,sub)
3950//DEFN_BIN_OP(/,div)
3951inline
3954{
3957 return sc_fxval_fast( a.m_val / b.m_val );
3958}
3959
3960inline
3963{
3965 return sc_fxval_fast( a.m_val / b.get_val() );
3966}
3967
3968inline
3971{
3973 return sc_fxval_fast( a.get_val() / b.m_val );
3974}
3975
3976DEFN_BIN_OP_T(/,int)
3977DEFN_BIN_OP_T(/,unsigned int)
3978DEFN_BIN_OP_T(/,long)
3979DEFN_BIN_OP_T(/,unsigned long)
3980DEFN_BIN_OP_T(/,float)
3981DEFN_BIN_OP_T(/,double)
3982DEFN_BIN_OP_T(/,const char*)
3983//DEFN_BIN_OP_OTHER(/)
3986DEFN_BIN_OP_T(/,const sc_int_base&)
3987DEFN_BIN_OP_T(/,const sc_uint_base&)
3988DEFN_BIN_OP_T(/,const sc_signed&)
3989DEFN_BIN_OP_T(/,const sc_unsigned&)
3990
3991#undef DEFN_BIN_OP_T
3992#undef DEFN_BIN_OP_OTHER
3993#undef DEFN_BIN_OP
3994
3995
3996inline
3998operator << ( const sc_fxnum_fast& a, int b )
3999{
4001 return sc_fxval_fast( a.m_val * scfx_pow2( b ) );
4002}
4003
4004inline
4007{
4009 return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );
4010}
4011
4012
4013// binary functions
4014
4015#define DEFN_BIN_FNC_T(fnc,op,tp) \
4016inline \
4017void \
4018fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, tp b ) \
4019{ \
4020 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4021 sc_fxval_fast tmp( b ); \
4022 c.set_val( a.m_val op tmp.get_val() ); \
4023} \
4024 \
4025inline \
4026void \
4027fnc ( sc_fxval_fast& c, tp a, const sc_fxnum_fast& b ) \
4028{ \
4029 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4030 sc_fxval_fast tmp( a ); \
4031 c.set_val( tmp.get_val() op b.m_val ); \
4032} \
4033 \
4034inline \
4035void \
4036fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, tp b ) \
4037{ \
4038 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4039 sc_fxval_fast tmp( b ); \
4040 c.m_val = a.m_val op tmp.get_val(); \
4041 c.cast(); \
4042 SC_FXNUM_FAST_OBSERVER_WRITE_( c ) \
4043} \
4044 \
4045inline \
4046void \
4047fnc ( sc_fxnum_fast& c, tp a, const sc_fxnum_fast& b ) \
4048{ \
4049 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4050 sc_fxval_fast tmp( a ); \
4051 c.m_val = tmp.get_val() op b.m_val; \
4052 c.cast(); \
4053 SC_FXNUM_FAST_OBSERVER_WRITE_( c ) \
4054}
4055
4056#define DEFN_BIN_FNC_OTHER(fnc,op) \
4057DEFN_BIN_FNC_T(fnc,op,int64) \
4058DEFN_BIN_FNC_T(fnc,op,uint64) \
4059DEFN_BIN_FNC_T(fnc,op,const sc_int_base&) \
4060DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&) \
4061DEFN_BIN_FNC_T(fnc,op,const sc_signed&) \
4062DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)
4063
4064#define DEFN_BIN_FNC(fnc,op) \
4065inline \
4066void \
4067fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b ) \
4068{ \
4069 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4070 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4071 c.set_val( a.m_val op b.m_val ); \
4072} \
4073 \
4074inline \
4075void \
4076fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b ) \
4077{ \
4078 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4079 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4080 c.m_val = a.m_val op b.m_val; \
4081 c.cast(); \
4082 SC_FXNUM_FAST_OBSERVER_WRITE_( c ) \
4083} \
4084 \
4085inline \
4086void \
4087fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b ) \
4088{ \
4089 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4090 c.set_val( a.m_val op b.get_val() ); \
4091} \
4092 \
4093inline \
4094void \
4095fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b ) \
4096{ \
4097 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4098 c.set_val( a.get_val() op b.m_val ); \
4099} \
4100 \
4101inline \
4102void \
4103fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b ) \
4104{ \
4105 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4106 c.m_val = a.m_val op b.get_val(); \
4107 c.cast(); \
4108 SC_FXNUM_FAST_OBSERVER_WRITE_( c ) \
4109} \
4110 \
4111inline \
4112void \
4113fnc ( sc_fxnum_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b ) \
4114{ \
4115 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4116 c.m_val = a.get_val() op b.m_val; \
4117 c.cast(); \
4118 SC_FXNUM_FAST_OBSERVER_WRITE_( c ) \
4119} \
4120 \
4121DEFN_BIN_FNC_T(fnc,op,int) \
4122DEFN_BIN_FNC_T(fnc,op,unsigned int) \
4123DEFN_BIN_FNC_T(fnc,op,long) \
4124DEFN_BIN_FNC_T(fnc,op,unsigned long) \
4125DEFN_BIN_FNC_T(fnc,op,float) \
4126DEFN_BIN_FNC_T(fnc,op,double) \
4127DEFN_BIN_FNC_T(fnc,op,const char*) \
4128DEFN_BIN_FNC_T(fnc,op,const sc_fxval&) \
4129DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&) \
4130DEFN_BIN_FNC_OTHER(fnc,op)
4131
4132DEFN_BIN_FNC(mult,*)
4134DEFN_BIN_FNC(add,+)
4135DEFN_BIN_FNC(sub,-)
4136
4137#undef DEFN_BIN_FNC_T
4138#undef DEFN_BIN_FNC_OTHER
4139#undef DEFN_BIN_FNC
4140
4141
4142inline
4143void
4145{
4147 c.set_val( a.m_val * scfx_pow2( b ) );
4148}
4149
4150inline
4151void
4153{
4155 c.set_val( a.m_val * scfx_pow2( -b ) );
4156}
4157
4158inline
4159void
4161{
4163 c.m_val = a.m_val * scfx_pow2( b );
4164 c.cast();
4166}
4167
4168inline
4169void
4171{
4173 c.m_val = a.m_val * scfx_pow2( -b );
4174 c.cast();
4176}
4177
4178
4179// relational (including equality) operators
4180
4181#define DEFN_REL_OP_T(op,tp) \
4182inline \
4183bool \
4184operator op ( const sc_fxnum_fast& a, tp b ) \
4185{ \
4186 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4187 sc_fxval_fast tmp( b ); \
4188 return ( a.m_val op tmp.get_val() ); \
4189} \
4190 \
4191inline \
4192bool \
4193operator op ( tp a, const sc_fxnum_fast& b ) \
4194{ \
4195 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4196 sc_fxval_fast tmp( a ); \
4197 return ( tmp.get_val() op b.m_val ); \
4198}
4199
4200#define DEFN_REL_OP_OTHER(op) \
4201DEFN_REL_OP_T(op,int64) \
4202DEFN_REL_OP_T(op,uint64) \
4203DEFN_REL_OP_T(op,const sc_int_base&) \
4204DEFN_REL_OP_T(op,const sc_uint_base&) \
4205DEFN_REL_OP_T(op,const sc_signed&) \
4206DEFN_REL_OP_T(op,const sc_unsigned&)
4207
4208#define DEFN_REL_OP(op) \
4209inline \
4210bool \
4211operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b ) \
4212{ \
4213 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4214 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4215 return ( a.m_val op b.m_val ); \
4216} \
4217 \
4218inline \
4219bool \
4220operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b ) \
4221{ \
4222 SC_FXNUM_FAST_OBSERVER_READ_( a ) \
4223 return ( a.m_val op b.get_val() ); \
4224} \
4225 \
4226inline \
4227bool \
4228operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b ) \
4229{ \
4230 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4231 return ( a.get_val() op b.m_val ); \
4232} \
4233 \
4234DEFN_REL_OP_T(op,int) \
4235DEFN_REL_OP_T(op,unsigned int) \
4236DEFN_REL_OP_T(op,long) \
4237DEFN_REL_OP_T(op,unsigned long) \
4238DEFN_REL_OP_T(op,float) \
4239DEFN_REL_OP_T(op,double) \
4240DEFN_REL_OP_T(op,const char*) \
4241DEFN_REL_OP_OTHER(op)
4242
4243DEFN_REL_OP(<)
4244DEFN_REL_OP(<=)
4245DEFN_REL_OP(>)
4246DEFN_REL_OP(>=)
4247DEFN_REL_OP(==)
4248DEFN_REL_OP(!=)
4249
4250#undef DEFN_REL_OP_T
4251#undef DEFN_REL_OP_OTHER
4252#undef DEFN_REL_OP
4253
4254
4255// assignment operators
4256
4257inline
4258sc_fxnum_fast&
4259sc_fxnum_fast::operator = ( const sc_fxnum_fast& a )
4260{
4261 if( &a != this )
4262 {
4264 m_val = a.m_val;
4265 cast();
4267 }
4268 return *this;
4269}
4270
4271inline
4273sc_fxnum_fast::operator = ( const sc_fxval_fast& a )
4274{
4275 m_val = a.get_val();
4276 cast();
4278 return *this;
4279}
4280
4281#define DEFN_ASN_OP_T(tp) \
4282inline \
4283sc_fxnum_fast& \
4284sc_fxnum_fast::operator = ( tp a ) \
4285{ \
4286 sc_fxval_fast tmp( a ); \
4287 m_val = tmp.get_val(); \
4288 cast(); \
4289 SC_FXNUM_FAST_OBSERVER_WRITE_( *this ) \
4290 return *this; \
4291}
4292
4293DEFN_ASN_OP_T(int)
4294DEFN_ASN_OP_T(unsigned int)
4295DEFN_ASN_OP_T(long)
4296DEFN_ASN_OP_T(unsigned long)
4297DEFN_ASN_OP_T(float)
4298DEFN_ASN_OP_T(double)
4299DEFN_ASN_OP_T(const char*)
4300DEFN_ASN_OP_T(const sc_fxval&)
4301DEFN_ASN_OP_T(const sc_fxnum&)
4304DEFN_ASN_OP_T(const sc_int_base&)
4305DEFN_ASN_OP_T(const sc_uint_base&)
4306DEFN_ASN_OP_T(const sc_signed&)
4307DEFN_ASN_OP_T(const sc_unsigned&)
4308
4309#undef DEFN_ASN_OP_T
4310
4311
4312#define DEFN_ASN_OP_T(op,tp) \
4313inline \
4314sc_fxnum_fast& \
4315sc_fxnum_fast::operator op ( tp b ) \
4316{ \
4317 SC_FXNUM_FAST_OBSERVER_READ_( *this ) \
4318 sc_fxval_fast tmp( b ); \
4319 m_val op tmp.get_val(); \
4320 cast(); \
4321 SC_FXNUM_FAST_OBSERVER_WRITE_( *this ) \
4322 return *this; \
4323}
4324
4325#define DEFN_ASN_OP_OTHER(op) \
4326DEFN_ASN_OP_T(op,int64) \
4327DEFN_ASN_OP_T(op,uint64) \
4328DEFN_ASN_OP_T(op,const sc_int_base&) \
4329DEFN_ASN_OP_T(op,const sc_uint_base&) \
4330DEFN_ASN_OP_T(op,const sc_signed&) \
4331DEFN_ASN_OP_T(op,const sc_unsigned&)
4332
4333#define DEFN_ASN_OP(op) \
4334inline \
4335sc_fxnum_fast& \
4336sc_fxnum_fast::operator op ( const sc_fxnum_fast& b ) \
4337{ \
4338 SC_FXNUM_FAST_OBSERVER_READ_( *this ) \
4339 SC_FXNUM_FAST_OBSERVER_READ_( b ) \
4340 m_val op b.m_val; \
4341 cast(); \
4342 SC_FXNUM_FAST_OBSERVER_WRITE_( *this ) \
4343 return *this; \
4344} \
4345 \
4346inline \
4347sc_fxnum_fast& \
4348sc_fxnum_fast::operator op ( const sc_fxval_fast& b ) \
4349{ \
4350 SC_FXNUM_FAST_OBSERVER_READ_( *this ) \
4351 m_val op b.get_val(); \
4352 cast(); \
4353 SC_FXNUM_FAST_OBSERVER_WRITE_( *this ) \
4354 return *this; \
4355} \
4356 \
4357DEFN_ASN_OP_T(op,int) \
4358DEFN_ASN_OP_T(op,unsigned int) \
4359DEFN_ASN_OP_T(op,long) \
4360DEFN_ASN_OP_T(op,unsigned long) \
4361DEFN_ASN_OP_T(op,float) \
4362DEFN_ASN_OP_T(op,double) \
4363DEFN_ASN_OP_T(op,const char*) \
4364DEFN_ASN_OP_T(op,const sc_fxval&) \
4365DEFN_ASN_OP_T(op,const sc_fxnum&) \
4366DEFN_ASN_OP_OTHER(op)
4367
4368DEFN_ASN_OP(*=)
4369DEFN_ASN_OP(/=)
4370DEFN_ASN_OP(+=)
4371DEFN_ASN_OP(-=)
4372
4373#undef DEFN_ASN_OP_T
4374#undef DEFN_ASN_OP_OTHER
4375#undef DEFN_ASN_OP
4376
4377
4378inline
4379sc_fxnum_fast&
4380sc_fxnum_fast::operator <<= ( int b )
4381{
4383 m_val *= scfx_pow2( b );
4384 cast();
4386 return *this;
4387}
4388
4389inline
4391sc_fxnum_fast::operator >>= ( int b )
4392{
4394 m_val *= scfx_pow2( -b );
4395 cast();
4397 return *this;
4398}
4399
4400
4401// auto-increment and auto-decrement
4402
4403inline
4405sc_fxnum_fast::operator ++ ( int )
4406{
4409 double c = m_val;
4410 m_val = m_val + 1;
4411 cast();
4413 return sc_fxval_fast( c );
4414}
4415
4416inline
4419{
4422 double c = m_val;
4423 m_val = m_val - 1;
4424 cast();
4426 return sc_fxval_fast( c );
4427}
4428
4429inline
4432{
4434 m_val = m_val + 1;
4435 cast();
4437 return *this;
4438}
4439
4440inline
4443{
4445 m_val = m_val - 1;
4446 cast();
4448 return *this;
4449}
4450
4451
4452// bit selection
4453
4454inline
4457{
4458 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4459 return sc_fxnum_fast_bitref_r( const_cast<sc_fxnum_fast&>( *this ),
4460 i - m_params.fwl() );
4461}
4462
4463inline
4466{
4467 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4468 return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
4469}
4470
4471inline
4474{
4475 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4476 return sc_fxnum_fast_bitref_r( const_cast<sc_fxnum_fast&>( *this ),
4477 i - m_params.fwl() );
4478}
4479
4480inline
4483{
4484 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4485 return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
4486}
4487
4488
4489// part selection
4490
4491inline
4493sc_fxnum_fast::operator () ( int i, int j ) const
4494{
4495 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4496 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4497
4498 return sc_fxnum_fast_subref_r( const_cast<sc_fxnum_fast&>( *this ),
4499 i - m_params.fwl(), j - m_params.fwl() );
4500}
4501
4502inline
4505{
4506 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4507 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4508
4509 return sc_fxnum_fast_subref( *this,
4510 i - m_params.fwl(), j - m_params.fwl() );
4511}
4512
4513inline
4515sc_fxnum_fast::range( int i, int j ) const
4516{
4517 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4518 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4519
4520 return sc_fxnum_fast_subref_r( const_cast<sc_fxnum_fast&>( *this ),
4521 i - m_params.fwl(), j - m_params.fwl() );
4522}
4523
4524inline
4527{
4528 SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4529 SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4530
4531 return sc_fxnum_fast_subref( *this,
4532 i - m_params.fwl(), j - m_params.fwl() );
4533}
4534
4535inline
4538{
4539 return this->operator () ( m_params.wl() - 1, 0 );
4540}
4541
4542inline
4545{
4546 return this->operator () ( m_params.wl() - 1, 0 );
4547}
4548
4549inline
4552{
4553 return this->range( m_params.wl() - 1, 0 );
4554}
4555
4556inline
4559{
4560 return this->range( m_params.wl() - 1, 0 );
4561}
4562
4563
4564// implicit conversion
4565
4566inline
4567sc_fxnum_fast::operator double() const
4568{
4570 return m_val;
4571}
4572
4573
4574// explicit conversion to primitive types
4575
4576inline
4577short
4579{
4580 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4581 return static_cast<short>( to_uint64() );
4582}
4583
4584inline
4585unsigned short
4587{
4588 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4589 return static_cast<unsigned short>( to_uint64() );
4590}
4591
4592inline
4593int
4595{
4596 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4597 return static_cast<int>( to_uint64() );
4598}
4599
4600inline
4601int64
4603{
4604 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4605 return static_cast<int64>( to_uint64() );
4606}
4607
4608inline
4609unsigned int
4611{
4612 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4613 return static_cast<unsigned int>( to_uint64() );
4614}
4615
4616inline
4617uint64
4619{
4620 // SC_FXNUM_FAST_OBSERVER_READ_ in is_normal
4621 if (!is_normal())
4622 {
4623 return 0;
4624 }
4625
4626 int exponent;
4627 double mantissa_dbl = frexp(m_val, &exponent);
4628
4629 uint64 mantissa = static_cast<uint64>(fabs(mantissa_dbl) * (UINT64_ONE << 53));
4630 exponent -= 53;
4631
4632 if (!(-64 < exponent && exponent < 64))
4633 {
4634 return 0;
4635 }
4636
4637 mantissa = exponent >= 0 ? mantissa << exponent : mantissa >> -exponent;
4638 return mantissa_dbl >= 0 ? mantissa : -mantissa;
4639}
4640
4641inline
4642long
4644{
4645 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4646 return static_cast<long>( to_uint64() );
4647}
4648
4649inline
4650unsigned long
4652{
4653 // SC_FXNUM_FAST_OBSERVER_READ_ in to_uint64
4654 return static_cast<unsigned long>( to_uint64() );
4655}
4656
4657inline
4658float
4660{
4662 return static_cast<float>( m_val );
4663}
4664
4665inline
4666double
4668{
4670 return m_val;
4671}
4672
4673
4674// query value
4675
4676inline
4677bool
4679{
4681 scfx_ieee_double id( m_val );
4682 return ( id.negative() != 0 );
4683}
4684
4685inline
4686bool
4688{
4690 scfx_ieee_double id( m_val );
4691 return id.is_zero();
4692}
4693
4694// internal use only;
4695inline
4696bool
4698{
4700 scfx_ieee_double id( m_val );
4701 return ( id.is_normal() || id.is_subnormal() || id.is_zero() );
4702}
4703
4704
4705inline
4706bool
4708{
4709 return m_q_flag;
4710}
4711
4712inline
4713bool
4715{
4716 return m_o_flag;
4717}
4718
4719
4720inline
4723{
4725 return sc_fxval_fast( m_val );
4726}
4727
4728
4729// query parameters
4730
4731inline
4732int
4734{
4735 return m_params.wl();
4736}
4737
4738inline
4739int
4741{
4742 return m_params.iwl();
4743}
4744
4745inline
4748{
4749 return m_params.q_mode();
4750}
4751
4752inline
4755{
4756 return m_params.o_mode();
4757}
4758
4759inline
4760int
4762{
4763 return m_params.n_bits();
4764}
4765
4766
4767inline
4768const sc_fxtype_params&
4770{
4771 return m_params.type_params();
4772}
4773
4774
4775inline
4776const sc_fxcast_switch&
4778{
4779 return m_params.cast_switch();
4780}
4781
4782
4783// internal use only;
4784inline
4785void
4787{
4789}
4790
4791
4792inline
4793::std::ostream&
4794operator << ( ::std::ostream& os, const sc_fxnum_fast& a )
4795{
4796 a.print( os );
4797 return os;
4798}
4799
4800inline
4801::std::istream&
4802operator >> ( ::std::istream& is, sc_fxnum_fast& a )
4803{
4804 a.scan( is );
4805 return is;
4806}
4807
4808
4809// ----------------------------------------------------------------------------
4810// CLASS : sc_fxval
4811//
4812// Fixed-point value type; arbitrary precision.
4813// ----------------------------------------------------------------------------
4814
4815// public constructors
4816
4817inline
4819 sc_fxval_observer* observer_ )
4820: m_rep( new scfx_rep( *a.get_rep() ) ),
4821 m_observer( observer_ )
4822{
4826}
4827
4828inline
4830 sc_fxval_observer* observer_ )
4831: m_rep( new scfx_rep( a.to_double() ) ),
4832 m_observer( observer_ )
4833{
4837}
4838
4839
4840// binary operators
4841
4842#define DEFN_BIN_OP_T(op,fnc,tp) \
4843inline \
4844sc_fxval \
4845operator op ( const sc_fxval& a, tp b ) \
4846{ \
4847 SC_FXVAL_OBSERVER_READ_( a ) \
4848 sc_fxval tmp( b ); \
4849 return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) ); \
4850} \
4851 \
4852inline \
4853sc_fxval \
4854operator op ( tp a, const sc_fxval& b ) \
4855{ \
4856 SC_FXVAL_OBSERVER_READ_( b ) \
4857 sc_fxval tmp( a ); \
4858 return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) ); \
4859}
4860
4861#define DEFN_BIN_OP(op,fnc) \
4862DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)
4863
4864DEFN_BIN_OP(*,mult)
4865DEFN_BIN_OP(+,add)
4866DEFN_BIN_OP(-,sub)
4867//DEFN_BIN_OP(/,div)
4868DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
4869
4870#undef DEFN_BIN_OP_T
4871#undef DEFN_BIN_OP
4872
4873
4874// binary functions
4875
4876#define DEFN_BIN_FNC_T(fnc,tp) \
4877inline \
4878void \
4879fnc ( sc_fxval& c, const sc_fxval& a, tp b ) \
4880{ \
4881 SC_FXVAL_OBSERVER_READ_( a ) \
4882 sc_fxval tmp( b ); \
4883 delete c.m_rep; \
4884 c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ); \
4885 SC_FXVAL_OBSERVER_WRITE_( c ) \
4886} \
4887 \
4888inline \
4889void \
4890fnc ( sc_fxval& c, tp a, const sc_fxval& b ) \
4891{ \
4892 SC_FXVAL_OBSERVER_READ_( b ) \
4893 sc_fxval tmp( a ); \
4894 delete c.m_rep; \
4895 c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ); \
4896 SC_FXVAL_OBSERVER_WRITE_( c ) \
4897}
4898
4899#define DEFN_BIN_FNC(fnc) \
4900DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)
4901
4902DEFN_BIN_FNC(mult)
4904DEFN_BIN_FNC(add)
4905DEFN_BIN_FNC(sub)
4906
4907#undef DEFN_BIN_FNC_T
4908#undef DEFN_BIN_FNC
4909
4910
4911// relational (including equality) operators
4912
4913#define DEFN_REL_OP_T(op,ret,tp) \
4914inline \
4915bool \
4916operator op ( const sc_fxval& a, tp b ) \
4917{ \
4918 SC_FXVAL_OBSERVER_READ_( a ) \
4919 sc_fxval tmp( b ); \
4920 int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep ); \
4921 return ( ret ); \
4922} \
4923 \
4924inline \
4925bool \
4926operator op ( tp a, const sc_fxval& b ) \
4927{ \
4928 SC_FXVAL_OBSERVER_READ_( b ) \
4929 sc_fxval tmp( a ); \
4930 int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep ); \
4931 return ( ret ); \
4932}
4933
4934
4935#define DEFN_REL_OP(op,ret) \
4936DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)
4937
4938DEFN_REL_OP(<,result < 0)
4939DEFN_REL_OP(<=,result <= 0)
4940DEFN_REL_OP(>,result > 0 && result != 2)
4941DEFN_REL_OP(>=,result >= 0 && result != 2)
4942DEFN_REL_OP(==,result == 0)
4943DEFN_REL_OP(!=,result != 0)
4944
4945#undef DEFN_REL_OP_T
4946#undef DEFN_REL_OP
4947
4948
4949// assignment operators
4950
4951inline
4952sc_fxval&
4953sc_fxval::operator = ( const sc_fxnum& a )
4954{
4955 *m_rep = *a.get_rep();
4957 return *this;
4958}
4959
4960#define DEFN_ASN_OP_T(tp) \
4961inline \
4962sc_fxval& \
4963sc_fxval::operator = ( tp b ) \
4964{ \
4965 sc_fxval tmp( b ); \
4966 *m_rep = *tmp.m_rep; \
4967 SC_FXVAL_OBSERVER_WRITE_( *this ) \
4968 return *this; \
4969}
4970
4971DEFN_ASN_OP_T(const sc_fxnum_fast&)
4972
4973#undef DEFN_ASN_OP_T
4974
4975
4976#define DEFN_ASN_OP_T(op,fnc,tp) \
4977inline \
4978sc_fxval& \
4979sc_fxval::operator op ( tp b ) \
4980{ \
4981 SC_FXVAL_OBSERVER_READ_( *this ) \
4982 sc_fxval tmp( b ); \
4983 scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep ); \
4984 delete m_rep; \
4985 m_rep = new_rep; \
4986 SC_FXVAL_OBSERVER_WRITE_( *this ) \
4987 return *this; \
4988}
4989
4990#define DEFN_ASN_OP(op,fnc) \
4991inline \
4992sc_fxval& \
4993sc_fxval::operator op ( const sc_fxnum& b ) \
4994{ \
4995 SC_FXVAL_OBSERVER_READ_( *this ) \
4996 scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() ); \
4997 delete m_rep; \
4998 m_rep = new_rep; \
4999 SC_FXVAL_OBSERVER_WRITE_( *this ) \
5000 return *this; \
5001} \
5002 \
5003DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)
5004
5005DEFN_ASN_OP(*=,mult)
5006DEFN_ASN_OP(/=,div)
5007DEFN_ASN_OP(+=,add)
5008DEFN_ASN_OP(-=,sub)
5009
5010#undef DEFN_ASN_OP_T
5011#undef DEFN_ASN_OP
5012
5013
5014// ----------------------------------------------------------------------------
5015// CLASS : sc_fxval_fast
5016//
5017// Fixed-point value types; limited precision.
5018// ----------------------------------------------------------------------------
5019
5020// public constructors
5021
5022inline
5024 sc_fxval_fast_observer* observer_ )
5025: m_val( a.to_double() ),
5026 m_observer( observer_ )
5027{
5031}
5032
5033inline
5035 sc_fxval_fast_observer* observer_ )
5036: m_val( a.get_val() ),
5037 m_observer( observer_ )
5038{
5042}
5043
5044
5045// binary functions
5046
5047#define DEFN_BIN_FNC_T(fnc,op,tp) \
5048inline \
5049void \
5050fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b ) \
5051{ \
5052 SC_FXVAL_FAST_OBSERVER_READ_( a ) \
5053 sc_fxval_fast tmp( b ); \
5054 c.m_val = a.m_val op tmp.m_val; \
5055 SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \
5056} \
5057 \
5058inline \
5059void \
5060fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b ) \
5061{ \
5062 SC_FXVAL_FAST_OBSERVER_READ_( b ) \
5063 sc_fxval_fast tmp( a ); \
5064 c.m_val = tmp.m_val op b.m_val; \
5065 SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \
5066}
5067
5068#define DEFN_BIN_FNC(fnc,op) \
5069DEFN_BIN_FNC_T(fnc,op,const sc_fxval&) \
5070DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)
5071
5072DEFN_BIN_FNC(mult,*)
5074DEFN_BIN_FNC(add,+)
5075DEFN_BIN_FNC(sub,-)
5076
5077#undef DEFN_BIN_FNC_T
5078#undef DEFN_BIN_FNC
5079
5080
5081// assignment operators
5082
5083inline
5084sc_fxval_fast&
5085sc_fxval_fast::operator = ( const sc_fxnum_fast& a )
5086{
5087 m_val = a.get_val();
5089 return *this;
5090}
5091
5092#define DEFN_ASN_OP_T(tp) \
5093inline \
5094sc_fxval_fast& \
5095sc_fxval_fast::operator = ( tp a ) \
5096{ \
5097 sc_fxval_fast tmp( a ); \
5098 m_val = tmp.m_val; \
5099 SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
5100 return *this; \
5101}
5102
5103DEFN_ASN_OP_T(const sc_fxnum&)
5104
5105#undef DEFN_ASN_OP_T
5106
5107
5108#define DEFN_ASN_OP_T(op,tp) \
5109inline \
5110sc_fxval_fast& \
5111sc_fxval_fast::operator op ( tp b ) \
5112{ \
5113 SC_FXVAL_FAST_OBSERVER_READ_( *this ) \
5114 sc_fxval_fast tmp( b ); \
5115 m_val op tmp.m_val; \
5116 SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
5117 return *this; \
5118}
5119
5120#define DEFN_ASN_OP(op) \
5121inline \
5122sc_fxval_fast& \
5123sc_fxval_fast::operator op ( const sc_fxnum_fast& b ) \
5124{ \
5125 SC_FXVAL_FAST_OBSERVER_READ_( *this ) \
5126 m_val op b.get_val(); \
5127 SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
5128 return *this; \
5129} \
5130 \
5131DEFN_ASN_OP_T(op,const sc_fxnum&)
5132
5133DEFN_ASN_OP(*=)
5134DEFN_ASN_OP(/=)
5135DEFN_ASN_OP(+=)
5136DEFN_ASN_OP(-=)
5137
5138#undef DEFN_ASN_OP_T
5139#undef DEFN_ASN_OP
5140
5141} // namespace sc_dt
5142
5143
5144#endif
5145
5146// Taf!
#define SC_ERROR_IF_(cnd, id)
Definition: sc_fxdefs.h:265
#define DECL_BIN_FNC(fnc)
Definition: sc_fxnum.h:1174
#define DECL_BIN_OP_T(op, tp)
Definition: sc_fxnum.h:1103
#define DEFN_BIN_FNC(fnc)
Definition: sc_fxnum.h:5068
#define DECL_CTOR_T(tp)
Definition: sc_fxnum.h:1054
#define DEFN_RED_FNC(fnc)
Definition: sc_fxnum.h:2340
#define DEFN_BIN_OP(op, fnc)
Definition: sc_fxnum.h:4861
#define DEFN_CTOR_T_B(tp)
Definition: sc_fxnum.h:3798
#define DEFN_CTOR_T_C(tp)
Definition: sc_fxnum.h:3799
#define DEFN_CTOR_T_A(tp)
Definition: sc_fxnum.h:3797
#define DEFN_REL_OP(op)
Definition: sc_fxnum.h:4935
#define DEFN_ASN_OP(op)
Definition: sc_fxnum.h:5120
#define DEFN_CTOR_T_D(tp)
Definition: sc_fxnum.h:2690
#define DEFN_ASN_OP_T(tp)
Definition: sc_fxnum.h:5108
#define DECL_ASN_OP_A(op)
Definition: sc_fxnum.h:593
#define DECL_ASN_OP_T(op, tp)
Definition: sc_fxnum.h:1246
#define DECL_REL_OP(op)
Definition: sc_fxnum.h:1220
#define DECL_BIN_OP(op, dummy)
Definition: sc_fxnum.h:1115
#define DECL_ASN_OP(op)
Definition: sc_fxnum.h:1257
#define SC_FXNUM_OBSERVER_WRITE_(object)
#define SC_FXNUM_OBSERVER_DEFAULT_
#define SC_FXNUM_OBSERVER_READ_(object)
#define SC_FXNUM_FAST_OBSERVER_DESTRUCT_(object)
#define SC_FXNUM_OBSERVER_CONSTRUCT_(object)
#define SC_FXNUM_OBSERVER_DESTRUCT_(object)
#define SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(object)
#define SC_FXNUM_FAST_OBSERVER_WRITE_(object)
#define SC_FXNUM_FAST_OBSERVER_READ_(object)
#define SC_FXNUM_FAST_OBSERVER_DEFAULT_
#define SC_FXVAL_OBSERVER_DEFAULT_
#define SC_FXVAL_OBSERVER_WRITE_(object)
#define SC_FXVAL_FAST_OBSERVER_CONSTRUCT_(object)
#define SC_FXVAL_FAST_OBSERVER_DEFAULT_
#define SC_FXVAL_FAST_OBSERVER_WRITE_(object)
#define SC_FXVAL_OBSERVER_CONSTRUCT_(object)
#define SC_API
Definition: sc_cmnhdr.h:148
const char SC_ID_INVALID_FX_VALUE_[]
const char SC_ID_OUT_OF_RANGE_[]
sc_enc
Definition: sc_fxdefs.h:67
void neg(sc_fxval &c, const sc_fxnum &a)
Definition: sc_fxnum.h:2758
SC_API scfx_rep * neg_scfx_rep(const scfx_rep &)
Definition: scfx_rep.h:378
X & operator|=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:474
sc_q_mode
Definition: sc_fxdefs.h:91
sc_proxy< X >::value_type or_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1496
sc_proxy< X >::value_type xor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1512
const sc_big_op_info< WL, true, WR, true >::add_result operator+(const sc_bigint< WL > &left, const sc_bigint< WR > &right)
Definition: sc_big_ops.h:125
sc_numrep
Definition: sc_string.h:56
sc_fxval operator/(const sc_fxnum &a, const sc_fxnum &b)
Definition: sc_fxnum.h:2849
X & operator^=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:613
unsigned long long uint64
Definition: sc_nbdefs.h:216
const T sc_min(const T &a, const T &b)
Definition: sc_macros.h:40
const sc_big_op_info< WL, true, WR, true >::sub_result operator-(const sc_bigint< WL > &left, const sc_bigint< WR > &right)
Definition: sc_big_ops.h:884
SC_API scfx_rep * div_scfx_rep(const scfx_rep &, const scfx_rep &, int max_wl=SC_DEFAULT_DIV_WL_)
void rshift(sc_fxval &c, const sc_fxnum &a, int b)
Definition: sc_fxnum.h:3055
sc_proxy< X >::value_type nor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1504
SC_API std::string to_string(sc_enc)
void lshift(sc_fxval &c, const sc_fxnum &a, int b)
Definition: sc_fxnum.h:3047
const T sc_max(const T &a, const T &b)
Definition: sc_macros.h:48
SC_API scfx_rep * lsh_scfx_rep(const scfx_rep &, int)
Definition: scfx_rep.h:396
double scfx_pow2(int exp)
Definition: scfx_ieee.h:645
X & operator&=(sc_proxy< X > &px, const sc_proxy< Y > &py)
Definition: sc_lv_base.h:340
DEFN_BIN_OP_T(/, div, int64) DEFN_BIN_OP_T(/
@ SC_ON
Definition: sc_fxdefs.h:151
inline::std::istream & operator>>(::std::istream &is, sc_bit &a)
Definition: sc_bit.h:396
sc_proxy< X >::value_type and_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1480
SC_API scfx_rep * rsh_scfx_rep(const scfx_rep &, int)
Definition: scfx_rep.h:405
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:388
uint64 const sc_uint_base int b
Definition: sc_fxval.h:955
sc_proxy< X >::value_type xnor_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1520
sc_proxy< X >::value_type nand_reduce(const sc_proxy< X > &a)
Definition: sc_proxy.h:1488
constexpr uint64 UINT64_ONE
Definition: sc_nbdefs.h:219
long long int64
Definition: sc_nbdefs.h:215
sc_o_mode
Definition: sc_fxdefs.h:120
sc_core::sc_signal_in_if< T > & value(const T &val)
Definition: sc_stub.h:217
int length() const
Definition: sc_bv_base.h:194
std::string to_string() const
Definition: sc_proxy.h:1386
long to_long() const
Definition: sc_proxy.h:502
int64 to_int64() const
Definition: sc_proxy.h:493
unsigned int to_uint() const
Definition: sc_proxy.h:499
unsigned long to_ulong() const
Definition: sc_proxy.h:505
int to_int() const
Definition: sc_proxy.h:496
uint64 to_uint64() const
Definition: sc_proxy.h:1453
void print(::std::ostream &=::std::cout) const
sc_fxnum_bitref_r(sc_fxnum &, int)
Definition: sc_fxnum.h:1432
void dump(::std::ostream &=::std::cout) const
friend class sc_fxnum_fast_bitref
Definition: sc_fxnum.h:101
void scan(::std::istream &=::std::cin)
sc_fxnum_fast_bitref_r(sc_fxnum_fast &, int)
Definition: sc_fxnum.h:1672
void print(::std::ostream &=::std::cout) const
void dump(::std::ostream &=::std::cout) const
friend class sc_fxnum_bitref
Definition: sc_fxnum.h:182
void scan(::std::istream &=::std::cin)
void dump(::std::ostream &=::std::cout) const
unsigned int to_uint() const
Definition: sc_fxnum.h:2029
sc_fxnum_subref_r(sc_fxnum &, int, int)
Definition: sc_fxnum.h:1906
unsigned long to_ulong() const
Definition: sc_fxnum.h:2056
std::string to_string() const
Definition: sc_fxnum.h:2085
int64 to_int64() const
Definition: sc_fxnum.h:2020
long to_long() const
Definition: sc_fxnum.h:2047
uint64 to_uint64() const
Definition: sc_fxnum.h:2038
void print(::std::ostream &=::std::cout) const
void scan(::std::istream &=::std::cin)
void dump(::std::ostream &=::std::cout) const
unsigned long to_ulong() const
Definition: sc_fxnum.h:2419
std::string to_string() const
Definition: sc_fxnum.h:2448
sc_fxnum_fast_subref_r(sc_fxnum_fast &, int, int)
Definition: sc_fxnum.h:2267
unsigned int to_uint() const
Definition: sc_fxnum.h:2392
void print(::std::ostream &=::std::cout) const
void scan(::std::istream &=::std::cin)
const sc_fxcast_switch & cast_switch() const
Definition: sc_fxnum.h:3659
uint64 to_uint64() const
Definition: sc_fxnum.h:3521
int iwl() const
Definition: sc_fxnum.h:3622
sc_o_mode o_mode() const
Definition: sc_fxnum.h:3636
friend class sc_fxnum_bitref_r
Definition: sc_fxnum.h:621
short to_short() const
Definition: sc_fxnum.h:3481
sc_fxval operator-() const
Definition: sc_fxnum.h:2739
std::string to_string(sc_numrep, bool) const
std::string to_string(sc_numrep, sc_fmt) const
void dump(::std::ostream &=::std::cout) const
void unlock_observer(sc_fxnum_observer *) const
float to_float() const
Definition: sc_fxnum.h:3545
std::string to_dec() const
bool is_normal() const
Definition: sc_fxnum.h:3581
bool get_slice(int, int, sc_bv_base &) const
Definition: sc_fxnum.h:3698
bool set_slice(int, int, const sc_bv_base &)
Definition: sc_fxnum.h:3705
bool get_bit(int) const
Definition: sc_fxnum.h:3677
void print(::std::ostream &=::std::cout) const
std::string to_oct() const
int n_bits() const
Definition: sc_fxnum.h:3643
sc_fxnum_observer * lock_observer() const
sc_q_mode q_mode() const
Definition: sc_fxnum.h:3629
std::string to_string(sc_fmt) const
friend class sc_fxnum_subref
Definition: sc_fxnum.h:622
std::string to_hex() const
bool is_neg() const
Definition: sc_fxnum.h:3564
void observer_read() const
Definition: sc_fxnum.h:3668
void scan(::std::istream &=::std::cin)
const sc_fxtype_params & type_params() const
Definition: sc_fxnum.h:3651
unsigned int to_uint() const
Definition: sc_fxnum.h:3513
sc_fxnum(const sc_fxtype_params &, sc_enc, const sc_fxcast_switch &, sc_fxnum_observer *)
Definition: sc_fxnum.h:2654
sc_fxval operator+() const
Definition: sc_fxnum.h:2747
int wl() const
Definition: sc_fxnum.h:3615
friend class sc_fxnum_subref_r
Definition: sc_fxnum.h:623
std::string to_string(sc_numrep) const
sc_fxnum_subref_r operator()() const
Definition: sc_fxnum.h:3440
bool is_zero() const
Definition: sc_fxnum.h:3572
bool set_bit(int, bool)
Definition: sc_fxnum.h:3687
std::string to_string(sc_numrep, bool, sc_fmt) const
sc_fxnum_subref_r range() const
Definition: sc_fxnum.h:3454
bool quantization_flag() const
Definition: sc_fxnum.h:3589
friend class sc_fxval
Definition: sc_fxnum.h:618
bool overflow_flag() const
Definition: sc_fxnum.h:3596
unsigned long to_ulong() const
Definition: sc_fxnum.h:3537
int to_int() const
Definition: sc_fxnum.h:3497
sc_fxval value() const
Definition: sc_fxnum.h:3604
unsigned short to_ushort() const
Definition: sc_fxnum.h:3489
friend sc_fxval operator>>(const sc_fxnum &, int)
Definition: sc_fxnum.h:2904
sc_fxnum & operator--()
Definition: sc_fxnum.h:3349
int64 to_int64() const
Definition: sc_fxnum.h:3505
long to_long() const
Definition: sc_fxnum.h:3529
sc_fxnum_bitref_r operator[](int) const
Definition: sc_fxnum.h:3360
sc_fxnum_observer * observer() const
Definition: sc_fxnum.h:2634
sc_fxnum & operator++()
Definition: sc_fxnum.h:3341
sc_fxnum_bitref_r bit(int) const
Definition: sc_fxnum.h:3377
const scfx_rep * get_rep() const
Definition: sc_fxnum.h:2728
friend void lshift(sc_fxval &, const sc_fxnum &, int)
Definition: sc_fxnum.h:3047
std::string to_bin() const
friend void rshift(sc_fxval &, const sc_fxnum &, int)
Definition: sc_fxnum.h:3055
friend sc_fxval operator<<(const sc_fxnum &, int)
Definition: sc_fxnum.h:2896
std::string to_string() const
double to_double() const
Definition: sc_fxnum.h:3553
friend class sc_fxnum_bitref
Definition: sc_fxnum.h:620
std::string to_string(sc_numrep, sc_fmt) const
sc_fxnum_fast & operator--()
Definition: sc_fxnum.h:4442
int n_bits() const
Definition: sc_fxnum.h:4761
sc_fxnum_fast_subref_r range() const
Definition: sc_fxnum.h:4551
std::string to_string() const
friend class sc_fxnum_fast_bitref_r
Definition: sc_fxnum.h:1032
friend void lshift(sc_fxval_fast &, const sc_fxnum_fast &, int)
Definition: sc_fxnum.h:4144
void unlock_observer(sc_fxnum_fast_observer *) const
sc_o_mode o_mode() const
Definition: sc_fxnum.h:4754
std::string to_string(sc_numrep) const
friend class sc_fxnum_fast_subref_r
Definition: sc_fxnum.h:1034
sc_fxnum_fast & operator++()
Definition: sc_fxnum.h:4431
sc_fxnum_fast_bitref_r bit(int) const
Definition: sc_fxnum.h:4473
friend class sc_fxnum_fast_subref
Definition: sc_fxnum.h:1033
friend sc_fxval_fast operator>>(const sc_fxnum_fast &, int)
Definition: sc_fxnum.h:4006
const sc_fxtype_params & type_params() const
Definition: sc_fxnum.h:4769
sc_fxval_fast operator+() const
Definition: sc_fxnum.h:3855
bool set_slice(int, int, const sc_bv_base &)
sc_fxnum_fast_subref_r operator()() const
Definition: sc_fxnum.h:4537
unsigned short to_ushort() const
Definition: sc_fxnum.h:4586
bool is_normal() const
Definition: sc_fxnum.h:4697
sc_fxval_fast operator-() const
Definition: sc_fxnum.h:3847
std::string to_string(sc_numrep, bool) const
friend void neg(sc_fxval_fast &, const sc_fxnum_fast &)
Definition: sc_fxnum.h:3866
int to_int() const
Definition: sc_fxnum.h:4594
int iwl() const
Definition: sc_fxnum.h:4740
friend sc_fxval_fast operator/(const sc_fxnum_fast &, const sc_fxnum_fast &)
Definition: sc_fxnum.h:3953
short to_short() const
Definition: sc_fxnum.h:4578
const sc_fxcast_switch & cast_switch() const
Definition: sc_fxnum.h:4777
double to_double() const
Definition: sc_fxnum.h:4667
void dump(::std::ostream &=::std::cout) const
void print(::std::ostream &=::std::cout) const
int64 to_int64() const
Definition: sc_fxnum.h:4602
bool is_neg() const
Definition: sc_fxnum.h:4678
std::string to_oct() const
friend class sc_fxval_fast
Definition: sc_fxnum.h:1027
void observer_read() const
Definition: sc_fxnum.h:4786
void scan(::std::istream &=::std::cin)
uint64 to_uint64() const
Definition: sc_fxnum.h:4618
float to_float() const
Definition: sc_fxnum.h:4659
bool quantization_flag() const
Definition: sc_fxnum.h:4707
sc_fxnum_fast_bitref_r operator[](int) const
Definition: sc_fxnum.h:4456
friend void rshift(sc_fxval_fast &, const sc_fxnum_fast &, int)
Definition: sc_fxnum.h:4152
std::string to_bin() const
long to_long() const
Definition: sc_fxnum.h:4643
std::string to_string(sc_numrep, bool, sc_fmt) const
sc_fxnum_fast(const sc_fxtype_params &, sc_enc, const sc_fxcast_switch &, sc_fxnum_fast_observer *)
Definition: sc_fxnum.h:3745
friend class sc_fxnum_fast_bitref
Definition: sc_fxnum.h:1031
int wl() const
Definition: sc_fxnum.h:4733
bool is_zero() const
Definition: sc_fxnum.h:4687
bool get_bit(int) const
std::string to_hex() const
double get_val() const
Definition: sc_fxnum.h:3836
std::string to_string(sc_fmt) const
sc_fxnum_fast_observer * lock_observer() const
bool overflow_flag() const
Definition: sc_fxnum.h:4714
sc_q_mode q_mode() const
Definition: sc_fxnum.h:4747
bool get_slice(int, int, sc_bv_base &) const
bool set_bit(int, bool)
unsigned long to_ulong() const
Definition: sc_fxnum.h:4651
sc_fxnum_fast_observer * observer() const
Definition: sc_fxnum.h:3736
std::string to_dec() const
unsigned int to_uint() const
Definition: sc_fxnum.h:4610
sc_fxval_fast value() const
Definition: sc_fxnum.h:4722
const scfx_rep * get_rep() const
Definition: sc_fxval.h:819
sc_fxval(scfx_rep *)
Definition: sc_fxval.h:742
void set_rep(scfx_rep *)
Definition: sc_fxval.h:828
double get_val() const
Definition: sc_fxval.h:1560
void set_val(double)
Definition: sc_fxval.h:1569
sc_fxval_fast(sc_fxval_fast_observer *=0)
Definition: sc_fxval.h:1491
int iwl() const
Definition: scfx_params.h:168
const sc_fxcast_switch & cast_switch() const
Definition: scfx_params.h:151
int fwl() const
Definition: scfx_params.h:175
sc_o_mode o_mode() const
Definition: scfx_params.h:189
sc_q_mode q_mode() const
Definition: scfx_params.h:182
const sc_fxtype_params & type_params() const
Definition: scfx_params.h:137
int n_bits() const
Definition: scfx_params.h:196
int wl() const
Definition: scfx_params.h:161
void cast(const scfx_params &, bool &, bool &)
uint64 to_uint64() const
bool get_bit(int) const
bool set(int, const scfx_params &)
bool set_slice(int, int, const scfx_params &, const sc_bv_base &)
double to_double() const
bool is_normal() const
Definition: scfx_rep.h:458
bool is_neg() const
Definition: scfx_rep.h:421
bool get_slice(int, int, const scfx_params &, sc_bv_base &) const
bool clear(int, const scfx_params &)
bool is_zero() const
Definition: scfx_rep.h:428