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