sc_ufix.hh revision 12853
12SN/A/*****************************************************************************
21762SN/A
32SN/A  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
42SN/A  more contributor license agreements.  See the NOTICE file distributed
52SN/A  with this work for additional information regarding copyright ownership.
62SN/A  Accellera licenses this file to you under the Apache License, Version 2.0
72SN/A  (the "License"); you may not use this file except in compliance with the
82SN/A  License.  You may obtain a copy of the License at
92SN/A
102SN/A    http://www.apache.org/licenses/LICENSE-2.0
112SN/A
122SN/A  Unless required by applicable law or agreed to in writing, software
132SN/A  distributed under the License is distributed on an "AS IS" BASIS,
142SN/A  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152SN/A  implied.  See the License for the specific language governing
162SN/A  permissions and limitations under the License.
172SN/A
182SN/A *****************************************************************************/
192SN/A
202SN/A/*****************************************************************************
212SN/A
222SN/A  sc_ufix.h -
232SN/A
242SN/A  Original Author: Martin Janssen, Synopsys, Inc.
252SN/A
262SN/A *****************************************************************************/
272665Ssaidi@eecs.umich.edu
282665Ssaidi@eecs.umich.edu/*****************************************************************************
292665Ssaidi@eecs.umich.edu
302SN/A  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
312SN/A  changes you are making here.
322SN/A
332SN/A      Name, Affiliation, Date:
342SN/A  Description of Modification:
352SN/A
362SN/A *****************************************************************************/
372SN/A
382SN/A// $Log: sc_ufix.h,v $
392SN/A// Revision 1.2  2011/01/20 22:52:30  acg
402SN/A//  Andy Goodrich: Add float constructors.
412SN/A//
422SN/A// Revision 1.1.1.1  2006/12/15 20:20:04  acg
432SN/A// SystemC 2.3
444762Snate@binkert.org//
4556SN/A// Revision 1.3  2006/01/13 18:53:58  acg
461127SN/A// Andy Goodrich: added $Log command so that CVS comments are reproduced in
472SN/A// the source.
482797Sktlim@umich.edu//
492797Sktlim@umich.edu
502609SN/A#ifndef __SYSTEMC_EXT_DT_FX_SC_UFIX_HH__
512SN/A#define __SYSTEMC_EXT_DT_FX_SC_UFIX_HH__
522SN/A
532SN/A#include "sc_fxnum.hh"
542SN/A
552SN/Anamespace sc_dt
561127SN/A{
572SN/A
581553SN/A// classes defined in this module
592797Sktlim@umich.educlass sc_ufix;
602901Ssaidi@eecs.umich.educlass sc_ufix_fast;
612839Sktlim@umich.edu
622901Ssaidi@eecs.umich.edu
632797Sktlim@umich.edu// ----------------------------------------------------------------------------
643202Shsul@eecs.umich.edu//  CLASS : sc_ufix
652901Ssaidi@eecs.umich.edu//
662901Ssaidi@eecs.umich.edu//  "Unconstrained" unsigned fixed-point class; arbitrary precision.
672797Sktlim@umich.edu// ----------------------------------------------------------------------------
68265SN/A
692797Sktlim@umich.educlass sc_ufix : public sc_fxnum
701553SN/A{
711553SN/A  public:
722797Sktlim@umich.edu    // constructors
732797Sktlim@umich.edu    explicit sc_ufix(sc_fxnum_observer * =0);
742SN/A    sc_ufix(int, int, sc_fxnum_observer * =0);
752SN/A    sc_ufix(sc_q_mode, sc_o_mode, sc_fxnum_observer * =0);
762SN/A    sc_ufix(sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0);
772SN/A    sc_ufix(int, int, sc_q_mode, sc_o_mode, sc_fxnum_observer * =0);
782SN/A    sc_ufix(int, int, sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0);
792SN/A    explicit sc_ufix(const sc_fxcast_switch &, sc_fxnum_observer * =0);
804762Snate@binkert.org    sc_ufix(int, int, const sc_fxcast_switch &, sc_fxnum_observer * =0);
814762Snate@binkert.org    sc_ufix(sc_q_mode, sc_o_mode, const sc_fxcast_switch &,
824762Snate@binkert.org            sc_fxnum_observer * =0);
832SN/A    sc_ufix(sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &,
844762Snate@binkert.org            sc_fxnum_observer * =0);
854762Snate@binkert.org    sc_ufix(int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &,
864762Snate@binkert.org            sc_fxnum_observer * =0);
872SN/A    sc_ufix(int, int, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &,
882SN/A            sc_fxnum_observer * =0);
895034Smilesck@eecs.umich.edu    explicit sc_ufix(const sc_fxtype_params &, sc_fxnum_observer * =0);
905034Smilesck@eecs.umich.edu    sc_ufix(const sc_fxtype_params &, const sc_fxcast_switch &,
915034Smilesck@eecs.umich.edu            sc_fxnum_observer * =0);
925034Smilesck@eecs.umich.edu
935034Smilesck@eecs.umich.edu#define DECL_CTORS_T(tp) \
945034Smilesck@eecs.umich.edu    sc_ufix(tp, int, int, sc_fxnum_observer * =0); \
951553SN/A    sc_ufix(tp, sc_q_mode, sc_o_mode, sc_fxnum_observer * =0); \
96265SN/A    sc_ufix(tp, sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0); \
971127SN/A    sc_ufix(tp, int, int, sc_q_mode, sc_o_mode, sc_fxnum_observer * =0); \
981127SN/A    sc_ufix(tp, int, int, sc_q_mode, sc_o_mode, int, sc_fxnum_observer * =0); \
99465SN/A    sc_ufix(tp, const sc_fxcast_switch &, sc_fxnum_observer * =0); \
100465SN/A    sc_ufix(tp, int, int, const sc_fxcast_switch &, sc_fxnum_observer * =0); \
101465SN/A    sc_ufix(tp, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
1022SN/A            sc_fxnum_observer * =0); \
1032SN/A    sc_ufix(tp, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &, \
1042SN/A            sc_fxnum_observer * =0); \
105330SN/A    sc_ufix(tp, int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
1062SN/A            sc_fxnum_observer * =0); \
1072SN/A    sc_ufix(tp, int, int, sc_q_mode, sc_o_mode, int, \
1082SN/A            const sc_fxcast_switch &, sc_fxnum_observer * =0); \
1092SN/A    sc_ufix(tp, const sc_fxtype_params &, sc_fxnum_observer * =0); \
110330SN/A    sc_ufix(tp, const sc_fxtype_params &, const sc_fxcast_switch &, \
111330SN/A            sc_fxnum_observer * =0);
112330SN/A
113395SN/A#define DECL_CTORS_T_A(tp) \
114395SN/A    sc_ufix(tp, sc_fxnum_observer * =0); \
1152797Sktlim@umich.edu    DECL_CTORS_T(tp)
116938SN/A
1172609SN/A#define DECL_CTORS_T_B(tp) \
1182609SN/A    explicit sc_ufix(tp, sc_fxnum_observer * =0); \
1192901Ssaidi@eecs.umich.edu    DECL_CTORS_T(tp)
1202901Ssaidi@eecs.umich.edu
1212901Ssaidi@eecs.umich.edu    DECL_CTORS_T_A(int)
1222901Ssaidi@eecs.umich.edu    DECL_CTORS_T_A(unsigned int)
1232797Sktlim@umich.edu    DECL_CTORS_T_A(long)
1242797Sktlim@umich.edu    DECL_CTORS_T_A(unsigned long)
1252797Sktlim@umich.edu    DECL_CTORS_T_A(float)
1262797Sktlim@umich.edu    DECL_CTORS_T_A(double)
1272609SN/A    DECL_CTORS_T_A(const char *)
1281031SN/A    DECL_CTORS_T_A(const sc_fxval &)
1291031SN/A    DECL_CTORS_T_A(const sc_fxval_fast &)
1301031SN/A    DECL_CTORS_T_A(const sc_fxnum &)
1311031SN/A    DECL_CTORS_T_A(const sc_fxnum_fast &)
1321031SN/A
1331031SN/A    DECL_CTORS_T_B(int64)
1345314Sstever@gmail.com    DECL_CTORS_T_B(uint64)
1355314Sstever@gmail.com    DECL_CTORS_T_B(const sc_int_base &)
1365314Sstever@gmail.com    DECL_CTORS_T_B(const sc_uint_base &)
1375314Sstever@gmail.com    DECL_CTORS_T_B(const sc_signed &)
1385314Sstever@gmail.com    DECL_CTORS_T_B(const sc_unsigned &)
1395314Sstever@gmail.com
1405314Sstever@gmail.com#undef DECL_CTORS_T
141938SN/A#undef DECL_CTORS_T_A
142938SN/A#undef DECL_CTORS_T_B
1432SN/A
1442SN/A    // copy constructor
1452SN/A    sc_ufix(const sc_ufix &);
146
147    // unary bitwise operators
148    const sc_ufix operator ~ () const;
149
150    // unary bitwise functions
151    friend void b_not(sc_ufix &, const sc_ufix &);
152
153    // binary bitwise operators
154    friend const sc_ufix operator & (const sc_ufix &, const sc_ufix &);
155    friend const sc_ufix operator & (const sc_ufix &, const sc_ufix_fast &);
156    friend const sc_ufix operator & (const sc_ufix_fast &, const sc_ufix &);
157    friend const sc_ufix operator | (const sc_ufix &, const sc_ufix &);
158    friend const sc_ufix operator | (const sc_ufix &, const sc_ufix_fast &);
159    friend const sc_ufix operator | (const sc_ufix_fast &, const sc_ufix &);
160    friend const sc_ufix operator ^ (const sc_ufix &, const sc_ufix &);
161    friend const sc_ufix operator ^ (const sc_ufix &, const sc_ufix_fast &);
162    friend const sc_ufix operator ^ (const sc_ufix_fast &, const sc_ufix &);
163
164    // binary bitwise functions
165    friend void b_and(sc_ufix &, const sc_ufix &, const sc_ufix &);
166    friend void b_and(sc_ufix &, const sc_ufix &, const sc_ufix_fast &);
167    friend void b_and(sc_ufix &, const sc_ufix_fast &, const sc_ufix &);
168    friend void b_or(sc_ufix &, const sc_ufix &, const sc_ufix &);
169    friend void b_or(sc_ufix &, const sc_ufix &, const sc_ufix_fast &);
170    friend void b_or(sc_ufix &, const sc_ufix_fast &, const sc_ufix &);
171    friend void b_xor(sc_ufix &, const sc_ufix &, const sc_ufix &);
172    friend void b_xor(sc_ufix &, const sc_ufix &, const sc_ufix_fast &);
173    friend void b_xor(sc_ufix &, const sc_ufix_fast &, const sc_ufix &);
174
175    // assignment operators
176    sc_ufix &operator = (const sc_ufix &);
177
178#define DECL_ASN_OP_T(op,tp) sc_ufix &operator op (tp);
179
180#define DECL_ASN_OP_OTHER(op) \
181    DECL_ASN_OP_T(op, int64) \
182    DECL_ASN_OP_T(op, uint64) \
183    DECL_ASN_OP_T(op, const sc_int_base &) \
184    DECL_ASN_OP_T(op, const sc_uint_base &) \
185    DECL_ASN_OP_T(op, const sc_signed &) \
186    DECL_ASN_OP_T(op, const sc_unsigned &)
187
188#define DECL_ASN_OP(op) \
189    DECL_ASN_OP_T(op, int) \
190    DECL_ASN_OP_T(op, unsigned int) \
191    DECL_ASN_OP_T(op, long) \
192    DECL_ASN_OP_T(op, unsigned long) \
193    DECL_ASN_OP_T(op, float) \
194    DECL_ASN_OP_T(op, double) \
195    DECL_ASN_OP_T(op, const char *) \
196    DECL_ASN_OP_T(op, const sc_fxval &) \
197    DECL_ASN_OP_T(op, const sc_fxval_fast &) \
198    DECL_ASN_OP_T(op, const sc_fxnum &) \
199    DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
200    DECL_ASN_OP_OTHER(op)
201
202    DECL_ASN_OP(=)
203
204    DECL_ASN_OP(*=)
205    DECL_ASN_OP(/=)
206    DECL_ASN_OP(+=)
207    DECL_ASN_OP(-=)
208
209    DECL_ASN_OP_T(<<=, int)
210    DECL_ASN_OP_T(>>=, int)
211
212    DECL_ASN_OP_T(&=, const sc_ufix &)
213    DECL_ASN_OP_T(&=, const sc_ufix_fast &)
214    DECL_ASN_OP_T(|=, const sc_ufix &)
215    DECL_ASN_OP_T(|=, const sc_ufix_fast &)
216    DECL_ASN_OP_T(^=, const sc_ufix &)
217    DECL_ASN_OP_T(^=, const sc_ufix_fast &)
218
219#undef DECL_ASN_OP_T
220#undef DECL_ASN_OP_OTHER
221#undef DECL_ASN_OP
222
223    // auto-increment and auto-decrement
224    const sc_fxval operator ++ (int);
225    const sc_fxval operator -- (int);
226
227    sc_ufix& operator ++ ();
228    sc_ufix& operator -- ();
229};
230
231
232// ----------------------------------------------------------------------------
233//  CLASS : sc_ufix_fast
234//
235//  "Unconstrained" unsigned fixed-point class; limited precision.
236// ----------------------------------------------------------------------------
237
238class sc_ufix_fast : public sc_fxnum_fast
239{
240  public:
241    // constructors
242    explicit sc_ufix_fast(sc_fxnum_fast_observer * =0);
243    sc_ufix_fast(int, int, sc_fxnum_fast_observer * =0);
244    sc_ufix_fast(sc_q_mode, sc_o_mode, sc_fxnum_fast_observer * =0);
245    sc_ufix_fast(sc_q_mode, sc_o_mode, int, sc_fxnum_fast_observer * =0);
246    sc_ufix_fast(int, int, sc_q_mode, sc_o_mode, sc_fxnum_fast_observer * =0);
247    sc_ufix_fast(int, int, sc_q_mode, sc_o_mode, int,
248                 sc_fxnum_fast_observer * =0);
249    explicit sc_ufix_fast(const sc_fxcast_switch &,
250                          sc_fxnum_fast_observer * =0);
251    sc_ufix_fast(int, int, const sc_fxcast_switch &,
252                 sc_fxnum_fast_observer * =0);
253    sc_ufix_fast(sc_q_mode, sc_o_mode, const sc_fxcast_switch &,
254                 sc_fxnum_fast_observer * =0);
255    sc_ufix_fast(sc_q_mode, sc_o_mode, int, const sc_fxcast_switch&,
256                 sc_fxnum_fast_observer * =0);
257    sc_ufix_fast(int, int, sc_q_mode, sc_o_mode, const sc_fxcast_switch &,
258                 sc_fxnum_fast_observer * =0);
259    sc_ufix_fast(int, int, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &,
260                 sc_fxnum_fast_observer * =0);
261    explicit sc_ufix_fast(const sc_fxtype_params &,
262                          sc_fxnum_fast_observer * =0);
263    sc_ufix_fast(const sc_fxtype_params &, const sc_fxcast_switch &,
264                 sc_fxnum_fast_observer * =0);
265
266#define DECL_CTORS_T(tp) \
267    sc_ufix_fast(tp, int, int, sc_fxnum_fast_observer * =0); \
268    sc_ufix_fast(tp, sc_q_mode, sc_o_mode, sc_fxnum_fast_observer * =0); \
269    sc_ufix_fast(tp, sc_q_mode, sc_o_mode, int, sc_fxnum_fast_observer * =0); \
270    sc_ufix_fast(tp, int, int, sc_q_mode, sc_o_mode, \
271                 sc_fxnum_fast_observer * =0); \
272    sc_ufix_fast(tp, int, int, sc_q_mode, sc_o_mode, int, \
273                 sc_fxnum_fast_observer * =0); \
274    sc_ufix_fast(tp, const sc_fxcast_switch &, sc_fxnum_fast_observer * =0); \
275    sc_ufix_fast(tp, int, int, const sc_fxcast_switch &, \
276                 sc_fxnum_fast_observer * =0); \
277    sc_ufix_fast(tp, sc_q_mode, sc_o_mode, const sc_fxcast_switch &, \
278                 sc_fxnum_fast_observer * =0); \
279    sc_ufix_fast(tp, sc_q_mode, sc_o_mode, int, const sc_fxcast_switch &, \
280                 sc_fxnum_fast_observer * =0); \
281    sc_ufix_fast(tp, int, int, sc_q_mode, sc_o_mode, \
282                 const sc_fxcast_switch &, sc_fxnum_fast_observer * =0); \
283    sc_ufix_fast(tp, int, int, sc_q_mode, sc_o_mode, int, \
284                 const sc_fxcast_switch &, sc_fxnum_fast_observer * =0); \
285    sc_ufix_fast(tp, const sc_fxtype_params &, sc_fxnum_fast_observer * =0); \
286    sc_ufix_fast(tp, const sc_fxtype_params &, const sc_fxcast_switch &, \
287                 sc_fxnum_fast_observer * =0);
288
289#define DECL_CTORS_T_A(tp) \
290    sc_ufix_fast(tp, sc_fxnum_fast_observer * =0); \
291    DECL_CTORS_T(tp)
292
293#define DECL_CTORS_T_B(tp) \
294    explicit sc_ufix_fast(tp, sc_fxnum_fast_observer * =0); \
295    DECL_CTORS_T(tp)
296
297    DECL_CTORS_T_A(int)
298    DECL_CTORS_T_A(unsigned int)
299    DECL_CTORS_T_A(long)
300    DECL_CTORS_T_A(unsigned long)
301    DECL_CTORS_T_A(float)
302    DECL_CTORS_T_A(double)
303    DECL_CTORS_T_A(const char *)
304    DECL_CTORS_T_A(const sc_fxval &)
305    DECL_CTORS_T_A(const sc_fxval_fast &)
306    DECL_CTORS_T_A(const sc_fxnum &)
307    DECL_CTORS_T_A(const sc_fxnum_fast &)
308
309    DECL_CTORS_T_B(int64)
310    DECL_CTORS_T_B(uint64)
311    DECL_CTORS_T_B(const sc_int_base &)
312    DECL_CTORS_T_B(const sc_uint_base &)
313    DECL_CTORS_T_B(const sc_signed &)
314    DECL_CTORS_T_B(const sc_unsigned &)
315
316#undef DECL_CTORS_T
317#undef DECL_CTORS_T_A
318#undef DECL_CTORS_T_B
319
320    // copy constructor
321    sc_ufix_fast(const sc_ufix_fast &);
322
323    // unary bitwise operators
324    const sc_ufix_fast operator ~ () const;
325
326    // unary bitwise functions
327    friend void b_not(sc_ufix_fast &, const sc_ufix_fast &);
328
329
330    // binary bitwise operators
331
332    friend const sc_ufix_fast operator & (const sc_ufix_fast &,
333                                          const sc_ufix_fast &);
334    friend const sc_ufix_fast operator ^ (const sc_ufix_fast &,
335                                          const sc_ufix_fast &);
336    friend const sc_ufix_fast operator | (const sc_ufix_fast &,
337                                          const sc_ufix_fast &);
338
339
340    // binary bitwise functions
341
342    friend void b_and(sc_ufix_fast &, const sc_ufix_fast &,
343                                      const sc_ufix_fast &);
344    friend void b_or(sc_ufix_fast &, const sc_ufix_fast &,
345                                     const sc_ufix_fast &);
346    friend void b_xor(sc_ufix_fast &, const sc_ufix_fast &,
347                                      const sc_ufix_fast &);
348
349    // assignment operators
350    sc_ufix_fast &operator = (const sc_ufix_fast &);
351
352#define DECL_ASN_OP_T(op,tp) sc_ufix_fast &operator op (tp);
353
354#define DECL_ASN_OP_OTHER(op) \
355    DECL_ASN_OP_T(op, int64) \
356    DECL_ASN_OP_T(op, uint64) \
357    DECL_ASN_OP_T(op, const sc_int_base &) \
358    DECL_ASN_OP_T(op, const sc_uint_base &) \
359    DECL_ASN_OP_T(op, const sc_signed &) \
360    DECL_ASN_OP_T(op, const sc_unsigned &)
361
362#define DECL_ASN_OP(op) \
363    DECL_ASN_OP_T(op, int) \
364    DECL_ASN_OP_T(op, unsigned int) \
365    DECL_ASN_OP_T(op, long) \
366    DECL_ASN_OP_T(op, unsigned long) \
367    DECL_ASN_OP_T(op, float) \
368    DECL_ASN_OP_T(op, double) \
369    DECL_ASN_OP_T(op, const char *) \
370    DECL_ASN_OP_T(op, const sc_fxval &) \
371    DECL_ASN_OP_T(op, const sc_fxval_fast &) \
372    DECL_ASN_OP_T(op, const sc_fxnum &) \
373    DECL_ASN_OP_T(op, const sc_fxnum_fast &) \
374    DECL_ASN_OP_OTHER(op)
375
376    DECL_ASN_OP(=)
377
378    DECL_ASN_OP(*=)
379    DECL_ASN_OP(/=)
380    DECL_ASN_OP(+=)
381    DECL_ASN_OP(-=)
382
383    DECL_ASN_OP_T(<<=, int)
384    DECL_ASN_OP_T(>>=, int)
385
386    DECL_ASN_OP_T(&=, const sc_ufix &)
387    DECL_ASN_OP_T(&=, const sc_ufix_fast &)
388    DECL_ASN_OP_T(|=, const sc_ufix &)
389    DECL_ASN_OP_T(|=, const sc_ufix_fast &)
390    DECL_ASN_OP_T(^=, const sc_ufix &)
391    DECL_ASN_OP_T(^=, const sc_ufix_fast &)
392
393#undef DECL_ASN_OP_T
394#undef DECL_ASN_OP_OTHER
395#undef DECL_ASN_OP
396
397    // auto-increment and auto-decrement
398    const sc_fxval_fast operator ++ (int);
399    const sc_fxval_fast operator -- (int);
400
401    sc_ufix_fast &operator ++ ();
402    sc_ufix_fast &operator -- ();
403};
404
405
406// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
407
408// ----------------------------------------------------------------------------
409//  CLASS : sc_ufix
410//
411//  "Unconstrained" unsigned fixed-point class; arbitrary precision.
412// ----------------------------------------------------------------------------
413
414// constructors
415
416inline sc_ufix::sc_ufix(sc_fxnum_observer *observer_) :
417        sc_fxnum(sc_fxtype_params(), SC_US_, sc_fxcast_switch(), observer_)
418{}
419
420inline sc_ufix::sc_ufix(int wl_, int iwl_, sc_fxnum_observer *observer_ ) :
421        sc_fxnum(sc_fxtype_params(wl_, iwl_), SC_US_, sc_fxcast_switch(),
422                 observer_)
423{}
424
425inline sc_ufix::sc_ufix(sc_q_mode qm, sc_o_mode om,
426                        sc_fxnum_observer *observer_) :
427        sc_fxnum(sc_fxtype_params(qm, om), SC_US_, sc_fxcast_switch(),
428                 observer_)
429{}
430
431inline
432sc_ufix::sc_ufix(sc_q_mode qm, sc_o_mode om, int nb,
433                 sc_fxnum_observer *observer_) :
434        sc_fxnum(sc_fxtype_params(qm, om, nb), SC_US_, sc_fxcast_switch(),
435                 observer_)
436{}
437
438inline sc_ufix::sc_ufix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
439                        sc_fxnum_observer *observer_) :
440        sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om), SC_US_,
441                 sc_fxcast_switch(), observer_)
442{}
443
444inline sc_ufix::sc_ufix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
445                        sc_fxnum_observer *observer_) :
446        sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_,
447                 sc_fxcast_switch(), observer_)
448{}
449
450inline sc_ufix::sc_ufix(const sc_fxcast_switch &cast_sw,
451                        sc_fxnum_observer *observer_) :
452        sc_fxnum(sc_fxtype_params(), SC_US_, cast_sw, observer_)
453{}
454
455inline sc_ufix::sc_ufix(int wl_, int iwl_, const sc_fxcast_switch &cast_sw,
456                        sc_fxnum_observer *observer_) :
457        sc_fxnum(sc_fxtype_params(wl_, iwl_), SC_US_, cast_sw, observer_)
458{}
459
460inline sc_ufix::sc_ufix(sc_q_mode qm, sc_o_mode om,
461                        const sc_fxcast_switch &cast_sw,
462                        sc_fxnum_observer *observer_) :
463        sc_fxnum(sc_fxtype_params(qm, om), SC_US_, cast_sw, observer_)
464{}
465
466inline sc_ufix::sc_ufix(sc_q_mode qm, sc_o_mode om, int nb,
467                        const sc_fxcast_switch &cast_sw,
468                        sc_fxnum_observer *observer_ ) :
469        sc_fxnum(sc_fxtype_params(qm, om, nb), SC_US_, cast_sw, observer_)
470{}
471
472inline sc_ufix::sc_ufix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
473                        const sc_fxcast_switch &cast_sw,
474                        sc_fxnum_observer *observer_) :
475        sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, cast_sw,
476                 observer_)
477{}
478
479inline sc_ufix::sc_ufix(int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
480                        const sc_fxcast_switch &cast_sw,
481                        sc_fxnum_observer *observer_) :
482        sc_fxnum(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, cast_sw,
483                 observer_)
484{}
485
486inline sc_ufix::sc_ufix(const sc_fxtype_params &type_params_,
487                        sc_fxnum_observer *observer_) :
488        sc_fxnum(type_params_, SC_US_, sc_fxcast_switch(), observer_)
489{}
490
491inline sc_ufix::sc_ufix(const sc_fxtype_params &type_params_,
492                        const sc_fxcast_switch &cast_sw,
493                        sc_fxnum_observer *observer_ ) :
494        sc_fxnum(type_params_, SC_US_, cast_sw, observer_)
495{}
496
497#define DEFN_CTORS_T_A(tp) \
498inline sc_ufix::sc_ufix(tp a, sc_fxnum_observer *observer_ ) : \
499        sc_fxnum(a, sc_fxtype_params(), SC_US_, sc_fxcast_switch(), \
500                 observer_) \
501{} \
502 \
503inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, \
504                        sc_fxnum_observer *observer_) : \
505        sc_fxnum(a, sc_fxtype_params(wl_, iwl_), SC_US_, sc_fxcast_switch(), \
506                 observer_ ) \
507{} \
508 \
509inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, \
510                        sc_fxnum_observer *observer_) : \
511        sc_fxnum(a, sc_fxtype_params(qm, om), SC_US_, sc_fxcast_switch(), \
512                 observer_ ) \
513{} \
514 \
515inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
516                        sc_fxnum_observer *observer_) : \
517        sc_fxnum(a, sc_fxtype_params(qm, om, nb), SC_US_, sc_fxcast_switch(), \
518                 observer_ ) \
519{} \
520 \
521inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
522                        sc_fxnum_observer *observer_) : \
523        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, \
524                 sc_fxcast_switch(), observer_) \
525{} \
526 \
527inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
528                        int nb, sc_fxnum_observer *observer_) : \
529        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, \
530                 sc_fxcast_switch(), observer_) \
531{} \
532 \
533inline sc_ufix::sc_ufix(tp a, const sc_fxcast_switch &cast_sw, \
534                        sc_fxnum_observer *observer_) : \
535        sc_fxnum(a, sc_fxtype_params(), SC_US_, cast_sw, observer_) \
536{} \
537 \
538inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, \
539                        const sc_fxcast_switch &cast_sw, \
540                        sc_fxnum_observer *observer_) : \
541        sc_fxnum(a, sc_fxtype_params(wl_, iwl_), SC_US_, cast_sw, observer_) \
542{} \
543 \
544inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, \
545                        const sc_fxcast_switch &cast_sw, \
546                        sc_fxnum_observer *observer_) : \
547        sc_fxnum(a, sc_fxtype_params(qm, om), SC_US_, cast_sw, observer_) \
548{} \
549 \
550inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
551                        const sc_fxcast_switch &cast_sw, \
552                        sc_fxnum_observer *observer_) : \
553        sc_fxnum(a, sc_fxtype_params(qm, om, nb), SC_US_, cast_sw, observer_) \
554{} \
555 \
556inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
557                        const sc_fxcast_switch &cast_sw, \
558                        sc_fxnum_observer *observer_) : \
559        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, cast_sw, \
560                 observer_) \
561{} \
562 \
563inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
564                        int nb, const sc_fxcast_switch &cast_sw, \
565                        sc_fxnum_observer *observer_) : \
566        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, cast_sw, \
567                 observer_) \
568{} \
569 \
570inline sc_ufix::sc_ufix(tp a, const sc_fxtype_params &type_params_, \
571                        sc_fxnum_observer * observer_) : \
572        sc_fxnum(a, type_params_, SC_US_, sc_fxcast_switch(), observer_) \
573{} \
574 \
575inline sc_ufix::sc_ufix(tp a, const sc_fxtype_params& type_params_, \
576                        const sc_fxcast_switch &cast_sw, \
577                        sc_fxnum_observer *observer_) : \
578        sc_fxnum(a, type_params_, SC_US_, cast_sw, observer_) \
579{}
580
581#define DEFN_CTORS_T_B(tp) \
582inline sc_ufix::sc_ufix(tp a, sc_fxnum_observer *observer_) : \
583        sc_fxnum(a, a.type_params(), SC_US_, sc_fxcast_switch(), observer_) \
584{} \
585 \
586inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, \
587                        sc_fxnum_observer *observer_) : \
588        sc_fxnum(a, sc_fxtype_params(a.type_params(), wl_, iwl_), SC_US_, \
589                 sc_fxcast_switch(), observer_) \
590{} \
591 \
592inline \
593sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, \
594                 sc_fxnum_observer *observer_) : \
595        sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om), SC_US_, \
596                 sc_fxcast_switch(), observer_) \
597{} \
598 \
599inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
600                        sc_fxnum_observer *observer_) : \
601        sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om, nb), SC_US_, \
602                 sc_fxcast_switch(), observer_) \
603{} \
604 \
605inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
606                        sc_fxnum_observer* observer_) : \
607        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, \
608                 sc_fxcast_switch(), observer_) \
609{} \
610 \
611inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
612                        int nb, sc_fxnum_observer *observer_) : \
613        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, \
614                 sc_fxcast_switch(), observer_) \
615{} \
616 \
617inline sc_ufix::sc_ufix(tp a, const sc_fxcast_switch& cast_sw, \
618                        sc_fxnum_observer* observer_) : \
619        sc_fxnum(a, a.type_params(), SC_US_, cast_sw, observer_) \
620{} \
621 \
622inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, \
623                        const sc_fxcast_switch &cast_sw, \
624                        sc_fxnum_observer *observer_) : \
625        sc_fxnum(a, sc_fxtype_params(a.type_params(), wl_, iwl_), SC_US_, \
626                 cast_sw, observer_) \
627{} \
628 \
629inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, \
630                        const sc_fxcast_switch &cast_sw, \
631                        sc_fxnum_observer *observer_) : \
632        sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om), SC_US_, \
633                 cast_sw, observer_) \
634{} \
635 \
636inline sc_ufix::sc_ufix(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
637                        const sc_fxcast_switch &cast_sw, \
638                        sc_fxnum_observer *observer_) : \
639        sc_fxnum(a, sc_fxtype_params(a.type_params(), qm, om, nb), SC_US_, \
640                 cast_sw, observer_) \
641{} \
642 \
643inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
644                        const sc_fxcast_switch &cast_sw, \
645                        sc_fxnum_observer *observer_) : \
646        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, cast_sw, \
647                 observer_) \
648{} \
649 \
650inline sc_ufix::sc_ufix(tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
651                        int nb, const sc_fxcast_switch &cast_sw, \
652                        sc_fxnum_observer *observer_) : \
653        sc_fxnum(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, cast_sw, \
654                 observer_) \
655{} \
656 \
657inline sc_ufix::sc_ufix(tp a, const sc_fxtype_params &type_params_, \
658                        sc_fxnum_observer *observer_) : \
659        sc_fxnum(a, type_params_, SC_US_, sc_fxcast_switch(), observer_) \
660{} \
661 \
662inline sc_ufix::sc_ufix(tp a, const sc_fxtype_params& type_params_, \
663                        const sc_fxcast_switch &cast_sw, \
664                        sc_fxnum_observer *observer_) : \
665        sc_fxnum(a, type_params_, SC_US_, cast_sw, observer_) \
666{}
667
668DEFN_CTORS_T_A(int)
669DEFN_CTORS_T_A(unsigned int)
670DEFN_CTORS_T_A(long)
671DEFN_CTORS_T_A(unsigned long)
672DEFN_CTORS_T_A(float)
673DEFN_CTORS_T_A(double)
674DEFN_CTORS_T_A(const char *)
675DEFN_CTORS_T_A(const sc_fxval &)
676DEFN_CTORS_T_A(const sc_fxval_fast &)
677DEFN_CTORS_T_B(const sc_fxnum &)
678DEFN_CTORS_T_B(const sc_fxnum_fast &)
679
680DEFN_CTORS_T_A(int64)
681DEFN_CTORS_T_A(uint64)
682DEFN_CTORS_T_A(const sc_int_base &)
683DEFN_CTORS_T_A(const sc_uint_base &)
684DEFN_CTORS_T_A(const sc_signed &)
685DEFN_CTORS_T_A(const sc_unsigned &)
686
687#undef DEFN_CTORS_T_A
688#undef DEFN_CTORS_T_B
689
690// copy constructor
691
692inline sc_ufix::sc_ufix(const sc_ufix &a) :
693        sc_fxnum(a, a.type_params(), SC_US_, sc_fxcast_switch(), 0)
694{}
695
696// unary bitwise operators
697inline const sc_ufix
698sc_ufix::operator ~ () const
699{
700    SC_FXNUM_OBSERVER_READ_(*this)
701    int iwl_c = iwl();
702    int wl_c = wl();
703    sc_ufix c(wl_c, iwl_c);
704    for (int i = iwl_c - wl_c; i < iwl_c; ++i)
705        c.set_bit(i, !get_bit(i));
706    return sc_ufix(c, wl_c, iwl_c);
707}
708
709// unary bitwise functions
710inline void
711b_not(sc_ufix &c, const sc_ufix &a)
712{
713    SC_FXNUM_OBSERVER_READ_(a)
714    int iwl_c = c.iwl();
715    for (int i = iwl_c - c.wl(); i < iwl_c; ++i)
716        c.set_bit(i, !a.get_bit(i));
717    c.cast();
718    SC_FXNUM_OBSERVER_WRITE_(c)
719}
720
721// binary bitwise operators
722#define DEFN_BIN_OP_T(op, op2, tp1, tp2) \
723inline const sc_ufix \
724operator op (const tp1 &a, const tp2 &b) \
725{ \
726    a.observer_read(); \
727    b.observer_read(); \
728    int iwl_a = a.iwl(); \
729    int iwl_b = b.iwl(); \
730    int iwl_c = sc_max(iwl_a, iwl_b); \
731    int fwl_c = sc_max(a.wl() - iwl_a, b.wl() - iwl_b); \
732    sc_ufix c(iwl_c + fwl_c, iwl_c); \
733    for (int i = -fwl_c; i < iwl_c; ++i) \
734        c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
735    return sc_ufix(c, iwl_c + fwl_c, iwl_c); \
736}
737
738DEFN_BIN_OP_T(&, &&, sc_ufix, sc_ufix)
739DEFN_BIN_OP_T(&, &&, sc_ufix, sc_ufix_fast)
740DEFN_BIN_OP_T(&, &&, sc_ufix_fast, sc_ufix)
741
742DEFN_BIN_OP_T(|, ||, sc_ufix, sc_ufix)
743DEFN_BIN_OP_T(|, ||, sc_ufix, sc_ufix_fast)
744DEFN_BIN_OP_T(|, ||, sc_ufix_fast, sc_ufix)
745
746DEFN_BIN_OP_T(^, !=, sc_ufix, sc_ufix)
747DEFN_BIN_OP_T(^, !=, sc_ufix, sc_ufix_fast)
748DEFN_BIN_OP_T(^, !=, sc_ufix_fast, sc_ufix)
749
750#undef DEFN_BIN_OP_T
751
752// binary bitwise functions
753#define DEFN_BIN_FNC_T(fnc, op2, tp1, tp2) \
754inline void \
755fnc (sc_ufix &c, const tp1 &a, const tp2 &b) \
756{ \
757    a.observer_read(); \
758    b.observer_read(); \
759    int iwl_c = c.iwl(); \
760    for (int i = iwl_c - c.wl(); i < iwl_c; ++i) \
761        c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
762    c.cast(); \
763    SC_FXNUM_OBSERVER_WRITE_(c) \
764}
765
766DEFN_BIN_FNC_T(b_and, &&, sc_ufix, sc_ufix)
767DEFN_BIN_FNC_T(b_and, &&, sc_ufix, sc_ufix_fast)
768DEFN_BIN_FNC_T(b_and, &&, sc_ufix_fast, sc_ufix)
769
770DEFN_BIN_FNC_T(b_or, ||, sc_ufix, sc_ufix)
771DEFN_BIN_FNC_T(b_or, ||, sc_ufix, sc_ufix_fast)
772DEFN_BIN_FNC_T(b_or, ||, sc_ufix_fast, sc_ufix)
773
774DEFN_BIN_FNC_T(b_xor, !=, sc_ufix, sc_ufix)
775DEFN_BIN_FNC_T(b_xor, !=, sc_ufix, sc_ufix_fast)
776DEFN_BIN_FNC_T(b_xor, !=, sc_ufix_fast, sc_ufix)
777
778#undef DEFN_BIN_FNC_T
779
780// assignment operators
781inline sc_ufix &
782sc_ufix::operator = (const sc_ufix &a)
783{
784    sc_fxnum::operator = (a);
785    return *this;
786}
787
788#define DEFN_ASN_OP_T(op, tp) \
789inline sc_ufix & \
790sc_ufix::operator op (tp a) \
791{ \
792    sc_fxnum::operator op(a); \
793    return *this; \
794}
795
796#define DEFN_ASN_OP_OTHER(op) \
797DEFN_ASN_OP_T(op, int64) \
798DEFN_ASN_OP_T(op, uint64) \
799DEFN_ASN_OP_T(op, const sc_int_base &) \
800DEFN_ASN_OP_T(op, const sc_uint_base &) \
801DEFN_ASN_OP_T(op, const sc_signed &) \
802DEFN_ASN_OP_T(op, const sc_unsigned &)
803
804#define DEFN_ASN_OP(op) \
805DEFN_ASN_OP_T(op, int) \
806DEFN_ASN_OP_T(op, unsigned int) \
807DEFN_ASN_OP_T(op, long) \
808DEFN_ASN_OP_T(op, unsigned long) \
809DEFN_ASN_OP_T(op, float) \
810DEFN_ASN_OP_T(op, double) \
811DEFN_ASN_OP_T(op, const char *) \
812DEFN_ASN_OP_T(op, const sc_fxval &) \
813DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
814DEFN_ASN_OP_T(op, const sc_fxnum &) \
815DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
816DEFN_ASN_OP_OTHER(op)
817
818DEFN_ASN_OP(=)
819
820DEFN_ASN_OP(*=)
821DEFN_ASN_OP(/=)
822DEFN_ASN_OP(+=)
823DEFN_ASN_OP(-=)
824
825DEFN_ASN_OP_T(<<=, int)
826DEFN_ASN_OP_T(>>=, int)
827
828#undef DEFN_ASN_OP_T
829#undef DEFN_ASN_OP_OTHER
830#undef DEFN_ASN_OP
831
832
833#define DEFN_ASN_OP_T(op, op2, tp) \
834inline sc_ufix & \
835sc_ufix::operator op (const tp &b) \
836{ \
837    SC_FXNUM_OBSERVER_READ_(*this) \
838    b.observer_read(); \
839    int iwl_c = iwl(); \
840    for (int i = iwl_c - wl(); i < iwl_c; ++i) \
841        set_bit(i, get_bit(i) op2 b.get_bit(i)); \
842    cast(); \
843    SC_FXNUM_OBSERVER_WRITE_(*this) \
844    return *this; \
845}
846
847DEFN_ASN_OP_T(&=, &&, sc_ufix)
848DEFN_ASN_OP_T(&=, &&, sc_ufix_fast)
849DEFN_ASN_OP_T(|=, ||, sc_ufix)
850DEFN_ASN_OP_T(|=, ||, sc_ufix_fast)
851DEFN_ASN_OP_T(^=, !=, sc_ufix)
852DEFN_ASN_OP_T(^=, !=, sc_ufix_fast)
853
854#undef DEFN_ASN_OP_T
855
856// auto-increment and auto-decrement
857inline const sc_fxval
858sc_ufix::operator ++ (int)
859{
860    return sc_fxval(sc_fxnum::operator ++ (0));
861}
862
863inline const sc_fxval
864sc_ufix::operator -- (int)
865{
866    return sc_fxval(sc_fxnum::operator -- (0));
867}
868
869inline sc_ufix &
870sc_ufix::operator ++ ()
871{
872    sc_fxnum::operator ++ ();
873    return *this;
874}
875
876inline sc_ufix &
877sc_ufix::operator -- ()
878{
879    sc_fxnum::operator -- ();
880    return *this;
881}
882
883
884// ----------------------------------------------------------------------------
885//  CLASS : sc_ufix_fast
886//
887//  "Unconstrained" unsigned fixed-point class; limited precision.
888// ----------------------------------------------------------------------------
889
890// constructors
891
892inline sc_ufix_fast::sc_ufix_fast(sc_fxnum_fast_observer *observer_) :
893        sc_fxnum_fast(sc_fxtype_params(), SC_US_, sc_fxcast_switch(),
894                      observer_)
895{}
896
897inline sc_ufix_fast::sc_ufix_fast(int wl_, int iwl_,
898                                  sc_fxnum_fast_observer *observer_) :
899        sc_fxnum_fast(sc_fxtype_params(wl_, iwl_), SC_US_, sc_fxcast_switch(),
900                      observer_ )
901{}
902
903inline sc_ufix_fast::sc_ufix_fast(sc_q_mode qm, sc_o_mode om,
904                                  sc_fxnum_fast_observer *observer_) :
905        sc_fxnum_fast(sc_fxtype_params(qm, om), SC_US_, sc_fxcast_switch(),
906                      observer_ )
907{}
908
909inline sc_ufix_fast::sc_ufix_fast(sc_q_mode qm, sc_o_mode om, int nb,
910                                  sc_fxnum_fast_observer *observer_) :
911        sc_fxnum_fast(sc_fxtype_params(qm, om, nb), SC_US_, sc_fxcast_switch(),
912                      observer_ )
913{}
914
915inline sc_ufix_fast::sc_ufix_fast(
916        int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
917        sc_fxnum_fast_observer *observer_) :
918    sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om), SC_US_,
919                  sc_fxcast_switch(), observer_)
920{}
921
922inline sc_ufix_fast::sc_ufix_fast(
923        int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
924        sc_fxnum_fast_observer *observer_) :
925    sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_,
926                  sc_fxcast_switch(), observer_)
927{}
928
929inline sc_ufix_fast::sc_ufix_fast(const sc_fxcast_switch &cast_sw,
930                                  sc_fxnum_fast_observer *observer_) :
931        sc_fxnum_fast(sc_fxtype_params(), SC_US_, cast_sw, observer_)
932{}
933
934inline sc_ufix_fast::sc_ufix_fast(
935        int wl_, int iwl_, const sc_fxcast_switch &cast_sw,
936        sc_fxnum_fast_observer *observer_) :
937    sc_fxnum_fast(sc_fxtype_params(wl_, iwl_), SC_US_, cast_sw, observer_)
938{}
939
940inline sc_ufix_fast::sc_ufix_fast(
941        sc_q_mode qm, sc_o_mode om, const sc_fxcast_switch &cast_sw,
942        sc_fxnum_fast_observer *observer_) :
943    sc_fxnum_fast(sc_fxtype_params(qm, om), SC_US_, cast_sw, observer_)
944{}
945
946inline sc_ufix_fast::sc_ufix_fast(
947        sc_q_mode qm, sc_o_mode om, int nb, const sc_fxcast_switch &cast_sw,
948        sc_fxnum_fast_observer *observer_) :
949    sc_fxnum_fast(sc_fxtype_params(qm, om, nb), SC_US_, cast_sw, observer_)
950{}
951
952inline sc_ufix_fast::sc_ufix_fast(
953        int wl_, int iwl_, sc_q_mode qm, sc_o_mode om,
954        const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) :
955    sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, cast_sw,
956                  observer_ )
957{}
958
959inline sc_ufix_fast::sc_ufix_fast(
960        int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb,
961        const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) :
962    sc_fxnum_fast(sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, cast_sw,
963                  observer_)
964{}
965
966inline sc_ufix_fast::sc_ufix_fast(const sc_fxtype_params &type_params_,
967                                  sc_fxnum_fast_observer *observer_) :
968    sc_fxnum_fast(type_params_, SC_US_, sc_fxcast_switch(), observer_)
969{}
970
971inline sc_ufix_fast::sc_ufix_fast(const sc_fxtype_params &type_params_,
972                                  const sc_fxcast_switch &cast_sw,
973                                  sc_fxnum_fast_observer *observer_) :
974    sc_fxnum_fast(type_params_, SC_US_, cast_sw, observer_)
975{}
976
977#define DEFN_CTORS_T_A(tp) \
978inline sc_ufix_fast::sc_ufix_fast(tp a, sc_fxnum_fast_observer *observer_) : \
979        sc_fxnum_fast(a, sc_fxtype_params(), SC_US_, sc_fxcast_switch(), \
980                      observer_) \
981{} \
982 \
983inline sc_ufix_fast::sc_ufix_fast(tp a, int wl_, int iwl_, \
984                                  sc_fxnum_fast_observer *observer_) : \
985    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_), SC_US_, sc_fxcast_switch(), \
986                  observer_) \
987{} \
988 \
989inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
990                                  sc_fxnum_fast_observer *observer_) : \
991    sc_fxnum_fast(a, sc_fxtype_params(qm, om), SC_US_, sc_fxcast_switch(), \
992                  observer_) \
993{} \
994 \
995inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
996                                  sc_fxnum_fast_observer *observer_) : \
997    sc_fxnum_fast(a, sc_fxtype_params(qm, om, nb), SC_US_, \
998                  sc_fxcast_switch(), observer_) \
999{} \
1000 \
1001inline sc_ufix_fast::sc_ufix_fast( \
1002        tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1003        sc_fxnum_fast_observer* observer_) : \
1004    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, \
1005                  sc_fxcast_switch(), observer_) \
1006{} \
1007 \
1008inline sc_ufix_fast::sc_ufix_fast( \
1009        tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
1010        sc_fxnum_fast_observer *observer_) : \
1011    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, \
1012                  sc_fxcast_switch(), observer_) \
1013{} \
1014 \
1015inline sc_ufix_fast::sc_ufix_fast(tp a, const sc_fxcast_switch &cast_sw, \
1016                                  sc_fxnum_fast_observer *observer_) : \
1017    sc_fxnum_fast(a, sc_fxtype_params(), SC_US_, cast_sw, observer_) \
1018{} \
1019 \
1020inline sc_ufix_fast::sc_ufix_fast(tp a, int wl_, int iwl_, \
1021                                  const sc_fxcast_switch &cast_sw, \
1022                                  sc_fxnum_fast_observer *observer_) : \
1023    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_), SC_US_, cast_sw, observer_) \
1024{} \
1025 \
1026inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
1027                                  const sc_fxcast_switch &cast_sw, \
1028                                  sc_fxnum_fast_observer *observer_) : \
1029    sc_fxnum_fast(a, sc_fxtype_params(qm, om), SC_US_, cast_sw, observer_) \
1030{} \
1031 \
1032inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
1033                                  const sc_fxcast_switch &cast_sw, \
1034                                  sc_fxnum_fast_observer *observer_) : \
1035    sc_fxnum_fast(a, sc_fxtype_params(qm, om, nb), SC_US_, cast_sw, \
1036                  observer_) \
1037{} \
1038 \
1039inline sc_ufix_fast::sc_ufix_fast(tp a, int wl_, int iwl_, \
1040                                  sc_q_mode qm, sc_o_mode om, \
1041                                  const sc_fxcast_switch &cast_sw, \
1042                                  sc_fxnum_fast_observer *observer_) : \
1043    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, cast_sw, \
1044                  observer_) \
1045{} \
1046 \
1047inline sc_ufix_fast::sc_ufix_fast(tp a, int wl_, int iwl_, \
1048                                  sc_q_mode qm, sc_o_mode om, int nb, \
1049                                  const sc_fxcast_switch &cast_sw, \
1050                                  sc_fxnum_fast_observer *observer_) : \
1051    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, \
1052                  cast_sw, observer_) \
1053{} \
1054 \
1055inline sc_ufix_fast::sc_ufix_fast( \
1056        tp a, const sc_fxtype_params &type_params_, \
1057        sc_fxnum_fast_observer *observer_) : \
1058    sc_fxnum_fast(a, type_params_, SC_US_, sc_fxcast_switch(), observer_) \
1059{} \
1060 \
1061inline sc_ufix_fast::sc_ufix_fast( \
1062        tp a, const sc_fxtype_params &type_params_, \
1063        const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) : \
1064    sc_fxnum_fast(a, type_params_, SC_US_, cast_sw, observer_) \
1065{}
1066
1067#define DEFN_CTORS_T_B(tp) \
1068inline sc_ufix_fast::sc_ufix_fast(tp a, sc_fxnum_fast_observer *observer_) : \
1069    sc_fxnum_fast(a, a.type_params(), SC_US_, sc_fxcast_switch(), observer_) \
1070{} \
1071 \
1072inline sc_ufix_fast::sc_ufix_fast(tp a, int wl_, int iwl_, \
1073                                  sc_fxnum_fast_observer* observer_) : \
1074    sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), wl_, iwl_), SC_US_, \
1075                  sc_fxcast_switch(), observer_) \
1076{} \
1077 \
1078inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
1079                                  sc_fxnum_fast_observer* observer_) : \
1080    sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om), SC_US_, \
1081                  sc_fxcast_switch(), observer_) \
1082{} \
1083 \
1084inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
1085                                  sc_fxnum_fast_observer* observer_) : \
1086    sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om, nb), SC_US_, \
1087                  sc_fxcast_switch(), observer_) \
1088{} \
1089 \
1090inline sc_ufix_fast::sc_ufix_fast( \
1091        tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1092        sc_fxnum_fast_observer *observer_) : \
1093    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, \
1094                  sc_fxcast_switch(), observer_) \
1095{} \
1096 \
1097inline sc_ufix_fast::sc_ufix_fast( \
1098        tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
1099        sc_fxnum_fast_observer *observer_) : \
1100    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, \
1101                  sc_fxcast_switch(), observer_) \
1102{} \
1103 \
1104inline sc_ufix_fast::sc_ufix_fast(tp a, const sc_fxcast_switch &cast_sw, \
1105                                  sc_fxnum_fast_observer *observer_) : \
1106    sc_fxnum_fast(a, a.type_params(), SC_US_, cast_sw, observer_) \
1107{} \
1108 \
1109inline sc_ufix_fast::sc_ufix_fast( \
1110        tp a, int wl_, int iwl_, const sc_fxcast_switch &cast_sw, \
1111        sc_fxnum_fast_observer *observer_) : \
1112    sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), wl_, iwl_), SC_US_, \
1113                  cast_sw, observer_) \
1114{} \
1115 \
1116inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, \
1117                                  const sc_fxcast_switch &cast_sw, \
1118                                  sc_fxnum_fast_observer *observer_) : \
1119    sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om), SC_US_, \
1120                  cast_sw, observer_) \
1121{} \
1122 \
1123inline sc_ufix_fast::sc_ufix_fast(tp a, sc_q_mode qm, sc_o_mode om, int nb, \
1124                                  const sc_fxcast_switch &cast_sw, \
1125                                  sc_fxnum_fast_observer *observer_) : \
1126    sc_fxnum_fast(a, sc_fxtype_params(a.type_params(), qm, om, nb), SC_US_, \
1127                  cast_sw, observer_) \
1128{} \
1129 \
1130inline sc_ufix_fast::sc_ufix_fast( \
1131        tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, \
1132        const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) : \
1133    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om), SC_US_, cast_sw, \
1134                  observer_) \
1135{} \
1136 \
1137inline sc_ufix_fast::sc_ufix_fast( \
1138        tp a, int wl_, int iwl_, sc_q_mode qm, sc_o_mode om, int nb, \
1139        const sc_fxcast_switch &cast_sw, sc_fxnum_fast_observer *observer_) : \
1140    sc_fxnum_fast(a, sc_fxtype_params(wl_, iwl_, qm, om, nb), SC_US_, \
1141                  cast_sw, observer_) \
1142{} \
1143 \
1144inline sc_ufix_fast::sc_ufix_fast(tp a, const sc_fxtype_params &type_params_, \
1145                                  sc_fxnum_fast_observer *observer_) : \
1146    sc_fxnum_fast(a, type_params_, SC_US_, sc_fxcast_switch(), observer_) \
1147{} \
1148 \
1149inline sc_ufix_fast::sc_ufix_fast(tp a, const sc_fxtype_params &type_params_, \
1150                                  const sc_fxcast_switch &cast_sw, \
1151                                  sc_fxnum_fast_observer* observer_) : \
1152    sc_fxnum_fast(a, type_params_, SC_US_, cast_sw, observer_) \
1153{}
1154
1155DEFN_CTORS_T_A(int)
1156DEFN_CTORS_T_A(unsigned int)
1157DEFN_CTORS_T_A(long)
1158DEFN_CTORS_T_A(unsigned long)
1159DEFN_CTORS_T_A(float)
1160DEFN_CTORS_T_A(double)
1161DEFN_CTORS_T_A(const char *)
1162DEFN_CTORS_T_A(const sc_fxval &)
1163DEFN_CTORS_T_A(const sc_fxval_fast &)
1164DEFN_CTORS_T_B(const sc_fxnum &)
1165DEFN_CTORS_T_B(const sc_fxnum_fast &)
1166
1167DEFN_CTORS_T_A(int64)
1168DEFN_CTORS_T_A(uint64)
1169DEFN_CTORS_T_A(const sc_int_base &)
1170DEFN_CTORS_T_A(const sc_uint_base &)
1171DEFN_CTORS_T_A(const sc_signed &)
1172DEFN_CTORS_T_A(const sc_unsigned &)
1173
1174#undef DEFN_CTORS_T_A
1175#undef DEFN_CTORS_T_B
1176
1177// copy constructor
1178inline sc_ufix_fast::sc_ufix_fast(const sc_ufix_fast &a) :
1179    sc_fxnum_fast(a, a.type_params(), SC_US_, sc_fxcast_switch(), 0)
1180{}
1181
1182// unary bitwise operators
1183inline const sc_ufix_fast
1184sc_ufix_fast::operator ~ () const
1185{
1186    SC_FXNUM_FAST_OBSERVER_READ_(*this)
1187    int iwl_c = iwl();
1188    int wl_c = wl();
1189    sc_ufix_fast c(wl_c, iwl_c);
1190    for (int i = iwl_c - wl_c; i < iwl_c; ++i)
1191        c.set_bit(i, !get_bit(i));
1192    return sc_ufix_fast(c, wl_c, iwl_c);
1193}
1194
1195// unary bitwise functions
1196inline void
1197b_not(sc_ufix_fast &c, const sc_ufix_fast &a)
1198{
1199    SC_FXNUM_FAST_OBSERVER_READ_(a)
1200    int iwl_c = c.iwl();
1201    for (int i = iwl_c - c.wl(); i < iwl_c; ++i)
1202        c.set_bit(i, !a.get_bit(i));
1203    c.cast();
1204    SC_FXNUM_FAST_OBSERVER_WRITE_(c)
1205}
1206
1207// binary bitwise operators
1208#define DEFN_BIN_OP_T(op, op2, tp1, tp2) \
1209inline const sc_ufix_fast \
1210operator op (const tp1 &a, const tp2 &b) \
1211{ \
1212    a.observer_read(); \
1213    b.observer_read(); \
1214    int iwl_a = a.iwl(); \
1215    int iwl_b = b.iwl(); \
1216    int iwl_c = sc_max(iwl_a, iwl_b); \
1217    int fwl_c = sc_max(a.wl() - iwl_a, b.wl() - iwl_b); \
1218    sc_ufix_fast c(iwl_c + fwl_c, iwl_c); \
1219    for (int i = -fwl_c; i < iwl_c; ++i) \
1220        c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
1221    return sc_ufix_fast(c, iwl_c + fwl_c, iwl_c); \
1222}
1223
1224DEFN_BIN_OP_T(&, &&, sc_ufix_fast, sc_ufix_fast)
1225DEFN_BIN_OP_T(|, ||, sc_ufix_fast, sc_ufix_fast)
1226DEFN_BIN_OP_T(^, !=, sc_ufix_fast, sc_ufix_fast)
1227
1228#undef DEFN_BIN_OP_T
1229
1230// binary bitwise functions
1231#define DEFN_BIN_FNC_T(fnc, op2, tp1, tp2) \
1232inline void \
1233fnc (sc_ufix_fast &c, const tp1 &a, const tp2 &b) \
1234{ \
1235    a.observer_read(); \
1236    b.observer_read(); \
1237    int iwl_c = c.iwl(); \
1238    for (int i = iwl_c - c.wl(); i < iwl_c; ++i) \
1239        c.set_bit(i, a.get_bit(i) op2 b.get_bit(i)); \
1240    c.cast(); \
1241    SC_FXNUM_FAST_OBSERVER_WRITE_(c) \
1242}
1243
1244DEFN_BIN_FNC_T(b_and, &&, sc_ufix_fast, sc_ufix_fast)
1245DEFN_BIN_FNC_T(b_or, ||, sc_ufix_fast, sc_ufix_fast)
1246DEFN_BIN_FNC_T(b_xor, !=, sc_ufix_fast, sc_ufix_fast)
1247
1248#undef DEFN_BIN_FNC_T
1249
1250// assignment operators
1251inline sc_ufix_fast &
1252sc_ufix_fast::operator = (const sc_ufix_fast &a)
1253{
1254    sc_fxnum_fast::operator = (a);
1255    return *this;
1256}
1257
1258#define DEFN_ASN_OP_T(op, tp) \
1259inline sc_ufix_fast & \
1260sc_ufix_fast::operator op (tp a) \
1261{ \
1262    sc_fxnum_fast::operator op(a); \
1263    return *this; \
1264}
1265
1266#define DEFN_ASN_OP_OTHER(op) \
1267DEFN_ASN_OP_T(op, int64) \
1268DEFN_ASN_OP_T(op, uint64) \
1269DEFN_ASN_OP_T(op, const sc_int_base &) \
1270DEFN_ASN_OP_T(op, const sc_uint_base &) \
1271DEFN_ASN_OP_T(op, const sc_signed &) \
1272DEFN_ASN_OP_T(op, const sc_unsigned &)
1273
1274#define DEFN_ASN_OP(op) \
1275DEFN_ASN_OP_T(op, int) \
1276DEFN_ASN_OP_T(op, unsigned int) \
1277DEFN_ASN_OP_T(op, long) \
1278DEFN_ASN_OP_T(op, unsigned long) \
1279DEFN_ASN_OP_T(op, float) \
1280DEFN_ASN_OP_T(op, double) \
1281DEFN_ASN_OP_T(op, const char *) \
1282DEFN_ASN_OP_T(op, const sc_fxval &) \
1283DEFN_ASN_OP_T(op, const sc_fxval_fast &) \
1284DEFN_ASN_OP_T(op, const sc_fxnum &) \
1285DEFN_ASN_OP_T(op, const sc_fxnum_fast &) \
1286DEFN_ASN_OP_OTHER(op)
1287
1288DEFN_ASN_OP(=)
1289
1290DEFN_ASN_OP(*=)
1291DEFN_ASN_OP(/=)
1292DEFN_ASN_OP(+=)
1293DEFN_ASN_OP(-=)
1294
1295DEFN_ASN_OP_T(<<=, int)
1296DEFN_ASN_OP_T(>>=, int)
1297
1298#undef DEFN_ASN_OP_T
1299#undef DEFN_ASN_OP_OTHER
1300#undef DEFN_ASN_OP
1301
1302#define DEFN_ASN_OP_T(op, op2, tp) \
1303inline sc_ufix_fast & \
1304sc_ufix_fast::operator op (const tp &b) \
1305{ \
1306    SC_FXNUM_FAST_OBSERVER_READ_(*this) \
1307    b.observer_read(); \
1308    int iwl_c = iwl(); \
1309    for (int i = iwl_c - wl(); i < iwl_c; ++i) \
1310        set_bit(i, get_bit(i) op2 b.get_bit(i)); \
1311    cast(); \
1312    SC_FXNUM_FAST_OBSERVER_WRITE_(*this) \
1313    return *this; \
1314}
1315
1316DEFN_ASN_OP_T(&=, &&, sc_ufix)
1317DEFN_ASN_OP_T(&=, &&, sc_ufix_fast)
1318DEFN_ASN_OP_T(|=, ||, sc_ufix)
1319DEFN_ASN_OP_T(|=, ||, sc_ufix_fast)
1320DEFN_ASN_OP_T(^=, !=, sc_ufix)
1321DEFN_ASN_OP_T(^=, !=, sc_ufix_fast)
1322
1323#undef DEFN_ASN_OP_T
1324
1325// auto-increment and auto-decrement
1326inline const sc_fxval_fast
1327sc_ufix_fast::operator ++ (int)
1328{
1329    return sc_fxval_fast(sc_fxnum_fast::operator ++ (0));
1330}
1331
1332inline const sc_fxval_fast
1333sc_ufix_fast::operator -- (int)
1334{
1335    return sc_fxval_fast(sc_fxnum_fast::operator -- (0));
1336}
1337
1338inline sc_ufix_fast &
1339sc_ufix_fast::operator ++ ()
1340{
1341    sc_fxnum_fast::operator ++ ();
1342    return *this;
1343}
1344
1345inline sc_ufix_fast &
1346sc_ufix_fast::operator -- ()
1347{
1348    sc_fxnum_fast::operator -- ();
1349    return *this;
1350}
1351
1352} // namespace sc_dt
1353
1354#endif // __SYSTEMC_EXT_DT_FX_SC_UFIX_HH__
1355