summaryrefslogtreecommitdiff
path: root/src/systemc/ext/dt/misc/sc_concatref.hh
blob: cd36eb526da5bf19f2c9bfe1fcc0fa797b6c9867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
/*****************************************************************************

  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
  more contributor license agreements.  See the NOTICE file distributed
  with this work for additional information regarding copyright ownership.
  Accellera licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  implied.  See the License for the specific language governing
  permissions and limitations under the License.

 *****************************************************************************/

/*****************************************************************************

  sc_concatref.h -- Concatenation support.

  Original Author: Andy Goodrich, Forte Design, Inc.

 *****************************************************************************/

/*****************************************************************************

  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
  changes you are making here.

      Name, Affiliation, Date:
  Description of Modification:

  Andy Goodrich, Forte Design Systems, 17 Nov 2002
  Creation of sc_concatref class by merging the capabilities of
  sc_int_concref, sc_int_concref, sc_uint_concref, sc_uint_concref,
  and implementing the capabilities of sc_signed_concref, sc_signed_concref,
  sc_unsigned_concref, and sc_unsigned_concref. The resultant class allows
  mixed mode concatenations on the left and right sides of an assignment.

 *****************************************************************************/

// $Log: sc_concatref.h,v $
// Revision 1.6  2011/08/24 22:05:48  acg
//  Torsten Maehne: initialization changes to remove warnings.
//
// Revision 1.5  2009/11/17 19:58:15  acg
//  Andy Goodrich: fix of shift rhs possibilities to include "int".
//
// Revision 1.4  2009/02/28 00:26:29  acg
//  Andy Goodrich: bug fixes.
//
// Revision 1.3  2008/04/29 20:23:55  acg
//  Andy Goodrich: fixed the code that assigns the value of a string to
//  an sc_concatref instance.
//
// Revision 1.2  2008/02/14 20:57:26  acg
//  Andy Goodrich: added casts to ~0 instances to keep MSVC compiler happy.
//
// Revision 1.1.1.1  2006/12/15 20:20:05  acg
// SystemC 2.3
//
// Revision 1.4  2006/10/23 19:36:59  acg
//  Andy Goodrich: changed casts for operations on concatenation values to
//  mirror those of sc_unsigned. For instance, an sc_unsigned minus a value
//  returns an sc_signed result, whereas an sc_concatref minus a value was
//  returning an sc_unsigned result. Now both sc_unsigned and sc_concatref
//  minus a value return an sc_signed result.
//
// Revision 1.3  2006/01/13 18:54:01  acg
// Andy Goodrich: added $Log command so that CVS comments are reproduced in
// the source.
//

#ifndef __SYSTEMC_EXT_DT_MISC_SC_CONCATREF_HH__
#define __SYSTEMC_EXT_DT_MISC_SC_CONCATREF_HH__

#include <iostream>

#include "../bit/sc_bv.hh"
#include "../bit/sc_lv.hh"
#include "../int/sc_int_base.hh"
#include "../int/sc_signed.hh"
#include "../int/sc_uint_base.hh"
#include "../int/sc_unsigned.hh"
#include "../sc_temporary.hh"
#include "sc_value_base.hh"

namespace sc_dt
{

// classes defined in this module
class sc_concatref;
class sc_concat_bool;

} // namespace sc_dt

namespace sc_core
{

extern sc_byte_heap sc_temp_heap; // Temporary storage.

// explicit template instantiations
extern template class sc_vpool<sc_dt::sc_concatref>;
extern template class sc_vpool<sc_dt::sc_concat_bool>;

} // namespace sc_core

namespace sc_dt {

// ----------------------------------------------------------------------------
//  CLASS TEMPLATE : sc_concatref
//
//  Proxy class for sized bit concatenation.
// ----------------------------------------------------------------------------

class sc_concatref : public sc_generic_base<sc_concatref>, public sc_value_base
{
  public:
    friend class sc_core::sc_vpool<sc_concatref>;

    inline void
    initialize(sc_value_base &left, sc_value_base &right)
    {
        bool left_xz; // True if x's and/or z's found in left.
        bool right_xz; // True if x's and/or z's found in right.

        m_left_p = (sc_value_base *)&left;
        m_right_p = (sc_value_base *)&right;
        m_len_r = right.concat_length(&right_xz);
        m_len = left.concat_length(&left_xz) + m_len_r;
        m_flags = (left_xz || right_xz) ? cf_xz_present : cf_none;
    }


    inline void
    initialize(const sc_value_base &left, const sc_value_base &right)
    {
        bool left_xz;   // True if x's and/or z's found in left.
        bool right_xz;  // True if x's and/or z's found in right.

        m_left_p = (sc_value_base *)&left;
        m_right_p = (sc_value_base *)&right;
        m_len_r = right.concat_length(&right_xz);
        m_len = left.concat_length(&left_xz) + m_len_r;
        m_flags = (left_xz || right_xz) ? cf_xz_present : cf_none;
    }

    // destructor
    virtual ~sc_concatref() {}

    // capacity
    unsigned int length() const { return m_len; }

    // concatenation
    virtual int
    concat_length(bool *xz_present_p) const
    {
        if (xz_present_p)
            *xz_present_p = m_flags & cf_xz_present ? true : false;
        return m_len;
    }

    virtual void
    concat_clear_data(bool to_ones)
    {
        m_left_p->concat_clear_data(to_ones);
        m_right_p->concat_clear_data(to_ones);
    }

    virtual bool
    concat_get_ctrl(sc_digit *dst_p, int low_i) const
    {
        bool rnz = m_right_p->concat_get_ctrl(dst_p, low_i);
        bool lnz = m_left_p->concat_get_ctrl(dst_p, low_i + m_len_r);
        return rnz || lnz;
    }

    virtual bool
    concat_get_data(sc_digit *dst_p, int low_i) const
    {
        bool rnz = m_right_p->concat_get_data(dst_p, low_i);
        bool lnz = m_left_p->concat_get_data(dst_p, low_i + m_len_r);
        return rnz || lnz;
    }

    virtual uint64
    concat_get_uint64() const
    {
        if (m_len_r >= 64) {
            return m_right_p->concat_get_uint64();
        } else {
            return (m_left_p->concat_get_uint64() << m_len_r) |
                m_right_p->concat_get_uint64();
        }
    }

    virtual void
    concat_set(int64 src, int low_i)
    {
        m_right_p->concat_set(src, low_i);
        m_left_p->concat_set(src, low_i + m_len_r);
    }

    virtual void
    concat_set(const sc_signed &src, int low_i)
    {
        m_right_p->concat_set(src, low_i);
        m_left_p->concat_set(src, low_i + m_len_r);
    }

    virtual void
    concat_set(const sc_unsigned &src, int low_i)
    {
        m_right_p->concat_set(src, low_i);
        m_left_p->concat_set(src, low_i + m_len_r);
    }

    virtual void
    concat_set(uint64 src, int low_i)
    {
        m_right_p->concat_set(src, low_i);
        m_left_p->concat_set(src, low_i + m_len_r);
    }

    // explicit conversions
    uint64
    to_uint64() const
    {
        uint64 mask;
        uint64 result;

        result = m_right_p->concat_get_uint64();
        if (m_len_r < 64) {
            mask = (uint64)~0;
            result = (m_left_p->concat_get_uint64() << m_len_r) |
                        (result & ~(mask << m_len_r));
        }
        if (m_len < 64) {
            mask = (uint64)~0;
            result = result & ~(mask << m_len);
        }
        return result;
    }

    const sc_unsigned &
    value() const
    {
        bool left_non_zero;
        sc_unsigned *result_p = sc_unsigned::m_pool.allocate();
        bool right_non_zero;

        result_p->nbits = result_p->num_bits(m_len);
        result_p->ndigits = DIV_CEIL(result_p->nbits);
        result_p->digit = (sc_digit *)sc_core::sc_temp_heap.allocate(
            sizeof(sc_digit) * result_p->ndigits);
        result_p->digit[result_p->ndigits - 1] = 0;
        right_non_zero = m_right_p->concat_get_data(result_p->digit, 0);
        left_non_zero = m_left_p->concat_get_data(result_p->digit, m_len_r);
        if (left_non_zero || right_non_zero)
            result_p->sgn = SC_POS;
        else
            result_p->sgn = SC_ZERO;
        return *result_p;
    }

    int64 to_int64() const { return (int64)to_uint64(); }
    int to_int() const { return (int)to_int64(); }
    unsigned int to_uint() const { return (unsigned int)to_uint64(); }
    long to_long() const { return (long)to_int64(); }
    unsigned long to_ulong() const { return (unsigned long)to_uint64(); }
    double to_double() const { return value().to_double(); }

    void to_sc_signed(sc_signed &target) const { target = value(); }

    void to_sc_unsigned(sc_unsigned &target) const { target = value(); }

    // implicit conversions:
    operator uint64 () const { return to_uint64(); }

    operator const sc_unsigned & () const { return value(); }

    // unary operators:
    sc_unsigned operator + () const { return value(); }

    sc_signed operator - () const { return -value(); }

    sc_unsigned operator ~ () const { return ~value(); }

    // explicit conversion to character string
    const std::string
    to_string(sc_numrep numrep=SC_DEC) const
    {
        return value().to_string(numrep);
    }

    const std::string
    to_string(sc_numrep numrep, bool w_prefix) const
    {
        return value().to_string(numrep,w_prefix);
    }

    // assignments
    inline const sc_concatref &
    operator = (int v)
    {
        m_right_p->concat_set((int64)v, 0);
        m_left_p->concat_set((int64)v, m_len_r);
        return *this;
    }

    inline const sc_concatref &
    operator = (long v)
    {
        m_right_p->concat_set((int64)v, 0);
        m_left_p->concat_set((int64)v, m_len_r);
        return *this;
    }

    inline const sc_concatref &
    operator = (int64 v)
    {
        m_right_p->concat_set(v, 0);
        m_left_p->concat_set(v, m_len_r);
        return *this;
    }

    inline const sc_concatref &
    operator = (unsigned int v)
    {
        m_right_p->concat_set((uint64)v, 0);
        m_left_p->concat_set((uint64)v, m_len_r);
        return *this;
    }

    inline const sc_concatref &
    operator = (unsigned long v)
    {
        m_right_p->concat_set((uint64)v, 0);
        m_left_p->concat_set((uint64)v, m_len_r);
        return *this;
    }

    inline const sc_concatref &
    operator = (uint64 v)
    {
        m_right_p->concat_set(v, 0);
        m_left_p->concat_set(v, m_len_r);
        return *this;
    }

    const sc_concatref &
    operator = (const sc_concatref &v)
    {
        sc_unsigned temp(v.length());
        temp = v.value();
        m_right_p->concat_set(temp, 0);
        m_left_p->concat_set(temp, m_len_r);
        return *this;
    }

    const sc_concatref &
    operator = (const sc_signed &v)
    {
        m_right_p->concat_set(v, 0);
        m_left_p->concat_set(v, m_len_r);
        return *this;
    }

    const sc_concatref &
    operator = (const sc_unsigned &v)
    {
        m_right_p->concat_set(v, 0);
        m_left_p->concat_set(v, m_len_r);
        return *this;
    }

    const sc_concatref &
    operator = (const char *v_p)
    {
        sc_unsigned v(m_len);
        v = v_p;
        m_right_p->concat_set(v, 0);
        m_left_p->concat_set(v, m_len_r);
        return *this;
    }

    const sc_concatref &
    operator = (const sc_bv_base &v)
    {
        sc_unsigned temp(v.length());
        temp = v;
        m_right_p->concat_set(temp, 0);
        m_left_p->concat_set(temp, m_len_r);
        return *this;
    }

    const sc_concatref &
    operator = (const sc_lv_base &v)
    {
        sc_unsigned data(v.length());
        data = v;
        m_right_p->concat_set(data, 0);
        m_left_p->concat_set(data, m_len_r);
        return *this;
    }

    // reduce methods
    bool and_reduce() const { return value().and_reduce(); }
    bool nand_reduce() const { return value().nand_reduce(); }
    bool or_reduce() const { return value().or_reduce(); }
    bool nor_reduce() const { return value().nor_reduce(); }
    bool xor_reduce() const { return value().xor_reduce(); }
    bool xnor_reduce() const { return value().xnor_reduce(); }

    // other methods
    void print(::std::ostream &os=::std::cout) const { os << this->value(); }

    void
    scan(::std::istream &is)
    {
        std::string s;
        is >> s;
        *this = s.c_str();
    }

  public:
    // Pool of temporary objects.
    static sc_core::sc_vpool<sc_concatref> m_pool;

  public:
    enum concat_flags {
        cf_none = 0,        // Normal value.
        cf_xz_present = 1   // X and/or Z values present.
    };

  protected:
    sc_value_base *m_left_p;  // Left hand operand of concatenation.
    sc_value_base *m_right_p; // Right hand operand of concatenation.
    int m_len;                // Length of concatenation.
    int m_len_r;              // Length of m_rightt_p.
    concat_flags m_flags;     // Value is read only.

  private:
    sc_concatref(const sc_concatref &);
    sc_concatref() : m_left_p(0), m_right_p(0), m_len(0), m_len_r(0), m_flags()
    {}
};

// functional notation for the reduce methods
inline bool and_reduce(const sc_concatref &a) { return a.and_reduce(); }
inline bool nand_reduce(const sc_concatref &a) { return a.nand_reduce(); }
inline bool or_reduce(const sc_concatref &a) { return a.or_reduce(); }
inline bool nor_reduce(const sc_concatref &a) { return a.nor_reduce(); }
inline bool xor_reduce(const sc_concatref &a) { return a.xor_reduce(); }
inline bool xnor_reduce(const sc_concatref &a) { return a.xnor_reduce(); }

// SHIFT OPERATORS FOR sc_concatref OBJECT INSTANCES:
//
// Because sc_concatref has implicit casts to both uint64 and sc_unsigned
// it is necessary to disambiguate the use of the shift operators. We do
// this in favor of sc_unsigned so that precision is not lost. To get an
// integer-based result use a cast to uint64 before performing the shift.

inline const sc_unsigned
operator << (const sc_concatref &target, uint64 shift)
{
    return target.value() << (int)shift;
}

inline const sc_unsigned
operator << (const sc_concatref &target, int64 shift)
{
    return target.value() << (int)shift;
}

inline const sc_unsigned
operator << (const sc_concatref &target, unsigned long shift)
{
    return target.value() << (int)shift;
}

inline const sc_unsigned
operator << (const sc_concatref &target, int shift)
{
    return target.value() << shift;
}

inline const sc_unsigned
operator << (const sc_concatref &target, unsigned int shift)
{
    return target.value() << (int)shift;
}

inline const sc_unsigned
operator << (const sc_concatref &target, long shift)
{
    return target.value() << (int)shift;
}

inline const sc_unsigned
operator >> (const sc_concatref &target, uint64 shift)
{
    return target.value() >> (int)shift;
}

inline const sc_unsigned
operator >> (const sc_concatref &target, int64 shift)
{
    return target.value() >> (int)shift;
}

inline const sc_unsigned
operator >> (const sc_concatref &target, unsigned long shift)
{
    return target.value() >> (int)shift;
}

inline const sc_unsigned
operator >> (const sc_concatref &target, int shift)
{
    return target.value() >> shift;
}

inline const sc_unsigned
operator >> (const sc_concatref &target, unsigned int shift)
{
    return target.value() >> (int)shift;
}

inline const sc_unsigned
operator >> (const sc_concatref &target, long shift)
{
    return target.value() >> (int)shift;
}

// STREAM OPERATORS FOR sc_concatref OBJECT INSTANCES:
inline ::std::ostream &
operator << (::std::ostream &os, const sc_concatref &v)
{
    return os << v.value();
}

inline ::std::istream &
operator >> (::std::istream &is, sc_concatref &a)
{
    sc_unsigned temp(a.concat_length(0));
    temp.scan(is);
    a = temp;
    return is;
}


// ----------------------------------------------------------------------------
//  CLASS TEMPLATE : sc_concat_bool
//
//  Proxy class for read-only boolean values in concatenations.
// ----------------------------------------------------------------------------

class sc_concat_bool : public sc_value_base
{
  protected:
    static sc_core::sc_vpool<sc_concat_bool> m_pool; // Temporaries pool.
    bool m_value;                                    // Value for this obj.

  public:
    // constructor:
    sc_concat_bool() : sc_value_base(), m_value() {}

    // destructor:
    virtual ~sc_concat_bool() { }

    // allocation of temporary object:
    static inline sc_concat_bool *
    allocate(bool v)
    {
        sc_concat_bool *result_p = m_pool.allocate();
        result_p->m_value = v;
        return result_p;
    }

    // concatenation:
    virtual int
    concat_length(bool *xz_present_p) const
    {
        if (xz_present_p)
            *xz_present_p = false;
        return 1;
    }

    virtual bool
    concat_get_ctrl(sc_digit *dst_p, int low_i) const
    {
        int bit = 1 << (low_i % BITS_PER_DIGIT);
        int word_i = low_i / BITS_PER_DIGIT;
        dst_p[word_i] &= ~bit;
        return false;
    }

    virtual bool
    concat_get_data(sc_digit *dst_p, int low_i) const
    {
        int bit = 1 << (low_i % BITS_PER_DIGIT);
        int word_i = low_i / BITS_PER_DIGIT;
        if (m_value)
            dst_p[word_i] |= bit;
        else
            dst_p[word_i] &= ~bit;
        return m_value;
    }

    virtual uint64
    concat_get_uint64() const
    {
        return m_value ? 1 : 0;
    }
};


// ----------------------------------------------------------------------------
// ARITHMETIC AND LOGIC OPERATORS FOR sc_concatref
// ----------------------------------------------------------------------------

#define SC_CONCAT_OP_TYPE(RESULT, OP, OTHER_TYPE) \
    inline RESULT \
    operator OP (const sc_concatref &a, OTHER_TYPE b) \
    { \
        return a.value() OP b; \
    } \
    inline RESULT \
    operator OP (OTHER_TYPE a, const sc_concatref &b) \
    { \
        return a OP b.value(); \
    }


#define SC_CONCAT_OP(RESULT, OP) \
    inline RESULT \
    operator OP (const sc_concatref &a, const sc_concatref &b) \
    { \
        return a.value() OP b.value(); \
    }  \
    SC_CONCAT_OP_TYPE(const sc_signed, OP, int) \
    SC_CONCAT_OP_TYPE(const sc_signed, OP, long) \
    SC_CONCAT_OP_TYPE(const sc_signed, OP, int64) \
    SC_CONCAT_OP_TYPE(RESULT, OP, unsigned int) \
    SC_CONCAT_OP_TYPE(RESULT, OP, unsigned long) \
    SC_CONCAT_OP_TYPE(RESULT, OP, uint64) \
    SC_CONCAT_OP_TYPE(const sc_signed, OP, const sc_int_base &) \
    SC_CONCAT_OP_TYPE(RESULT, OP, const sc_uint_base &) \
    SC_CONCAT_OP_TYPE(const sc_signed, OP, const sc_signed &) \
    SC_CONCAT_OP_TYPE(RESULT, OP, const sc_unsigned &) \
    inline RESULT \
    operator OP (const sc_concatref &a, bool b) \
    { \
        return a.value() OP (int)b; \
    } \
    inline RESULT \
    operator OP (bool a, const sc_concatref &b) \
    { \
        return (int)a OP b.value(); \
    }

#define SC_CONCAT_BOOL_OP(OP) \
    inline bool \
    operator OP (const sc_concatref &a, const sc_concatref &b) \
    { \
        return a.value() OP b.value(); \
    }  \
    SC_CONCAT_OP_TYPE(bool, OP, int) \
    SC_CONCAT_OP_TYPE(bool, OP, long) \
    SC_CONCAT_OP_TYPE(bool, OP, int64) \
    SC_CONCAT_OP_TYPE(bool, OP, unsigned int) \
    SC_CONCAT_OP_TYPE(bool, OP, unsigned long) \
    SC_CONCAT_OP_TYPE(bool, OP, uint64) \
    SC_CONCAT_OP_TYPE(bool, OP, const sc_int_base &) \
    SC_CONCAT_OP_TYPE(bool, OP, const sc_uint_base &) \
    SC_CONCAT_OP_TYPE(bool, OP, const sc_signed &) \
    SC_CONCAT_OP_TYPE(bool, OP, const sc_unsigned &) \
    inline bool \
    operator OP (const sc_concatref &a, bool b) \
    { \
        return a.value() OP (int)b; \
    } \
    inline bool \
    operator OP (bool a, const sc_concatref &b) \
    { \
        return (int)a OP b.value(); \
    }

SC_CONCAT_OP(const sc_unsigned, +)
SC_CONCAT_OP(const sc_signed, -)
SC_CONCAT_OP(const sc_unsigned, *)
SC_CONCAT_OP(const sc_unsigned, /)
SC_CONCAT_OP(const sc_unsigned, %)
SC_CONCAT_OP(const sc_unsigned, &)
SC_CONCAT_OP(const sc_unsigned, |)
SC_CONCAT_OP(const sc_unsigned, ^)
SC_CONCAT_BOOL_OP(==)
SC_CONCAT_BOOL_OP(<=)
SC_CONCAT_BOOL_OP(>=)
SC_CONCAT_BOOL_OP(!=)
SC_CONCAT_BOOL_OP(>)
SC_CONCAT_BOOL_OP(<)

#undef SC_CONCAT_OP
#undef SC_CONCAT_OP_TYPE


// ----------------------------------------------------------------------------
// CONCATENATION FUNCTION AND OPERATOR FOR STANDARD SYSTEM C DATA TYPES:
// ----------------------------------------------------------------------------

inline sc_dt::sc_concatref &
concat(sc_dt::sc_value_base &a, sc_dt::sc_value_base &b)
{
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(a, b);
    return *result_p;
}

inline const sc_dt::sc_concatref &
concat(const sc_dt::sc_value_base &a, const sc_dt::sc_value_base &b)
{
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(a, b);
    return *result_p;
}

inline const sc_dt::sc_concatref &
concat(const sc_dt::sc_value_base &a, bool b)
{
    const sc_dt::sc_concat_bool *b_p; // Proxy for boolean value.
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    b_p = sc_dt::sc_concat_bool::allocate(b);
    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(a, *b_p);
    return *result_p;
}

inline const sc_dt::sc_concatref &
concat(bool a, const sc_dt::sc_value_base &b)
{
    const sc_dt::sc_concat_bool *a_p; // Proxy for boolean value.
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    a_p = sc_dt::sc_concat_bool::allocate(a);
    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(*a_p, b);
    return *result_p;
}

inline sc_dt::sc_concatref &
operator , (sc_dt::sc_value_base &a, sc_dt::sc_value_base &b)
{
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(a, b);
    return *result_p;
}

inline const sc_dt::sc_concatref &
operator , (const sc_dt::sc_value_base &a, const sc_dt::sc_value_base &b)
{
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(a, b);
    return *result_p;
}

inline const sc_dt::sc_concatref &
operator , (const sc_dt::sc_value_base &a, bool b)
{
    const sc_dt::sc_concat_bool *b_p; // Proxy for boolean value.
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    b_p = sc_dt::sc_concat_bool::allocate(b);
    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(a, *b_p);
    return *result_p;
}

inline const sc_dt::sc_concatref &
operator , (bool a, const sc_dt::sc_value_base &b)
{
    const sc_dt::sc_concat_bool *a_p; // Proxy for boolean value.
    sc_dt::sc_concatref *result_p; // Proxy for the concatenation.

    a_p = sc_dt::sc_concat_bool::allocate(a);
    result_p = sc_dt::sc_concatref::m_pool.allocate();
    result_p->initialize(*a_p, b);
    return *result_p;
}

} // namespace sc_dt

#endif //  __SYSTEMC_EXT_DT_MISC_SC_CONCATREF_HH__