17#ifndef __AP_INT_REF_H__
18#define __AP_INT_REF_H__
21#error "Only ap_fixed.h and ap_int.h can be included directly in user code."
25#error "C++ is required to include this header file"
36template <
int _AP_W1,
typename _AP_T1,
int _AP_W2,
typename _AP_T2>
39 _AP_WR = _AP_W1 + _AP_W2,
46 : mbv1(ref.mbv1), mbv2(ref.mbv2) {}
48 INLINE
ap_concat_ref(_AP_T1& bv1, _AP_T2& bv2) : mbv1(bv1), mbv2(bv2) {}
50 template <
int _AP_W3,
bool _AP_S3>
53 int W_ref1 = mbv1.length();
54 int W_ref2 = mbv2.length();
56 Part1.V = _AP_ROOT_op_get_range(vval.V, W_ref2, W_ref1 + W_ref2 - 1);
59 Part2.V = _AP_ROOT_op_get_range(vval.V, 0, W_ref2 - 1);
73#define ASSIGN_WITH_CTYPE(_Tp) \
74 INLINE ap_concat_ref& operator=(_Tp val) { \
75 ap_int_base<_AP_W1 + _AP_W2, false> tmpVal(val); \
76 return operator=(tmpVal); \
79 ASSIGN_WITH_CTYPE(
bool)
80 ASSIGN_WITH_CTYPE(
char)
81 ASSIGN_WITH_CTYPE(
signed char)
82 ASSIGN_WITH_CTYPE(
unsigned char)
83 ASSIGN_WITH_CTYPE(
short)
84 ASSIGN_WITH_CTYPE(
unsigned short)
85 ASSIGN_WITH_CTYPE(
int)
86 ASSIGN_WITH_CTYPE(
unsigned int)
87 ASSIGN_WITH_CTYPE(
long)
88 ASSIGN_WITH_CTYPE(
unsigned long)
89 ASSIGN_WITH_CTYPE(ap_slong)
90 ASSIGN_WITH_CTYPE(ap_ulong)
91#if _AP_ENABLE_HALF_ == 1
92 ASSIGN_WITH_CTYPE(half)
94 ASSIGN_WITH_CTYPE(
float)
95 ASSIGN_WITH_CTYPE(
double)
97#undef ASSIGN_WITH_CTYPE
104 return operator=(tmpVal);
107 template <
int _AP_W3,
typename _AP_T3,
int _AP_W4,
typename _AP_T4>
111 return operator=(tmpVal);
114 template <
int _AP_W3,
bool _AP_S3>
117 return operator=(tmpVal);
119 template <
int _AP_W3,
bool _AP_S3>
122 return operator=(tmpVal);
125 template <
int _AP_W3,
int _AP_I3,
bool _AP_S3, ap_q_mode _AP_Q3,
126 ap_o_mode _AP_O3,
int _AP_N3>
132 template <
int _AP_W3,
int _AP_I3,
bool _AP_S3, ap_q_mode _AP_Q3,
133 ap_o_mode _AP_O3,
int _AP_N3>
137 return operator=(val.to_ap_int_base());
140 template <
int _AP_W3,
int _AP_I3,
bool _AP_S3, ap_q_mode _AP_Q3,
141 ap_o_mode _AP_O3,
int _AP_N3>
144 return operator=((ap_ulong)(
bool)(val));
149 INLINE
operator ap_ulong()
const {
return get().to_uint64(); }
151 template <
int _AP_W3,
bool _AP_S3>
160 template <
int _AP_W3,
bool _AP_S3>
168 template <
int _AP_W3,
bool _AP_S3>
177 template <
int _AP_W3,
bool _AP_S3>
186 template <
int _AP_W3,
bool _AP_S3>
197 template <
int _AP_W3,
bool _AP_S3>
204 template <
int _AP_W3,
typename _AP_T3,
int _AP_W4,
typename _AP_T4>
213 template <
int _AP_W3,
int _AP_I3,
bool _AP_S3, ap_q_mode _AP_Q3,
214 ap_o_mode _AP_O3,
int _AP_N3>
228 template <
int _AP_W3,
int _AP_I3,
bool _AP_S3, ap_q_mode _AP_Q3,
229 ap_o_mode _AP_O3,
int _AP_N3>
243 template <
int _AP_W3,
bool _AP_S3>
244 INLINE
ap_int_base<AP_MAX(_AP_WR, _AP_W3), _AP_S3> operator&(
249 template <
int _AP_W3,
bool _AP_S3>
250 INLINE
ap_int_base<AP_MAX(_AP_WR, _AP_W3), _AP_S3> operator|(
255 template <
int _AP_W3,
bool _AP_S3>
256 INLINE
ap_int_base<AP_MAX(_AP_WR, _AP_W3), _AP_S3> operator^(
262 template<
int Hi,
int Lo>
265 return bv.slice<Hi,Lo>();
271 int W_ref1 = mbv1.length();
272 int W_ref2 = mbv2.length();
275 tmpVal.V = _AP_ROOT_op_set_range(tmpVal.V, 0, W_ref2 - 1, v2.V);
277 _AP_ROOT_op_set_range(tmpVal.V, W_ref2, W_ref1 + W_ref2 - 1, v1.V);
281 template <
int _AP_W3>
284 int W_ref1 = mbv1.length();
285 int W_ref2 = mbv2.length();
287 tmpVal1.V = _AP_ROOT_op_get_range(vval.V, W_ref2, W_ref1 + W_ref2 - 1);
290 tmpVal2.V = _AP_ROOT_op_get_range(vval.V, 0, W_ref2 - 1);
294 INLINE
int length()
const {
return mbv1.length() + mbv2.length(); }
300template <
int _AP_W,
bool _AP_S>
312 : d_bv(ref.d_bv), l_index(ref.l_index), h_index(ref.h_index) {}
315 : d_bv(*bv), l_index(l), h_index(h) {}
318 : d_bv(*const_cast<ref_type*>(bv)), l_index(l), h_index(h) {}
322 ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
326 INLINE
operator ap_ulong()
const {
return to_uint64(); }
343#define ASSIGN_WITH_CTYPE(_Tp) \
344 INLINE ap_range_ref& operator=(_Tp val) { \
345 ap_int_base<_AP_W, false> tmp(val); \
346 d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, tmp.V); \
350 ASSIGN_WITH_CTYPE(
bool)
351 ASSIGN_WITH_CTYPE(
char)
352 ASSIGN_WITH_CTYPE(
signed char)
353 ASSIGN_WITH_CTYPE(
unsigned char)
354 ASSIGN_WITH_CTYPE(
short)
355 ASSIGN_WITH_CTYPE(
unsigned short)
356 ASSIGN_WITH_CTYPE(
int)
357 ASSIGN_WITH_CTYPE(
unsigned int)
358 ASSIGN_WITH_CTYPE(
long)
359 ASSIGN_WITH_CTYPE(
unsigned long)
360 ASSIGN_WITH_CTYPE(ap_slong)
361 ASSIGN_WITH_CTYPE(ap_ulong)
362#if _AP_ENABLE_HALF_ == 1
363 ASSIGN_WITH_CTYPE(half)
365 ASSIGN_WITH_CTYPE(
float)
366 ASSIGN_WITH_CTYPE(
double)
368#undef ASSIGN_WITH_CTYPE
373 d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, tmp.V);
378 template <
int _AP_W2,
bool _AP_S2>
381 d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, tmp.V);
393 template <
int _AP_W2,
bool _AP_S2>
399 template <
int _AP_W2,
bool _AP_S2>
401 return operator=((ap_ulong)(
bool)(val));
405 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
406 ap_o_mode _AP_O2,
int _AP_N2>
410 return operator=(val.to_ap_int_base());
414 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
415 ap_o_mode _AP_O2,
int _AP_N2>
422 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
423 ap_o_mode _AP_O2,
int _AP_N2>
426 return operator=((ap_ulong)(
bool)(val));
430 template <
int _AP_W2,
typename _AP_T2,
int _AP_W3,
typename _AP_T3>
437 template <
int _AP_W2,
bool _AP_S2>
446 template <
int _AP_W2,
bool _AP_S2>
461 template <
int _AP_W2,
bool _AP_S2>
470 template <
int _AP_W2,
bool _AP_S2>
479 template <
int _AP_W2,
bool _AP_S2>
488 template <
int _AP_W2,
bool _AP_S2>
495 template <
int _AP_W2,
typename _AP_T2,
int _AP_W3,
typename _AP_T3>
504 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
505 ap_o_mode _AP_O2,
int _AP_N2>
519 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
520 ap_o_mode _AP_O2,
int _AP_N2>
534 template <
int _AP_W2,
bool _AP_S2>
541 template <
int _AP_W2,
bool _AP_S2>
543 return !(operator==(op2));
546 template <
int _AP_W2,
bool _AP_S2>
553 template <
int _AP_W2,
bool _AP_S2>
560 template <
int _AP_W2,
bool _AP_S2>
562 return !(operator<=(op2));
565 template <
int _AP_W2,
bool _AP_S2>
567 return !(operator<(op2));
570 template <
int _AP_W2,
bool _AP_S2>
573 (this->d_bv).V |= (op2.d_bv).V;
577 template <
int _AP_W2,
bool _AP_S2>
580 (this->d_bv).V |= op2.V;
584 template <
int _AP_W2,
bool _AP_S2>
587 (this->d_bv).V &= (op2.d_bv).V;
591 template <
int _AP_W2,
bool _AP_S2>
594 (this->d_bv).V &= op2.V;
598 template <
int _AP_W2,
bool _AP_S2>
601 (this->d_bv).V ^= (op2.d_bv).V;
605 template <
int _AP_W2,
bool _AP_S2>
608 (this->d_bv).V ^= op2.V;
614 ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
618 template <
int _AP_W2>
620 d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
623 INLINE
int length()
const {
624 return h_index >= l_index ? h_index - l_index + 1 : l_index - h_index + 1;
627 INLINE
int to_int()
const {
628 return (
int)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
631 INLINE
unsigned to_uint()
const {
632 return (
unsigned)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
635 INLINE
long to_long()
const {
636 return (
long)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
639 INLINE
unsigned long to_ulong()
const {
640 return (
unsigned long)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
643 INLINE ap_slong to_int64()
const {
644 return (ap_slong)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
647 INLINE ap_ulong to_uint64()
const {
648 return (ap_ulong)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
651 INLINE
bool and_reduce()
const {
653 bool reverse = l_index > h_index;
654 unsigned low = reverse ? h_index : l_index;
655 unsigned high = reverse ? l_index : h_index;
656 for (
unsigned i = low; i != high; ++i) {
660 ret &= _AP_ROOT_op_get_bit(d_bv.V, i);
665 INLINE
bool or_reduce()
const {
667 bool reverse = l_index > h_index;
668 unsigned low = reverse ? h_index : l_index;
669 unsigned high = reverse ? l_index : h_index;
670 for (
unsigned i = low; i != high; ++i) {
674 ret |= _AP_ROOT_op_get_bit(d_bv.V, i);
679 INLINE
bool xor_reduce()
const {
681 bool reverse = l_index > h_index;
682 unsigned low = reverse ? h_index : l_index;
683 unsigned high = reverse ? l_index : h_index;
684 for (
unsigned i = low; i != high; ++i) {
688 ret ^= _AP_ROOT_op_get_bit(d_bv.V, i);
693 std::string to_string(
signed char radix = 2)
const {
695 ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
696 return ret.to_string(radix);
700 INLINE
char* to_string(
signed char radix = 2)
const {
return 0; }
707template <
int _AP_W,
bool _AP_S>
708INLINE std::ostream& operator<<(std::ostream& os,
710 std::ios_base::fmtflags ff = std::cout.flags();
711 if (ff & std::cout.hex) {
712 os << x.to_string(16);
713 }
else if (ff & std::cout.oct) {
714 os << x.to_string(8);
716 os << x.to_string(10);
723template <
int _AP_W,
bool _AP_S>
724INLINE std::istream& operator>>(std::istream& in,
737template <
int _AP_W,
bool _AP_S>
749 : d_bv(ref.d_bv), d_index(ref.d_index) {}
751 INLINE
ap_bit_ref(ref_type* bv,
int index = 0) : d_bv(*bv), d_index(index) {}
753 INLINE
ap_bit_ref(
const ref_type* bv,
int index = 0)
754 : d_bv(*const_cast<ref_type*>(bv)), d_index(index) {}
756 INLINE
operator bool()
const {
return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
757 INLINE
bool to_bool()
const {
return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
769#define ASSIGN_WITH_CTYPE(_Tp) \
770 INLINE ap_bit_ref& operator=(_Tp val) { \
771 d_bv.V = _AP_ROOT_op_set_bit(d_bv.V, d_index, val); \
775 ASSIGN_WITH_CTYPE(
bool)
776 ASSIGN_WITH_CTYPE(
char)
777 ASSIGN_WITH_CTYPE(
signed char)
778 ASSIGN_WITH_CTYPE(
unsigned char)
779 ASSIGN_WITH_CTYPE(
short)
780 ASSIGN_WITH_CTYPE(
unsigned short)
781 ASSIGN_WITH_CTYPE(
int)
782 ASSIGN_WITH_CTYPE(
unsigned int)
783 ASSIGN_WITH_CTYPE(
long)
784 ASSIGN_WITH_CTYPE(
unsigned long)
785 ASSIGN_WITH_CTYPE(ap_slong)
786 ASSIGN_WITH_CTYPE(ap_ulong)
788#undef ASSIGN_WITH_CTYPE
790#define ASSIGN_WITH_CTYPE_FP(_Tp) \
791 INLINE ap_bit_ref& operator=(_Tp val) { \
792 bool tmp_val = val; \
793 d_bv.V = _AP_ROOT_op_set_bit(d_bv.V, d_index, tmp_val); \
797#if _AP_ENABLE_HALF_ == 1
798 ASSIGN_WITH_CTYPE_FP(half)
800 ASSIGN_WITH_CTYPE_FP(
float)
801 ASSIGN_WITH_CTYPE_FP(
double)
803#undef ASSIGN_WITH_CTYPE_FP
805 template <
int _AP_W2,
bool _AP_S2>
807 return operator=((ap_ulong)(val.V != 0));
810 template <
int _AP_W2,
bool _AP_S2>
818 return operator=((ap_ulong)(
bool)val);
821 template <
int _AP_W2,
bool _AP_S2>
823 return operator=((ap_ulong)(
bool)val);
826 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
827 ap_o_mode _AP_O2,
int _AP_N2>
833 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
834 ap_o_mode _AP_O2,
int _AP_N2>
837 return operator=((ap_ulong)(
bool)val);
840 template <
int _AP_W2,
typename _AP_T2,
int _AP_W3,
typename _AP_T3>
846 template <
int _AP_W2,
bool _AP_S2>
853 template <
int _AP_W2,
bool _AP_S2>
860 template <
int _AP_W2,
bool _AP_S2>
868 template <
int _AP_W2,
bool _AP_S2>
876 template <
int _AP_W2,
bool _AP_S2>
883 template <
int _AP_W2,
bool _AP_S2>
890 template <
int _AP_W2,
typename _AP_T2,
int _AP_W3,
typename _AP_T3>
899 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
900 ap_o_mode _AP_O2,
int _AP_N2>
914 template <
int _AP_W2,
int _AP_I2,
bool _AP_S2, ap_q_mode _AP_Q2,
915 ap_o_mode _AP_O2,
int _AP_N2>
929 template <
int _AP_W2,
bool _AP_S2>
931 return get() == op.get();
934 template <
int _AP_W2,
bool _AP_S2>
936 return get() != op.get();
939 INLINE
bool get()
const {
return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
941 INLINE
bool get() {
return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
943 template <
int _AP_W3>
948 INLINE
bool operator~()
const {
949 bool bit = _AP_ROOT_op_get_bit(d_bv.V, d_index);
950 return bit ? false :
true;
953 INLINE
int length()
const {
return 1; }
956 std::string to_string()
const {
return get() ?
"1" :
"0"; }
959 INLINE
char* to_string()
const {
return 0; }
967#define REF_REL_OP_WITH_INT(REL_OP, C_TYPE, _AP_W2, _AP_S2) \
968 template <int _AP_W, bool _AP_S> \
969 INLINE bool operator REL_OP(const ap_range_ref<_AP_W, _AP_S>& op, \
971 return ap_int_base<_AP_W, false>(op) \
972 REL_OP ap_int_base<_AP_W2, _AP_S2>(op2); \
974 template <int _AP_W, bool _AP_S> \
975 INLINE bool operator REL_OP(const ap_bit_ref<_AP_W, _AP_S>& op, \
977 return bool(op) REL_OP op2; \
979 template <int _AP_W, bool _AP_S> \
980 INLINE bool operator REL_OP(C_TYPE op2, \
981 const ap_bit_ref<_AP_W, _AP_S>& op) { \
982 return op2 REL_OP bool(op); \
984 template <int _AP_W, typename _AP_T, int _AP_W1, typename _AP_T1> \
985 INLINE bool operator REL_OP( \
986 const ap_concat_ref<_AP_W, _AP_T, _AP_W1, _AP_T1>& op, C_TYPE op2) { \
987 return ap_int_base<_AP_W + _AP_W1, false>(op) \
988 REL_OP ap_int_base<_AP_W2, _AP_S2>(op2); \
992#define REF_REL_WITH_INT_1(C_TYPE, _AP_WI, _AP_SI) \
993 REF_REL_OP_WITH_INT(>, C_TYPE, _AP_WI, _AP_SI) \
994 REF_REL_OP_WITH_INT(<, C_TYPE, _AP_WI, _AP_SI) \
995 REF_REL_OP_WITH_INT(>=, C_TYPE, _AP_WI, _AP_SI) \
996 REF_REL_OP_WITH_INT(<=, C_TYPE, _AP_WI, _AP_SI)
998REF_REL_WITH_INT_1(
bool, 1,
false)
999REF_REL_WITH_INT_1(
char, 8, CHAR_IS_SIGNED)
1000REF_REL_WITH_INT_1(
signed char, 8, true)
1001REF_REL_WITH_INT_1(
unsigned char, 8, false)
1002REF_REL_WITH_INT_1(
short, _AP_SIZE_short, true)
1003REF_REL_WITH_INT_1(
unsigned short, _AP_SIZE_short, false)
1004REF_REL_WITH_INT_1(
int, _AP_SIZE_int, true)
1005REF_REL_WITH_INT_1(
unsigned int, _AP_SIZE_int, false)
1006REF_REL_WITH_INT_1(
long, _AP_SIZE_long, true)
1007REF_REL_WITH_INT_1(
unsigned long, _AP_SIZE_long, false)
1008REF_REL_WITH_INT_1(ap_slong, _AP_SIZE_ap_slong, true)
1009REF_REL_WITH_INT_1(ap_ulong, _AP_SIZE_ap_slong, false)
1012#define REF_REL_WITH_INT_2(C_TYPE, _AP_WI, _AP_SI) \
1013 REF_REL_OP_WITH_INT(==, C_TYPE, _AP_WI, _AP_SI) \
1014 REF_REL_OP_WITH_INT(!=, C_TYPE, _AP_WI, _AP_SI)
1016REF_REL_WITH_INT_2(
bool, 1,
false)
1017REF_REL_WITH_INT_2(
char, 8, CHAR_IS_SIGNED)
1018REF_REL_WITH_INT_2(
signed char, 8, true)
1019REF_REL_WITH_INT_2(
unsigned char, 8, false)
1020REF_REL_WITH_INT_2(
short, _AP_SIZE_short, true)
1021REF_REL_WITH_INT_2(
unsigned short, _AP_SIZE_short, false)
1022REF_REL_WITH_INT_2(
int, _AP_SIZE_int, true)
1023REF_REL_WITH_INT_2(
unsigned int, _AP_SIZE_int, false)
1024REF_REL_WITH_INT_2(
long, _AP_SIZE_long, true)
1025REF_REL_WITH_INT_2(
unsigned long, _AP_SIZE_long, false)
1026REF_REL_WITH_INT_2(ap_slong, _AP_SIZE_ap_slong, true)
1027REF_REL_WITH_INT_2(ap_ulong, _AP_SIZE_ap_slong, false)
1029#undef REF_REL_OP_WITH_INT
1030#undef REF_REL_WITH_INT_1
1031#undef REF_REL_WITH_INT_2
1033#define REF_BIN_OP_WITH_INT(BIN_OP, RTYPE, C_TYPE, _AP_W2, _AP_S2) \
1034 template <int _AP_W, bool _AP_S> \
1035 INLINE typename ap_int_base<_AP_W, false>::template RType<_AP_W2, \
1037 operator BIN_OP(const ap_range_ref<_AP_W, _AP_S>& op, C_TYPE op2) { \
1038 return ap_int_base<_AP_W, false>(op) \
1039 BIN_OP ap_int_base<_AP_W2, _AP_S2>(op2); \
1041 template <int _AP_W, bool _AP_S> \
1042 INLINE typename ap_int_base<_AP_W2, _AP_S2>::template RType<_AP_W, \
1044 operator BIN_OP(C_TYPE op2, const ap_range_ref<_AP_W, _AP_S>& op) { \
1045 return ap_int_base<_AP_W2, _AP_S2>(op2) \
1046 BIN_OP ap_int_base<_AP_W, false>(op); \
1050#define REF_BIN_OP_WITH_INT_ARITH(C_TYPE, _AP_W2, _AP_S2) \
1051 REF_BIN_OP_WITH_INT(+, plus, C_TYPE, (_AP_W2), (_AP_S2)) \
1052 REF_BIN_OP_WITH_INT(-, minus, C_TYPE, (_AP_W2), (_AP_S2)) \
1053 REF_BIN_OP_WITH_INT(*, mult, C_TYPE, (_AP_W2), (_AP_S2)) \
1054 REF_BIN_OP_WITH_INT(/, div, C_TYPE, (_AP_W2), (_AP_S2)) \
1055 REF_BIN_OP_WITH_INT(%, mod, C_TYPE, (_AP_W2), (_AP_S2))
1057REF_BIN_OP_WITH_INT_ARITH(
bool, 1,
false)
1058REF_BIN_OP_WITH_INT_ARITH(
char, 8, CHAR_IS_SIGNED)
1059REF_BIN_OP_WITH_INT_ARITH(
signed char, 8, true)
1060REF_BIN_OP_WITH_INT_ARITH(
unsigned char, 8, false)
1061REF_BIN_OP_WITH_INT_ARITH(
short, _AP_SIZE_short, true)
1062REF_BIN_OP_WITH_INT_ARITH(
unsigned short, _AP_SIZE_short, false)
1063REF_BIN_OP_WITH_INT_ARITH(
int, _AP_SIZE_int, true)
1064REF_BIN_OP_WITH_INT_ARITH(
unsigned int, _AP_SIZE_int, false)
1065REF_BIN_OP_WITH_INT_ARITH(
long, _AP_SIZE_long, true)
1066REF_BIN_OP_WITH_INT_ARITH(
unsigned long, _AP_SIZE_long, false)
1067REF_BIN_OP_WITH_INT_ARITH(ap_slong, _AP_SIZE_ap_slong, true)
1068REF_BIN_OP_WITH_INT_ARITH(ap_ulong, _AP_SIZE_ap_slong, false)
1070#undef REF_BIN_OP_WITH_INT_ARITH
1073#define REF_BIN_OP_WITH_INT_BITS(C_TYPE, _AP_W2, _AP_S2) \
1074 REF_BIN_OP_WITH_INT(&, logic, C_TYPE, (_AP_W2), (_AP_S2)) \
1075 REF_BIN_OP_WITH_INT(|, logic, C_TYPE, (_AP_W2), (_AP_S2)) \
1076 REF_BIN_OP_WITH_INT(^, logic, C_TYPE, (_AP_W2), (_AP_S2)) \
1077 REF_BIN_OP_WITH_INT(>>, arg1, C_TYPE, (_AP_W2), (_AP_S2)) \
1078 REF_BIN_OP_WITH_INT(<<, arg1, C_TYPE, (_AP_W2), (_AP_S2))
1080REF_BIN_OP_WITH_INT_BITS(
bool, 1,
false)
1081REF_BIN_OP_WITH_INT_BITS(
char, 8, CHAR_IS_SIGNED)
1082REF_BIN_OP_WITH_INT_BITS(
signed char, 8, true)
1083REF_BIN_OP_WITH_INT_BITS(
unsigned char, 8, false)
1084REF_BIN_OP_WITH_INT_BITS(
short, _AP_SIZE_short, true)
1085REF_BIN_OP_WITH_INT_BITS(
unsigned short, _AP_SIZE_short, false)
1086REF_BIN_OP_WITH_INT_BITS(
int, _AP_SIZE_int, true)
1087REF_BIN_OP_WITH_INT_BITS(
unsigned int, _AP_SIZE_int, false)
1088REF_BIN_OP_WITH_INT_BITS(
long, _AP_SIZE_long, true)
1089REF_BIN_OP_WITH_INT_BITS(
unsigned long, _AP_SIZE_long, false)
1090REF_BIN_OP_WITH_INT_BITS(ap_slong, _AP_SIZE_ap_slong, true)
1091REF_BIN_OP_WITH_INT_BITS(ap_ulong, _AP_SIZE_ap_slong, false)
1093#undef REF_BIN_OP_WITH_INT_BITS
1098#define REF_BIN_OP(BIN_OP, RTYPE) \
1099 template <int _AP_W, bool _AP_S, int _AP_W2, bool _AP_S2> \
1101 typename ap_int_base<_AP_W, false>::template RType<_AP_W2, false>::RTYPE \
1102 operator BIN_OP(const ap_range_ref<_AP_W, _AP_S>& lhs, \
1103 const ap_range_ref<_AP_W2, _AP_S2>& rhs) { \
1104 return (lhs.operator ap_int_base<_AP_W, false>())BIN_OP( \
1105 rhs.operator ap_int_base<_AP_W2, false>()); \
1144#undef SYN_CONCAT_REF_BIN_OP
1146#define SYN_CONCAT_REF_BIN_OP(BIN_OP, RTYPE) \
1147 template <int _AP_LW1, typename _AP_LT1, int _AP_LW2, typename _AP_LT2, \
1148 int _AP_RW1, typename _AP_RT1, int _AP_RW2, typename _AP_RT2> \
1149 INLINE typename ap_int_base<_AP_LW1 + _AP_LW2, false>::template RType< \
1150 _AP_RW1 + _AP_RW2, false>::RTYPE \
1152 const ap_concat_ref<_AP_LW1, _AP_LT1, _AP_LW2, _AP_LT2>& lhs, \
1153 const ap_concat_ref<_AP_RW1, _AP_RT1, _AP_RW2, _AP_RT2>& rhs) { \
1154 return lhs.get() BIN_OP rhs.get(); \
1157SYN_CONCAT_REF_BIN_OP(+, plus)
1158SYN_CONCAT_REF_BIN_OP(-, minus)
1159SYN_CONCAT_REF_BIN_OP(*, mult)
1160SYN_CONCAT_REF_BIN_OP(/, div)
1161SYN_CONCAT_REF_BIN_OP(%, mod)
1162SYN_CONCAT_REF_BIN_OP(&, logic)
1163SYN_CONCAT_REF_BIN_OP(|, logic)
1164SYN_CONCAT_REF_BIN_OP(^, logic)
1165SYN_CONCAT_REF_BIN_OP(>>, arg1)
1166SYN_CONCAT_REF_BIN_OP(<<, arg1)
1168#undef SYN_CONCAT_REF_BIN_OP
1170#define CONCAT_OP_WITH_INT(C_TYPE, _AP_WI, _AP_SI) \
1171 template <int _AP_W, bool _AP_S> \
1172 INLINE ap_int_base<_AP_W + _AP_WI, false> operator,( \
1173 const ap_int_base<_AP_W, _AP_S>&op1, C_TYPE op2) { \
1174 ap_int_base<_AP_WI + _AP_W, false> val(op2); \
1175 ap_int_base<_AP_WI + _AP_W, false> ret(op1); \
1184 template <int _AP_W, bool _AP_S> \
1185 INLINE ap_int_base<_AP_W + _AP_WI, false> operator,( \
1186 C_TYPE op1, const ap_int_base<_AP_W, _AP_S>&op2) { \
1187 ap_int_base<_AP_WI + _AP_W, false> val(op1); \
1188 ap_int_base<_AP_WI + _AP_W, false> ret(op2); \
1193 ret |= val << _AP_W; \
1196 template <int _AP_W, bool _AP_S> \
1197 INLINE ap_int_base<_AP_W + _AP_WI, false> operator,( \
1198 const ap_range_ref<_AP_W, _AP_S>&op1, C_TYPE op2) { \
1199 ap_int_base<_AP_WI + _AP_W, false> val(op2); \
1200 ap_int_base<_AP_WI + _AP_W, false> ret(op1); \
1209 template <int _AP_W, bool _AP_S> \
1210 INLINE ap_int_base<_AP_W + _AP_WI, false> operator,( \
1211 C_TYPE op1, const ap_range_ref<_AP_W, _AP_S>&op2) { \
1212 ap_int_base<_AP_WI + _AP_W, false> val(op1); \
1213 ap_int_base<_AP_WI + _AP_W, false> ret(op2); \
1214 int len = op2.length(); \
1219 template <int _AP_W, bool _AP_S> \
1220 INLINE ap_int_base<_AP_WI + 1, false> operator,( \
1221 const ap_bit_ref<_AP_W, _AP_S>&op1, C_TYPE op2) { \
1222 ap_int_base<_AP_WI + 1, false> val(op2); \
1223 val[_AP_WI] = op1; \
1226 template <int _AP_W, bool _AP_S> \
1227 INLINE ap_int_base<_AP_WI + 1, false> operator,( \
1228 C_TYPE op1, const ap_bit_ref<_AP_W, _AP_S>&op2) { \
1229 ap_int_base<_AP_WI + 1, false> val(op1); \
1234 template <int _AP_W, typename _AP_T, int _AP_W2, typename _AP_T2> \
1235 INLINE ap_int_base<_AP_W + _AP_W2 + _AP_WI, false> operator,( \
1236 const ap_concat_ref<_AP_W, _AP_T, _AP_W2, _AP_T2>&op1, C_TYPE op2) { \
1237 ap_int_base<_AP_WI + _AP_W + _AP_W2, _AP_SI> val(op2); \
1238 ap_int_base<_AP_WI + _AP_W + _AP_W2, _AP_SI> ret(op1); \
1240 val <<= _AP_W + _AP_W2; \
1241 val >>= _AP_W + _AP_W2; \
1247 template <int _AP_W, typename _AP_T, int _AP_W2, typename _AP_T2> \
1248 INLINE ap_int_base<_AP_W + _AP_W2 + _AP_WI, false> operator,( \
1249 C_TYPE op1, const ap_concat_ref<_AP_W, _AP_T, _AP_W2, _AP_T2>&op2) { \
1250 ap_int_base<_AP_WI + _AP_W + _AP_W2, _AP_SI> val(op1); \
1251 ap_int_base<_AP_WI + _AP_W + _AP_W2, _AP_SI> ret(op2); \
1252 int len = op2.length(); \
1257 template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
1258 ap_o_mode _AP_O, int _AP_N> \
1259 INLINE ap_int_base<_AP_W + _AP_WI, false> operator,( \
1260 const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>&op1, \
1262 ap_int_base<_AP_WI + _AP_W, false> val(op2); \
1263 ap_int_base<_AP_WI + _AP_W, false> ret(op1); \
1272 template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
1273 ap_o_mode _AP_O, int _AP_N> \
1274 INLINE ap_int_base<_AP_W + _AP_WI, false> operator,( \
1276 const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>&op2) { \
1277 ap_int_base<_AP_WI + _AP_W, false> val(op1); \
1278 ap_int_base<_AP_WI + _AP_W, false> ret(op2); \
1279 int len = op2.length(); \
1284 template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
1285 ap_o_mode _AP_O, int _AP_N> \
1286 INLINE ap_int_base<1 + _AP_WI, false> operator,( \
1287 const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>&op1, \
1289 ap_int_base<_AP_WI + 1, _AP_SI> val(op2); \
1290 val[_AP_WI] = op1; \
1293 template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
1294 ap_o_mode _AP_O, int _AP_N> \
1295 INLINE ap_int_base<1 + _AP_WI, false> operator,( \
1297 const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>&op2) { \
1298 ap_int_base<_AP_WI + 1, _AP_SI> val(op1); \
1304CONCAT_OP_WITH_INT(
bool, 1,
false)
1305CONCAT_OP_WITH_INT(
char, 8, CHAR_IS_SIGNED)
1306CONCAT_OP_WITH_INT(
signed char, 8, true)
1307CONCAT_OP_WITH_INT(
unsigned char, 8, false)
1308CONCAT_OP_WITH_INT(
short, _AP_SIZE_short, true)
1309CONCAT_OP_WITH_INT(
unsigned short, _AP_SIZE_short, false)
1310CONCAT_OP_WITH_INT(
int, _AP_SIZE_int, true)
1311CONCAT_OP_WITH_INT(
unsigned int, _AP_SIZE_int, false)
1312CONCAT_OP_WITH_INT(
long, _AP_SIZE_long, true)
1313CONCAT_OP_WITH_INT(
unsigned long, _AP_SIZE_long, false)
1314CONCAT_OP_WITH_INT(ap_slong, _AP_SIZE_ap_slong, true)
1315CONCAT_OP_WITH_INT(ap_ulong, _AP_SIZE_ap_slong, false)
1317#undef CONCAT_OP_WITH_INT
1319#define CONCAT_SHIFT_WITH_INT(C_TYPE, OP) \
1320 template <int _AP_W, typename _AP_T, int _AP_W1, typename _AP_T1> \
1321 INLINE ap_uint<_AP_W + _AP_W1> operator OP( \
1322 const ap_concat_ref<_AP_W, _AP_T, _AP_W1, _AP_T1> lhs, C_TYPE rhs) { \
1323 return ap_uint<_AP_W + _AP_W1>(lhs).get() OP int(rhs); \
1328CONCAT_SHIFT_WITH_INT(
int, <<)
1329CONCAT_SHIFT_WITH_INT(
unsigned int, <<)
1330CONCAT_SHIFT_WITH_INT(
long, <<)
1331CONCAT_SHIFT_WITH_INT(
unsigned long, <<)
1332CONCAT_SHIFT_WITH_INT(ap_slong, <<)
1333CONCAT_SHIFT_WITH_INT(ap_ulong, <<)
1335CONCAT_SHIFT_WITH_INT(
int, >>)
1336CONCAT_SHIFT_WITH_INT(
unsigned int, >>)
1337CONCAT_SHIFT_WITH_INT(
long, >>)
1338CONCAT_SHIFT_WITH_INT(
unsigned long, >>)
1339CONCAT_SHIFT_WITH_INT(ap_slong, >>)
1340CONCAT_SHIFT_WITH_INT(ap_ulong, >>)