avoid standard C++ header as much as possible

This commit is contained in:
Yuanjie Huang 2019-01-16 18:11:20 +08:00
parent beba102899
commit 243d1f094e
5 changed files with 18 additions and 22 deletions

View file

@ -56,9 +56,9 @@
#include <ap_decl.h>
// 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 <climits>
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__

View file

@ -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)

View file

@ -59,7 +59,7 @@
// for ap_int_base and its reference types.
#include <ap_int.h>
#ifndef __SYNTHESIS__
#ifdef _AP_ENABLE_HALF_
#if _AP_ENABLE_HALF_ == 1
// for half type
#include <hls_half.h>
#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

View file

@ -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

View file

@ -62,16 +62,13 @@
#include <ap_common.h>
#ifndef __SYNTHESIS__
#ifdef _AP_ENABLE_HALF_
#if _AP_ENABLE_HALF_ == 1
#include <hls_half.h>
#endif
#include <iostream>
#include <string.h>
#endif
// for ptrdiff_t used in increasing pointer.
#include <cstddef>
/* ----------------------------------------------------------------
* 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 <typename PTR_TYPE, int _AP_W, bool _AP_S> \
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 <typename PTR_TYPE, int _AP_W, bool _AP_S> \
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)