da4ml 0.2.0__py3-none-any.whl → 0.3.0__py3-none-any.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.
Potentially problematic release.
This version of da4ml might be problematic. Click here for more details.
- da4ml/_version.py +2 -2
- da4ml/cmvm/api.py +2 -6
- da4ml/cmvm/core/__init__.py +0 -1
- da4ml/cmvm/types.py +99 -19
- da4ml/codegen/__init__.py +5 -4
- da4ml/codegen/cpp/__init__.py +2 -1
- da4ml/codegen/cpp/cpp_codegen.py +58 -25
- da4ml/codegen/cpp/hls_model.py +252 -0
- da4ml/codegen/cpp/source/ap_types/ap_binary.h +78 -0
- da4ml/codegen/cpp/source/ap_types/ap_common.h +376 -0
- da4ml/codegen/cpp/source/ap_types/ap_decl.h +212 -0
- da4ml/codegen/cpp/source/ap_types/ap_fixed.h +360 -0
- da4ml/codegen/cpp/source/ap_types/ap_fixed_base.h +2354 -0
- da4ml/codegen/cpp/source/ap_types/ap_fixed_ref.h +718 -0
- da4ml/codegen/cpp/source/ap_types/ap_fixed_special.h +230 -0
- da4ml/codegen/cpp/source/ap_types/ap_int.h +330 -0
- da4ml/codegen/cpp/source/ap_types/ap_int_base.h +1885 -0
- da4ml/codegen/cpp/source/ap_types/ap_int_ref.h +1346 -0
- da4ml/codegen/cpp/source/ap_types/ap_int_special.h +223 -0
- da4ml/codegen/cpp/source/ap_types/ap_shift_reg.h +138 -0
- da4ml/codegen/cpp/source/ap_types/etc/ap_private.h +7199 -0
- da4ml/codegen/cpp/source/ap_types/hls_math.h +27 -0
- da4ml/codegen/cpp/source/ap_types/hls_stream.h +263 -0
- da4ml/codegen/cpp/source/ap_types/utils/x_hls_utils.h +80 -0
- da4ml/codegen/cpp/source/binder_util.hh +56 -0
- da4ml/codegen/cpp/source/build_binder.mk +24 -0
- da4ml/codegen/cpp/source/{vitis.h → vitis_bitshift.hh} +1 -1
- da4ml/codegen/verilog/__init__.py +2 -3
- da4ml/codegen/verilog/comb.py +65 -24
- da4ml/codegen/verilog/io_wrapper.py +36 -141
- da4ml/codegen/verilog/pipeline.py +21 -3
- da4ml/codegen/verilog/source/binder_util.hh +72 -0
- da4ml/codegen/verilog/source/build_prj.tcl +0 -1
- da4ml/codegen/verilog/source/mux.v +58 -0
- da4ml/codegen/verilog/source/negative.v +28 -0
- da4ml/codegen/verilog/source/shift_adder.v +4 -1
- da4ml/codegen/verilog/source/template.xdc +3 -0
- da4ml/codegen/verilog/verilog_model.py +42 -15
- da4ml/converter/__init__.py +0 -0
- da4ml/converter/hgq2/parser.py +105 -0
- da4ml/converter/hgq2/replica.py +383 -0
- da4ml/trace/__init__.py +2 -2
- da4ml/trace/fixed_variable.py +177 -18
- da4ml/trace/fixed_variable_array.py +124 -9
- da4ml/trace/ops/__init__.py +22 -6
- da4ml/trace/ops/conv_utils.py +146 -14
- da4ml/trace/ops/einsum_utils.py +9 -6
- da4ml/trace/ops/reduce_utils.py +103 -0
- da4ml/trace/pipeline.py +36 -34
- da4ml/trace/tracer.py +37 -5
- da4ml-0.3.0.dist-info/METADATA +107 -0
- da4ml-0.3.0.dist-info/RECORD +64 -0
- da4ml/codegen/cpp/source/vitis_bridge.h +0 -17
- da4ml-0.2.0.dist-info/METADATA +0 -65
- da4ml-0.2.0.dist-info/RECORD +0 -39
- /da4ml/codegen/verilog/source/{ioutils.hh → ioutil.hh} +0 -0
- {da4ml-0.2.0.dist-info → da4ml-0.3.0.dist-info}/WHEEL +0 -0
- {da4ml-0.2.0.dist-info → da4ml-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {da4ml-0.2.0.dist-info → da4ml-0.3.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024-2024 Chang Sun
|
|
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_BINARY_H__
|
|
18
|
+
#define __AP_BINARY_H__
|
|
19
|
+
|
|
20
|
+
#include <ap_fixed.h>
|
|
21
|
+
#include <cassert>
|
|
22
|
+
|
|
23
|
+
struct ap_binary {
|
|
24
|
+
|
|
25
|
+
bool is_one;
|
|
26
|
+
|
|
27
|
+
INLINE ap_binary() {}
|
|
28
|
+
|
|
29
|
+
INLINE ap_binary(const bool value) : is_one(value) {}
|
|
30
|
+
INLINE ap_binary(const ap_binary &value) : is_one(value.is_one) {}
|
|
31
|
+
|
|
32
|
+
INLINE operator int() const { return is_one ? 1 : -1; }
|
|
33
|
+
INLINE operator float() const { return is_one ? 1.0 : -1.0; }
|
|
34
|
+
|
|
35
|
+
template <typename T> INLINE ap_binary(T value) : is_one(value >= 0) {}
|
|
36
|
+
|
|
37
|
+
template <typename T>
|
|
38
|
+
INLINE auto operator=(T value) -> decltype(std::enable_if_t<std::is_same<T, ap_binary>::value, int>()) {
|
|
39
|
+
is_one = value.is_one;
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
template <typename T>
|
|
44
|
+
INLINE auto operator=(T value) -> decltype(std::enable_if_t<!std::is_same<T, ap_binary>::value, int>()) {
|
|
45
|
+
is_one = value >= 0;
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
INLINE ap_fixed<2, 1> value() const { return is_one ? 1 : -1; }
|
|
50
|
+
|
|
51
|
+
template <typename T> INLINE bool operator==(T value) const { return value() == value; }
|
|
52
|
+
|
|
53
|
+
template <typename T> INLINE bool operator!=(T value) const { return value() != value; }
|
|
54
|
+
|
|
55
|
+
template <typename T> INLINE bool operator<(T value) const { return value() < value; }
|
|
56
|
+
|
|
57
|
+
template <typename T> INLINE bool operator<=(T value) const { return value() <= value; }
|
|
58
|
+
|
|
59
|
+
template <typename T> INLINE bool operator>(T value) const { return value() > value; }
|
|
60
|
+
|
|
61
|
+
template <typename T> INLINE bool operator>=(T value) const { return value() >= value; }
|
|
62
|
+
|
|
63
|
+
template <typename T> INLINE ap_binary operator+(T value) const { return ap_binary(is_one || value.is_one); }
|
|
64
|
+
|
|
65
|
+
template <typename T> INLINE ap_binary operator*(T value) const { return ap_binary(is_one && value.is_one); }
|
|
66
|
+
|
|
67
|
+
template <typename T> INLINE ap_binary operator-(T value) const { return ap_binary(is_one && !value.is_one); }
|
|
68
|
+
|
|
69
|
+
template <typename T> INLINE T operator+(T value) { return value + value(); }
|
|
70
|
+
|
|
71
|
+
template <typename T> INLINE T operator*(T value) { return value * value(); }
|
|
72
|
+
|
|
73
|
+
template <typename T> INLINE T operator-(T value) { return value - value(); }
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
typedef ap_fixed<2, 1, AP_RND_CONV, AP_SAT_SYM> ap_ternary;
|
|
77
|
+
|
|
78
|
+
#endif
|
|
@@ -0,0 +1,376 @@
|
|
|
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_COMMON_H__
|
|
18
|
+
#define __AP_COMMON_H__
|
|
19
|
+
|
|
20
|
+
// ----------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
// Forward declaration of all AP types.
|
|
23
|
+
#include <ap_decl.h>
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#ifdef __SYNTHESIS__
|
|
27
|
+
#error "The open-source version of AP types does not support synthesis."
|
|
28
|
+
#endif // ifdef __SYNTHESIS__
|
|
29
|
+
#define _AP_ENABLE_HALF_ 0
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
#if _AP_ENABLE_HALF_ == 1
|
|
33
|
+
// Before ap_private definition.
|
|
34
|
+
#ifdef __SYNTHESIS__
|
|
35
|
+
#define _HLS_HALF_DEFINED_
|
|
36
|
+
typedef __fp16 half;
|
|
37
|
+
#else
|
|
38
|
+
class half;
|
|
39
|
+
#endif // __SYNTHESIS__
|
|
40
|
+
#endif // _AP_ENABLE_HALF_
|
|
41
|
+
|
|
42
|
+
// ----------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
// Macro functions
|
|
45
|
+
#define AP_MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
46
|
+
#define AP_MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
47
|
+
#define AP_ABS(a) ((a) >= 0 ? (a) : -(a))
|
|
48
|
+
|
|
49
|
+
#ifndef AP_ASSERT
|
|
50
|
+
#ifndef __SYNTHESIS__
|
|
51
|
+
#include <assert.h>
|
|
52
|
+
#define AP_ASSERT(cond, msg) assert((cond) && (msg))
|
|
53
|
+
#else
|
|
54
|
+
#define AP_ASSERT(cond, msg)
|
|
55
|
+
#endif // ifndef __SYNTHESIS__
|
|
56
|
+
#endif // ifndef AP_ASSERT
|
|
57
|
+
|
|
58
|
+
#ifndef __SYNTHESIS__
|
|
59
|
+
// for fprintf messages.
|
|
60
|
+
#include <stdio.h>
|
|
61
|
+
// for exit on error.
|
|
62
|
+
#include <stdlib.h>
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
// same disable condition as assert.
|
|
66
|
+
#if !defined(__SYNTHESIS__) && !defined(NDEBUG)
|
|
67
|
+
|
|
68
|
+
#define _AP_DEBUG(cond, ...) \
|
|
69
|
+
do { \
|
|
70
|
+
if ((cond)) { \
|
|
71
|
+
fprintf(stderr, "DEBUG: " __VA_ARGS__); \
|
|
72
|
+
fprintf(stderr, "\n"); \
|
|
73
|
+
} \
|
|
74
|
+
} while (0)
|
|
75
|
+
#define _AP_WARNING(cond, ...) \
|
|
76
|
+
do { \
|
|
77
|
+
if ((cond)) { \
|
|
78
|
+
fprintf(stderr, "WARNING: " __VA_ARGS__); \
|
|
79
|
+
fprintf(stderr, "\n"); \
|
|
80
|
+
} \
|
|
81
|
+
} while (0)
|
|
82
|
+
#define _AP_ERROR(cond, ...) \
|
|
83
|
+
do { \
|
|
84
|
+
if ((cond)) { \
|
|
85
|
+
fprintf(stderr, "ERROR: " __VA_ARGS__); \
|
|
86
|
+
fprintf(stderr, "\n"); \
|
|
87
|
+
abort(); \
|
|
88
|
+
} \
|
|
89
|
+
} while (0)
|
|
90
|
+
|
|
91
|
+
#else // if !defined(__SYNTHESIS__) && !defined(NDEBUG)
|
|
92
|
+
|
|
93
|
+
#define __AP_VOID_CAST static_cast<void>
|
|
94
|
+
#define _AP_DEBUG(cond, ...) (__AP_VOID_CAST(0))
|
|
95
|
+
#define _AP_WARNING(cond, ...) (__AP_VOID_CAST(0))
|
|
96
|
+
#define _AP_ERROR(cond, ...) (__AP_VOID_CAST(0))
|
|
97
|
+
|
|
98
|
+
#endif // if !defined(__SYNTHESIS__) && !defined(NDEBUG) else
|
|
99
|
+
|
|
100
|
+
// ----------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
// Attribute only for synthesis
|
|
103
|
+
#ifdef __SYNTHESIS__
|
|
104
|
+
#define INLINE inline __attribute__((always_inline))
|
|
105
|
+
//#define INLINE inline __attribute__((noinline))
|
|
106
|
+
#else
|
|
107
|
+
#define INLINE inline
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
#define AP_WEAK
|
|
111
|
+
// __attribute__((weak))
|
|
112
|
+
|
|
113
|
+
#ifndef AP_INT_MAX_W
|
|
114
|
+
#define AP_INT_MAX_W 1024
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
#define BIT_WIDTH_UPPER_LIMIT (1 << 15)
|
|
118
|
+
#if AP_INT_MAX_W > BIT_WIDTH_UPPER_LIMIT
|
|
119
|
+
#error "Bitwidth exceeds 32768 (1 << 15), the maximum allowed value"
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
#define MAX_MODE(BITS) ((BITS + 1023) / 1024)
|
|
123
|
+
|
|
124
|
+
// ----------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
// XXX apcc cannot handle global std::ios_base::Init() brought in by <iostream>
|
|
127
|
+
#ifndef AP_AUTOCC
|
|
128
|
+
#ifndef __SYNTHESIS__
|
|
129
|
+
// for overload operator<<
|
|
130
|
+
#include <iostream>
|
|
131
|
+
#endif
|
|
132
|
+
#endif // ifndef AP_AUTOCC
|
|
133
|
+
|
|
134
|
+
#ifndef __SYNTHESIS__
|
|
135
|
+
// for string format.
|
|
136
|
+
#include <sstream>
|
|
137
|
+
// for string.
|
|
138
|
+
#include <string>
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
// for detecting if char is signed.
|
|
142
|
+
enum { CHAR_IS_SIGNED = (char)-1 < 0 };
|
|
143
|
+
|
|
144
|
+
// TODO we have similar traits in x_hls_utils.h, should consider unify.
|
|
145
|
+
namespace _ap_type {
|
|
146
|
+
template <typename _Tp>
|
|
147
|
+
struct is_signed {
|
|
148
|
+
static const bool value = _Tp(-1) < _Tp(1);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
template <typename _Tp>
|
|
152
|
+
struct is_integral {
|
|
153
|
+
static const bool value = false;
|
|
154
|
+
};
|
|
155
|
+
#define DEF_IS_INTEGRAL(CTYPE) \
|
|
156
|
+
template <> \
|
|
157
|
+
struct is_integral<CTYPE> { \
|
|
158
|
+
static const bool value = true; \
|
|
159
|
+
};
|
|
160
|
+
DEF_IS_INTEGRAL(bool)
|
|
161
|
+
DEF_IS_INTEGRAL(char)
|
|
162
|
+
DEF_IS_INTEGRAL(signed char)
|
|
163
|
+
DEF_IS_INTEGRAL(unsigned char)
|
|
164
|
+
DEF_IS_INTEGRAL(short)
|
|
165
|
+
DEF_IS_INTEGRAL(unsigned short)
|
|
166
|
+
DEF_IS_INTEGRAL(int)
|
|
167
|
+
DEF_IS_INTEGRAL(unsigned int)
|
|
168
|
+
DEF_IS_INTEGRAL(long)
|
|
169
|
+
DEF_IS_INTEGRAL(unsigned long)
|
|
170
|
+
DEF_IS_INTEGRAL(ap_slong)
|
|
171
|
+
DEF_IS_INTEGRAL(ap_ulong)
|
|
172
|
+
#undef DEF_IS_INTEGRAL
|
|
173
|
+
|
|
174
|
+
template <bool, typename _Tp = void>
|
|
175
|
+
struct enable_if {};
|
|
176
|
+
// partial specialization for true
|
|
177
|
+
template <typename _Tp>
|
|
178
|
+
struct enable_if<true, _Tp> {
|
|
179
|
+
typedef _Tp type;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
template <typename _Tp>
|
|
183
|
+
struct remove_const {
|
|
184
|
+
typedef _Tp type;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
template <typename _Tp>
|
|
188
|
+
struct remove_const<_Tp const> {
|
|
189
|
+
typedef _Tp type;
|
|
190
|
+
};
|
|
191
|
+
} // namespace _ap_type
|
|
192
|
+
|
|
193
|
+
// ----------------------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
// Define ssdm_int and _ssdm_op.
|
|
196
|
+
// XXX deleted in open-source version
|
|
197
|
+
|
|
198
|
+
#ifndef NON_C99STRING
|
|
199
|
+
#define _AP_C99 true
|
|
200
|
+
#else
|
|
201
|
+
#define _AP_C99 false
|
|
202
|
+
#endif
|
|
203
|
+
|
|
204
|
+
static inline unsigned char guess_radix(const char* s) {
|
|
205
|
+
unsigned char rd = 10; ///< default radix
|
|
206
|
+
const char* p = s;
|
|
207
|
+
// skip neg sign if it exists
|
|
208
|
+
if (p[0] == '-' || p[0] == '+') ++p;
|
|
209
|
+
// guess based on following two bits.
|
|
210
|
+
if (p[0] == '0') {
|
|
211
|
+
if (p[1] == 'b' || p[1] == 'B') {
|
|
212
|
+
rd = 2;
|
|
213
|
+
} else if (p[1] == 'o' || p[1] == 'O') {
|
|
214
|
+
rd = 8;
|
|
215
|
+
} else if (p[1] == 'x' || p[1] == 'X') {
|
|
216
|
+
rd = 16;
|
|
217
|
+
} else if (p[1] == 'd' || p[1] == 'D') {
|
|
218
|
+
rd = 10;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return rd;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ----------------------------------------------------------------------
|
|
225
|
+
|
|
226
|
+
// Basic integral struct upon which ap_int and ap_fixed are defined.
|
|
227
|
+
#ifdef __SYNTHESIS__
|
|
228
|
+
// Use ssdm_int, a compiler dependent, attribute constrained integeral type as
|
|
229
|
+
// basic data type.
|
|
230
|
+
#define _AP_ROOT_TYPE ssdm_int
|
|
231
|
+
// Basic ops.
|
|
232
|
+
#define _AP_ROOT_op_concat(Ret, X, Y) _ssdm_op_concat(Ret, X, Y)
|
|
233
|
+
#define _AP_ROOT_op_get_bit(Val, Bit) _ssdm_op_get_bit(Val, Bit)
|
|
234
|
+
#define _AP_ROOT_op_set_bit(Val, Bit, Repl) _ssdm_op_set_bit(Val, Bit, Repl)
|
|
235
|
+
#define _AP_ROOT_op_get_range(Val, Lo, Hi) _ssdm_op_get_range(Val, Lo, Hi)
|
|
236
|
+
#define _AP_ROOT_op_set_range(Val, Lo, Hi, Repl) \
|
|
237
|
+
_ssdm_op_set_range(Val, Lo, Hi, Repl)
|
|
238
|
+
#define _AP_ROOT_op_reduce(Op, Val) _ssdm_op_reduce(Op, Val)
|
|
239
|
+
#else // ifdef __SYNTHESIS__
|
|
240
|
+
// Use ap_private for compiler-independent basic data type
|
|
241
|
+
template <int _AP_W, bool _AP_S, bool _AP_C = _AP_W <= 64>
|
|
242
|
+
class ap_private;
|
|
243
|
+
/// model ssdm_int in standard C++ for simulation.
|
|
244
|
+
template <int _AP_W, bool _AP_S>
|
|
245
|
+
struct ssdm_int_sim {
|
|
246
|
+
/// integral type with template-specified width and signedness.
|
|
247
|
+
ap_private<_AP_W, _AP_S> V;
|
|
248
|
+
ssdm_int_sim() {}
|
|
249
|
+
};
|
|
250
|
+
#define _AP_ROOT_TYPE ssdm_int_sim
|
|
251
|
+
// private's ref uses _AP_ROOT_TYPE.
|
|
252
|
+
#include <etc/ap_private.h>
|
|
253
|
+
// XXX The C-sim model cannot use GCC-extension
|
|
254
|
+
// Basic ops. Ret and Val are ap_private.
|
|
255
|
+
template <typename _Tp1, typename _Tp2, typename _Tp3>
|
|
256
|
+
inline _Tp1 _AP_ROOT_op_concat(const _Tp1& Ret, const _Tp2& X, const _Tp3& Y) {
|
|
257
|
+
_Tp1 r = (X).operator,(Y);
|
|
258
|
+
return r;
|
|
259
|
+
}
|
|
260
|
+
#define _AP_ROOT_op_get_bit(Val, Bit) (Val).get_bit((Bit))
|
|
261
|
+
template <typename _Tp1, typename _Tp2, typename _Tp3>
|
|
262
|
+
inline _Tp1& _AP_ROOT_op_set_bit(_Tp1& Val, const _Tp2& Bit, const _Tp3& Repl) {
|
|
263
|
+
(Val).set_bit((Bit), (Repl));
|
|
264
|
+
return Val;
|
|
265
|
+
}
|
|
266
|
+
// notice the order of high and low index is different in ssdm call and
|
|
267
|
+
// ap_private.range()...
|
|
268
|
+
#define _AP_ROOT_op_get_range(Val, Lo, Hi) (Val).range((Hi), (Lo))
|
|
269
|
+
template <typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4>
|
|
270
|
+
inline _Tp1& _AP_ROOT_op_set_range(_Tp1& Val, const _Tp2& Lo, const _Tp3& Hi,
|
|
271
|
+
const _Tp4& Repl) {
|
|
272
|
+
(Val).range((Hi), (Lo)) = Repl;
|
|
273
|
+
return (Val);
|
|
274
|
+
}
|
|
275
|
+
#define _AP_ROOT_op_and_reduce(Val) (Val).and_reduce()
|
|
276
|
+
#define _AP_ROOT_op_nand_reduce(Val) (Val).nand_reduce()
|
|
277
|
+
#define _AP_ROOT_op_or_reduce(Val) (Val).or_reduce()
|
|
278
|
+
#define _AP_ROOT_op_xor_reduce(Val) (Val).xor_reduce()
|
|
279
|
+
// ## is the concatenation in preprocessor:
|
|
280
|
+
#define _AP_ROOT_op_reduce(Op, Val) _AP_ROOT_op_##Op##_reduce(Val)
|
|
281
|
+
#endif // ifdef __SYNTHESIS__ else
|
|
282
|
+
|
|
283
|
+
// ----------------------------------------------------------------------
|
|
284
|
+
|
|
285
|
+
// Constants for half, single, double pricision floating points
|
|
286
|
+
#define HALF_MAN 10
|
|
287
|
+
#define FLOAT_MAN 23
|
|
288
|
+
#define DOUBLE_MAN 52
|
|
289
|
+
|
|
290
|
+
#define HALF_EXP 5
|
|
291
|
+
#define FLOAT_EXP 8
|
|
292
|
+
#define DOUBLE_EXP 11
|
|
293
|
+
|
|
294
|
+
#define BIAS(e) ((1L << (e - 1L)) - 1L)
|
|
295
|
+
#define HALF_BIAS BIAS(HALF_EXP)
|
|
296
|
+
#define FLOAT_BIAS BIAS(FLOAT_EXP)
|
|
297
|
+
#define DOUBLE_BIAS BIAS(DOUBLE_EXP)
|
|
298
|
+
|
|
299
|
+
#define APFX_IEEE_DOUBLE_E_MAX DOUBLE_BIAS
|
|
300
|
+
#define APFX_IEEE_DOUBLE_E_MIN (-DOUBLE_BIAS + 1)
|
|
301
|
+
|
|
302
|
+
INLINE ap_ulong doubleToRawBits(double pf) {
|
|
303
|
+
union {
|
|
304
|
+
ap_ulong __L;
|
|
305
|
+
double __D;
|
|
306
|
+
} LD;
|
|
307
|
+
LD.__D = pf;
|
|
308
|
+
return LD.__L;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
INLINE unsigned int floatToRawBits(float pf) {
|
|
312
|
+
union {
|
|
313
|
+
unsigned int __L;
|
|
314
|
+
float __D;
|
|
315
|
+
} LD;
|
|
316
|
+
LD.__D = pf;
|
|
317
|
+
return LD.__L;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
#if _AP_ENABLE_HALF_ == 1
|
|
321
|
+
INLINE unsigned short halfToRawBits(half pf) {
|
|
322
|
+
#ifdef __SYNTHESIS__
|
|
323
|
+
union {
|
|
324
|
+
unsigned short __L;
|
|
325
|
+
half __D;
|
|
326
|
+
} LD;
|
|
327
|
+
LD.__D = pf;
|
|
328
|
+
return LD.__L;
|
|
329
|
+
#else
|
|
330
|
+
return pf.get_bits();
|
|
331
|
+
#endif
|
|
332
|
+
}
|
|
333
|
+
#endif
|
|
334
|
+
|
|
335
|
+
// usigned long long is at least 64-bit
|
|
336
|
+
INLINE double rawBitsToDouble(ap_ulong pi) {
|
|
337
|
+
union {
|
|
338
|
+
ap_ulong __L;
|
|
339
|
+
double __D;
|
|
340
|
+
} LD;
|
|
341
|
+
LD.__L = pi;
|
|
342
|
+
return LD.__D;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// long is at least 32-bit
|
|
346
|
+
INLINE float rawBitsToFloat(unsigned long pi) {
|
|
347
|
+
union {
|
|
348
|
+
unsigned int __L;
|
|
349
|
+
float __D;
|
|
350
|
+
} LD;
|
|
351
|
+
LD.__L = pi;
|
|
352
|
+
return LD.__D;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#if _AP_ENABLE_HALF_ == 1
|
|
356
|
+
// short is at least 16-bit
|
|
357
|
+
INLINE half rawBitsToHalf(unsigned short pi) {
|
|
358
|
+
#ifdef __SYNTHESIS__
|
|
359
|
+
union {
|
|
360
|
+
unsigned short __L;
|
|
361
|
+
half __D;
|
|
362
|
+
} LD;
|
|
363
|
+
LD.__L = pi;
|
|
364
|
+
return LD.__D;
|
|
365
|
+
#else
|
|
366
|
+
// sim model of half has a non-trivial constructor
|
|
367
|
+
half __D;
|
|
368
|
+
__D.set_bits(pi);
|
|
369
|
+
return __D;
|
|
370
|
+
#endif
|
|
371
|
+
}
|
|
372
|
+
#endif
|
|
373
|
+
|
|
374
|
+
#endif // ifndef __AP_COMMON_H__
|
|
375
|
+
|
|
376
|
+
// -*- cpp -*-
|
|
@@ -0,0 +1,212 @@
|
|
|
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_DECL_H__
|
|
18
|
+
#define __AP_DECL_H__
|
|
19
|
+
|
|
20
|
+
// ----------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
#if !defined(__AP_FIXED_H__) && !defined(__AP_INT_H__) && !defined(__AUTOPILOT_CBE_H__) && !defined(__HLS_HALF_H__)
|
|
23
|
+
#error "Only ap_fixed.h and ap_int.h can be included directly in user code."
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
// Test __SYNTHESIS__ only for mode
|
|
27
|
+
#if !defined(__SYNTHESIS__) && (defined(AESL_SYN) || defined(__HLS_SYN__))
|
|
28
|
+
//#pragma message "AESL_SYN and __HLS_SYN__ should be replaced by __SYNTHESIS__"
|
|
29
|
+
#define __SYNTHESIS__
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
/* for safety*/
|
|
33
|
+
#if (defined(_AP_N) || defined(_AP_C))
|
|
34
|
+
#error One or more of the following is defined: _AP_N, _AP_C. Definition conflicts with their usage as template parameters.
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
/* for safety*/
|
|
38
|
+
#if (defined(_AP_W) || defined(_AP_I) || defined(_AP_S) || defined(_AP_Q) || \
|
|
39
|
+
defined(_AP_O) || defined(_AP_W2) || defined(_AP_I2) || \
|
|
40
|
+
defined(_AP_S2) || defined(_AP_Q2) || defined(_AP_O2) || \
|
|
41
|
+
defined(_AP_N) || defined(_AP_N2))
|
|
42
|
+
#error \
|
|
43
|
+
"One or more of the following is defined: _AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N, _AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2. Definition conflicts with their usage as template parameters."
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
/*for safety*/
|
|
47
|
+
#if (defined(_AP_W3) || defined(_AP_S3) || defined(_AP_W4) || defined(_AP_S4))
|
|
48
|
+
#error \
|
|
49
|
+
"One or more of the following is defined: _AP_W3, _AP_S3, _AP_W4,_AP_S4. Definition conflicts with their usage as template parameters."
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
#if (defined(_AP_W1) || defined(_AP_S1) || defined(_AP_T) || \
|
|
53
|
+
defined(_AP_T1) || defined(_AP_T2) || defined(_AP_T3) || defined(_AP_T4))
|
|
54
|
+
#error \
|
|
55
|
+
"One or more of the following is defined: _AP_W1, _AP_S1, _AP_T, _AP_T1, _AP_T2, _AP_T3, _AP_T4. Definition conflicts with their usage as template parameters."
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
#ifndef __cplusplus
|
|
59
|
+
#error "AP data type can only be used in C++"
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
// ----------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
#ifndef __SC_COMPATIBLE__
|
|
65
|
+
/// ap_fixed quantification mode
|
|
66
|
+
enum ap_q_mode {
|
|
67
|
+
AP_RND, //< rounding to plus infinity
|
|
68
|
+
AP_RND_ZERO, //< rounding to zero
|
|
69
|
+
AP_RND_MIN_INF, //< rounding to minus infinity
|
|
70
|
+
AP_RND_INF, //< rounding to infinity
|
|
71
|
+
AP_RND_CONV, //< convergent rounding
|
|
72
|
+
AP_TRN, //< truncation
|
|
73
|
+
AP_TRN_ZERO, //< truncation to zero
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// FIXME for legacy code
|
|
77
|
+
#ifndef SYSTEMC_INCLUDED
|
|
78
|
+
#define SC_RND AP_RND
|
|
79
|
+
#define SC_RND_ZERO AP_RND_ZERO
|
|
80
|
+
#define SC_RND_MIN_INF AP_RND_MIN_INF
|
|
81
|
+
#define SC_RND_INF AP_RND_INF
|
|
82
|
+
#define SC_RND_CONV AP_RND_CONV
|
|
83
|
+
#define SC_TRN AP_TRN
|
|
84
|
+
#define SC_TRN_ZERO AP_TRN_ZERO
|
|
85
|
+
#endif // !defined(SYSTEMC_INCLUDED)
|
|
86
|
+
|
|
87
|
+
/// ap_fixed saturation mode
|
|
88
|
+
enum ap_o_mode {
|
|
89
|
+
AP_SAT, //< saturation
|
|
90
|
+
AP_SAT_ZERO, //< saturation to zero
|
|
91
|
+
AP_SAT_SYM, //< symmetrical saturation
|
|
92
|
+
AP_WRAP, //< wrap-around (*)
|
|
93
|
+
AP_WRAP_SM, //< sign magnitude wrap-around (*)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// FIXME for legacy code
|
|
97
|
+
#ifndef SYSTEMC_INCLUDED
|
|
98
|
+
#define SC_SAT AP_SAT
|
|
99
|
+
#define SC_SAT_ZERO AP_SAT_ZERO
|
|
100
|
+
#define SC_SAT_SYM AP_SAT_SYM
|
|
101
|
+
#define SC_WRAP AP_WRAP
|
|
102
|
+
#define SC_WRAP_SM AP_WRAP_SM
|
|
103
|
+
#endif // !defined(SYSTEMC_INCLUDED)
|
|
104
|
+
|
|
105
|
+
#else // defined(__SC_COMPATIBLE__)
|
|
106
|
+
|
|
107
|
+
// There will not be sc_fxdefs.h, and the emu should be defined by ap_fixed.
|
|
108
|
+
|
|
109
|
+
/// ap_fixed quantification mode
|
|
110
|
+
enum ap_q_mode {
|
|
111
|
+
SC_RND, //< rounding to plus infinity
|
|
112
|
+
SC_RND_ZERO, //< rounding to zero
|
|
113
|
+
SC_RND_MIN_INF, //< rounding to minus infinity
|
|
114
|
+
SC_RND_INF, //< rounding to infinity
|
|
115
|
+
SC_RND_CONV, //< convergent rounding
|
|
116
|
+
SC_TRN, //< truncation
|
|
117
|
+
SC_TRN_ZERO, //< truncation to zero
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
#define AP_RND SC_RND
|
|
121
|
+
#define AP_RND_ZERO SC_RND_ZERO
|
|
122
|
+
#define AP_RND_MIN_INF SC_RND_MIN_INF
|
|
123
|
+
#define AP_RND_INF SC_RND_INF
|
|
124
|
+
#define AP_RND_CONV SC_RND_CONV
|
|
125
|
+
#define AP_TRN SC_TRN
|
|
126
|
+
#define AP_TRN_ZERO SC_TRN_ZERO
|
|
127
|
+
|
|
128
|
+
/// ap_fixed saturation mode
|
|
129
|
+
enum ap_o_mode {
|
|
130
|
+
SC_SAT, //< saturation
|
|
131
|
+
SC_SAT_ZERO, //< saturation to zero
|
|
132
|
+
SC_SAT_SYM, //< symmetrical saturation
|
|
133
|
+
SC_WRAP, //< wrap-around (*)
|
|
134
|
+
SC_WRAP_SM, //< sign magnitude wrap-around (*)
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
#define AP_SAT SC_SAT
|
|
138
|
+
#define AP_SAT_ZERO SC_SAT_ZERO
|
|
139
|
+
#define AP_SAT_SYM SC_SAT_SYM
|
|
140
|
+
#define AP_WRAP SC_WRAP
|
|
141
|
+
#define AP_WRAP_SM SC_WRAP_SM
|
|
142
|
+
|
|
143
|
+
#endif // defined(__SC_COMPATIBLE__)
|
|
144
|
+
|
|
145
|
+
template <int _AP_W, bool _AP_S>
|
|
146
|
+
struct ap_int_base;
|
|
147
|
+
|
|
148
|
+
template <int _AP_W>
|
|
149
|
+
struct ap_int;
|
|
150
|
+
|
|
151
|
+
template <int _AP_W>
|
|
152
|
+
struct ap_uint;
|
|
153
|
+
|
|
154
|
+
template <int _AP_W, bool _AP_S>
|
|
155
|
+
struct ap_range_ref;
|
|
156
|
+
|
|
157
|
+
template <int _AP_W, bool _AP_S>
|
|
158
|
+
struct ap_bit_ref;
|
|
159
|
+
|
|
160
|
+
template <int _AP_W1, typename _AP_T1, int _AP_W2, typename _AP_T2>
|
|
161
|
+
struct ap_concat_ref;
|
|
162
|
+
|
|
163
|
+
template <int _AP_W, int _AP_I, bool _AP_S = true, ap_q_mode _AP_Q = AP_TRN,
|
|
164
|
+
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
|
|
165
|
+
struct ap_fixed_base;
|
|
166
|
+
|
|
167
|
+
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
|
|
168
|
+
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
|
|
169
|
+
struct ap_fixed;
|
|
170
|
+
|
|
171
|
+
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
|
|
172
|
+
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
|
|
173
|
+
struct ap_ufixed;
|
|
174
|
+
|
|
175
|
+
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
|
|
176
|
+
int _AP_N>
|
|
177
|
+
struct af_range_ref;
|
|
178
|
+
|
|
179
|
+
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
|
|
180
|
+
int _AP_N>
|
|
181
|
+
struct af_bit_ref;
|
|
182
|
+
|
|
183
|
+
/// string base mode
|
|
184
|
+
enum BaseMode { AP_BIN = 2, AP_OCT = 8, AP_DEC = 10, AP_HEX = 16 };
|
|
185
|
+
|
|
186
|
+
#ifndef SYSTEMC_INCLUDED
|
|
187
|
+
#define SC_BIN 2
|
|
188
|
+
#define SC_OCT 8
|
|
189
|
+
#define SC_DEC 10
|
|
190
|
+
#define SC_HEX 16
|
|
191
|
+
#endif // !defined(SYSTEMC_INCLUDED)
|
|
192
|
+
|
|
193
|
+
// Alias C data types
|
|
194
|
+
#ifdef _MSC_VER
|
|
195
|
+
typedef signed __int64 ap_slong;
|
|
196
|
+
typedef unsigned __int64 ap_ulong;
|
|
197
|
+
#else // !defined(_MSC_VER)
|
|
198
|
+
typedef signed long long ap_slong;
|
|
199
|
+
typedef unsigned long long ap_ulong;
|
|
200
|
+
#endif // !defined(_MSC_VER)
|
|
201
|
+
|
|
202
|
+
enum {
|
|
203
|
+
_AP_SIZE_char = 8,
|
|
204
|
+
_AP_SIZE_short = sizeof(short) * 8,
|
|
205
|
+
_AP_SIZE_int = sizeof(int) * 8,
|
|
206
|
+
_AP_SIZE_long = sizeof(long) * 8,
|
|
207
|
+
_AP_SIZE_ap_slong = sizeof(ap_slong) * 8
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
#endif // !defined(__AP_DECL_H__)
|
|
211
|
+
|
|
212
|
+
// -*- cpp -*-
|