17#ifndef __AP_COMMON_H__
18#define __AP_COMMON_H__
26#error "The open-source version of AP types does not support synthesis."
28#define _AP_ENABLE_HALF_ 0
30#if _AP_ENABLE_HALF_ == 1
33#define _HLS_HALF_DEFINED_
43#define AP_MAX(a, b) ((a) > (b) ? (a) : (b))
44#define AP_MIN(a, b) ((a) < (b) ? (a) : (b))
45#define AP_ABS(a) ((a) >= 0 ? (a) : -(a))
50#define AP_ASSERT(cond, msg) assert((cond) && (msg))
52#define AP_ASSERT(cond, msg)
64#if !defined(__SYNTHESIS__) && !defined(NDEBUG)
66#define _AP_DEBUG(cond, ...) \
69 fprintf(stderr, "DEBUG: " __VA_ARGS__); \
70 fprintf(stderr, "\n"); \
73#define _AP_WARNING(cond, ...) \
76 fprintf(stderr, "WARNING: " __VA_ARGS__); \
77 fprintf(stderr, "\n"); \
80#define _AP_ERROR(cond, ...) \
83 fprintf(stderr, "ERROR: " __VA_ARGS__); \
84 fprintf(stderr, "\n"); \
91#define __AP_VOID_CAST static_cast<void>
92#define _AP_DEBUG(cond, ...) (__AP_VOID_CAST(0))
93#define _AP_WARNING(cond, ...) (__AP_VOID_CAST(0))
94#define _AP_ERROR(cond, ...) (__AP_VOID_CAST(0))
102#define INLINE inline __attribute__((always_inline))
112#define AP_INT_MAX_W 1024
115#define BIT_WIDTH_UPPER_LIMIT (1 << 15)
116#if AP_INT_MAX_W > BIT_WIDTH_UPPER_LIMIT
117#error "Bitwidth exceeds 32768 (1 << 15), the maximum allowed value"
120#define MAX_MODE(BITS) ((BITS + 1023) / 1024)
140enum { CHAR_IS_SIGNED = (char)-1 < 0 };
144template <
typename _Tp>
146 static const bool value = _Tp(-1) < _Tp(1);
149template <
typename _Tp>
151 static const bool value =
false;
153#define DEF_IS_INTEGRAL(CTYPE) \
155 struct is_integral<CTYPE> { \
156 static const bool value = true; \
160DEF_IS_INTEGRAL(
signed char)
161DEF_IS_INTEGRAL(
unsigned char)
162DEF_IS_INTEGRAL(
short)
163DEF_IS_INTEGRAL(
unsigned short)
165DEF_IS_INTEGRAL(
unsigned int)
167DEF_IS_INTEGRAL(
unsigned long)
168DEF_IS_INTEGRAL(ap_slong)
169DEF_IS_INTEGRAL(ap_ulong)
170#undef DEF_IS_INTEGRAL
172template <
bool,
typename _Tp =
void>
175template <
typename _Tp>
180template <
typename _Tp>
185template <
typename _Tp>
202static inline unsigned char guess_radix(
const char* s) {
203 unsigned char rd = 10;
206 if (p[0] ==
'-' || p[0] ==
'+') ++p;
209 if (p[1] ==
'b' || p[1] ==
'B') {
211 }
else if (p[1] ==
'o' || p[1] ==
'O') {
213 }
else if (p[1] ==
'x' || p[1] ==
'X') {
215 }
else if (p[1] ==
'd' || p[1] ==
'D') {
228#define _AP_ROOT_TYPE ssdm_int
230#define _AP_ROOT_op_concat(Ret, X, Y) _ssdm_op_concat(Ret, X, Y)
231#define _AP_ROOT_op_get_bit(Val, Bit) _ssdm_op_get_bit(Val, Bit)
232#define _AP_ROOT_op_set_bit(Val, Bit, Repl) _ssdm_op_set_bit(Val, Bit, Repl)
233#define _AP_ROOT_op_get_range(Val, Lo, Hi) _ssdm_op_get_range(Val, Lo, Hi)
234#define _AP_ROOT_op_set_range(Val, Lo, Hi, Repl) \
235 _ssdm_op_set_range(Val, Lo, Hi, Repl)
236#define _AP_ROOT_op_reduce(Op, Val) _ssdm_op_reduce(Op, Val)
239template <
int _AP_W,
bool _AP_S,
bool _AP_C = _AP_W <= 64>
242template <
int _AP_W,
bool _AP_S>
245 ap_private<_AP_W, _AP_S> V;
248#define _AP_ROOT_TYPE ssdm_int_sim
250#include "ap_private.h"
253template <
typename _Tp1,
typename _Tp2,
typename _Tp3>
254inline _Tp1 _AP_ROOT_op_concat(
const _Tp1& Ret,
const _Tp2& X,
const _Tp3& Y) {
255 _Tp1 r = (X).
operator,(Y);
258#define _AP_ROOT_op_get_bit(Val, Bit) (Val).get_bit((Bit))
259template <
typename _Tp1,
typename _Tp2,
typename _Tp3>
260inline _Tp1& _AP_ROOT_op_set_bit(_Tp1& Val,
const _Tp2& Bit,
const _Tp3& Repl) {
261 (Val).set_bit((Bit), (Repl));
266#define _AP_ROOT_op_get_range(Val, Lo, Hi) (Val).range((Hi), (Lo))
267template <
typename _Tp1,
typename _Tp2,
typename _Tp3,
typename _Tp4>
268inline _Tp1& _AP_ROOT_op_set_range(_Tp1& Val,
const _Tp2& Lo,
const _Tp3& Hi,
270 (Val).range((Hi), (Lo)) = Repl;
273#define _AP_ROOT_op_and_reduce(Val) (Val).and_reduce()
274#define _AP_ROOT_op_nand_reduce(Val) (Val).nand_reduce()
275#define _AP_ROOT_op_or_reduce(Val) (Val).or_reduce()
276#define _AP_ROOT_op_xor_reduce(Val) (Val).xor_reduce()
278#define _AP_ROOT_op_reduce(Op, Val) _AP_ROOT_op_##Op##_reduce(Val)
292#define BIAS(e) ((1L << (e - 1L)) - 1L)
293#define HALF_BIAS BIAS(HALF_EXP)
294#define FLOAT_BIAS BIAS(FLOAT_EXP)
295#define DOUBLE_BIAS BIAS(DOUBLE_EXP)
297#define APFX_IEEE_DOUBLE_E_MAX DOUBLE_BIAS
298#define APFX_IEEE_DOUBLE_E_MIN (-DOUBLE_BIAS + 1)
300INLINE ap_ulong doubleToRawBits(
double pf) {
309INLINE
unsigned int floatToRawBits(
float pf) {
318#if _AP_ENABLE_HALF_ == 1
319INLINE
unsigned short halfToRawBits(half pf) {
328 return pf.get_bits();
334INLINE
double rawBitsToDouble(ap_ulong pi) {
344INLINE
float rawBitsToFloat(
unsigned long pi) {
353#if _AP_ENABLE_HALF_ == 1
355INLINE half rawBitsToHalf(
unsigned short pi) {