LDMX Software
ap_decl.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_DECL_H__
18#define __AP_DECL_H__
19
20// ----------------------------------------------------------------------
21
22#if !defined(__AP_FIXED_H__) && !defined(__AP_INT_H__) && \
23 !defined(__AUTOPILOT_CBE_H__) && !defined(__HLS_HALF_H__)
24#error "Only ap_fixed.h and ap_int.h can be included directly in user code."
25#endif
26
27// Test __SYNTHESIS__ only for mode
28#if !defined(__SYNTHESIS__) && (defined(AESL_SYN) || defined(__HLS_SYN__))
29// #pragma message "AESL_SYN and __HLS_SYN__ should be replaced by
30// __SYNTHESIS__"
31#define __SYNTHESIS__
32#endif
33
34/* for safety*/
35#if (defined(_AP_N) || defined(_AP_C))
36#error One or more of the following is defined: _AP_N, _AP_C. Definition conflicts with their usage as template parameters.
37#endif
38
39/* for safety*/
40#if (defined(_AP_W) || defined(_AP_I) || defined(_AP_S) || defined(_AP_Q) || \
41 defined(_AP_O) || defined(_AP_W2) || defined(_AP_I2) || \
42 defined(_AP_S2) || defined(_AP_Q2) || defined(_AP_O2) || \
43 defined(_AP_N) || defined(_AP_N2))
44#error \
45 "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."
46#endif
47
48/*for safety*/
49#if (defined(_AP_W3) || defined(_AP_S3) || defined(_AP_W4) || defined(_AP_S4))
50#error \
51 "One or more of the following is defined: _AP_W3, _AP_S3, _AP_W4,_AP_S4. Definition conflicts with their usage as template parameters."
52#endif
53
54#if (defined(_AP_W1) || defined(_AP_S1) || defined(_AP_T) || \
55 defined(_AP_T1) || defined(_AP_T2) || defined(_AP_T3) || defined(_AP_T4))
56#error \
57 "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."
58#endif
59
60#ifndef __cplusplus
61#error "AP data type can only be used in C++"
62#endif
63
64// ----------------------------------------------------------------------
65
66#ifndef __SC_COMPATIBLE__
68enum ap_q_mode {
69 AP_RND, //< rounding to plus infinity
70 AP_RND_ZERO, //< rounding to zero
71 AP_RND_MIN_INF, //< rounding to minus infinity
72 AP_RND_INF, //< rounding to infinity
73 AP_RND_CONV, //< convergent rounding
74 AP_TRN, //< truncation
75 AP_TRN_ZERO, //< truncation to zero
76};
77
78// FIXME for legacy code
79#ifndef SYSTEMC_INCLUDED
80#define SC_RND AP_RND
81#define SC_RND_ZERO AP_RND_ZERO
82#define SC_RND_MIN_INF AP_RND_MIN_INF
83#define SC_RND_INF AP_RND_INF
84#define SC_RND_CONV AP_RND_CONV
85#define SC_TRN AP_TRN
86#define SC_TRN_ZERO AP_TRN_ZERO
87#endif // !defined(SYSTEMC_INCLUDED)
88
90enum ap_o_mode {
91 AP_SAT, //< saturation
92 AP_SAT_ZERO, //< saturation to zero
93 AP_SAT_SYM, //< symmetrical saturation
94 AP_WRAP, //< wrap-around (*)
95 AP_WRAP_SM, //< sign magnitude wrap-around (*)
96};
97
98// FIXME for legacy code
99#ifndef SYSTEMC_INCLUDED
100#define SC_SAT AP_SAT
101#define SC_SAT_ZERO AP_SAT_ZERO
102#define SC_SAT_SYM AP_SAT_SYM
103#define SC_WRAP AP_WRAP
104#define SC_WRAP_SM AP_WRAP_SM
105#endif // !defined(SYSTEMC_INCLUDED)
106
107#else // defined(__SC_COMPATIBLE__)
108
109// There will not be sc_fxdefs.h, and the emu should be defined by ap_fixed.
110
112enum ap_q_mode {
113 SC_RND, //< rounding to plus infinity
114 SC_RND_ZERO, //< rounding to zero
115 SC_RND_MIN_INF, //< rounding to minus infinity
116 SC_RND_INF, //< rounding to infinity
117 SC_RND_CONV, //< convergent rounding
118 SC_TRN, //< truncation
119 SC_TRN_ZERO, //< truncation to zero
120};
121
122#define AP_RND SC_RND
123#define AP_RND_ZERO SC_RND_ZERO
124#define AP_RND_MIN_INF SC_RND_MIN_INF
125#define AP_RND_INF SC_RND_INF
126#define AP_RND_CONV SC_RND_CONV
127#define AP_TRN SC_TRN
128#define AP_TRN_ZERO SC_TRN_ZERO
129
131enum ap_o_mode {
132 SC_SAT, //< saturation
133 SC_SAT_ZERO, //< saturation to zero
134 SC_SAT_SYM, //< symmetrical saturation
135 SC_WRAP, //< wrap-around (*)
136 SC_WRAP_SM, //< sign magnitude wrap-around (*)
137};
138
139#define AP_SAT SC_SAT
140#define AP_SAT_ZERO SC_SAT_ZERO
141#define AP_SAT_SYM SC_SAT_SYM
142#define AP_WRAP SC_WRAP
143#define AP_WRAP_SM SC_WRAP_SM
144
145#endif // defined(__SC_COMPATIBLE__)
146
147template <int _AP_W, bool _AP_S>
149
150template <int _AP_W>
151struct ap_int;
152
153template <int _AP_W>
154struct ap_uint;
155
156template <int _AP_W, bool _AP_S>
158
159template <int _AP_W, bool _AP_S>
161
162template <int _AP_W1, typename _AP_T1, int _AP_W2, typename _AP_T2>
164
165template <int _AP_W, int _AP_I, bool _AP_S = true, ap_q_mode _AP_Q = AP_TRN,
166 ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
168
169template <int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
170 ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
171struct ap_fixed;
172
173template <int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
174 ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
175struct ap_ufixed;
176
177template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
178 int _AP_N>
180
181template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
182 int _AP_N>
184
186enum BaseMode { AP_BIN = 2, AP_OCT = 8, AP_DEC = 10, AP_HEX = 16 };
187
188#ifndef SYSTEMC_INCLUDED
189#define SC_BIN 2
190#define SC_OCT 8
191#define SC_DEC 10
192#define SC_HEX 16
193#endif // !defined(SYSTEMC_INCLUDED)
194
195// Alias C data types
196#ifdef _MSC_VER
197typedef signed __int64 ap_slong;
198typedef unsigned __int64 ap_ulong;
199#else // !defined(_MSC_VER)
200typedef signed long long ap_slong;
201typedef unsigned long long ap_ulong;
202#endif // !defined(_MSC_VER)
203
204enum {
205 _AP_SIZE_char = 8,
206 _AP_SIZE_short = sizeof(short) * 8,
207 _AP_SIZE_int = sizeof(int) * 8,
208 _AP_SIZE_long = sizeof(long) * 8,
209 _AP_SIZE_ap_slong = sizeof(ap_slong) * 8
210};
211
212#endif // !defined(__AP_DECL_H__)
213
214// -*- 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