LDMX Software
ap_int.h
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_INT_H__
18#define __AP_INT_H__
19
20#include <ap_impl/ap_common.h>
21#include <ap_impl/ap_int_base.h>
22#include <ap_impl/ap_int_ref.h>
23
24//---------------------------------------------------------------
25
27template <int _AP_W>
28struct ap_int : ap_int_base<_AP_W, true> {
30 // Constructor
31 INLINE ap_int() : Base() {}
32
33 // Copy ctor
34 INLINE ap_int(const ap_int& op) { Base::V = op.V; }
35
36 template <int _AP_W2>
37 INLINE ap_int(const ap_int<_AP_W2>& op) {
38 Base::V = op.V;
39 }
40
41 template <int _AP_W2>
42 INLINE ap_int(const volatile ap_int<_AP_W2>& op) {
43 Base::V = op.V;
44 }
45
46 template <int _AP_W2>
47 INLINE ap_int(const ap_uint<_AP_W2>& op) {
48 Base::V = op.V;
49 }
50
51 template <int _AP_W2>
52 INLINE ap_int(const volatile ap_uint<_AP_W2>& op) {
53 Base::V = op.V;
54 }
55
56 template <int _AP_W2, bool _AP_S2>
57 INLINE ap_int(const ap_range_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
58
59 template <int _AP_W2, bool _AP_S2>
60 INLINE ap_int(const ap_bit_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
61
62 template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
64 : Base(ref) {}
65
66 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
67 int _AP_N2>
70
71 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
72 int _AP_N2>
75 }
76
77 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
78 int _AP_N2>
79 INLINE ap_int(
82
83 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
84 int _AP_N2>
85 INLINE ap_int(
88 }
89
90 template <int _AP_W2, bool _AP_S2>
91 INLINE ap_int(const ap_int_base<_AP_W2, _AP_S2>& op) {
92 Base::V = op.V;
93 }
94
95 template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
96 ap_o_mode _AP_O2, int _AP_N2>
97 INLINE ap_int(
99 : Base(op) {}
100
101 template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
102 ap_o_mode _AP_O2, int _AP_N2>
103 INLINE ap_int(
105 : Base(op) {}
106
107 template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
108 ap_o_mode _AP_O2, int _AP_N2>
109 INLINE ap_int(
111 : Base(op) {}
112
113#define CTOR(TYPE) \
114 INLINE ap_int(TYPE val) { Base::V = val; }
115 CTOR(bool)
116 CTOR(char)
117 CTOR(signed char)
118 CTOR(unsigned char)
119 CTOR(short)
120 CTOR(unsigned short)
121 CTOR(int)
122 CTOR(unsigned int)
123 CTOR(long)
124 CTOR(unsigned long)
125 CTOR(ap_slong)
126 CTOR(ap_ulong)
127#undef CTOR
128 ap_int(double val) : Base(val) {}
129 ap_int(float val) : Base(val) {}
130#if _AP_ENABLE_HALF_ == 1
131 ap_int(half val) : Base(val) {}
132#endif
133
134 // ap_int_base will guess radix if radix is not provided.
135 INLINE ap_int(const char* s) : Base(s) {}
136
137 INLINE ap_int(const char* s, signed char rd) : Base(s, rd) {}
138
139 // Assignment
140 /* ctor will be used when right is not of proper type. */
141
142 INLINE ap_int& operator=(const ap_int<_AP_W>& op2) {
143 Base::V = op2.V;
144 return *this;
145 }
146
147 /* cannot bind volatile reference to non-volatile type. */
148 INLINE ap_int& operator=(const volatile ap_int<_AP_W>& op2) {
149 Base::V = op2.V;
150 return *this;
151 }
152
153 /* cannot return volatile *this. */
154 INLINE void operator=(const ap_int<_AP_W>& op2) volatile { Base::V = op2.V; }
155
156 INLINE void operator=(const volatile ap_int<_AP_W>& op2) volatile {
157 Base::V = op2.V;
158 }
159
160}; // struct ap_int.
161
162//---------------------------------------------------------------
163
165template <int _AP_W>
166struct ap_uint : ap_int_base<_AP_W, false> {
168 // Constructor
169 INLINE ap_uint() : Base() {}
170
171 // Copy ctor
172 INLINE ap_uint(const ap_uint& op) { Base::V = op.V; }
173
174 template <int _AP_W2>
175 INLINE ap_uint(const ap_uint<_AP_W2>& op) {
176 Base::V = op.V;
177 }
178
179 template <int _AP_W2>
180 INLINE ap_uint(const ap_int<_AP_W2>& op) {
181 Base::V = op.V;
182 }
183
184 template <int _AP_W2>
185 INLINE ap_uint(const volatile ap_uint<_AP_W2>& op) {
186 Base::V = op.V;
187 }
188
189 template <int _AP_W2>
190 INLINE ap_uint(const volatile ap_int<_AP_W2>& op) {
191 Base::V = op.V;
192 }
193
194 template <int _AP_W2, bool _AP_S2>
195 INLINE ap_uint(const ap_range_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
196
197 template <int _AP_W2, bool _AP_S2>
198 INLINE ap_uint(const ap_bit_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
199
200 template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
202 : Base(ref) {}
203
204 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
205 int _AP_N2>
208
209 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
210 int _AP_N2>
213 }
214
215 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
216 int _AP_N2>
217 INLINE ap_uint(
220
221 template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
222 int _AP_N2>
223 INLINE ap_uint(
226 }
227
228 template <int _AP_W2, bool _AP_S2>
229 INLINE ap_uint(const ap_int_base<_AP_W2, _AP_S2>& op) {
230 Base::V = op.V;
231 }
232
233 template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
234 ap_o_mode _AP_O2, int _AP_N2>
235 INLINE ap_uint(
237 : Base(op) {}
238
239 template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
240 ap_o_mode _AP_O2, int _AP_N2>
241 INLINE ap_uint(
243 : Base(op) {}
244
245 template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
246 ap_o_mode _AP_O2, int _AP_N2>
247 INLINE ap_uint(
249 : Base(op) {}
250
251#define CTOR(TYPE) \
252 INLINE ap_uint(TYPE val) { Base::V = val; }
253 CTOR(bool)
254 CTOR(char)
255 CTOR(signed char)
256 CTOR(unsigned char)
257 CTOR(short)
258 CTOR(unsigned short)
259 CTOR(int)
260 CTOR(unsigned int)
261 CTOR(long)
262 CTOR(unsigned long)
263 CTOR(ap_slong)
264 CTOR(ap_ulong)
265#undef CTOR
266 ap_uint(double val) : Base(val) {}
267 ap_uint(float val) : Base(val) {}
268#if _AP_ENABLE_HALF_ == 1
269 ap_uint(half val) : Base(val) {}
270#endif
271
272 // ap_int_base will guess radix if radix is not provided.
273 INLINE ap_uint(const char* s) : Base(s) {}
274
275 INLINE ap_uint(const char* s, signed char rd) : Base(s, rd) {}
276
277 // Assignment
278 /* XXX ctor will be used when right is not of proper type. */
279
280 INLINE ap_uint& operator=(const ap_uint<_AP_W>& op2) {
281 Base::V = op2.V;
282 return *this;
283 }
284
285 /* cannot bind volatile reference to non-volatile type. */
286 INLINE ap_uint& operator=(const volatile ap_uint<_AP_W>& op2) {
287 Base::V = op2.V;
288 return *this;
289 }
290
291 /* cannot return volatile *this. */
292 INLINE void operator=(const ap_uint<_AP_W>& op2) volatile { Base::V = op2.V; }
293
294 INLINE void operator=(const volatile ap_uint<_AP_W>& op2) volatile {
295 Base::V = op2.V;
296 }
297
298}; // struct ap_uint.
299
300#define ap_bigint ap_int
301#define ap_biguint ap_uint
302
303#if !defined(__SYNTHESIS__) && (defined(SYSTEMC_H) || defined(SYSTEMC_INCLUDED))
304// XXX sc_trace overload for ap_fixed is already included in
305// "ap_sysc/ap_sc_extras.h", so do not define in synthesis.
306template <int _AP_W>
307INLINE void sc_trace(sc_core::sc_trace_file* tf, const ap_int<_AP_W>& op,
308 const std::string& name) {
309 if (tf) tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
310}
311
312template <int _AP_W>
313INLINE void sc_trace(sc_core::sc_trace_file* tf, const ap_uint<_AP_W>& op,
314 const std::string& name) {
315 if (tf) tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
316}
317#endif // System C sim
318
319#include <ap_impl/ap_int_special.h>
320
321#endif // ifndef __AP_INT_H__ else
322
323// FIXME user should include ap_fixed.h when using ap_fixed.
324// to avoid circular inclusion, must check whether this is required by
325// ap_fixed.h
326#ifndef __AP_FIXED_H__
327#include <ap_fixed.h>
328#endif
329
330// -*- cpp -*-
Signed Arbitrary Precision Fixed-Point Type.
Definition ap_fixed.h:29
Sign Arbitrary Precision Type.
Definition ap_int.h:28
Unsigned Arbitrary Precision Type.
Definition ap_int.h:166