da4ml 0.5.0__cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. da4ml/__init__.py +4 -0
  2. da4ml/_binary/__init__.py +15 -0
  3. da4ml/_binary/dais_bin.cpython-312-x86_64-linux-gnu.so +0 -0
  4. da4ml/_binary/dais_bin.pyi +5 -0
  5. da4ml/_cli/__init__.py +30 -0
  6. da4ml/_cli/convert.py +194 -0
  7. da4ml/_cli/report.py +295 -0
  8. da4ml/_version.py +32 -0
  9. da4ml/cmvm/__init__.py +4 -0
  10. da4ml/cmvm/api.py +264 -0
  11. da4ml/cmvm/core/__init__.py +221 -0
  12. da4ml/cmvm/core/indexers.py +83 -0
  13. da4ml/cmvm/core/state_opr.py +284 -0
  14. da4ml/cmvm/types.py +739 -0
  15. da4ml/cmvm/util/__init__.py +7 -0
  16. da4ml/cmvm/util/bit_decompose.py +86 -0
  17. da4ml/cmvm/util/mat_decompose.py +121 -0
  18. da4ml/codegen/__init__.py +9 -0
  19. da4ml/codegen/hls/__init__.py +4 -0
  20. da4ml/codegen/hls/hls_codegen.py +196 -0
  21. da4ml/codegen/hls/hls_model.py +255 -0
  22. da4ml/codegen/hls/source/ap_types/ap_binary.h +78 -0
  23. da4ml/codegen/hls/source/ap_types/ap_common.h +376 -0
  24. da4ml/codegen/hls/source/ap_types/ap_decl.h +212 -0
  25. da4ml/codegen/hls/source/ap_types/ap_fixed.h +360 -0
  26. da4ml/codegen/hls/source/ap_types/ap_fixed_base.h +2354 -0
  27. da4ml/codegen/hls/source/ap_types/ap_fixed_ref.h +718 -0
  28. da4ml/codegen/hls/source/ap_types/ap_fixed_special.h +230 -0
  29. da4ml/codegen/hls/source/ap_types/ap_int.h +330 -0
  30. da4ml/codegen/hls/source/ap_types/ap_int_base.h +1885 -0
  31. da4ml/codegen/hls/source/ap_types/ap_int_ref.h +1346 -0
  32. da4ml/codegen/hls/source/ap_types/ap_int_special.h +223 -0
  33. da4ml/codegen/hls/source/ap_types/ap_shift_reg.h +138 -0
  34. da4ml/codegen/hls/source/ap_types/etc/ap_private.h +7199 -0
  35. da4ml/codegen/hls/source/ap_types/hls_math.h +27 -0
  36. da4ml/codegen/hls/source/ap_types/hls_stream.h +263 -0
  37. da4ml/codegen/hls/source/ap_types/utils/x_hls_utils.h +80 -0
  38. da4ml/codegen/hls/source/binder_util.hh +71 -0
  39. da4ml/codegen/hls/source/build_binder.mk +22 -0
  40. da4ml/codegen/hls/source/vitis_bitshift.hh +32 -0
  41. da4ml/codegen/rtl/__init__.py +15 -0
  42. da4ml/codegen/rtl/common_source/binder_util.hh +99 -0
  43. da4ml/codegen/rtl/common_source/build_binder.mk +34 -0
  44. da4ml/codegen/rtl/common_source/build_quartus_prj.tcl +104 -0
  45. da4ml/codegen/rtl/common_source/build_vivado_prj.tcl +111 -0
  46. da4ml/codegen/rtl/common_source/ioutil.hh +124 -0
  47. da4ml/codegen/rtl/common_source/template.sdc +27 -0
  48. da4ml/codegen/rtl/common_source/template.xdc +30 -0
  49. da4ml/codegen/rtl/rtl_model.py +486 -0
  50. da4ml/codegen/rtl/verilog/__init__.py +10 -0
  51. da4ml/codegen/rtl/verilog/comb.py +239 -0
  52. da4ml/codegen/rtl/verilog/io_wrapper.py +113 -0
  53. da4ml/codegen/rtl/verilog/pipeline.py +67 -0
  54. da4ml/codegen/rtl/verilog/source/lookup_table.v +27 -0
  55. da4ml/codegen/rtl/verilog/source/multiplier.v +37 -0
  56. da4ml/codegen/rtl/verilog/source/mux.v +58 -0
  57. da4ml/codegen/rtl/verilog/source/negative.v +31 -0
  58. da4ml/codegen/rtl/verilog/source/shift_adder.v +59 -0
  59. da4ml/codegen/rtl/vhdl/__init__.py +9 -0
  60. da4ml/codegen/rtl/vhdl/comb.py +206 -0
  61. da4ml/codegen/rtl/vhdl/io_wrapper.py +120 -0
  62. da4ml/codegen/rtl/vhdl/pipeline.py +71 -0
  63. da4ml/codegen/rtl/vhdl/source/lookup_table.vhd +52 -0
  64. da4ml/codegen/rtl/vhdl/source/multiplier.vhd +40 -0
  65. da4ml/codegen/rtl/vhdl/source/mux.vhd +102 -0
  66. da4ml/codegen/rtl/vhdl/source/negative.vhd +35 -0
  67. da4ml/codegen/rtl/vhdl/source/shift_adder.vhd +101 -0
  68. da4ml/converter/__init__.py +63 -0
  69. da4ml/converter/hgq2/__init__.py +3 -0
  70. da4ml/converter/hgq2/layers/__init__.py +11 -0
  71. da4ml/converter/hgq2/layers/_base.py +132 -0
  72. da4ml/converter/hgq2/layers/activation.py +81 -0
  73. da4ml/converter/hgq2/layers/attn.py +148 -0
  74. da4ml/converter/hgq2/layers/batchnorm.py +15 -0
  75. da4ml/converter/hgq2/layers/conv.py +149 -0
  76. da4ml/converter/hgq2/layers/dense.py +39 -0
  77. da4ml/converter/hgq2/layers/ops.py +240 -0
  78. da4ml/converter/hgq2/layers/pool.py +107 -0
  79. da4ml/converter/hgq2/layers/table.py +176 -0
  80. da4ml/converter/hgq2/parser.py +161 -0
  81. da4ml/trace/__init__.py +6 -0
  82. da4ml/trace/fixed_variable.py +965 -0
  83. da4ml/trace/fixed_variable_array.py +600 -0
  84. da4ml/trace/ops/__init__.py +13 -0
  85. da4ml/trace/ops/einsum_utils.py +305 -0
  86. da4ml/trace/ops/quantization.py +74 -0
  87. da4ml/trace/ops/reduce_utils.py +105 -0
  88. da4ml/trace/pipeline.py +181 -0
  89. da4ml/trace/tracer.py +186 -0
  90. da4ml/typing/__init__.py +3 -0
  91. da4ml-0.5.0.dist-info/METADATA +85 -0
  92. da4ml-0.5.0.dist-info/RECORD +96 -0
  93. da4ml-0.5.0.dist-info/WHEEL +6 -0
  94. da4ml-0.5.0.dist-info/entry_points.txt +3 -0
  95. da4ml-0.5.0.dist-info/sboms/auditwheel.cdx.json +1 -0
  96. da4ml.libs/libgomp-e985bcbb.so.1.0.0 +0 -0
@@ -0,0 +1,718 @@
1
+ /*
2
+ * Copyright 2011-2019 Xilinx, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef __AP_FIXED_REF_H__
18
+ #define __AP_FIXED_REF_H__
19
+
20
+ #ifndef __AP_FIXED_H__
21
+ #error "Only ap_fixed.h and ap_int.h can be included directly in user code."
22
+ #endif
23
+
24
+ #ifndef __cplusplus
25
+ #error "C++ is required to include this header file"
26
+
27
+ #else
28
+ #ifndef __SYNTHESIS__
29
+ #include <iostream>
30
+ #endif
31
+ /// Proxy class, which allows bit selection to be used as both rvalue (for
32
+ /// reading) and lvalue (for writing)
33
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
34
+ int _AP_N>
35
+ struct af_bit_ref {
36
+ #ifdef _MSC_VER
37
+ #pragma warning(disable : 4521 4522)
38
+ #endif
39
+ typedef ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> ref_type;
40
+ ref_type& d_bv;
41
+ int d_index;
42
+
43
+ public:
44
+ INLINE af_bit_ref(
45
+ const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ref)
46
+ : d_bv(ref.d_bv), d_index(ref.d_index) {
47
+ #ifndef __SYNTHESIS__
48
+ _AP_WARNING(d_index < 0, "Index of bit vector (%d) cannot be negative.",
49
+ d_index);
50
+ _AP_WARNING(d_index >= _AP_W, "Index of bit vector (%d) out of range (%d).",
51
+ d_index, _AP_W);
52
+ #endif
53
+ }
54
+
55
+ INLINE af_bit_ref(ref_type* bv, int index = 0) : d_bv(*bv), d_index(index) {}
56
+
57
+ INLINE af_bit_ref(const ref_type* bv, int index = 0)
58
+ : d_bv(*const_cast<ref_type*>(bv)), d_index(index) {}
59
+
60
+ /// convert operators.
61
+ INLINE operator bool() const { return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
62
+
63
+ /// @name assign operators
64
+ // @{
65
+ INLINE af_bit_ref& operator=(bool val) {
66
+ d_bv.V = _AP_ROOT_op_set_bit(d_bv.V, d_index, val);
67
+ return *this;
68
+ }
69
+
70
+ // Be explicit to prevent it from being deleted, as field d_bv
71
+ // is of reference type.
72
+ INLINE af_bit_ref& operator=(const af_bit_ref& val) {
73
+ return operator=(bool(val));
74
+ }
75
+
76
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
77
+ ap_o_mode _AP_O2, int _AP_N2>
78
+ INLINE af_bit_ref& operator=(
79
+ const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
80
+ return operator=(bool(val));
81
+ }
82
+
83
+ template <int _AP_W2, bool _AP_S2>
84
+ INLINE af_bit_ref& operator=(const ap_bit_ref<_AP_W2, _AP_S2>& val) {
85
+ return operator=(bool(val));
86
+ }
87
+
88
+ template <int _AP_W2, bool _AP_S2>
89
+ INLINE af_bit_ref& operator=(const ap_int_base<_AP_W2, _AP_S2>& val) {
90
+ return operator=(val != 0);
91
+ }
92
+
93
+ template <int _AP_W2, bool _AP_S2>
94
+ INLINE af_bit_ref& operator=(const ap_range_ref<_AP_W2, _AP_S2>& val) {
95
+ return operator=(ap_int_base<_AP_W2, false>(val));
96
+ }
97
+
98
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
99
+ ap_o_mode _AP_O2, int _AP_N2>
100
+ INLINE af_bit_ref& operator=(
101
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
102
+ return operator=(ap_int_base<_AP_W2, false>(val));
103
+ }
104
+
105
+ template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
106
+ INLINE af_bit_ref& operator=(
107
+ const ap_concat_ref<_AP_W2, _AP_T3, _AP_W3, _AP_T3>& val) {
108
+ return operator=(ap_int_base<_AP_W2 + _AP_W3, false>(val));
109
+ }
110
+ // @}
111
+
112
+ /// @name concatenate operators
113
+ // @{
114
+ template <int _AP_W2, int _AP_S2>
115
+ INLINE ap_concat_ref<1, af_bit_ref, _AP_W2, ap_int_base<_AP_W2, _AP_S2> >
116
+ operator,(ap_int_base<_AP_W2, _AP_S2> &op) {
117
+ return ap_concat_ref<1, af_bit_ref, _AP_W2, ap_int_base<_AP_W2, _AP_S2> >(
118
+ *this, op);
119
+ }
120
+
121
+ template <int _AP_W2, int _AP_S2>
122
+ INLINE ap_concat_ref<1, af_bit_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> > operator,(
123
+ const ap_bit_ref<_AP_W2, _AP_S2> &op) {
124
+ return ap_concat_ref<1, af_bit_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >(*this,
125
+ op);
126
+ }
127
+
128
+ template <int _AP_W2, int _AP_S2>
129
+ INLINE ap_concat_ref<1, af_bit_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >
130
+ operator,(const ap_range_ref<_AP_W2, _AP_S2> &op) {
131
+ return ap_concat_ref<1, af_bit_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >(
132
+ *this, op);
133
+ }
134
+
135
+ template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
136
+ INLINE ap_concat_ref<1, af_bit_ref, _AP_W2 + _AP_W3,
137
+ ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
138
+ operator,(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &op) {
139
+ return ap_concat_ref<1, af_bit_ref, _AP_W2 + _AP_W3,
140
+ ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(*this,
141
+ op);
142
+ }
143
+
144
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
145
+ ap_o_mode _AP_O2, int _AP_N2>
146
+ INLINE ap_concat_ref<
147
+ 1, af_bit_ref, _AP_W2,
148
+ af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
149
+ operator,(
150
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> &op) {
151
+ return ap_concat_ref<
152
+ 1, af_bit_ref, _AP_W2,
153
+ af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
154
+ op);
155
+ }
156
+
157
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
158
+ ap_o_mode _AP_O2, int _AP_N2>
159
+ INLINE ap_concat_ref<1, af_bit_ref, 1, af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
160
+ _AP_Q2, _AP_O2, _AP_N2> >
161
+ operator,(
162
+ const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> &op) {
163
+ return ap_concat_ref<1, af_bit_ref, 1, af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
164
+ _AP_Q2, _AP_O2, _AP_N2> >(
165
+ *this,
166
+ const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&>(
167
+ op));
168
+ }
169
+ // @}
170
+
171
+ /// @name comparison
172
+ // @{
173
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
174
+ ap_o_mode _AP_O2, int _AP_N2>
175
+ INLINE bool operator==(
176
+ const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
177
+ return get() == op.get();
178
+ }
179
+
180
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
181
+ ap_o_mode _AP_O2, int _AP_N2>
182
+ INLINE bool operator!=(
183
+ const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
184
+ return get() != op.get();
185
+ }
186
+ // @}
187
+
188
+ INLINE bool operator~() const {
189
+ bool bit = _AP_ROOT_op_get_bit(d_bv.V, d_index);
190
+ return bit ? false : true;
191
+ }
192
+
193
+ INLINE bool get() const { return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
194
+
195
+ INLINE int length() const { return 1; }
196
+
197
+ #ifndef __SYNTHESIS__
198
+ std::string to_string() const { return get() ? "1" : "0"; }
199
+ #else
200
+ // XXX HLS will delete this in synthesis
201
+ INLINE char* to_string() const { return 0; }
202
+ #endif
203
+ }; // struct af_bit_ref
204
+
205
+ // XXX apcc cannot handle global std::ios_base::Init() brought in by <iostream>
206
+ #ifndef AP_AUTOCC
207
+ #ifndef __SYNTHESIS__
208
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
209
+ int _AP_N>
210
+ INLINE std::ostream& operator<<(
211
+ std::ostream& os,
212
+ const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& x) {
213
+ os << x.to_string();
214
+ return os;
215
+ }
216
+ #endif // ifndef __SYNTHESIS__
217
+ #endif // ifndef AP_AUTOCC
218
+
219
+ /// Range (slice) reference.
220
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
221
+ int _AP_N>
222
+ struct af_range_ref {
223
+ #ifdef _MSC_VER
224
+ #pragma warning(disable : 4521 4522)
225
+ #endif
226
+ typedef ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> ref_type;
227
+ ref_type& d_bv;
228
+ int l_index;
229
+ int h_index;
230
+
231
+ public:
232
+ /// copy ctor
233
+ INLINE af_range_ref(
234
+ const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ref)
235
+ : d_bv(ref.d_bv), l_index(ref.l_index), h_index(ref.h_index) {}
236
+
237
+ /// ctor from ap_fixed_base, higher and lower bound.
238
+ /** if h is less than l, the bits selected will be returned in reverse order.
239
+ */
240
+ INLINE af_range_ref(ref_type* bv, int h, int l)
241
+ : d_bv(*bv), l_index(l), h_index(h) {
242
+ #ifndef __SYNTHESIS__
243
+ _AP_WARNING(h < 0 || l < 0,
244
+ "Higher bound(%d) and lower(%d) bound cannot be negative.", h,
245
+ l);
246
+ _AP_WARNING(h >= _AP_W || l >= _AP_W,
247
+ "Higher bound(%d) or lower(%d) bound out of range.", h, l);
248
+ _AP_WARNING(h < l, "The bits selected will be returned in reverse order.");
249
+ #endif
250
+ }
251
+
252
+ INLINE af_range_ref(const ref_type* bv, int h, int l)
253
+ : d_bv(*const_cast<ref_type*>(bv)), l_index(l), h_index(h) {
254
+ #ifndef __SYNTHESIS__
255
+ _AP_WARNING(h < 0 || l < 0,
256
+ "Higher bound(%d) and lower(%d) bound cannot be negative.", h,
257
+ l);
258
+ _AP_WARNING(h >= _AP_W || l >= _AP_W,
259
+ "Higher bound(%d) or lower(%d) bound out of range.", h, l);
260
+ _AP_WARNING(h < l, "The bits selected will be returned in reverse order.");
261
+ #endif
262
+ }
263
+
264
+ /// @name assign operators
265
+ // @{
266
+
267
+ #define ASSIGN_CTYPE_TO_AF_RANGE(DATA_TYPE) \
268
+ INLINE af_range_ref& operator=(const DATA_TYPE val) { \
269
+ ap_int_base<_AP_W, false> loc(val); \
270
+ d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, loc.V); \
271
+ return *this; \
272
+ }
273
+
274
+ ASSIGN_CTYPE_TO_AF_RANGE(bool)
275
+ ASSIGN_CTYPE_TO_AF_RANGE(char)
276
+ ASSIGN_CTYPE_TO_AF_RANGE(signed char)
277
+ ASSIGN_CTYPE_TO_AF_RANGE(unsigned char)
278
+ ASSIGN_CTYPE_TO_AF_RANGE(short)
279
+ ASSIGN_CTYPE_TO_AF_RANGE(unsigned short)
280
+ ASSIGN_CTYPE_TO_AF_RANGE(int)
281
+ ASSIGN_CTYPE_TO_AF_RANGE(unsigned int)
282
+ ASSIGN_CTYPE_TO_AF_RANGE(long)
283
+ ASSIGN_CTYPE_TO_AF_RANGE(unsigned long)
284
+ ASSIGN_CTYPE_TO_AF_RANGE(ap_slong)
285
+ ASSIGN_CTYPE_TO_AF_RANGE(ap_ulong)
286
+ #if _AP_ENABLE_HALF_ == 1
287
+ ASSIGN_CTYPE_TO_AF_RANGE(half)
288
+ #endif
289
+ ASSIGN_CTYPE_TO_AF_RANGE(float)
290
+ ASSIGN_CTYPE_TO_AF_RANGE(double)
291
+ #undef ASSIGN_CTYPE_TO_AF_RANGE
292
+
293
+ /// assgin using a string. XXX crucial for cosim.
294
+ INLINE af_range_ref& operator=(const char* val) {
295
+ const ap_int_base<_AP_W, false> tmp(val); // XXX figure out radix
296
+ d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, tmp.V);
297
+ return *this;
298
+ }
299
+
300
+ /// assign from ap_int_base.
301
+ // NOTE Base of other assgin operators.
302
+ template <int _AP_W3, bool _AP_S3>
303
+ INLINE af_range_ref& operator=(const ap_int_base<_AP_W3, _AP_S3>& val) {
304
+ d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
305
+ return *this;
306
+ }
307
+
308
+ /// assign from range reference to ap_int_base.
309
+ template <int _AP_W2, bool _AP_S2>
310
+ INLINE af_range_ref& operator=(const ap_range_ref<_AP_W2, _AP_S2>& val) {
311
+ const ap_int_base<_AP_W2, false> tmp(val);
312
+ return operator=(tmp);
313
+ }
314
+
315
+ /// assign from bit reference to ap_int_base..
316
+ template <int _AP_W2, bool _AP_S2>
317
+ INLINE af_range_ref& operator=(const ap_bit_ref<_AP_W2, _AP_S2>& val) {
318
+ const ap_int_base<1, false> tmp((bool)val);
319
+ return operator=(tmp);
320
+ }
321
+
322
+ /// assgin from ap_fixed_base.
323
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
324
+ ap_o_mode _AP_O2, int _AP_N2>
325
+ INLINE af_range_ref& operator=(
326
+ const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&
327
+ val) {
328
+ d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
329
+ return *this;
330
+ }
331
+
332
+ /// copy assgin.
333
+ // XXX This has to be explicit, otherwise it will be deleted, as d_bv is
334
+ // of reference type.
335
+ INLINE af_range_ref& operator=(const af_range_ref& val) {
336
+ ap_int_base<_AP_W, false> tmp(val);
337
+ return operator=(tmp);
338
+ }
339
+
340
+ /// assign from range reference to ap_fixed_base.
341
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
342
+ ap_o_mode _AP_O2, int _AP_N2>
343
+ INLINE af_range_ref& operator=(
344
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
345
+ ap_int_base<_AP_W2, false> tmp(val);
346
+ return operator=(tmp);
347
+ }
348
+
349
+ /// assign from bit reference to ap_fixed_base.
350
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
351
+ ap_o_mode _AP_O2, int _AP_N2>
352
+ INLINE af_range_ref& operator=(
353
+ const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
354
+ ap_int_base<1, false> tmp((bool)val);
355
+ return operator=(tmp);
356
+ }
357
+
358
+ /// assign from compound reference.
359
+ template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
360
+ INLINE af_range_ref& operator=(
361
+ const ap_concat_ref<_AP_W2, _AP_T3, _AP_W3, _AP_T3>& val) {
362
+ const ap_int_base<_AP_W2 + _AP_W3, false> tmp(val);
363
+ return operator=(tmp);
364
+ }
365
+ // @}
366
+
367
+ /// @name comparison operators with ap_range_ref.
368
+ // @{
369
+ template <int _AP_W2, bool _AP_S2>
370
+ INLINE bool operator==(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
371
+ ap_int_base<_AP_W, false> lop(*this);
372
+ ap_int_base<_AP_W2, false> rop(op2);
373
+ return lop == rop;
374
+ }
375
+
376
+ template <int _AP_W2, bool _AP_S2>
377
+ INLINE bool operator!=(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
378
+ return !(operator==(op2));
379
+ }
380
+
381
+ template <int _AP_W2, bool _AP_S2>
382
+ INLINE bool operator<(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
383
+ ap_int_base<_AP_W, false> lop(*this);
384
+ ap_int_base<_AP_W2, false> rop(op2);
385
+ return lop < rop;
386
+ }
387
+
388
+ template <int _AP_W2, bool _AP_S2>
389
+ INLINE bool operator>(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
390
+ ap_int_base<_AP_W, false> lop(*this);
391
+ ap_int_base<_AP_W2, false> rop(op2);
392
+ return lop > rop;
393
+ }
394
+
395
+ template <int _AP_W2, bool _AP_S2>
396
+ INLINE bool operator<=(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
397
+ return !(operator>(op2));
398
+ }
399
+
400
+ template <int _AP_W2, bool _AP_S2>
401
+ INLINE bool operator>=(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
402
+ return !(operator<(op2));
403
+ }
404
+ // @}
405
+
406
+ /// @name comparison operators with af_range_ref.
407
+ // @{
408
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
409
+ ap_o_mode _AP_O2, int _AP_N2>
410
+ INLINE bool operator==(
411
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
412
+ ap_int_base<_AP_W, false> lop(*this);
413
+ ap_int_base<_AP_W2, false> rop(op2);
414
+ return lop == rop;
415
+ }
416
+
417
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
418
+ ap_o_mode _AP_O2, int _AP_N2>
419
+ INLINE bool operator!=(
420
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
421
+ return !(operator==(op2));
422
+ }
423
+
424
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
425
+ ap_o_mode _AP_O2, int _AP_N2>
426
+ INLINE bool operator<(
427
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
428
+ ap_int_base<_AP_W, false> lop(*this);
429
+ ap_int_base<_AP_W2, false> rop(op2);
430
+ return lop < rop;
431
+ }
432
+
433
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
434
+ ap_o_mode _AP_O2, int _AP_N2>
435
+ INLINE bool operator>(
436
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
437
+ ap_int_base<_AP_W, false> lop(*this);
438
+ ap_int_base<_AP_W2, false> rop(op2);
439
+ return lop > rop;
440
+ }
441
+
442
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
443
+ ap_o_mode _AP_O2, int _AP_N2>
444
+ INLINE bool operator<=(
445
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
446
+ return !(operator>(op2));
447
+ }
448
+
449
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
450
+ ap_o_mode _AP_O2, int _AP_N2>
451
+ INLINE bool operator>=(
452
+ const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
453
+ return !(operator<(op2));
454
+ }
455
+ // @}
456
+
457
+ /// @name concatenate operators.
458
+ /// @{
459
+ /// concatenate with ap_int_base.
460
+ template <int _AP_W2, int _AP_S2>
461
+ INLINE
462
+ ap_concat_ref<_AP_W, af_range_ref, _AP_W2, ap_int_base<_AP_W2, _AP_S2> >
463
+ operator,(ap_int_base<_AP_W2, _AP_S2> &op) {
464
+ return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
465
+ ap_int_base<_AP_W2, _AP_S2> >(*this, op);
466
+ }
467
+
468
+ /// concatenate with ap_bit_ref.
469
+ template <int _AP_W2, int _AP_S2>
470
+ INLINE ap_concat_ref<_AP_W, af_range_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >
471
+ operator,(const ap_bit_ref<_AP_W2, _AP_S2> &op) {
472
+ return ap_concat_ref<_AP_W, af_range_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >(
473
+ *this, const_cast<ap_bit_ref<_AP_W2, _AP_S2>&>(op));
474
+ }
475
+
476
+ /// concatenate with ap_bit_ref.
477
+ template <int _AP_W2, int _AP_S2>
478
+ INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >
479
+ operator,(const ap_range_ref<_AP_W2, _AP_S2> &op) {
480
+ return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
481
+ ap_range_ref<_AP_W2, _AP_S2> >(
482
+ *this, const_cast<ap_range_ref<_AP_W2, _AP_S2>&>(op));
483
+ }
484
+
485
+ /// concatenate with ap_concat_ref.
486
+ template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
487
+ INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2 + _AP_W3,
488
+ ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
489
+ operator,(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &op) {
490
+ return ap_concat_ref<_AP_W, af_range_ref, _AP_W2 + _AP_W3,
491
+ ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(
492
+ *this, const_cast<ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>&>(op));
493
+ }
494
+
495
+ /// concatenate with another af_range_ref.
496
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
497
+ ap_o_mode _AP_O2, int _AP_N2>
498
+ INLINE
499
+ ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
500
+ af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
501
+ operator,(const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>
502
+ &op) {
503
+ return ap_concat_ref<
504
+ _AP_W, af_range_ref, _AP_W2,
505
+ af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(
506
+ *this,
507
+ const_cast<af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&>(
508
+ op));
509
+ }
510
+
511
+ /// concatenate with another af_bit_ref.
512
+ template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
513
+ ap_o_mode _AP_O2, int _AP_N2>
514
+ INLINE
515
+ ap_concat_ref<_AP_W, af_range_ref, 1,
516
+ af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
517
+ operator,(
518
+ const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> &op) {
519
+ return ap_concat_ref<
520
+ _AP_W, af_range_ref, 1,
521
+ af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(
522
+ *this,
523
+ const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&>(
524
+ op));
525
+ }
526
+ // @}
527
+
528
+ INLINE operator ap_ulong() const {
529
+ ap_int_base<_AP_W, false> ret;
530
+ ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
531
+ return ret.to_uint64();
532
+ }
533
+
534
+ INLINE operator ap_int_base<_AP_W, false>() const {
535
+ ap_int_base<_AP_W, false> ret;
536
+ ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
537
+ return ret;
538
+ }
539
+
540
+ INLINE ap_int_base<_AP_W, false> to_ap_int_base() const {
541
+ ap_int_base<_AP_W, false> ret;
542
+ ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
543
+ return ret;
544
+ }
545
+
546
+ // used in ap_fixed_base::to_string()
547
+ INLINE char to_char() const {
548
+ return (char)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
549
+ }
550
+
551
+ INLINE int to_int() const {
552
+ return (int)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
553
+ }
554
+
555
+ INLINE unsigned to_uint() const {
556
+ return (unsigned)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
557
+ }
558
+
559
+ INLINE long to_long() const {
560
+ return (long)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
561
+ }
562
+
563
+ INLINE unsigned long to_ulong() const {
564
+ return (unsigned long)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
565
+ }
566
+
567
+ INLINE ap_slong to_int64() const {
568
+ return (ap_slong)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
569
+ }
570
+
571
+ INLINE ap_ulong to_uint64() const {
572
+ return (ap_ulong)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
573
+ }
574
+
575
+ INLINE ap_int_base<_AP_W, false> get() const {
576
+ ap_int_base<_AP_W, false> ret;
577
+ ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
578
+ return ret;
579
+ }
580
+
581
+ template <int _AP_W2>
582
+ INLINE void set(const ap_int_base<_AP_W2, false>& val) {
583
+ d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
584
+ }
585
+
586
+ INLINE int length() const {
587
+ return h_index >= l_index ? h_index - l_index + 1 : l_index - h_index + 1;
588
+ }
589
+
590
+ #ifndef __SYNTHESIS__
591
+ std::string to_string(signed char rd = 2) const {
592
+ ap_int_base<_AP_W, false> ret;
593
+ ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
594
+ return ret.to_string(rd);
595
+ }
596
+ #else
597
+ // XXX HLS will delete this in synthesis
598
+ INLINE char* to_string(signed char rd = 2) const {
599
+ return 0;
600
+ }
601
+ #endif
602
+ }; // struct af_range_ref
603
+
604
+ // XXX apcc cannot handle global std::ios_base::Init() brought in by <iostream>
605
+ #ifndef AP_AUTOCC
606
+ #ifndef __SYNTHESIS__
607
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
608
+ int _AP_N>
609
+ INLINE std::ostream& operator<<(
610
+ std::ostream& os,
611
+ const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& x) {
612
+ os << x.to_string();
613
+ return os;
614
+ }
615
+ #endif
616
+ #endif // ifndef AP_AUTOCC
617
+
618
+ #define AF_REF_REL_OP_WITH_INT(REL_OP, C_TYPE, _AP_W2, _AP_S2) \
619
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
620
+ ap_o_mode _AP_O, int _AP_N> \
621
+ INLINE bool operator REL_OP( \
622
+ const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
623
+ C_TYPE op2) { \
624
+ return ap_int_base<_AP_W, false>(op) \
625
+ REL_OP ap_int_base<_AP_W2, _AP_S2>(op2); \
626
+ } \
627
+ \
628
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
629
+ ap_o_mode _AP_O, int _AP_N> \
630
+ INLINE bool operator REL_OP( \
631
+ C_TYPE op2, \
632
+ const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
633
+ return ap_int_base<_AP_W2, _AP_S2>(op2) \
634
+ REL_OP ap_int_base<_AP_W, false>(op); \
635
+ } \
636
+ \
637
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
638
+ ap_o_mode _AP_O, int _AP_N> \
639
+ INLINE bool operator REL_OP( \
640
+ const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
641
+ C_TYPE op2) { \
642
+ return bool(op) REL_OP op2; \
643
+ } \
644
+ \
645
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
646
+ ap_o_mode _AP_O, int _AP_N> \
647
+ INLINE bool operator REL_OP( \
648
+ C_TYPE op2, \
649
+ const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
650
+ return op2 REL_OP bool(op); \
651
+ }
652
+
653
+ #define AF_REF_REL_OPS_WITH_INT(C_TYPE, _AP_W2, _AP_S2) \
654
+ AF_REF_REL_OP_WITH_INT(>, C_TYPE, (_AP_W2), (_AP_S2)) \
655
+ AF_REF_REL_OP_WITH_INT(<, C_TYPE, (_AP_W2), (_AP_S2)) \
656
+ AF_REF_REL_OP_WITH_INT(>=, C_TYPE, (_AP_W2), (_AP_S2)) \
657
+ AF_REF_REL_OP_WITH_INT(<=, C_TYPE, (_AP_W2), (_AP_S2)) \
658
+ AF_REF_REL_OP_WITH_INT(==, C_TYPE, (_AP_W2), (_AP_S2)) \
659
+ AF_REF_REL_OP_WITH_INT(!=, C_TYPE, (_AP_W2), (_AP_S2))
660
+
661
+ AF_REF_REL_OPS_WITH_INT(bool, 1, false)
662
+ AF_REF_REL_OPS_WITH_INT(char, 8, CHAR_IS_SIGNED)
663
+ AF_REF_REL_OPS_WITH_INT(signed char, 8, true)
664
+ AF_REF_REL_OPS_WITH_INT(unsigned char, 8, false)
665
+ AF_REF_REL_OPS_WITH_INT(short, _AP_SIZE_short, true)
666
+ AF_REF_REL_OPS_WITH_INT(unsigned short, _AP_SIZE_short, false)
667
+ AF_REF_REL_OPS_WITH_INT(int, _AP_SIZE_int, true)
668
+ AF_REF_REL_OPS_WITH_INT(unsigned int, _AP_SIZE_int, false)
669
+ AF_REF_REL_OPS_WITH_INT(long, _AP_SIZE_long, true)
670
+ AF_REF_REL_OPS_WITH_INT(unsigned long, _AP_SIZE_long, false)
671
+ AF_REF_REL_OPS_WITH_INT(ap_slong, _AP_SIZE_ap_slong, true)
672
+ AF_REF_REL_OPS_WITH_INT(ap_ulong, _AP_SIZE_ap_slong, false)
673
+
674
+ #undef AF_REF_REL_OP_INT
675
+ #undef AF_REF_REL_OPS_WITH_INT
676
+
677
+ #define AF_REF_REL_OP_WITH_AP_INT(REL_OP) \
678
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
679
+ ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
680
+ INLINE bool operator REL_OP( \
681
+ const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
682
+ const ap_int_base<_AP_W2, _AP_S>& op2) { \
683
+ return ap_int_base<_AP_W, false>(op) REL_OP op2; \
684
+ } \
685
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
686
+ ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
687
+ INLINE bool operator REL_OP( \
688
+ const ap_int_base<_AP_W2, _AP_S2>& op2, \
689
+ const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
690
+ return op2 REL_OP ap_int_base<_AP_W, false>(op); \
691
+ } \
692
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
693
+ ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
694
+ INLINE bool operator REL_OP( \
695
+ const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
696
+ const ap_int_base<_AP_W2, _AP_S2>& op2) { \
697
+ return ap_int_base<1, false>(op) REL_OP op2; \
698
+ } \
699
+ template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
700
+ ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
701
+ INLINE bool operator REL_OP( \
702
+ const ap_int_base<_AP_W2, _AP_S2>& op2, \
703
+ const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
704
+ return op2 REL_OP ap_int_base<1, false>(op); \
705
+ }
706
+
707
+ AF_REF_REL_OP_WITH_AP_INT(>)
708
+ AF_REF_REL_OP_WITH_AP_INT(<)
709
+ AF_REF_REL_OP_WITH_AP_INT(>=)
710
+ AF_REF_REL_OP_WITH_AP_INT(<=)
711
+ AF_REF_REL_OP_WITH_AP_INT(==)
712
+ AF_REF_REL_OP_WITH_AP_INT(!=)
713
+
714
+ #endif // ifndef __cplusplus
715
+
716
+ #endif // ifndef __AP_FIXED_REF_H__
717
+
718
+ // -*- cpp -*-