mirror of
https://github.com/DrasLorus/HLS_arbitrary_Precision_Types.git
synced 2024-07-06 14:35:18 +02:00
avoid standard C++ header as much as possible
This commit is contained in:
parent
beba102899
commit
243d1f094e
|
@ -56,9 +56,9 @@
|
||||||
#include <ap_decl.h>
|
#include <ap_decl.h>
|
||||||
|
|
||||||
// TODO Undefine in open-source release.
|
// 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.
|
// Before ap_private definition.
|
||||||
#ifdef __SYNTHESIS__
|
#ifdef __SYNTHESIS__
|
||||||
#define _HLS_HALF_DEFINED_
|
#define _HLS_HALF_DEFINED_
|
||||||
|
@ -168,8 +168,7 @@ class half;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for detecting if char is signed.
|
// for detecting if char is signed.
|
||||||
#include <climits>
|
enum { CHAR_IS_SIGNED = (char)-1 < 0 };
|
||||||
enum { CHAR_IS_SIGNED = CHAR_MIN < 0 };
|
|
||||||
|
|
||||||
// TODO we have similar traits in x_hls_utils.h, should consider unify.
|
// TODO we have similar traits in x_hls_utils.h, should consider unify.
|
||||||
namespace _ap_type {
|
namespace _ap_type {
|
||||||
|
@ -702,7 +701,7 @@ INLINE unsigned int floatToRawBits(float pf) {
|
||||||
return LD.__L;
|
return LD.__L;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
INLINE unsigned short halfToRawBits(half pf) {
|
INLINE unsigned short halfToRawBits(half pf) {
|
||||||
#ifdef __SYNTHESIS__
|
#ifdef __SYNTHESIS__
|
||||||
union {
|
union {
|
||||||
|
@ -737,7 +736,7 @@ INLINE float rawBitsToFloat(unsigned long pi) {
|
||||||
return LD.__D;
|
return LD.__D;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
// short is at least 16-bit
|
// short is at least 16-bit
|
||||||
INLINE half rawBitsToHalf(unsigned short pi) {
|
INLINE half rawBitsToHalf(unsigned short pi) {
|
||||||
#ifdef __SYNTHESIS__
|
#ifdef __SYNTHESIS__
|
||||||
|
|
|
@ -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(unsigned long)
|
||||||
CTOR(ap_slong)
|
CTOR(ap_slong)
|
||||||
CTOR(ap_ulong)
|
CTOR(ap_ulong)
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
CTOR(half)
|
CTOR(half)
|
||||||
#endif
|
#endif
|
||||||
CTOR(float)
|
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(unsigned long)
|
||||||
CTOR(ap_slong)
|
CTOR(ap_slong)
|
||||||
CTOR(ap_ulong)
|
CTOR(ap_ulong)
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
CTOR(half)
|
CTOR(half)
|
||||||
#endif
|
#endif
|
||||||
CTOR(float)
|
CTOR(float)
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
// for ap_int_base and its reference types.
|
// for ap_int_base and its reference types.
|
||||||
#include <ap_int.h>
|
#include <ap_int.h>
|
||||||
#ifndef __SYNTHESIS__
|
#ifndef __SYNTHESIS__
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
// for half type
|
// for half type
|
||||||
#include <hls_half.h>
|
#include <hls_half.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -671,7 +671,7 @@ struct ap_fixed_base : _AP_ROOT_TYPE<_AP_W, _AP_S> {
|
||||||
// TODO more optimized implementation.
|
// TODO more optimized implementation.
|
||||||
INLINE ap_fixed_base(float d) { *this = ap_fixed_base(double(d)); }
|
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.
|
// TODO more optimized implementation.
|
||||||
INLINE ap_fixed_base(half d) { *this = ap_fixed_base(double(d)); }
|
INLINE ap_fixed_base(half d) { *this = ap_fixed_base(double(d)); }
|
||||||
#endif
|
#endif
|
||||||
|
@ -973,7 +973,7 @@ struct ap_fixed_base : _AP_ROOT_TYPE<_AP_W, _AP_S> {
|
||||||
return rawBitsToFloat(m);
|
return rawBitsToFloat(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
/// convert function to half.
|
/// convert function to half.
|
||||||
/** only round-half-to-even mode supported, does not obey FE env. */
|
/** only round-half-to-even mode supported, does not obey FE env. */
|
||||||
INLINE half to_half() const {
|
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(); }
|
INLINE operator float() const { return to_float(); }
|
||||||
|
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
INLINE operator half() const { return to_half(); }
|
INLINE operator half() const { return to_half(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ struct ap_int : ap_int_base<_AP_W, true> {
|
||||||
#undef CTOR
|
#undef CTOR
|
||||||
ap_int(double val) : Base(val) {}
|
ap_int(double val) : Base(val) {}
|
||||||
ap_int(float val) : Base(val) {}
|
ap_int(float val) : Base(val) {}
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
ap_int(half val) : Base(val) {}
|
ap_int(half val) : Base(val) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ struct ap_uint : ap_int_base<_AP_W, false> {
|
||||||
#undef CTOR
|
#undef CTOR
|
||||||
ap_uint(double val) : Base(val) {}
|
ap_uint(double val) : Base(val) {}
|
||||||
ap_uint(float val) : Base(val) {}
|
ap_uint(float val) : Base(val) {}
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
ap_uint(half val) : Base(val) {}
|
ap_uint(half val) : Base(val) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -62,16 +62,13 @@
|
||||||
|
|
||||||
#include <ap_common.h>
|
#include <ap_common.h>
|
||||||
#ifndef __SYNTHESIS__
|
#ifndef __SYNTHESIS__
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
#include <hls_half.h>
|
#include <hls_half.h>
|
||||||
#endif
|
#endif
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for ptrdiff_t used in increasing pointer.
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
* ap_int_base: AutoPilot integer/Arbitrary precision integer.
|
* 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)
|
CTOR_FROM_INT(ap_ulong, _AP_SIZE_ap_slong, false)
|
||||||
#undef CTOR_FROM_INT
|
#undef CTOR_FROM_INT
|
||||||
|
|
||||||
#ifdef _AP_ENABLE_HALF_
|
#if _AP_ENABLE_HALF_ == 1
|
||||||
/// ctor from half.
|
/// ctor from half.
|
||||||
// TODO optimize
|
// TODO optimize
|
||||||
INLINE ap_int_base(half op) {
|
INLINE ap_int_base(half op) {
|
||||||
|
@ -1391,13 +1388,13 @@ OP_BIN_AP2(%, mod)
|
||||||
template <typename PTR_TYPE, int _AP_W, bool _AP_S> \
|
template <typename PTR_TYPE, int _AP_W, bool _AP_S> \
|
||||||
INLINE PTR_TYPE* operator BIN_OP(PTR_TYPE* i_op, \
|
INLINE PTR_TYPE* operator BIN_OP(PTR_TYPE* i_op, \
|
||||||
const ap_int_base<_AP_W, _AP_S>& 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; \
|
return i_op BIN_OP op2; \
|
||||||
} \
|
} \
|
||||||
template <typename PTR_TYPE, int _AP_W, bool _AP_S> \
|
template <typename PTR_TYPE, int _AP_W, bool _AP_S> \
|
||||||
INLINE PTR_TYPE* operator BIN_OP(const ap_int_base<_AP_W, _AP_S>& op, \
|
INLINE PTR_TYPE* operator BIN_OP(const ap_int_base<_AP_W, _AP_S>& op, \
|
||||||
PTR_TYPE* i_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; \
|
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) \
|
||||||
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)
|
ALL_OP_WITH_FLOAT(half)
|
||||||
#endif
|
#endif
|
||||||
ALL_OP_WITH_FLOAT(float)
|
ALL_OP_WITH_FLOAT(float)
|
||||||
|
|
Loading…
Reference in a new issue