diff --git a/include/ap_common.h b/include/ap_common.h index b49b7e2..75b0d8f 100644 --- a/include/ap_common.h +++ b/include/ap_common.h @@ -56,9 +56,9 @@ #include // TODO Undefine in open-source release. -#define _AP_ENABLE_HALF_ 1 +// #define _AP_ENABLE_HALF_ 1 -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 // Before ap_private definition. #ifdef __SYNTHESIS__ #define _HLS_HALF_DEFINED_ @@ -168,8 +168,7 @@ class half; #endif // for detecting if char is signed. -#include -enum { CHAR_IS_SIGNED = CHAR_MIN < 0 }; +enum { CHAR_IS_SIGNED = (char)-1 < 0 }; // TODO we have similar traits in x_hls_utils.h, should consider unify. namespace _ap_type { @@ -702,7 +701,7 @@ INLINE unsigned int floatToRawBits(float pf) { return LD.__L; } -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 INLINE unsigned short halfToRawBits(half pf) { #ifdef __SYNTHESIS__ union { @@ -737,7 +736,7 @@ INLINE float rawBitsToFloat(unsigned long pi) { return LD.__D; } -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 // short is at least 16-bit INLINE half rawBitsToHalf(unsigned short pi) { #ifdef __SYNTHESIS__ diff --git a/include/ap_fixed.h b/include/ap_fixed.h index 631e1b4..1847c49 100644 --- a/include/ap_fixed.h +++ b/include/ap_fixed.h @@ -174,7 +174,7 @@ struct ap_fixed : ap_fixed_base<_AP_W, _AP_I, true, _AP_Q, _AP_O, _AP_N> { CTOR(unsigned long) CTOR(ap_slong) CTOR(ap_ulong) -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 CTOR(half) #endif CTOR(float) @@ -324,7 +324,7 @@ struct ap_ufixed : ap_fixed_base<_AP_W, _AP_I, false, _AP_Q, _AP_O, _AP_N> { CTOR(unsigned long) CTOR(ap_slong) CTOR(ap_ulong) -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 CTOR(half) #endif CTOR(float) diff --git a/include/ap_fixed_base.h b/include/ap_fixed_base.h index f486574..411679d 100644 --- a/include/ap_fixed_base.h +++ b/include/ap_fixed_base.h @@ -59,7 +59,7 @@ // for ap_int_base and its reference types. #include #ifndef __SYNTHESIS__ -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 // for half type #include #endif @@ -671,7 +671,7 @@ struct ap_fixed_base : _AP_ROOT_TYPE<_AP_W, _AP_S> { // TODO more optimized implementation. INLINE ap_fixed_base(float d) { *this = ap_fixed_base(double(d)); } -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 // TODO more optimized implementation. INLINE ap_fixed_base(half d) { *this = ap_fixed_base(double(d)); } #endif @@ -973,7 +973,7 @@ struct ap_fixed_base : _AP_ROOT_TYPE<_AP_W, _AP_S> { return rawBitsToFloat(m); } -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 /// convert function to half. /** only round-half-to-even mode supported, does not obey FE env. */ INLINE half to_half() const { @@ -1029,7 +1029,7 @@ struct ap_fixed_base : _AP_ROOT_TYPE<_AP_W, _AP_S> { INLINE operator float() const { return to_float(); } -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 INLINE operator half() const { return to_half(); } #endif diff --git a/include/ap_int.h b/include/ap_int.h index a0831c0..af2e805 100644 --- a/include/ap_int.h +++ b/include/ap_int.h @@ -156,7 +156,7 @@ struct ap_int : ap_int_base<_AP_W, true> { #undef CTOR ap_int(double val) : Base(val) {} ap_int(float val) : Base(val) {} -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 ap_int(half val) : Base(val) {} #endif @@ -290,7 +290,7 @@ struct ap_uint : ap_int_base<_AP_W, false> { #undef CTOR ap_uint(double val) : Base(val) {} ap_uint(float val) : Base(val) {} -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 ap_uint(half val) : Base(val) {} #endif diff --git a/include/ap_int_base.h b/include/ap_int_base.h index 720c9d7..aea2009 100644 --- a/include/ap_int_base.h +++ b/include/ap_int_base.h @@ -62,16 +62,13 @@ #include #ifndef __SYNTHESIS__ -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 #include #endif #include #include #endif -// for ptrdiff_t used in increasing pointer. -#include - /* ---------------------------------------------------------------- * ap_int_base: AutoPilot integer/Arbitrary precision integer. * ---------------------------------------------------------------- @@ -251,7 +248,7 @@ struct ap_int_base : public _AP_ROOT_TYPE<_AP_W, _AP_S> { CTOR_FROM_INT(ap_ulong, _AP_SIZE_ap_slong, false) #undef CTOR_FROM_INT -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 /// ctor from half. // TODO optimize INLINE ap_int_base(half op) { @@ -1391,13 +1388,13 @@ OP_BIN_AP2(%, mod) template \ INLINE PTR_TYPE* operator BIN_OP(PTR_TYPE* i_op, \ const ap_int_base<_AP_W, _AP_S>& op) { \ - std::ptrdiff_t op2 = op.to_long(); /* Not all implementation */ \ + ap_slong op2 = op.to_int64(); /* Not all implementation */ \ return i_op BIN_OP op2; \ } \ template \ INLINE PTR_TYPE* operator BIN_OP(const ap_int_base<_AP_W, _AP_S>& op, \ PTR_TYPE* i_op) { \ - std::ptrdiff_t op2 = op.to_long(); /* Not all implementation */ \ + ap_slong op2 = op.to_int64(); /* Not all implementation */ \ return op2 BIN_OP i_op; \ } @@ -1429,7 +1426,7 @@ OP_BIN_WITH_PTR(-) OP_BIN_WITH_FLOAT(+, C_TYPE) \ OP_BIN_WITH_FLOAT(-, C_TYPE) -#ifdef _AP_ENABLE_HALF_ +#if _AP_ENABLE_HALF_ == 1 ALL_OP_WITH_FLOAT(half) #endif ALL_OP_WITH_FLOAT(float)