init with headers from 2019.1 (CL 2399090)

This commit is contained in:
Yuanjie Huang 2018-11-28 20:24:04 -08:00
commit 5ae3fee9fa
17 changed files with 23890 additions and 0 deletions

764
include/ap_common.h Normal file
View file

@ -0,0 +1,764 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef __AP_COMMON_H__
#define __AP_COMMON_H__
// ----------------------------------------------------------------------
#include <ap_decl.h>
// Macro functions
#define AP_MAX(a, b) ((a) > (b) ? (a) : (b))
#define AP_MIN(a, b) ((a) < (b) ? (a) : (b))
#define AP_ABS(a) ((a) >= 0 ? (a) : -(a))
#ifndef AP_ASSERT
#ifndef __SYNTHESIS__
#include <assert.h>
#define AP_ASSERT(cond, msg) assert((cond) && (msg))
#else
#define AP_ASSERT(cond, msg)
#endif // ifndef __SYNTHESIS__
#endif // ifndef AP_ASSERT
#ifndef __SYNTHESIS__
// for fprintf messages.
#include <stdio.h>
// for exit on error.
#include <stdlib.h>
#endif
// same disable condition as assert.
#if !defined(__SYNTHESIS__) && !defined(NDEBUG)
#define _AP_DEBUG(cond, ...) \
do { \
if ((cond)) { \
fprintf(stderr, "DEBUG: " __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
} while (0)
#define _AP_WARNING(cond, ...) \
do { \
if ((cond)) { \
fprintf(stderr, "WARNING: " __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
} while (0)
#define _AP_ERROR(cond, ...) \
do { \
if ((cond)) { \
fprintf(stderr, "ERROR: " __VA_ARGS__); \
fprintf(stderr, "\n"); \
abort(); \
} \
} while (0)
#else // if !defined(__SYNTHESIS__) && !defined(NDEBUG)
#define __AP_VOID_CAST static_cast<void>
#define _AP_DEBUG(cond, ...) (__AP_VOID_CAST(0))
#define _AP_WARNING(cond, ...) (__AP_VOID_CAST(0))
#define _AP_ERROR(cond, ...) (__AP_VOID_CAST(0))
#endif // if !defined(__SYNTHESIS__) && !defined(NDEBUG) else
// ----------------------------------------------------------------------
// Attribute only for synthesis
#ifdef __SYNTHESIS__
#define INLINE inline __attribute__((always_inline))
//#define INLINE inline __attribute__((noinline))
#else
#define INLINE inline
#endif
#define AP_WEAK
// __attribute__((weak))
#ifndef AP_INT_MAX_W
#define AP_INT_MAX_W 1024
#endif
#define BIT_WIDTH_UPPER_LIMIT (1 << 15)
#if AP_INT_MAX_W > BIT_WIDTH_UPPER_LIMIT
#error "Bitwidth exceeds 32768 (1 << 15), the maximum allowed value"
#endif
#define MAX_MODE(BITS) ((BITS + 1023) / 1024)
// ----------------------------------------------------------------------
// XXX apcc cannot handle global std::ios_base::Init() brought in by <iostream>
#ifndef AP_AUTOCC
#ifndef __SYNTHESIS__
// for overload operator<<
#include <iostream>
#endif
#endif // ifndef AP_AUTOCC
#ifndef __SYNTHESIS__
// for string format.
#include <sstream>
// for string.
#include <string>
#endif
// for detecting if char is signed.
#include <climits>
enum { CHAR_IS_SIGNED = CHAR_MIN < 0 };
// TODO we have similar traits in x_hls_utils.h, should consider unify.
namespace _ap_type {
template <typename _Tp>
struct is_signed {
static const bool value = _Tp(-1) < _Tp(1);
};
template <typename _Tp>
struct is_integral {
static const bool value = false;
};
#define DEF_IS_INTEGRAL(CTYPE) \
template <> \
struct is_integral<CTYPE> { \
static const bool value = true; \
};
DEF_IS_INTEGRAL(bool)
DEF_IS_INTEGRAL(char)
DEF_IS_INTEGRAL(signed char)
DEF_IS_INTEGRAL(unsigned char)
DEF_IS_INTEGRAL(short)
DEF_IS_INTEGRAL(unsigned short)
DEF_IS_INTEGRAL(int)
DEF_IS_INTEGRAL(unsigned int)
DEF_IS_INTEGRAL(long)
DEF_IS_INTEGRAL(unsigned long)
DEF_IS_INTEGRAL(ap_slong)
DEF_IS_INTEGRAL(ap_ulong)
#undef DEF_IS_INTEGRAL
template <bool, typename _Tp = void>
struct enable_if {};
// partial specialization for true
template <typename _Tp>
struct enable_if<true, _Tp> {
typedef _Tp type;
};
template <typename _Tp>
struct remove_const {
typedef _Tp type;
};
template <typename _Tp>
struct remove_const<_Tp const> {
typedef _Tp type;
};
} // namespace _ap_type
// ----------------------------------------------------------------------
// Define ssdm_int and _ssdm_op.
#ifdef __SYNTHESIS__
#if ((__clang_major__ == 3) && (__clang_minor__ == 1))
/* HECTOR is a tool for formal system-level to RTL equivalence checking.
* https://www.research.ibm.com/haifa/conferences/hvc2008/present/CarlPixleyHVC08.pdf
* we used to used Hector.h here instead of following ssdm_int definition,
* but now it is deleted.
*/
template <int _AP_N, bool _AP_S>
struct ssdm_int;
#define AP_INT_BASE(_AP_N, mode) \
template <> \
struct ssdm_int<_AP_N + 1024 * mode, true> { \
int V __attribute__((bitwidth(_AP_N + 1024 * mode))); \
INLINE ssdm_int<_AP_N + 1024 * mode, true>(){}; \
}; \
template <> \
struct ssdm_int<_AP_N + 1024 * mode, false> { \
unsigned int V __attribute__((bitwidth(_AP_N + 1024 * mode))); \
INLINE ssdm_int<_AP_N + 1024 * mode, false>(){}; \
};
#if MAX_MODE(AP_INT_MAX_W) >= 1
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 0)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 2
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 1)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 3
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 2)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 4
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 3)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 5
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 4)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 6
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 5)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 7
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 6)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 8
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 7)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 9
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 8)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 10
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 9)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 11
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 10)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 12
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 11)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 13
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 12)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 14
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 13)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 15
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 14)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 16
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 15)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 17
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 16)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 18
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 17)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 19
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 18)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 20
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 19)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 21
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 20)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 22
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 21)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 23
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 22)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 24
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 23)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 25
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 24)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 26
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 25)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 27
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 26)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 28
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 27)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 29
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 28)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 30
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 29)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 31
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 30)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#if MAX_MODE(AP_INT_MAX_W) >= 32
#define HANDLE_BAT(TYPE, _AP_N) AP_INT_BASE(_AP_N, 31)
#define APINT_DEFINE_INT64
#include "etc/autopilot_dt.def"
#undef APINT_DEFINE_INT64
#undef HANDLE_BAT
#endif
#undef MAX_MODE
#undef AP_INT_BASE
#else // HLS clang of higher version than 3.1
template <int _AP_N, bool _AP_S>
struct ssdm_int;
template <int _AP_N>
struct ssdm_int<_AP_N, true> {
int V __attribute__((bitwidth(_AP_N)));
INLINE ssdm_int<_AP_N, true>(){};
};
template <int _AP_N>
struct ssdm_int<_AP_N, false> {
unsigned V __attribute__((bitwidth(_AP_N)));
INLINE ssdm_int<_AP_N, false>(){};
};
#endif // clang 3.1 test
// FIXME typeof is an compiler extension.
// FIXME use ({}) to return value is GCC extension.
#define _ssdm_op_concat(Ret, X, Y) \
({ \
typeof(Ret) __Result__ = 0; \
typeof(X) __X2__ = X; \
typeof(Y) __Y2__ = Y; \
__builtin_bit_concat((void*)(&__Result__), (void*)(&__X2__), \
(void*)(&__Y2__)); \
__Result__; \
})
#define _ssdm_op_get_bit(Val, Bit) \
({ \
typeof(Val) __Val2__ = Val; \
bool __Result__ = __builtin_bit_select((void*)(&__Val2__), Bit); \
__Result__; \
})
#define _ssdm_op_set_bit(Val, Bit, Repl) \
({ \
typename _ap_type::remove_const<typeof(Val)>::type __Result__ = 0; \
typeof(Val) __Val2__ = Val; \
typeof(Repl) __Repl2__ = !!Repl; \
__builtin_bit_part_set((void*)(&__Result__), (void*)(&__Val2__), \
(void*)(&__Repl2__), Bit, Bit); \
__Result__; \
})
#define _ssdm_op_get_range(Val, Lo, Hi) \
({ \
typename _ap_type::remove_const<typeof(Val)>::type __Result__ = 0; \
typeof(Val) __Val2__ = Val; \
__builtin_bit_part_select((void*)(&__Result__), (void*)(&__Val2__), Lo, \
Hi); \
__Result__; \
})
#define _ssdm_op_set_range(Val, Lo, Hi, Repl) \
({ \
typename _ap_type::remove_const<typeof(Val)>::type __Result__ = 0; \
typeof(Val) __Val2__ = Val; \
typeof(Repl) __Repl2__ = Repl; \
__builtin_bit_part_set((void*)(&__Result__), (void*)(&__Val2__), \
(void*)(&__Repl2__), Lo, Hi); \
__Result__; \
})
#include "etc/autopilot_ssdm_bits.h"
extern "C" void _ssdm_string2bits(...);
#endif // ifdef __SYNTHESIS__
#ifndef NON_C99STRING
#define _AP_C99 true
#else
#define _AP_C99 false
#endif
static inline unsigned char guess_radix(const char* s) {
unsigned char rd = 10; ///< default radix
const char* p = s;
// skip neg sign if it exists
if (p[0] == '-' || p[0] == '+') ++p;
// guess based on following two bits.
if (p[0] == '0') {
if (p[1] == 'b' || p[1] == 'B') {
rd = 2;
} else if (p[1] == 'o' || p[1] == 'O') {
rd = 8;
} else if (p[1] == 'x' || p[1] == 'X') {
rd = 16;
} else if (p[1] == 'd' || p[1] == 'D') {
rd = 10;
}
}
return rd;
}
// ----------------------------------------------------------------------
// Forward declaration of all AP types.
// Before ap_private definition.
#ifdef __SYNTHESIS__
#define _HLS_HALF_DEFINED_
typedef __fp16 half;
#else
class half;
#endif
// FIXME previously, ap_int_syn.h includes hls_half.h, which includes cmath.h
// even during synthesis. Some test cases are spoiled...
#ifdef __cplusplus
#ifndef __SYNTHESIS__
#include <cmath>
#endif
#endif
// ----------------------------------------------------------------------
// Basic integral struct upon which ap_int and ap_fixed are defined.
#ifdef __SYNTHESIS__
// Use ssdm_int, a compiler dependent, attribute constrained integeral type as
// basic data type.
#define _AP_ROOT_TYPE ssdm_int
// Basic ops.
#define _AP_ROOT_op_concat(Ret, X, Y) _ssdm_op_concat(Ret, X, Y)
#define _AP_ROOT_op_get_bit(Val, Bit) _ssdm_op_get_bit(Val, Bit)
#define _AP_ROOT_op_set_bit(Val, Bit, Repl) _ssdm_op_set_bit(Val, Bit, Repl)
#define _AP_ROOT_op_get_range(Val, Lo, Hi) _ssdm_op_get_range(Val, Lo, Hi)
#define _AP_ROOT_op_set_range(Val, Lo, Hi, Repl) \
_ssdm_op_set_range(Val, Lo, Hi, Repl)
#define _AP_ROOT_op_reduce(Op, Val) _ssdm_op_reduce(Op, Val)
#else // ifdef __SYNTHESIS__
// Use ap_private for compiler-independent basic data type
template <int _AP_W, bool _AP_S, bool _AP_C = _AP_W <= 64>
class ap_private;
/// model ssdm_int in standard C++ for simulation.
template <int _AP_W, bool _AP_S>
struct ssdm_int_sim {
/// integral type with template-specified width and signedness.
ap_private<_AP_W, _AP_S> V;
ssdm_int_sim() {}
};
#define _AP_ROOT_TYPE ssdm_int_sim
// private's ref uses _AP_ROOT_TYPE.
#include <etc/ap_private.h>
// XXX The C-sim model cannot use GCC-extension
// Basic ops. Ret and Val are ap_private.
template <typename _Tp1, typename _Tp2, typename _Tp3>
inline _Tp1 _AP_ROOT_op_concat(const _Tp1& Ret, const _Tp2& X, const _Tp3& Y) {
_Tp1 r = (X).operator,(Y);
return r;
}
#define _AP_ROOT_op_get_bit(Val, Bit) (Val).get_bit((Bit))
template <typename _Tp1, typename _Tp2, typename _Tp3>
inline _Tp1& _AP_ROOT_op_set_bit(_Tp1& Val, const _Tp2& Bit, const _Tp3& Repl) {
(Val).set_bit((Bit), (Repl));
return Val;
}
// notice the order of high and low index is different in ssdm call and
// ap_private.range()...
#define _AP_ROOT_op_get_range(Val, Lo, Hi) (Val).range((Hi), (Lo))
template <typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4>
inline _Tp1& _AP_ROOT_op_set_range(_Tp1& Val, const _Tp2& Lo, const _Tp3& Hi,
const _Tp4& Repl) {
(Val).range((Hi), (Lo)) = Repl;
return (Val);
}
#define _AP_ROOT_op_and_reduce(Val) (Val).and_reduce()
#define _AP_ROOT_op_nand_reduce(Val) (Val).nand_reduce()
#define _AP_ROOT_op_or_reduce(Val) (Val).or_reduce()
#define _AP_ROOT_op_xor_reduce(Val) (Val).xor_reduce()
// ## is the concatenation in preprocessor:
#define _AP_ROOT_op_reduce(Op, Val) _AP_ROOT_op_##Op##_reduce(Val)
#endif // ifdef __SYNTHESIS__ else
// ----------------------------------------------------------------------
// Constants for half, single, double pricision floating points
#define HALF_MAN 10
#define FLOAT_MAN 23
#define DOUBLE_MAN 52
#define HALF_EXP 5
#define FLOAT_EXP 8
#define DOUBLE_EXP 11
#define BIAS(e) ((1L << (e - 1L)) - 1L)
#define HALF_BIAS BIAS(HALF_EXP)
#define FLOAT_BIAS BIAS(FLOAT_EXP)
#define DOUBLE_BIAS BIAS(DOUBLE_EXP)
#define APFX_IEEE_DOUBLE_E_MAX DOUBLE_BIAS
#define APFX_IEEE_DOUBLE_E_MIN (-DOUBLE_BIAS + 1)
INLINE ap_ulong doubleToRawBits(double pf) {
union {
ap_ulong __L;
double __D;
} LD;
LD.__D = pf;
return LD.__L;
}
INLINE unsigned int floatToRawBits(float pf) {
union {
unsigned int __L;
float __D;
} LD;
LD.__D = pf;
return LD.__L;
}
INLINE unsigned short halfToRawBits(half pf) {
#ifdef __SYNTHESIS__
union {
unsigned short __L;
half __D;
} LD;
LD.__D = pf;
return LD.__L;
#else
return pf.get_bits();
#endif
}
// usigned long long is at least 64-bit
INLINE double rawBitsToDouble(ap_ulong pi) {
union {
ap_ulong __L;
double __D;
} LD;
LD.__L = pi;
return LD.__D;
}
// long is at least 32-bit
INLINE float rawBitsToFloat(unsigned long pi) {
union {
unsigned int __L;
float __D;
} LD;
LD.__L = pi;
return LD.__D;
}
// short is at least 16-bit
INLINE half rawBitsToHalf(unsigned short pi) {
#ifdef __SYNTHESIS__
union {
unsigned short __L;
half __D;
} LD;
LD.__L = pi;
return LD.__D;
#else
// sim model of half has a non-trivial constructor
half __D;
__D.set_bits(pi);
return __D;
#endif
}
#endif // ifndef __AP_COMMON_H__ else
// -*- cpp -*-
// vim: fdm=marker:foldmarker=#if,#endif:nofoldenable
// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689

246
include/ap_decl.h Normal file
View file

@ -0,0 +1,246 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef __AP_DECL_H__
#define __AP_DECL_H__
// ----------------------------------------------------------------------
#if !defined(__AP_FIXED_H__) && !defined(__AP_INT_H__) && !defined(__AUTOPILOT_CBE_H__) && !defined(__HLS_HALF_H__)
#error "Only ap_fixed.h and ap_int.h can be included directly in user code."
#endif
// Test __SYNTHESIS__ only for mode
#if !defined(__SYNTHESIS__) && (defined(AESL_SYN) || defined(__HLS_SYN__))
//#pragma message "AESL_SYN and __HLS_SYN__ should be replaced by __SYNTHESIS__"
#define __SYNTHESIS__
#endif
/* for safety*/
#if (defined(_AP_N) || defined(_AP_C))
#error One or more of the following is defined: _AP_N, _AP_C. Definition conflicts with their usage as template parameters.
#endif
/* for safety*/
#if (defined(_AP_W) || defined(_AP_I) || defined(_AP_S) || defined(_AP_Q) || \
defined(_AP_O) || defined(_AP_W2) || defined(_AP_I2) || \
defined(_AP_S2) || defined(_AP_Q2) || defined(_AP_O2) || \
defined(_AP_N) || defined(_AP_N2))
#error \
"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."
#endif
/*for safety*/
#if (defined(_AP_W3) || defined(_AP_S3) || defined(_AP_W4) || defined(_AP_S4))
#error \
"One or more of the following is defined: _AP_W3, _AP_S3, _AP_W4,_AP_S4. Definition conflicts with their usage as template parameters."
#endif
#if (defined(_AP_W1) || defined(_AP_S1) || defined(_AP_T) || \
defined(_AP_T1) || defined(_AP_T2) || defined(_AP_T3) || defined(_AP_T4))
#error \
"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."
#endif
#ifndef __cplusplus
#error "AP data type can only be used in C++"
#endif
// ----------------------------------------------------------------------
#ifndef __SC_COMPATIBLE__
/// ap_fixed quantification mode
enum ap_q_mode {
AP_RND, //< rounding to plus infinity
AP_RND_ZERO, //< rounding to zero
AP_RND_MIN_INF, //< rounding to minus infinity
AP_RND_INF, //< rounding to infinity
AP_RND_CONV, //< convergent rounding
AP_TRN, //< truncation
AP_TRN_ZERO, //< truncation to zero
};
// FIXME for legacy code
#ifndef SYSTEMC_INCLUDED
#define SC_RND AP_RND
#define SC_RND_ZERO AP_RND_ZERO
#define SC_RND_MIN_INF AP_RND_MIN_INF
#define SC_RND_INF AP_RND_INF
#define SC_RND_CONV AP_RND_CONV
#define SC_TRN AP_TRN
#define SC_TRN_ZERO AP_TRN_ZERO
#endif // !defined(SYSTEMC_INCLUDED)
/// ap_fixed saturation mode
enum ap_o_mode {
AP_SAT, //< saturation
AP_SAT_ZERO, //< saturation to zero
AP_SAT_SYM, //< symmetrical saturation
AP_WRAP, //< wrap-around (*)
AP_WRAP_SM, //< sign magnitude wrap-around (*)
};
// FIXME for legacy code
#ifndef SYSTEMC_INCLUDED
#define SC_SAT AP_SAT
#define SC_SAT_ZERO AP_SAT_ZERO
#define SC_SAT_SYM AP_SAT_SYM
#define SC_WRAP AP_WRAP
#define SC_WRAP_SM AP_WRAP_SM
#endif // !defined(SYSTEMC_INCLUDED)
#else // defined(__SC_COMPATIBLE__)
// There will not be sc_fxdefs.h, and the emu should be defined by ap_fixed.
/// ap_fixed quantification mode
enum ap_q_mode {
SC_RND, //< rounding to plus infinity
SC_RND_ZERO, //< rounding to zero
SC_RND_MIN_INF, //< rounding to minus infinity
SC_RND_INF, //< rounding to infinity
SC_RND_CONV, //< convergent rounding
SC_TRN, //< truncation
SC_TRN_ZERO, //< truncation to zero
};
#define AP_RND SC_RND
#define AP_RND_ZERO SC_RND_ZERO
#define AP_RND_MIN_INF SC_RND_MIN_INF
#define AP_RND_INF SC_RND_INF
#define AP_RND_CONV SC_RND_CONV
#define AP_TRN SC_TRN
#define AP_TRN_ZERO SC_TRN_ZERO
/// ap_fixed saturation mode
enum ap_o_mode {
SC_SAT, //< saturation
SC_SAT_ZERO, //< saturation to zero
SC_SAT_SYM, //< symmetrical saturation
SC_WRAP, //< wrap-around (*)
SC_WRAP_SM, //< sign magnitude wrap-around (*)
};
#define AP_SAT SC_SAT
#define AP_SAT_ZERO SC_SAT_ZERO
#define AP_SAT_SYM SC_SAT_SYM
#define AP_WRAP SC_WRAP
#define AP_WRAP_SM SC_WRAP_SM
#endif // defined(__SC_COMPATIBLE__)
template <int _AP_W, bool _AP_S>
struct ap_int_base;
template <int _AP_W>
struct ap_int;
template <int _AP_W>
struct ap_uint;
template <int _AP_W, bool _AP_S>
struct ap_range_ref;
template <int _AP_W, bool _AP_S>
struct ap_bit_ref;
template <int _AP_W1, typename _AP_T1, int _AP_W2, typename _AP_T2>
struct ap_concat_ref;
template <int _AP_W, int _AP_I, bool _AP_S = true, ap_q_mode _AP_Q = AP_TRN,
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
struct ap_fixed_base;
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
struct ap_fixed;
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q = AP_TRN,
ap_o_mode _AP_O = AP_WRAP, int _AP_N = 0>
struct ap_ufixed;
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
struct af_range_ref;
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
struct af_bit_ref;
/// string base mode
enum BaseMode { AP_BIN = 2, AP_OCT = 8, AP_DEC = 10, AP_HEX = 16 };
#ifndef SYSTEMC_INCLUDED
#define SC_BIN 2
#define SC_OCT 8
#define SC_DEC 10
#define SC_HEX 16
#endif // !defined(SYSTEMC_INCLUDED)
// Alias C data types
#ifdef _MSC_VER
typedef signed __int64 ap_slong;
typedef unsigned __int64 ap_ulong;
#else // !defined(_MSC_VER)
typedef signed long long ap_slong;
typedef unsigned long long ap_ulong;
#endif // !defined(_MSC_VER)
enum {
_AP_SIZE_char = 8,
_AP_SIZE_short = sizeof(short) * 8,
_AP_SIZE_int = sizeof(int) * 8,
_AP_SIZE_long = sizeof(long) * 8,
_AP_SIZE_ap_slong = sizeof(ap_slong) * 8
};
#endif // !defined(__AP_DECL_H__)
// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689

384
include/ap_fixed.h Normal file
View file

@ -0,0 +1,384 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef __AP_FIXED_H__
#define __AP_FIXED_H__
#include <ap_common.h>
#include <ap_fixed_base.h>
#include <ap_fixed_ref.h>
//---------------------------------------------------------------
/// Signed Arbitrary Precision Fixed-Point Type.
// default for _AP_Q, _AP_O and _AP_N set in ap_decl.h
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
struct ap_fixed : ap_fixed_base<_AP_W, _AP_I, true, _AP_Q, _AP_O, _AP_N> {
typedef ap_fixed_base<_AP_W, _AP_I, true, _AP_Q, _AP_O, _AP_N> Base;
// Constructor
/// default ctor
INLINE ap_fixed() : Base() {}
/// copy ctor from ap_fixed_base.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(const volatile ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& op)
: Base(op) {}
//// from ap_fixed
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_fixed(
// const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_fixed(
// const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
//// from ap_ufixed.
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_fixed(
// const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>(op)) {
//}
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_fixed(
// const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>(op)) {
//}
/// copy ctor from ap_int_base.
template <int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const ap_int_base<_AP_W2, _AP_S2>& op) : Base(op) {}
template <int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const volatile ap_int_base<_AP_W2, _AP_S2>& op) : Base(op) {}
//// from ap_int.
//template <int _AP_W2>
//INLINE ap_fixed(const ap_int<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, true>(op)) {}
//template <int _AP_W2>
//INLINE ap_fixed(const volatile ap_int<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, true>(op)) {}
//// from ap_uint.
//template <int _AP_W2>
//INLINE ap_fixed(const ap_uint<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, false>(op)) {}
//template <int _AP_W2>
//INLINE ap_fixed(const volatile ap_uint<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, false>(op)) {}
// from ap_bit_ref.
template <int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const ap_bit_ref<_AP_W2, _AP_S2>& op) : Base(op) {}
// from ap_range_ref.
template <int _AP_W2, bool _AP_S2>
INLINE ap_fixed(const ap_range_ref<_AP_W2, _AP_S2>& op) : Base(op) {}
// from ap_concat_ref.
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_fixed(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& op)
: Base(op) {}
// from af_bit_ref.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
// from af_range_ref.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_fixed(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
// from c types.
#define CTOR(TYPE) \
INLINE ap_fixed(TYPE v) : Base(v) {}
CTOR(bool)
CTOR(char)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(ap_slong)
CTOR(ap_ulong)
CTOR(half)
CTOR(float)
CTOR(double)
#undef CTOR
INLINE ap_fixed(const char* s) : Base(s) {}
INLINE ap_fixed(const char* s, signed char rd) : Base(s, rd) {}
// Assignment
// The assignment operator is technically inherited; however, it is always
// hidden by an explicitly or implicitly defined assignment operator for the
// derived class.
/* XXX ctor will be used when right is not of proper type. */
INLINE ap_fixed& operator=(
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) {
Base::V = op.V;
return *this;
}
INLINE void operator=(
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) volatile {
Base::V = op.V;
}
INLINE ap_fixed& operator=(
const volatile ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) {
Base::V = op.V;
return *this;
}
INLINE void operator=(
const volatile ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) volatile {
Base::V = op.V;
}
}; // struct ap_fixed.
//-------------------------------------------------------------------
// Unsigned Arbitrary Precision Fixed-Point Type.
// default for _AP_Q, _AP_O and _AP_N set in ap_decl.h
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
struct ap_ufixed : ap_fixed_base<_AP_W, _AP_I, false, _AP_Q, _AP_O, _AP_N> {
typedef ap_fixed_base<_AP_W, _AP_I, false, _AP_Q, _AP_O, _AP_N> Base;
// Constructor
/// default ctor
INLINE ap_ufixed() : Base() {}
/// copy ctor from ap_fixed_base
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& op)
: Base(op) {}
/// copy ctor from ap_fixed_base
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(const volatile ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2,
_AP_O2, _AP_N2>& op)
: Base(op) {}
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_ufixed(
// const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_ufixed(
// const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>(op)) {}
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_ufixed(
// const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>(op)) {
//}
//template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
// int _AP_N2>
//INLINE ap_ufixed(
// const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
// : Base(ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>(op)) {
//}
/// copy ctor from ap_int_base.
template <int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const ap_int_base<_AP_W2, _AP_S2>& op) : Base(op) {}
template <int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const volatile ap_int_base<_AP_W2, _AP_S2>& op) : Base(op) {}
//template <int _AP_W2>
//INLINE ap_ufixed(const ap_int<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, true>(op)) {}
//template <int _AP_W2>
//INLINE ap_ufixed(const volatile ap_int<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, true>(op)) {}
//template <int _AP_W2>
//INLINE ap_ufixed(const ap_uint<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, false>(op)) {}
//template <int _AP_W2>
//INLINE ap_ufixed(const volatile ap_uint<_AP_W2>& op)
// : Base(ap_int_base<_AP_W2, false>(op)) {}
template <int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const ap_bit_ref<_AP_W2, _AP_S2>& op) : Base(op) {}
template <int _AP_W2, bool _AP_S2>
INLINE ap_ufixed(const ap_range_ref<_AP_W2, _AP_S2>& op) : Base(op) {}
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_ufixed(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_ufixed(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
#define CTOR(TYPE) \
INLINE ap_ufixed(TYPE v) : Base(v) {}
CTOR(bool)
CTOR(char)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(ap_slong)
CTOR(ap_ulong)
CTOR(half)
CTOR(float)
CTOR(double)
#undef CTOR
INLINE ap_ufixed(const char* s) : Base(s) {}
INLINE ap_ufixed(const char* s, signed char rd) : Base(s, rd) {}
// Assignment
INLINE ap_ufixed& operator=(
const ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) {
Base::V = op.V;
return *this;
}
INLINE void operator=(
const ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) volatile {
Base::V = op.V;
}
INLINE ap_ufixed& operator=(
const volatile ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op) {
Base::V = op.V;
return *this;
}
INLINE void operator=(const volatile ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O,
_AP_N>& op) volatile {
Base::V = op.V;
}
}; // struct ap_ufixed
#if !defined(__SYNTHESIS__) && (defined(SYSTEMC_H) || defined(SYSTEMC_INCLUDED))
// XXX sc_trace overload for ap_fixed is already included in
// "ap_sysc/ap_sc_extras.h", so do not define in synthesis.
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void sc_trace(sc_core::sc_trace_file* tf,
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op,
const std::string& name) {
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
INLINE void sc_trace(sc_core::sc_trace_file* tf,
const ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>& op,
const std::string& name) {
tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
#endif // System C sim
// Specialization of std containers, so that std::complex<ap_fixed> can have its
// image part automatically zero-initialized when only real part is provided.
#include <ap_fixed_special.h>
#endif // ifndef __AP_FIXED_H__ else
// -*- cpp -*-

2384
include/ap_fixed_base.h Normal file

File diff suppressed because it is too large Load diff

754
include/ap_fixed_ref.h Normal file
View file

@ -0,0 +1,754 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef __AP_FIXED_REF_H__
#define __AP_FIXED_REF_H__
#ifndef __AP_FIXED_H__
// TODO make this an error
#pragma message \
"Only ap_fixed.h and ap_int.h can be included directly in user code."
#endif
#ifndef __cplusplus
#error "C++ is required to include this header file"
#else
#ifndef __SYNTHESIS__
#include <iostream>
#endif
/// Proxy class, which allows bit selection to be used as both rvalue (for
/// reading) and lvalue (for writing)
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
struct af_bit_ref {
#ifdef _MSC_VER
#pragma warning(disable : 4521 4522)
#endif
typedef ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> ref_type;
ref_type& d_bv;
int d_index;
public:
INLINE af_bit_ref(
const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ref)
: d_bv(ref.d_bv), d_index(ref.d_index) {
#ifndef __SYNTHESIS__
_AP_WARNING(d_index < 0, "Index of bit vector (%d) cannot be negative.",
d_index);
_AP_WARNING(d_index >= _AP_W, "Index of bit vector (%d) out of range (%d).",
d_index, _AP_W);
#endif
}
INLINE af_bit_ref(ref_type* bv, int index = 0) : d_bv(*bv), d_index(index) {}
INLINE af_bit_ref(const ref_type* bv, int index = 0)
: d_bv(*const_cast<ref_type*>(bv)), d_index(index) {}
/// convert operators.
INLINE operator bool() const { return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
/// @name assign operators
// @{
INLINE af_bit_ref& operator=(bool val) {
d_bv.V = _AP_ROOT_op_set_bit(d_bv.V, d_index, val);
return *this;
}
// Be explicit to prevent it from being deleted, as field d_bv
// is of reference type.
INLINE af_bit_ref& operator=(const af_bit_ref& val) {
return operator=(bool(val));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE af_bit_ref& operator=(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=(bool(val));
}
template <int _AP_W2, bool _AP_S2>
INLINE af_bit_ref& operator=(const ap_bit_ref<_AP_W2, _AP_S2>& val) {
return operator=(bool(val));
}
template <int _AP_W2, bool _AP_S2>
INLINE af_bit_ref& operator=(const ap_int_base<_AP_W2, _AP_S2>& val) {
return operator=(val != 0);
}
template <int _AP_W2, bool _AP_S2>
INLINE af_bit_ref& operator=(const ap_range_ref<_AP_W2, _AP_S2>& val) {
return operator=(ap_int_base<_AP_W2, false>(val));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE af_bit_ref& operator=(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
return operator=(ap_int_base<_AP_W2, false>(val));
}
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE af_bit_ref& operator=(
const ap_concat_ref<_AP_W2, _AP_T3, _AP_W3, _AP_T3>& val) {
return operator=(ap_int_base<_AP_W2 + _AP_W3, false>(val));
}
// @}
/// @name concatenate operators
// @{
template <int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2, ap_int_base<_AP_W2, _AP_S2> >
operator,(ap_int_base<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2, ap_int_base<_AP_W2, _AP_S2> >(
*this, op);
}
template <int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<1, af_bit_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> > operator,(
const ap_bit_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<1, af_bit_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >(*this,
op);
}
template <int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >
operator,(const ap_range_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >(
*this, op);
}
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_concat_ref<1, af_bit_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
operator,(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &op) {
return ap_concat_ref<1, af_bit_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(*this,
op);
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_concat_ref<
1, af_bit_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator,(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> &op) {
return ap_concat_ref<
1, af_bit_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(*this,
op);
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_concat_ref<1, af_bit_ref, 1, af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2> >
operator,(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> &op) {
return ap_concat_ref<1, af_bit_ref, 1, af_bit_ref<_AP_W2, _AP_I2, _AP_S2,
_AP_Q2, _AP_O2, _AP_N2> >(
*this,
const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&>(
op));
}
// @}
/// @name comparison
// @{
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator==(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
return get() == op.get();
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator!=(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op) {
return get() != op.get();
}
// @}
INLINE bool operator~() const {
bool bit = _AP_ROOT_op_get_bit(d_bv.V, d_index);
return bit ? false : true;
}
INLINE bool get() const { return _AP_ROOT_op_get_bit(d_bv.V, d_index); }
INLINE int length() const { return 1; }
#ifndef __SYNTHESIS__
std::string to_string() const { return get() ? "1" : "0"; }
#else
// XXX HLS will delete this in synthesis
INLINE char* to_string() const { return 0; }
#endif
}; // struct af_bit_ref
// XXX apcc cannot handle global std::ios_base::Init() brought in by <iostream>
#ifndef AP_AUTOCC
#ifndef __SYNTHESIS__
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
INLINE std::ostream& operator<<(
std::ostream& os,
const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& x) {
os << x.to_string();
return os;
}
#endif // ifndef __SYNTHESIS__
#endif // ifndef AP_AUTOCC
/// Range (slice) reference.
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
struct af_range_ref {
#ifdef _MSC_VER
#pragma warning(disable : 4521 4522)
#endif
typedef ap_fixed_base<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N> ref_type;
ref_type& d_bv;
int l_index;
int h_index;
public:
/// copy ctor
INLINE af_range_ref(
const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& ref)
: d_bv(ref.d_bv), l_index(ref.l_index), h_index(ref.h_index) {}
/// ctor from ap_fixed_base, higher and lower bound.
/** if h is less than l, the bits selected will be returned in reverse order.
*/
INLINE af_range_ref(ref_type* bv, int h, int l)
: d_bv(*bv), l_index(l), h_index(h) {
#ifndef __SYNTHESIS__
_AP_WARNING(h < 0 || l < 0,
"Higher bound(%d) and lower(%d) bound cannot be negative.", h,
l);
_AP_WARNING(h >= _AP_W || l >= _AP_W,
"Higher bound(%d) or lower(%d) bound out of range.", h, l);
_AP_WARNING(h < l, "The bits selected will be returned in reverse order.");
#endif
}
INLINE af_range_ref(const ref_type* bv, int h, int l)
: d_bv(*const_cast<ref_type*>(bv)), l_index(l), h_index(h) {
#ifndef __SYNTHESIS__
_AP_WARNING(h < 0 || l < 0,
"Higher bound(%d) and lower(%d) bound cannot be negative.", h,
l);
_AP_WARNING(h >= _AP_W || l >= _AP_W,
"Higher bound(%d) or lower(%d) bound out of range.", h, l);
_AP_WARNING(h < l, "The bits selected will be returned in reverse order.");
#endif
}
/// @name assign operators
// @{
#define ASSIGN_CTYPE_TO_AF_RANGE(DATA_TYPE) \
INLINE af_range_ref& operator=(const DATA_TYPE val) { \
ap_int_base<_AP_W, false> loc(val); \
d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, loc.V); \
return *this; \
}
ASSIGN_CTYPE_TO_AF_RANGE(bool)
ASSIGN_CTYPE_TO_AF_RANGE(char)
ASSIGN_CTYPE_TO_AF_RANGE(signed char)
ASSIGN_CTYPE_TO_AF_RANGE(unsigned char)
ASSIGN_CTYPE_TO_AF_RANGE(short)
ASSIGN_CTYPE_TO_AF_RANGE(unsigned short)
ASSIGN_CTYPE_TO_AF_RANGE(int)
ASSIGN_CTYPE_TO_AF_RANGE(unsigned int)
ASSIGN_CTYPE_TO_AF_RANGE(long)
ASSIGN_CTYPE_TO_AF_RANGE(unsigned long)
ASSIGN_CTYPE_TO_AF_RANGE(ap_slong)
ASSIGN_CTYPE_TO_AF_RANGE(ap_ulong)
ASSIGN_CTYPE_TO_AF_RANGE(half)
ASSIGN_CTYPE_TO_AF_RANGE(float)
ASSIGN_CTYPE_TO_AF_RANGE(double)
#undef ASSIGN_CTYPE_TO_AF_RANGE
/// assgin using a string. XXX crucial for cosim.
INLINE af_range_ref& operator=(const char* val) {
const ap_int_base<_AP_W, false> tmp(val); // XXX figure out radix
d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, tmp.V);
return *this;
}
/// assign from ap_int_base.
// NOTE Base of other assgin operators.
template <int _AP_W3, bool _AP_S3>
INLINE af_range_ref& operator=(const ap_int_base<_AP_W3, _AP_S3>& val) {
d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
return *this;
}
/// assign from range reference to ap_int_base.
template <int _AP_W2, bool _AP_S2>
INLINE af_range_ref& operator=(const ap_range_ref<_AP_W2, _AP_S2>& val) {
const ap_int_base<_AP_W2, false> tmp(val);
return operator=(tmp);
}
/// assign from bit reference to ap_int_base..
template <int _AP_W2, bool _AP_S2>
INLINE af_range_ref& operator=(const ap_bit_ref<_AP_W2, _AP_S2>& val) {
const ap_int_base<1, false> tmp((bool)val);
return operator=(tmp);
}
/// assgin from ap_fixed_base.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE af_range_ref& operator=(
const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&
val) {
d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
return *this;
}
/// copy assgin.
// XXX This has to be explicit, otherwise it will be deleted, as d_bv is
// of reference type.
INLINE af_range_ref& operator=(const af_range_ref& val) {
ap_int_base<_AP_W, false> tmp(val);
return operator=(tmp);
}
/// assign from range reference to ap_fixed_base.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE af_range_ref& operator=(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
ap_int_base<_AP_W2, false> tmp(val);
return operator=(tmp);
}
/// assign from bit reference to ap_fixed_base.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE af_range_ref& operator=(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& val) {
ap_int_base<1, false> tmp((bool)val);
return operator=(tmp);
}
/// assign from compound reference.
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE af_range_ref& operator=(
const ap_concat_ref<_AP_W2, _AP_T3, _AP_W3, _AP_T3>& val) {
const ap_int_base<_AP_W2 + _AP_W3, false> tmp(val);
return operator=(tmp);
}
// @}
/// @name comparison operators with ap_range_ref.
// @{
template <int _AP_W2, bool _AP_S2>
INLINE bool operator==(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_int_base<_AP_W, false> lop(*this);
ap_int_base<_AP_W2, false> rop(op2);
return lop == rop;
}
template <int _AP_W2, bool _AP_S2>
INLINE bool operator!=(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
return !(operator==(op2));
}
template <int _AP_W2, bool _AP_S2>
INLINE bool operator<(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_int_base<_AP_W, false> lop(*this);
ap_int_base<_AP_W2, false> rop(op2);
return lop < rop;
}
template <int _AP_W2, bool _AP_S2>
INLINE bool operator>(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
ap_int_base<_AP_W, false> lop(*this);
ap_int_base<_AP_W2, false> rop(op2);
return lop > rop;
}
template <int _AP_W2, bool _AP_S2>
INLINE bool operator<=(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
return !(operator>(op2));
}
template <int _AP_W2, bool _AP_S2>
INLINE bool operator>=(const ap_range_ref<_AP_W2, _AP_S2>& op2) {
return !(operator<(op2));
}
// @}
/// @name comparison operators with af_range_ref.
// @{
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator==(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_int_base<_AP_W, false> lop(*this);
ap_int_base<_AP_W2, false> rop(op2);
return lop == rop;
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator!=(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
return !(operator==(op2));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator<(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_int_base<_AP_W, false> lop(*this);
ap_int_base<_AP_W2, false> rop(op2);
return lop < rop;
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator>(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
ap_int_base<_AP_W, false> lop(*this);
ap_int_base<_AP_W2, false> rop(op2);
return lop > rop;
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator<=(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
return !(operator>(op2));
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE bool operator>=(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op2) {
return !(operator<(op2));
}
// @}
/// @name concatenate operators.
/// @{
/// concatenate with ap_int_base.
template <int _AP_W2, int _AP_S2>
INLINE
ap_concat_ref<_AP_W, af_range_ref, _AP_W2, ap_int_base<_AP_W2, _AP_S2> >
operator,(ap_int_base<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
ap_int_base<_AP_W2, _AP_S2> >(*this, op);
}
/// concatenate with ap_bit_ref.
template <int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<_AP_W, af_range_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >
operator,(const ap_bit_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, 1, ap_bit_ref<_AP_W2, _AP_S2> >(
*this, const_cast<ap_bit_ref<_AP_W2, _AP_S2>&>(op));
}
/// concatenate with ap_bit_ref.
template <int _AP_W2, int _AP_S2>
INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2, ap_range_ref<_AP_W2, _AP_S2> >
operator,(const ap_range_ref<_AP_W2, _AP_S2> &op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
ap_range_ref<_AP_W2, _AP_S2> >(
*this, const_cast<ap_range_ref<_AP_W2, _AP_S2>&>(op));
}
/// concatenate with ap_concat_ref.
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_concat_ref<_AP_W, af_range_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >
operator,(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> &op) {
return ap_concat_ref<_AP_W, af_range_ref, _AP_W2 + _AP_W3,
ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3> >(
*this, const_cast<ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>&>(op));
}
/// concatenate with another af_range_ref.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE
ap_concat_ref<_AP_W, af_range_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator,(const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>
&op) {
return ap_concat_ref<
_AP_W, af_range_ref, _AP_W2,
af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(
*this,
const_cast<af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&>(
op));
}
/// concatenate with another af_bit_ref.
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE
ap_concat_ref<_AP_W, af_range_ref, 1,
af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >
operator,(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> &op) {
return ap_concat_ref<
_AP_W, af_range_ref, 1,
af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2> >(
*this,
const_cast<af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>&>(
op));
}
// @}
INLINE operator ap_ulong() const {
ap_int_base<_AP_W, false> ret;
ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
return ret.to_uint64();
}
INLINE operator ap_int_base<_AP_W, false>() const {
ap_int_base<_AP_W, false> ret;
ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
return ret;
}
INLINE ap_int_base<_AP_W, false> to_ap_int_base() const {
ap_int_base<_AP_W, false> ret;
ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
return ret;
}
// used in ap_fixed_base::to_string()
INLINE char to_char() const {
return (char)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE int to_int() const {
return (int)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE unsigned to_uint() const {
return (unsigned)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE long to_long() const {
return (long)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE unsigned long to_ulong() const {
return (unsigned long)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE ap_slong to_int64() const {
return (ap_slong)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE ap_ulong to_uint64() const {
return (ap_ulong)(_AP_ROOT_op_get_range(d_bv.V, l_index, h_index));
}
INLINE ap_int_base<_AP_W, false> get() const {
ap_int_base<_AP_W, false> ret;
ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
return ret;
}
template <int _AP_W2>
INLINE void set(const ap_int_base<_AP_W2, false>& val) {
d_bv.V = _AP_ROOT_op_set_range(d_bv.V, l_index, h_index, val.V);
}
INLINE int length() const {
return h_index >= l_index ? h_index - l_index + 1 : l_index - h_index + 1;
}
#ifndef __SYNTHESIS__
std::string to_string(signed char rd = 2) const {
ap_int_base<_AP_W, false> ret;
ret.V = _AP_ROOT_op_get_range(d_bv.V, l_index, h_index);
return ret.to_string(rd);
}
#else
// XXX HLS will delete this in synthesis
INLINE char* to_string(signed char rd = 2) const {
return 0;
}
#endif
}; // struct af_range_ref
// XXX apcc cannot handle global std::ios_base::Init() brought in by <iostream>
#ifndef AP_AUTOCC
#ifndef __SYNTHESIS__
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, ap_o_mode _AP_O,
int _AP_N>
INLINE std::ostream& operator<<(
std::ostream& os,
const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& x) {
os << x.to_string();
return os;
}
#endif
#endif // ifndef AP_AUTOCC
#define AF_REF_REL_OP_WITH_INT(REL_OP, C_TYPE, _AP_W2, _AP_S2) \
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP( \
const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
C_TYPE op2) { \
return ap_int_base<_AP_W, false>(op) \
REL_OP ap_int_base<_AP_W2, _AP_S2>(op2); \
} \
\
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP( \
C_TYPE op2, \
const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
return ap_int_base<_AP_W2, _AP_S2>(op2) \
REL_OP ap_int_base<_AP_W, false>(op); \
} \
\
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP( \
const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
C_TYPE op2) { \
return bool(op) REL_OP op2; \
} \
\
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N> \
INLINE bool operator REL_OP( \
C_TYPE op2, \
const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
return op2 REL_OP bool(op); \
}
#define AF_REF_REL_OPS_WITH_INT(C_TYPE, _AP_W2, _AP_S2) \
AF_REF_REL_OP_WITH_INT(>, C_TYPE, (_AP_W2), (_AP_S2)) \
AF_REF_REL_OP_WITH_INT(<, C_TYPE, (_AP_W2), (_AP_S2)) \
AF_REF_REL_OP_WITH_INT(>=, C_TYPE, (_AP_W2), (_AP_S2)) \
AF_REF_REL_OP_WITH_INT(<=, C_TYPE, (_AP_W2), (_AP_S2)) \
AF_REF_REL_OP_WITH_INT(==, C_TYPE, (_AP_W2), (_AP_S2)) \
AF_REF_REL_OP_WITH_INT(!=, C_TYPE, (_AP_W2), (_AP_S2))
AF_REF_REL_OPS_WITH_INT(bool, 1, false)
AF_REF_REL_OPS_WITH_INT(char, 8, CHAR_IS_SIGNED)
AF_REF_REL_OPS_WITH_INT(signed char, 8, true)
AF_REF_REL_OPS_WITH_INT(unsigned char, 8, false)
AF_REF_REL_OPS_WITH_INT(short, _AP_SIZE_short, true)
AF_REF_REL_OPS_WITH_INT(unsigned short, _AP_SIZE_short, false)
AF_REF_REL_OPS_WITH_INT(int, _AP_SIZE_int, true)
AF_REF_REL_OPS_WITH_INT(unsigned int, _AP_SIZE_int, false)
AF_REF_REL_OPS_WITH_INT(long, _AP_SIZE_long, true)
AF_REF_REL_OPS_WITH_INT(unsigned long, _AP_SIZE_long, false)
AF_REF_REL_OPS_WITH_INT(ap_slong, _AP_SIZE_ap_slong, true)
AF_REF_REL_OPS_WITH_INT(ap_ulong, _AP_SIZE_ap_slong, false)
#undef AF_REF_REL_OP_INT
#undef AF_REF_REL_OPS_WITH_INT
#define AF_REF_REL_OP_WITH_AP_INT(REL_OP) \
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP( \
const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
const ap_int_base<_AP_W2, _AP_S>& op2) { \
return ap_int_base<_AP_W, false>(op) REL_OP op2; \
} \
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP( \
const ap_int_base<_AP_W2, _AP_S2>& op2, \
const af_range_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
return op2 REL_OP ap_int_base<_AP_W, false>(op); \
} \
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP( \
const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op, \
const ap_int_base<_AP_W2, _AP_S2>& op2) { \
return ap_int_base<1, false>(op) REL_OP op2; \
} \
template <int _AP_W, int _AP_I, bool _AP_S, ap_q_mode _AP_Q, \
ap_o_mode _AP_O, int _AP_N, int _AP_W2, bool _AP_S2> \
INLINE bool operator REL_OP( \
const ap_int_base<_AP_W2, _AP_S2>& op2, \
const af_bit_ref<_AP_W, _AP_I, _AP_S, _AP_Q, _AP_O, _AP_N>& op) { \
return op2 REL_OP ap_int_base<1, false>(op); \
}
AF_REF_REL_OP_WITH_AP_INT(>)
AF_REF_REL_OP_WITH_AP_INT(<)
AF_REF_REL_OP_WITH_AP_INT(>=)
AF_REF_REL_OP_WITH_AP_INT(<=)
AF_REF_REL_OP_WITH_AP_INT(==)
AF_REF_REL_OP_WITH_AP_INT(!=)
#endif // ifndef __cplusplus
#endif // ifndef __AP_FIXED_REF_H__
// -*- cpp -*-
// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689

258
include/ap_fixed_special.h Normal file
View file

@ -0,0 +1,258 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef AP_FIXED_SPECIAL_H
#define AP_FIXED_SPECIAL_H
#ifndef __SYNTHESIS__
#include <cstdio>
#include <cstdlib>
#endif
// FIXME AP_AUTOCC cannot handle many standard headers, so declare instead of
// include.
// #include <complex>
namespace std {
template<typename _Tp> class complex;
}
/*
TODO: Modernize the code using C++11/C++14
1. constexpr http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0415r0.html
2. move constructor
*/
namespace std {
/*
Specialize std::complex<ap_fixed> to zero initialization ap_fixed.
To reduce the area cost, ap_fixed is not zero initialized, just like basic
types float or double. However, libstdc++ provides specialization for float,
double and long double, initializing image part to 0 when not specified.
This has become a difficulty in switching legacy code from these C types to
ap_fixed. To ease the tranform of legacy code, we have to implement
specialization of std::complex<> for our type.
As ap_fixed is a template, it is impossible to specialize only the methods
that causes default initialization of value type in std::complex<>. An
explicit full specialization of the template class has to be done, covering
all the member functions and operators of std::complex<> as specified
in standard 26.2.4 and 26.2.5.
*/
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
struct complex<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> > {
typedef ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> _Tp;
typedef _Tp value_type;
// 26.2.4/1
// Constructor without argument
// Default initialize, so that in dataflow, the variable is only written once.
complex() : _M_real(_Tp()), _M_imag(_Tp()) {}
// Constructor with ap_fixed.
// Zero initialize image part when not specified, so that `C(1) == C(1,0)`
complex(const _Tp &__r, const _Tp &__i = _Tp(0))
: _M_real(__r), _M_imag(__i) {}
// Constructor with another complex number
template <typename _Up>
complex(const complex<_Up> &__z) : _M_real(__z.real()), _M_imag(__z.imag()) {}
#if __cplusplus >= 201103L
const _Tp& real() const { return _M_real; }
const _Tp& imag() const { return _M_imag; }
#else
_Tp& real() { return _M_real; }
const _Tp& real() const { return _M_real; }
_Tp& imag() { return _M_imag; }
const _Tp& imag() const { return _M_imag; }
#endif
void real(_Tp __val) { _M_real = __val; }
void imag(_Tp __val) { _M_imag = __val; }
// Assign this complex number with ap_fixed.
// Zero initialize image poarrt, so that `C c; c = 1; c == C(1,0);`
complex<_Tp> &operator=(const _Tp __t) {
_M_real = __t;
_M_imag = _Tp(0);
return *this;
}
// 26.2.5/1
// Add ap_fixed to this complex number.
complex<_Tp> &operator+=(const _Tp &__t) {
_M_real += __t;
return *this;
}
// 26.2.5/3
// Subtract ap_fixed from this complex number.
complex<_Tp> &operator-=(const _Tp &__t) {
_M_real -= __t;
return *this;
}
// 26.2.5/5
// Multiply this complex number by ap_fixed.
complex<_Tp> &operator*=(const _Tp &__t) {
_M_real *= __t;
_M_imag *= __t;
return *this;
}
// 26.2.5/7
// Divide this complex number by ap_fixed.
complex<_Tp> &operator/=(const _Tp &__t) {
_M_real /= __t;
_M_imag /= __t;
return *this;
}
// Assign complex number to this complex number.
template <typename _Up>
complex<_Tp> &operator=(const complex<_Up> &__z) {
_M_real = __z.real();
_M_imag = __z.imag();
return *this;
}
// 26.2.5/9
// Add complex number to this.
template <typename _Up>
complex<_Tp> &operator+=(const complex<_Up> &__z) {
_M_real += __z.real();
_M_imag += __z.imag();
return *this;
}
// 26.2.5/11
// Subtract complex number from this.
template <typename _Up>
complex<_Tp> &operator-=(const complex<_Up> &__z) {
_M_real -= __z.real();
_M_imag -= __z.imag();
return *this;
}
// 26.2.5/13
// Multiply this by complex number.
template <typename _Up>
complex<_Tp> &operator*=(const complex<_Up> &__z) {
const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
_M_imag = _M_real * __z.imag() + _M_imag * __z.real();
_M_real = __r;
return *this;
}
// 26.2.5/15
// Divide this by complex number.
template <typename _Up>
complex<_Tp> &operator/=(const complex<_Up> &__z) {
complex<_Tp> cj (__z.real(), -__z.imag());
complex<_Tp> a = (*this) * cj;
complex<_Tp> b = cj * __z;
_M_real = a.real() / b.real();
_M_imag = a.imag() / b.real();
return *this;
}
private:
_Tp _M_real;
_Tp _M_imag;
}; // struct complex<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> >
/*
Non-member operations
These operations are not required by standard in 26.2.6, but libstdc++
defines them for
float, double or long double's specialization.
*/
// Compare complex number with ap_fixed.
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
inline bool operator==(
const complex<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> > &__x,
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> &__y) {
return __x.real() == __y &&
__x.imag() == 0;
}
// Compare ap_fixed with complex number.
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
inline bool operator==(
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> &__x,
const complex<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> > &__y) {
return __x == __y.real() &&
0 == __y.imag();
}
// Compare complex number with ap_fixed.
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
inline bool operator!=(
const complex<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> > &__x,
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> &__y) {
return __x.real() != __y ||
__x.imag() != 0;
}
// Compare ap_fixed with complex number.
template <int _AP_W, int _AP_I, ap_q_mode _AP_Q, ap_o_mode _AP_O, int _AP_N>
inline bool operator!=(
const ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> &__x,
const complex<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N> > &__y) {
return __x != __y.real() ||
0 != __y.imag();
}
} // namespace std
#endif // ifndef AP_FIXED_SPECIAL_H
// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689

352
include/ap_int.h Normal file
View file

@ -0,0 +1,352 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef __AP_INT_H__
#define __AP_INT_H__
#include <ap_common.h>
#include <ap_int_base.h>
#include <ap_int_ref.h>
//---------------------------------------------------------------
/// Sign Arbitrary Precision Type.
template <int _AP_W>
struct ap_int : ap_int_base<_AP_W, true> {
typedef ap_int_base<_AP_W, true> Base;
// Constructor
INLINE ap_int() : Base() {}
template <int _AP_W2>
INLINE ap_int(const ap_int<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2>
INLINE ap_int(const volatile ap_int<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2>
INLINE ap_int(const ap_uint<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2>
INLINE ap_int(const volatile ap_uint<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2, bool _AP_S2>
INLINE ap_int(const ap_range_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
template <int _AP_W2, bool _AP_S2>
INLINE ap_int(const ap_bit_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_int(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& ref)
: Base(ref) {}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_int(const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>)op) {}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_int(const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>)op) {
}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_int(
const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>)op) {}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_int(
const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>)op) {
}
template <int _AP_W2, bool _AP_S2>
INLINE ap_int(const ap_int_base<_AP_W2, _AP_S2>& op) {
Base::V = op.V;
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_int(
const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
#define CTOR(TYPE) \
INLINE ap_int(TYPE val) { Base::V = val; }
CTOR(bool)
CTOR(char)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(ap_slong)
CTOR(ap_ulong)
#undef CTOR
ap_int(double val) : Base(val) {}
ap_int(float val) : Base(val) {}
ap_int(half val) : Base(val) {}
// ap_int_base will guess radix if radix is not provided.
INLINE ap_int(const char* s) : Base(s) {}
INLINE ap_int(const char* s, signed char rd) : Base(s, rd) {}
// Assignment
/* ctor will be used when right is not of proper type. */
INLINE ap_int& operator=(const ap_int<_AP_W>& op2) {
Base::V = op2.V;
return *this;
}
/* cannot bind volatile reference to non-volatile type. */
INLINE ap_int& operator=(const volatile ap_int<_AP_W>& op2) {
Base::V = op2.V;
return *this;
}
/* cannot return volatile *this. */
INLINE void operator=(const ap_int<_AP_W>& op2) volatile { Base::V = op2.V; }
INLINE void operator=(const volatile ap_int<_AP_W>& op2) volatile {
Base::V = op2.V;
}
}; // struct ap_int.
//---------------------------------------------------------------
/// Unsigned Arbitrary Precision Type.
template <int _AP_W>
struct ap_uint : ap_int_base<_AP_W, false> {
typedef ap_int_base<_AP_W, false> Base;
// Constructor
INLINE ap_uint() : Base() {}
template <int _AP_W2>
INLINE ap_uint(const ap_uint<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2>
INLINE ap_uint(const ap_int<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2>
INLINE ap_uint(const volatile ap_uint<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2>
INLINE ap_uint(const volatile ap_int<_AP_W2>& op) {
Base::V = op.V;
}
template <int _AP_W2, bool _AP_S2>
INLINE ap_uint(const ap_range_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
template <int _AP_W2, bool _AP_S2>
INLINE ap_uint(const ap_bit_ref<_AP_W2, _AP_S2>& ref) : Base(ref) {}
template <int _AP_W2, typename _AP_T2, int _AP_W3, typename _AP_T3>
INLINE ap_uint(const ap_concat_ref<_AP_W2, _AP_T2, _AP_W3, _AP_T3>& ref)
: Base(ref) {}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_uint(const ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>)op) {}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_uint(const ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>)op) {
}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_uint(
const volatile ap_fixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, true, _AP_Q2, _AP_O2, _AP_N2>)op) {}
template <int _AP_W2, int _AP_I2, ap_q_mode _AP_Q2, ap_o_mode _AP_O2,
int _AP_N2>
INLINE ap_uint(
const volatile ap_ufixed<_AP_W2, _AP_I2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base((ap_fixed_base<_AP_W2, _AP_I2, false, _AP_Q2, _AP_O2, _AP_N2>)op) {
}
template <int _AP_W2, bool _AP_S2>
INLINE ap_uint(const ap_int_base<_AP_W2, _AP_S2>& op) {
Base::V = op.V;
}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(
const af_bit_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(
const af_range_ref<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
template <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
INLINE ap_uint(
const ap_fixed_base<_AP_W2, _AP_I2, _AP_S2, _AP_Q2, _AP_O2, _AP_N2>& op)
: Base(op) {}
#define CTOR(TYPE) \
INLINE ap_uint(TYPE val) { Base::V = val; }
CTOR(bool)
CTOR(char)
CTOR(signed char)
CTOR(unsigned char)
CTOR(short)
CTOR(unsigned short)
CTOR(int)
CTOR(unsigned int)
CTOR(long)
CTOR(unsigned long)
CTOR(ap_slong)
CTOR(ap_ulong)
#undef CTOR
ap_uint(double val) : Base(val) {}
ap_uint(float val) : Base(val) {}
ap_uint(half val) : Base(val) {}
// ap_int_base will guess radix if radix is not provided.
INLINE ap_uint(const char* s) : Base(s) {}
INLINE ap_uint(const char* s, signed char rd) : Base(s, rd) {}
// Assignment
/* XXX ctor will be used when right is not of proper type. */
INLINE ap_uint& operator=(const ap_uint<_AP_W>& op2) {
Base::V = op2.V;
return *this;
}
/* cannot bind volatile reference to non-volatile type. */
INLINE ap_uint& operator=(const volatile ap_uint<_AP_W>& op2) {
Base::V = op2.V;
return *this;
}
/* cannot return volatile *this. */
INLINE void operator=(const ap_uint<_AP_W>& op2) volatile { Base::V = op2.V; }
INLINE void operator=(const volatile ap_uint<_AP_W>& op2) volatile {
Base::V = op2.V;
}
}; // struct ap_uint.
#define ap_bigint ap_int
#define ap_biguint ap_uint
#if !defined(__SYNTHESIS__) && (defined(SYSTEMC_H) || defined(SYSTEMC_INCLUDED))
// XXX sc_trace overload for ap_fixed is already included in
// "ap_sysc/ap_sc_extras.h", so do not define in synthesis.
template <int _AP_W>
INLINE void sc_trace(sc_core::sc_trace_file* tf, const ap_int<_AP_W>& op,
const std::string& name) {
if (tf) tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
template <int _AP_W>
INLINE void sc_trace(sc_core::sc_trace_file* tf, const ap_uint<_AP_W>& op,
const std::string& name) {
if (tf) tf->trace(sc_dt::sc_lv<_AP_W>(op.to_string(2).c_str()), name);
}
#endif // System C sim
#include <ap_int_special.h>
#endif // ifndef __AP_INT_H__ else
// FIXME user should include ap_fixed.h when using ap_fixed.
// to avoid circular inclusion, must check whether this is required by
// ap_fixed.h
#ifndef __AP_FIXED_H__
#include <ap_fixed.h>
#endif
// -*- cpp -*-

1918
include/ap_int_base.h Normal file

File diff suppressed because it is too large Load diff

1378
include/ap_int_ref.h Normal file

File diff suppressed because it is too large Load diff

251
include/ap_int_special.h Normal file
View file

@ -0,0 +1,251 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*/
#ifndef AP_INT_SPECIAL_H
#define AP_INT_SPECIAL_H
#ifndef __SYNTHESIS__
#include <cstdio>
#include <cstdlib>
#endif
// FIXME AP_AUTOCC cannot handle many standard headers, so declare instead of
// include.
// #include <complex>
namespace std {
template<typename _Tp> class complex;
}
/*
TODO: Modernize the code using C++11/C++14
1. constexpr http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0415r0.html
2. move constructor
*/
namespace std {
/*
Specialize std::complex<ap_int> to zero initialization ap_int.
To reduce the area cost, ap_int is not zero initialized, just like basic
types float or double. However, libstdc++ provides specialization for float,
double and long double, initializing image part to 0 when not specified.
This has become a difficulty in switching legacy code from these C types to
ap_int. To ease the tranform of legacy code, we have to implement
specialization of std::complex<> for our type.
As ap_int is a template, it is impossible to specialize only the methods
that causes default initialization of value type in std::complex<>. An
explicit full specialization of the template class has to be done, covering
all the member functions and operators of std::complex<> as specified
in standard 26.2.4 and 26.2.5.
*/
template <int _AP_W>
struct complex<ap_int<_AP_W> > {
typedef ap_int<_AP_W> _Tp;
typedef _Tp value_type;
// 26.2.4/1
// Constructor without argument
// Default initialize, so that in dataflow, the variable is only written once.
complex() : _M_real(_Tp()), _M_imag(_Tp()) {}
// Constructor with ap_int.
// Zero initialize image part when not specified, so that `C(1) == C(1,0)`
complex(const _Tp &__r, const _Tp &__i = _Tp(0))
: _M_real(__r), _M_imag(__i) {}
// Constructor with another complex number
template <typename _Up>
complex(const complex<_Up> &__z) : _M_real(__z.real()), _M_imag(__z.imag()) {}
#if __cplusplus >= 201103L
const _Tp& real() const { return _M_real; }
const _Tp& imag() const { return _M_imag; }
#else
_Tp& real() { return _M_real; }
const _Tp& real() const { return _M_real; }
_Tp& imag() { return _M_imag; }
const _Tp& imag() const { return _M_imag; }
#endif
void real(_Tp __val) { _M_real = __val; }
void imag(_Tp __val) { _M_imag = __val; }
// Assign this complex number with ap_int.
// Zero initialize image poarrt, so that `C c; c = 1; c == C(1,0);`
complex<_Tp> &operator=(const _Tp __t) {
_M_real = __t;
_M_imag = _Tp(0);
return *this;
}
// 26.2.5/1
// Add ap_int to this complex number.
complex<_Tp> &operator+=(const _Tp &__t) {
_M_real += __t;
return *this;
}
// 26.2.5/3
// Subtract ap_int from this complex number.
complex<_Tp> &operator-=(const _Tp &__t) {
_M_real -= __t;
return *this;
}
// 26.2.5/5
// Multiply this complex number by ap_int.
complex<_Tp> &operator*=(const _Tp &__t) {
_M_real *= __t;
_M_imag *= __t;
return *this;
}
// 26.2.5/7
// Divide this complex number by ap_int.
complex<_Tp> &operator/=(const _Tp &__t) {
_M_real /= __t;
_M_imag /= __t;
return *this;
}
// Assign complex number to this complex number.
template <typename _Up>
complex<_Tp> &operator=(const complex<_Up> &__z) {
_M_real = __z.real();
_M_imag = __z.imag();
return *this;
}
// 26.2.5/9
// Add complex number to this.
template <typename _Up>
complex<_Tp> &operator+=(const complex<_Up> &__z) {
_M_real += __z.real();
_M_imag += __z.imag();
return *this;
}
// 26.2.5/11
// Subtract complex number from this.
template <typename _Up>
complex<_Tp> &operator-=(const complex<_Up> &__z) {
_M_real -= __z.real();
_M_imag -= __z.imag();
return *this;
}
// 26.2.5/13
// Multiply this by complex number.
template <typename _Up>
complex<_Tp> &operator*=(const complex<_Up> &__z) {
const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
_M_imag = _M_real * __z.imag() + _M_imag * __z.real();
_M_real = __r;
return *this;
}
// 26.2.5/15
// Divide this by complex number.
template <typename _Up>
complex<_Tp> &operator/=(const complex<_Up> &__z) {
complex<_Tp> cj (__z.real(), -__z.imag());
complex<_Tp> a = (*this) * cj;
complex<_Tp> b = cj * __z;
_M_real = a.real() / b.real();
_M_imag = a.imag() / b.real();
return *this;
}
private:
_Tp _M_real;
_Tp _M_imag;
}; // struct complex<ap_int<_AP_W> >
/*
Non-member operations
These operations are not required by standard in 26.2.6, but libstdc++
defines them for
float, double or long double's specialization.
*/
// Compare complex number with ap_int.
template <int _AP_W>
inline bool operator==(const complex<ap_int<_AP_W> > &__x, const ap_int<_AP_W> &__y) {
return __x.real() == __y &&
__x.imag() == 0;
}
// Compare ap_int with complex number.
template <int _AP_W>
inline bool operator==(const ap_int<_AP_W> &__x, const complex<ap_int<_AP_W> > &__y) {
return __x == __y.real() &&
0 == __y.imag();
}
// Compare complex number with ap_int.
template <int _AP_W>
inline bool operator!=(const complex<ap_int<_AP_W> > &__x, const ap_int<_AP_W> &__y) {
return __x.real() != __y ||
__x.imag() != 0;
}
// Compare ap_int with complex number.
template <int _AP_W>
inline bool operator!=(const ap_int<_AP_W> &__x, const complex<ap_int<_AP_W> > &__y) {
return __x != __y.real() ||
0 != __y.imag();
}
} // namespace std
#endif // ifndef AP_INT_SPECIAL_H
// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689

7213
include/etc/ap_private.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,371 @@
//----------------------------------------------------------------------------
// ____ ____
// / /\/ /
// /___/ \ / Vendor: Xilinx
// \ \ \/ Version: 6.0
// \ \ Filename: $RCSfile: floating_point_v7_0_bitacc_cmodel.h,v $
// / / Date Last Modified: $Date: 2011/06/15 13:06:43 $
// /___/ /\ Date Created: 2011
//
// Device : All
// Library : floating_point_v7_0
// Purpose : Header file for bit accurate model of Floating Point Operator
// Revision: $Revision: 1.6.6.2 $
//
//------------------------------------------------------------------------------
// (c) Copyright 2011-2012 Xilinx, Inc. All rights reserved.
//
// This file contains confidential and proprietary information
// of Xilinx, Inc. and is protected under U.S. and
// international copyright and other intellectual property
// laws.
//
// DISCLAIMER
// This disclaimer is not a license and does not grant any
// rights to the materials distributed herewith. Except as
// otherwise provided in a valid license issued to you by
// Xilinx, and to the maximum extent permitted by applicable
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
// (2) Xilinx shall not be liable (whether in contract or tort,
// including negligence, or under any other theory of
// liability) for any loss or damage of any kind or nature
// related to, arising under or in connection with these
// materials, including for any direct, or any indirect,
// special, incidental, or consequential loss or damage
// (including loss of data, profits, goodwill, or any type of
// loss or damage suffered as a result of any action brought
// by a third party) even if such damage or loss was
// reasonably foreseeable or Xilinx had been advised of the
// possibility of the same.
//
// CRITICAL APPLICATIONS
// Xilinx products are not designed or intended to be fail-
// safe, or for use in any application requiring fail-safe
// performance, such as life-support or safety devices or
// systems, Class III medical devices, nuclear facilities,
// applications related to the deployment of airbags, or any
// other applications that could lead to death, personal
// injury, or severe property or environmental damage
// (individually and collectively, "Critical
// Applications"). Customer assumes the sole risk and
// liability of any use of Xilinx products in Critical
// Applications, subject only to applicable laws and
// regulations governing limitations on product liability.
//
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
// PART OF THIS FILE AT ALL TIMES.
//------------------------------------------------------------------------------
#ifndef __xip_fpo_bitacc_cmodel_h
#define __xip_fpo_bitacc_cmodel_h
#ifdef NT
#define __XIP_FPO_DLLIMPORT __declspec(dllimport)
#define __XIP_FPO_DLLEXPORT __declspec(dllexport)
#else
#define __XIP_FPO_DLLIMPORT
#define __XIP_FPO_DLLEXPORT
#endif
// Only define __XIP_FPO_BUILD_DLL when building the C model DLL; do not define it when using the C model
#ifdef __XIP_FPO_BUILD_DLL
#define __XIP_FPO_DLL __XIP_FPO_DLLEXPORT
#else
#define __XIP_FPO_DLL __XIP_FPO_DLLIMPORT
#endif
/* Extra define for functions with variable numbers of arguments */
#define __XIP_FPO_SENTINEL_ATTR
#if defined (__GNUC__)
# if __GNUC__ >= 4
# undef __XIP_FPO_SENTINEL_ATTR
# define __XIP_FPO_SENTINEL_ATTR __attribute__ ((sentinel))
# endif
#endif
/* Define Floating Point Operator core version number */
#define XIP_FPO_VERSION_MAJOR 6
#define XIP_FPO_VERSION_MINOR 2
#define XIP_FPO_REVISION 0
/* Version string does not include revision if revision is 0 (revision >0 reserved for future use) */
#define XIP_FPO_VERSION_STRING "6.2"
/* Use C99 exact width integer types for 64-bit integers and *_uj and *_sj functions */
// For Windows platforms, stdint.h and inttypes.h are not present in Visual Studio 2005/2008
// Therefore we define the required types ourselves
// For Linux platforms, we need to continue using stdint.h (and not re-define intmax_t, uintmax_t)
// because SysGen already uses this header.
#ifdef NT
typedef signed char xint8;
typedef signed short xint16;
typedef signed int xint32;
typedef signed long long xint64;
typedef unsigned char xuint8;
typedef unsigned short xuint16;
typedef unsigned int xuint32;
typedef unsigned long long xuint64;
typedef xint64 intmax_t;
typedef xuint64 uintmax_t;
#else
#include <stdint.h>
typedef int8_t xint8;
typedef int16_t xint16;
typedef int32_t xint32;
typedef int64_t xint64;
typedef uint8_t xuint8;
typedef uint16_t xuint16;
typedef uint32_t xuint32;
typedef uint64_t xuint64;
#endif
#include <stdbool.h>
// REVISIT: included before mpfr.h to permit definition of prototypes for mpfr_printf
#include <stdio.h>
// Force MPFR to use intmax_t and uintmax_t types (the compiled libraries have the functions that use these)
#define MPFR_USE_INTMAX_T
// Tell MPIR on Windows platforms that it is compiled into a DLL
#ifdef NT
#define __GMP_LIBGMP_DLL 1
#endif
/* Check if GMP is included, and try to include it (Works with local GMP)
Note that where MPIR is provided as a compatible alternative to GMP,
it also provides a gmp.h header file to allow MPIR and GMP to be easily interchanged.
Select the correct gmp.h by setting the -I option (includes path) for your compiler. */
#ifndef __GMP_H__
#include <gmp.h>
#endif
/* Check if MPFR is included, and try to include it (Works with local MPFR) */
#ifndef __MPFR_H
#include <mpfr.h>
#endif
/* Precision of mantissa or exponent (bits) */
typedef long xip_fpo_prec_t;
/* Definition of sign */
typedef int xip_fpo_sign_t;
/* Definition of exponent */
typedef long xip_fpo_exp_t;
/* The main floating point number structure */
typedef struct {
xip_fpo_prec_t _xip_fpo_exp_prec;
xip_fpo_prec_t _xip_fpo_mant_prec;
xip_fpo_sign_t _xip_fpo_sign;
xip_fpo_exp_t _xip_fpo_exp;
mp_limb_t *_xip_fpo_d;
} __xip_fpo_struct;
/* The main fixed point number structure */
typedef struct {
xip_fpo_prec_t _xip_fpo_i_prec;
xip_fpo_prec_t _xip_fpo_frac_prec;
xint64 _xip_fpo_i;
xint64 _xip_fpo_frac;
} __xip_fpo_fix_struct;
/* User-visible types for floating point and fixed point numbers */
typedef __xip_fpo_struct xip_fpo_t[1];
typedef __xip_fpo_fix_struct xip_fpo_fix_t[1];
/* Pointers to floating point and fixed point numbers, for function prototypes */
typedef __xip_fpo_struct *xip_fpo_ptr;
typedef const __xip_fpo_struct *xip_fpo_srcptr;
typedef __xip_fpo_fix_struct *xip_fpo_fix_ptr;
typedef const __xip_fpo_fix_struct *xip_fpo_fix_srcptr;
/* Definition of exception flags - return type of most functions
Flags are as follows:
bit 0 : underflow
bit 1 : overflow
bit 2 : invalid operation
bit 3 : divide by zero
bit 4 : operation not supported
bit 5 : Accumulator Input Overflow
bit 6 : Accumulator Overflow
*/
typedef int xip_fpo_exc_t;
#ifdef __cplusplus
extern "C" {
#endif
typedef struct xil_fpo_accum_state xil_fpo_accum_state;
/* Information functions */
__XIP_FPO_DLL const char * xip_fpo_get_version (void);
/* Initialization functions */
__XIP_FPO_DLL void xip_fpo_init2 (xip_fpo_ptr, xip_fpo_prec_t, xip_fpo_prec_t);
__XIP_FPO_DLL void xip_fpo_fix_init2 (xip_fpo_fix_ptr, xip_fpo_prec_t, xip_fpo_prec_t);
__XIP_FPO_DLL void xip_fpo_inits2 (xip_fpo_prec_t, xip_fpo_prec_t, xip_fpo_ptr, ...) __XIP_FPO_SENTINEL_ATTR;
__XIP_FPO_DLL void xip_fpo_fix_inits2 (xip_fpo_prec_t, xip_fpo_prec_t, xip_fpo_fix_ptr, ...) __XIP_FPO_SENTINEL_ATTR;
__XIP_FPO_DLL void xip_fpo_clear (xip_fpo_ptr);
__XIP_FPO_DLL void xip_fpo_fix_clear (xip_fpo_fix_ptr);
__XIP_FPO_DLL void xip_fpo_clears (xip_fpo_ptr, ...) __XIP_FPO_SENTINEL_ATTR;
__XIP_FPO_DLL void xip_fpo_fix_clears (xip_fpo_fix_ptr, ...) __XIP_FPO_SENTINEL_ATTR;
__XIP_FPO_DLL void xip_fpo_set_prec (xip_fpo_ptr, xip_fpo_prec_t, xip_fpo_prec_t);
__XIP_FPO_DLL void xip_fpo_fix_set_prec (xip_fpo_fix_ptr, xip_fpo_prec_t, xip_fpo_prec_t);
__XIP_FPO_DLL xip_fpo_prec_t xip_fpo_get_prec_mant (xip_fpo_ptr);
__XIP_FPO_DLL xip_fpo_prec_t xip_fpo_get_prec_exp (xip_fpo_ptr);
__XIP_FPO_DLL xip_fpo_prec_t xip_fpo_fix_get_prec_frac (xip_fpo_fix_ptr);
__XIP_FPO_DLL xip_fpo_prec_t xip_fpo_fix_get_prec_int (xip_fpo_fix_ptr);
/* Assignment functions */
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set (xip_fpo_fix_ptr, xip_fpo_fix_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_ui (xip_fpo_ptr, unsigned long);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_ui (xip_fpo_fix_ptr, unsigned long);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_si (xip_fpo_ptr, long);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_si (xip_fpo_fix_ptr, long);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_uj (xip_fpo_ptr, uintmax_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_uj (xip_fpo_fix_ptr, uintmax_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_sj (xip_fpo_ptr, intmax_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_sj (xip_fpo_fix_ptr, intmax_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_flt (xip_fpo_ptr, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_flt (xip_fpo_fix_ptr, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_d (xip_fpo_ptr, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_d (xip_fpo_fix_ptr, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_z (xip_fpo_ptr, mpz_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_z (xip_fpo_fix_ptr, mpz_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_q (xip_fpo_ptr, mpq_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_q (xip_fpo_fix_ptr, mpq_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_f (xip_fpo_ptr, mpf_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_f (xip_fpo_fix_ptr, mpf_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_fr (xip_fpo_ptr, mpfr_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_fr (xip_fpo_fix_ptr, mpfr_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_ui_2exp (xip_fpo_ptr, unsigned long, xip_fpo_exp_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_si_2exp (xip_fpo_ptr, long, xip_fpo_exp_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_uj_2exp (xip_fpo_ptr, uintmax_t, intmax_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_sj_2exp (xip_fpo_ptr, intmax_t, intmax_t);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_set_str (xip_fpo_ptr, const char *, int);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_set_str (xip_fpo_fix_ptr, const char *, int);
__XIP_FPO_DLL void xip_fpo_set_nan (xip_fpo_ptr);
__XIP_FPO_DLL void xip_fpo_set_inf (xip_fpo_ptr, int);
__XIP_FPO_DLL void xip_fpo_set_zero (xip_fpo_ptr, int);
/* Conversion functions */
__XIP_FPO_DLL unsigned long xip_fpo_get_ui (xip_fpo_srcptr);
__XIP_FPO_DLL unsigned long xip_fpo_fix_get_ui (xip_fpo_fix_srcptr);
__XIP_FPO_DLL long xip_fpo_get_si (xip_fpo_srcptr);
__XIP_FPO_DLL long xip_fpo_fix_get_si (xip_fpo_fix_srcptr);
__XIP_FPO_DLL uintmax_t xip_fpo_get_uj (xip_fpo_srcptr);
__XIP_FPO_DLL uintmax_t xip_fpo_fix_get_uj (xip_fpo_fix_srcptr);
__XIP_FPO_DLL intmax_t xip_fpo_get_sj (xip_fpo_srcptr);
__XIP_FPO_DLL intmax_t xip_fpo_fix_get_sj (xip_fpo_fix_srcptr);
__XIP_FPO_DLL float xip_fpo_get_flt (xip_fpo_srcptr);
__XIP_FPO_DLL float xip_fpo_fix_get_flt (xip_fpo_fix_srcptr);
__XIP_FPO_DLL double xip_fpo_get_d (xip_fpo_srcptr);
__XIP_FPO_DLL double xip_fpo_fix_get_d (xip_fpo_fix_srcptr);
__XIP_FPO_DLL double xip_fpo_get_d_2exp (long *, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_get_z (mpz_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_get_z (mpz_ptr, xip_fpo_fix_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_get_f (mpf_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_get_f (mpf_ptr, xip_fpo_fix_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_get_fr (mpfr_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fix_get_fr (mpfr_ptr, xip_fpo_fix_srcptr);
__XIP_FPO_DLL char * xip_fpo_get_str (char *, xip_fpo_exp_t *, int, int, xip_fpo_srcptr);
__XIP_FPO_DLL char * xip_fpo_fix_get_str (char *, int, xip_fpo_fix_srcptr);
__XIP_FPO_DLL void xip_fpo_free_str (char *);
__XIP_FPO_DLL void xip_fpo_fix_free_str (char *);
__XIP_FPO_DLL int xip_fpo_sizeinbase (xip_fpo_srcptr, int);
__XIP_FPO_DLL int xip_fpo_fix_sizeinbase (xip_fpo_fix_srcptr, int);
/* Operation functions */
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_add (xip_fpo_ptr, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_add_flt (float *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_add_d (double *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_sub (xip_fpo_ptr, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_sub_flt (float *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_sub_d (double *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_mul (xip_fpo_ptr, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_mul_flt (float *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_mul_d (double *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fma (xip_fpo_ptr, xip_fpo_srcptr, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fma_flt (float *, float, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fma_d (double *, double, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fms (xip_fpo_ptr, xip_fpo_srcptr, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fms_flt (float *, float, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fms_d (double *, double, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_div (xip_fpo_ptr, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_div_flt (float *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_div_d (double *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_rec (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_rec_flt (float *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_rec_d (double *, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_abs (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_abs_flt (float *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_abs_d (double *, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_log (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_log_flt (float *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_log_d (double *, double);
__XIP_FPO_DLL int xip_fpo_exp_array (xip_fpo_t * , xip_fpo_t * , xip_fpo_exc_t *, unsigned long long);
__XIP_FPO_DLL void xip_fpo_exp_flt_array (float * , float * , xip_fpo_exc_t *, unsigned long long);
__XIP_FPO_DLL void xip_fpo_exp_d_array (double * , double * , xip_fpo_exc_t *, unsigned long long);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_exp (xip_fpo_ptr , xip_fpo_srcptr );
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_exp_flt (float * , float );
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_exp_d (double * , double );
__XIP_FPO_DLL struct xil_fpo_accum_state * xip_fpo_accum_create_state (int , int , int , int , int);
__XIP_FPO_DLL void xip_fpo_accum_reset_state (struct xil_fpo_accum_state *);
__XIP_FPO_DLL void xip_fpo_accum_destroy_state (struct xil_fpo_accum_state *);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_accum_sample (xip_fpo_t, xip_fpo_t, bool, struct xil_fpo_accum_state *);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_accum_sample_flt (float *, float , bool, struct xil_fpo_accum_state *);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_accum_sample_d (double *, double , bool, struct xil_fpo_accum_state *);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_sqrt (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_sqrt_flt (float *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_sqrt_d (double *, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_recsqrt (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_recsqrt_flt (float *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_recsqrt_d (double *, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_unordered (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_unordered_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_unordered_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_equal (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_equal_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_equal_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_less (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_less_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_less_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_lessequal (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_lessequal_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_lessequal_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_greater (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_greater_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_greater_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_greaterequal (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_greaterequal_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_greaterequal_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_notequal (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_notequal_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_notequal_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_condcode (int *, xip_fpo_srcptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_condcode_flt (int *, float, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_condcode_d (int *, double, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttofix (xip_fpo_fix_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttofix_int_flt (int *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttofix_int_d (int *, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fixtoflt (xip_fpo_ptr, xip_fpo_fix_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fixtoflt_flt_int (float *, int);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_fixtoflt_d_int (double *, int);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttoflt (xip_fpo_ptr, xip_fpo_srcptr);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttoflt_flt_flt (float *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttoflt_flt_d (float *, double);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttoflt_d_flt (double *, float);
__XIP_FPO_DLL xip_fpo_exc_t xip_fpo_flttoflt_d_d (double *, double);
#ifdef __cplusplus
} /* End of "C" linkage block */
#endif
#endif // __xip_fpo_bitacc_cmodel_h

2391
include/gmp.h Normal file

File diff suppressed because it is too large Load diff

665
include/hls_fpo.h Normal file
View file

@ -0,0 +1,665 @@
/* -*- c -*-*/
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
*
*
*/
#ifndef __AESL_FPO_H__
#define __AESL_FPO_H__
#ifndef __SYNTHESIS__
#include <math.h>
#endif
#include <assert.h>
#if defined __arm__ && !(defined HLS_NO_XIL_FPO_LIB)
#warning "Xilinx Floating Point Operator IP core does not provide simulation models for ARM architecture. Automatically defining HLS_NO_XIL_FPO_LIB in order to avoid this library dependency, although bit-accurate simulation of some functions is no longer possible. You can make this warning go away by adding this define yourself before including any other files."
#define HLS_NO_XIL_FPO_LIB
#endif
#ifdef __SYNTHESIS__
#define HLS_FPO_SQRTF(a) __builtin_sqrtf(a)
#define HLS_FPO_SQRT(a) __builtin_sqrt(a)
#define HLS_FPO_RECSQRTF(a) (1.0f/__builtin_sqrtf(a))
#define HLS_FPO_RECSQRT(a) (1.0/__builtin_sqrt(a))
#define HLS_FPO_ABSF(a) __builtin_fabsf(a)
#define HLS_FPO_ABS(a) __builtin_fabs(a)
#define HLS_FPO_LOGF(a) __builtin_logf(a)
#define HLS_FPO_LOG(a) __builtin_log(a)
#define HLS_FPO_EXPF(a) __builtin_expf(a)
#define HLS_FPO_EXP(a) __builtin_exp(a)
#else// csim
#ifdef HLS_NO_XIL_FPO_LIB
#define HLS_FPO_SQRTF(a) sqrtf(a)
#define HLS_FPO_SQRT(a) sqrt(a)
#define HLS_FPO_RECSQRTF(a) (1.0f/sqrtf(a))
#define HLS_FPO_RECSQRT(a) (1.0/sqrt(a))
#define HLS_FPO_ABSF(a) fabsf(a)
#define HLS_FPO_ABS(a) fabs(a)
#define HLS_FPO_LOGF(a) logf(a)
#define HLS_FPO_LOG(a) log(a)
#define HLS_FPO_EXPF(a) expf(a)
#define HLS_FPO_EXP(a) exp(a)
#else
#define HLS_FPO_SQRTF(a) xil_fpo_sqrt_flt(a)
#define HLS_FPO_SQRT(a) xil_fpo_sqrt_d(a)
#define HLS_FPO_RECSQRTF(a) xil_fpo_recsqrt_flt(a)
#define HLS_FPO_RECSQRT(a) xil_fpo_recsqrt_d(a)
#define HLS_FPO_ABSF(a) xil_fpo_abs_flt(a)
#define HLS_FPO_ABS(a) xil_fpo_abs_d(a)
#define HLS_FPO_LOGF(a) xil_fpo_log_flt(a)
#define HLS_FPO_LOG(a) xil_fpo_log_d(a)
#define HLS_FPO_EXPF(a) xil_fpo_exp_flt(a)
#define HLS_FPO_EXP(a) xil_fpo_exp_d(a)
#endif //HLS_NO_XIL_FPO_LIB
#endif //__SYNTHESIS__
#if (defined __SYNTHESIS__ || defined HLS_NO_XIL_FPO_LIB)
#define HLS_FPO_ADDF(a,b) ((a) + (b))
#define HLS_FPO_ADD(a,b) ((a) + (b))
#define HLS_FPO_SUBF(a,b) ((a) - (b))
#define HLS_FPO_SUB(a,b) ((a) - (b))
#define HLS_FPO_MULF(a,b) ((a) * (b))
#define HLS_FPO_MUL(a,b) ((a) * (b))
#define HLS_FPO_DIVF(a,b) ((a)/(b))
#define HLS_FPO_DIV(a,b) ((a)/(b))
#define HLS_FPO_RECF(a) (1.0f/(a))
#define HLS_FPO_RECIPF(a) HLS_FPO_RECF(a)
#define HLS_FPO_REC(a) (1.0/(a))
#define HLS_FPO_RECIP(a) HLS_FPO_REC(a)
#define HLS_FPO_RSQRTF(a) HLS_FPO_RECSQRTF(a)
#define HLS_FPO_RSQRT(a) HLS_FPO_RECSQRT(a)
//#define HLS_FPO_UNORDEREDF(a,b)
//#define HLS_FPO_UNORDERED(a,b)
#define HLS_FPO_EQUALF(a,b) ((a) == (b))
#define HLS_FPO_EQUAL(a,b) ((a) == (b))
#define HLS_FPO_LESSF(a,b) ((a) < (b))
#define HLS_FPO_LESS(a,b) ((a) < (b))
#define HLS_FPO_LESSEQUALF(a,b) ((a) <= (b))
#define HLS_FPO_LESSEQUAL(a,b) ((a) <= (b))
#define HLS_FPO_GREATERF(a,b) ((a) > (b))
#define HLS_FPO_GREATER(a,b) ((a) > (b))
#define HLS_FPO_GREATEREQUALF(a,b) ((a) >= (b))
#define HLS_FPO_GREATEREQUAL(a,b) ((a) >= (b))
#define HLS_FPO_NOTEQUALF(a,b) ((a) != (b))
#define HLS_FPO_NOTEQUAL(a,b) ((a) != (b))
//#define HLS_FPO_CONDCODEF(a,b)
//#define HLS_FPO_CONDCODE(a,b)
#define HLS_FPO_FTOI(a) ((int)(a))
#define HLS_FPO_DTOI(a) ((int)(a))
#define HLS_FPO_ITOF(a) ((float)(a))
#define HLS_FPO_ITOD(a) ((double)(a))
#define HLS_FPO_FTOF(a) ((float)(a))
#define HLS_FPO_DTOF(a) ((float)(a))
#define HLS_FPO_FTOD(a) ((double)(a))
#define HLS_FPO_DTOD(a) ((double)(a))
#else
#define HLS_FPO_ADDF(a,b) xil_fpo_add_flt(a,b)
#define HLS_FPO_ADD(a,b) xil_fpo_add_d(a,b)
#define HLS_FPO_SUBF(a,b) xil_fpo_sub_flt(a,b)
#define HLS_FPO_SUB(a,b) xil_fpo_sub_d(a,b)
#define HLS_FPO_MULF(a,b) xil_fpo_mul_flt(a,b)
#define HLS_FPO_MUL(a,b) xil_fpo_mul_d(a,b)
#define HLS_FPO_DIVF(a,b) xil_fpo_div_flt(a,b)
#define HLS_FPO_DIV(a,b) xil_fpo_div_d(a,b)
#define HLS_FPO_RECF(a) xil_fpo_rec_flt(a)
#define HLS_FPO_RECIPF(a) HLS_FPO_RECF(a)
#define HLS_FPO_REC(a) xil_fpo_rec_d(a)
#define HLS_FPO_RECIP(a) HLS_FPO_REC(a)
#define HLS_FPO_RSQRTF(a) HLS_FPO_RECSQRTF(a)
#define HLS_FPO_RSQRT(a) HLS_FPO_RECSQRT(a)
#define HLS_FPO_UNORDEREDF(a,b) xil_fpo_unordered_flt(a,b)
#define HLS_FPO_UNORDERED(a,b) xil_fpo_unordered_d(a,b)
#define HLS_FPO_EQUALF(a,b) xil_fpo_equal_flt(a,b)
#define HLS_FPO_EQUAL(a,b) xil_fpo_equal_d(a,b)
#define HLS_FPO_LESSF(a,b) xil_fpo_less_flt(a,b)
#define HLS_FPO_LESS(a,b) xil_fpo_less_d(a,b)
#define HLS_FPO_LESSEQUALF(a,b) xil_fpo_lessequal_flt(a,b)
#define HLS_FPO_LESSEQUAL(a,b) xil_fpo_lessequal_d(a,b)
#define HLS_FPO_GREATERF(a,b) xil_fpo_greater_flt(a,b)
#define HLS_FPO_GREATER(a,b) xil_fpo_greater_d(a,b)
#define HLS_FPO_GREATEREQUALF(a,b) xil_fpo_greaterequal_flt(a,b)
#define HLS_FPO_GREATEREQUAL(a,b) xil_fpo_greaterequal_d(a,b)
#define HLS_FPO_NOTEQUALF(a,b) xil_fpo_notequal_flt(a,b)
#define HLS_FPO_NOTEQUAL(a,b) xil_fpo_notequal_d(a,b)
#define HLS_FPO_CONDCODEF(a,b) xil_fpo_condcode_flt(a,b)
#define HLS_FPO_CONDCODE(a,b) xil_fpo_condcode_d(a,b)
#define HLS_FPO_FTOI(a) xil_fpo_flttofix_int_flt(a)
#define HLS_FPO_DTOI(a) xil_fpo_flttofix_int_d(a)
#define HLS_FPO_ITOF(a) xil_fpo_fixtoflt_flt_int(a)
#define HLS_FPO_ITOD(a) xil_fpo_fixtoflt_d_int(a)
#define HLS_FPO_FTOF(a) xil_fpo_flttoflt_flt_flt(a)
#define HLS_FPO_DTOF(a) xil_fpo_flttoflt_flt_d(a)
#define HLS_FPO_FTOD(a) xil_fpo_flttoflt_d_flt(a)
#define HLS_FPO_DTOD(a) xil_fpo_flttoflt_d_d(a)
#include "floating_point_v7_0_bitacc_cmodel.h" // Must include before GMP and MPFR
#include "gmp.h"
#include "mpfr.h"
////////////////////////////////////////////////////////////////////////
// Operation functions: add
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_add_flt(float a, float b)
{
float res_flt = 0.0f;
// xip_fpo_add_flt
xip_fpo_add_flt(&res_flt, a, b); // normal operation
return res_flt;
}
inline double xil_fpo_add_d(double a, double b)
{
double res_d = 0.0;
// xip_fpo_add_d
xip_fpo_add_d(&res_d, a, b); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: subtract
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_sub_flt(float a, float b)
{
float res_flt = 0.0f;
// xip_fpo_sub_flt
xip_fpo_sub_flt(&res_flt, a, b); // normal operation
return res_flt;
}
inline double xil_fpo_sub_d(double a, double b)
{
double res_d = 0.0;
// xip_fpo_sub_d
xip_fpo_sub_d(&res_d, a, b); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: multiply
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_mul_flt(float a, float b)
{
float res_flt = 0.0f;
// xip_fpo_mul_flt
xip_fpo_mul_flt(&res_flt, a, b); // normal operation
return res_flt;
}
inline double xil_fpo_mul_d(double a, double b)
{
double res_d = 0.0;
// xip_fpo_mul_d
xip_fpo_mul_d(&res_d, a, b); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: divide
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_div_flt(float a, float b)
{
float res_flt = 0.0f;
// xip_fpo_div_flt
xip_fpo_div_flt(&res_flt, a, b); // normal operation
return res_flt;
}
inline double xil_fpo_div_d(double a, double b)
{
double res_d = 0.0;
// xip_fpo_div_d
xip_fpo_div_d(&res_d, a, b); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: reciprocal
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_rec_flt(float a)
{
float res_flt = 0.0f;
// xip_fpo_rec_flt
xip_fpo_rec_flt(&res_flt, a); // normal operation
return res_flt;
}
inline double xil_fpo_rec_d(double a)
{
double res_d = 0.0;
// xip_fpo_rec_d
xip_fpo_rec_d(&res_d, a); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: square root
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_sqrt_flt(float a)
{
// printf("Testing operation functions: square root\n");
float res_flt = 0.0f;
// xip_fpo_sqrt_flt
xip_fpo_sqrt_flt(&res_flt, a); // normal operation
// printf("float = sqrtf(a), and got res_flt=%f\n", res_flt);
return res_flt;
}
inline double xil_fpo_sqrt_d(double a)
{
double res_d = 0.0;
// xip_fpo_sqrt_d
xip_fpo_sqrt_d(&res_d, a); // normal operation
// printf("double = sqrt(a), and got res_d=%f\n", res_d);
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: reciprocal square root
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_recsqrt_flt(float a)
{
float res_flt = 0.0f;
// xip_fpo_recsqrt_flt
xip_fpo_recsqrt_flt(&res_flt, a); // normal operation
return res_flt;
}
inline double xil_fpo_recsqrt_d(double a)
{
double res_d = 0.0;
// xip_fpo_recsqrt_d
xip_fpo_recsqrt_d(&res_d, a); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: absolute value
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_abs_flt(float a)
{
float res_flt = 0.0f;
xip_fpo_abs_flt(&res_flt, a);
return res_flt;
}
inline double xil_fpo_abs_d(double a)
{
double res_d = 0.0;
xip_fpo_abs_d(&res_d, a);
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: logarithm
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_log_flt(float a)
{
float res_flt = 0.0f;
// xip_fpo_log_flt
xip_fpo_log_flt(&res_flt, a); // normal operation
return res_flt;
}
inline double xil_fpo_log_d(double a)
{
double res_d = 0.0;
// xip_fpo_log_d
xip_fpo_log_d(&res_d, a); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: Exponential
////////////////////////////////////////////////////////////////////////
inline float xil_fpo_exp_flt(float a)
{
float res_flt = 0.0f;
// xip_fpo_exp_flt
xip_fpo_exp_flt(&res_flt, a); // normal operation
return res_flt;
}
inline double xil_fpo_exp_d(double a)
{
double res_d = 0.0;
// xip_fpo_exp_d
xip_fpo_exp_d(&res_d, a); // normal operation
return res_d;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare unordered
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_unordered_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_unordered_flt
xip_fpo_unordered_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_unordered_d(double a, double b)
{
int res_int = 0;
// xip_fpo_unordered_d
xip_fpo_unordered_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare equal
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_equal_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_equal_flt
xip_fpo_equal_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_equal_d(double a, double b)
{
int res_int = 0;
// xip_fpo_equal_d
xip_fpo_equal_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare less than
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_less_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_less_flt
xip_fpo_less_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_less_d(double a, double b)
{
int res_int = 0;
// xip_fpo_less_d
xip_fpo_less_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare less than or equal
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_lessequal_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_lessequal_flt
xip_fpo_lessequal_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_lessequal_d(double a, double b)
{
int res_int = 0;
// xip_fpo_lessequal_d
xip_fpo_lessequal_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare greater than
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_greater_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_greater_flt
xip_fpo_greater_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_greater_d(double a, double b)
{
int res_int = 0;
// xip_fpo_greater_d
xip_fpo_greater_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare greater than or equal
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_greaterequal_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_greaterequal_flt
xip_fpo_greaterequal_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_greaterequal_d(double a, double b)
{
int res_int = 0;
// xip_fpo_greaterequal_d
xip_fpo_greaterequal_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare not equal
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_notequal_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_notequal_flt
xip_fpo_notequal_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_notequal_d(double a, double b)
{
int res_int = 0;
xip_fpo_notequal_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Operation functions: compare condition code
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_condcode_flt(float a, float b)
{
int res_int = 0;
// xip_fpo_condcode_flt
xip_fpo_condcode_flt(&res_int, a, b); // normal operation
return res_int;
}
inline int xil_fpo_condcode_d(double a, double b)
{
int res_int = 0;
// xip_fpo_condcode_d
xip_fpo_condcode_d(&res_int, a, b); // normal operation
return res_int;
}
////////////////////////////////////////////////////////////////////////
// Conversion functions: conversion code
////////////////////////////////////////////////////////////////////////
inline int xil_fpo_flttofix_int_flt(float a)
{
int res_int = 0;
// xip_fpo_flttofix_int_flt
xip_fpo_flttofix_int_flt(&res_int, a); // normal operation
return res_int;
}
inline int xil_fpo_flttofix_int_d(double a)
{
int res_int = 0;
// xip_fpo_flttofix_int_d
xip_fpo_flttofix_int_d(&res_int, a); // normal operation
return res_int;
}
inline float xil_fpo_fixtoflt_flt_int(int a)
{
float res_flt = 0.0f;
// xip_fpo_fixtoflt_flt_int
xip_fpo_fixtoflt_flt_int(&res_flt, a); // normal operation
return res_flt;
}
inline double xil_fpo_fixtoflt_d_int(int a)
{
double res_d = 0.0;
// xip_fpo_fixtoflt_d_int
xip_fpo_fixtoflt_d_int(&res_d, a); // normal operation
return res_d;
}
inline float xil_fpo_flttoflt_flt_flt(float a)
{
float res_flt = 0.0f;
// xip_fpo_flttoflt_flt_flt
xip_fpo_flttoflt_flt_flt(&res_flt, a); // normal operation
return res_flt;
}
inline float xil_fpo_flttoflt_flt_d(double a)
{
float res_flt = 0.0f;
// xip_fpo_flttoflt_flt_d
xip_fpo_flttoflt_flt_d(&res_flt, a); // normal operation
return res_flt;
}
inline double xil_fpo_flttoflt_d_flt(float a)
{
double res_d = 0.0;
// xip_fpo_flttoflt_d_flt
xip_fpo_flttoflt_d_flt(&res_d, a); // normal operation
return res_d;
}
inline double xil_fpo_flttoflt_d_d(double a)
{
double res_d = 0.0;
// xip_fpo_flttoflt_d_d
xip_fpo_flttoflt_d_d(&res_d, a); // normal operation
return res_d;
}
#endif
#endif /* #ifndef __AESL_FPO_H__*/

3348
include/hls_half.h Normal file

File diff suppressed because it is too large Load diff

268
include/hls_stream.h Normal file
View file

@ -0,0 +1,268 @@
/*
#- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved.
#-
#- This file contains confidential and proprietary information
#- of Xilinx, Inc. and is protected under U.S. and
#- international copyright and other intellectual property
#- laws.
#-
#- DISCLAIMER
#- This disclaimer is not a license and does not grant any
#- rights to the materials distributed herewith. Except as
#- otherwise provided in a valid license issued to you by
#- Xilinx, and to the maximum extent permitted by applicable
#- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
#- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
#- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
#- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
#- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
#- (2) Xilinx shall not be liable (whether in contract or tort,
#- including negligence, or under any other theory of
#- liability) for any loss or damage of any kind or nature
#- related to, arising under or in connection with these
#- materials, including for any direct, or any indirect,
#- special, incidental, or consequential loss or damage
#- (including loss of data, profits, goodwill, or any type of
#- loss or damage suffered as a result of any action brought
#- by a third party) even if such damage or loss was
#- reasonably foreseeable or Xilinx had been advised of the
#- possibility of the same.
#-
#- CRITICAL APPLICATIONS
#- Xilinx products are not designed or intended to be fail-
#- safe, or for use in any application requiring fail-safe
#- performance, such as life-support or safety devices or
#- systems, Class III medical devices, nuclear facilities,
#- applications related to the deployment of airbags, or any
#- other applications that could lead to death, personal
#- injury, or severe property or environmental damage
#- (individually and collectively, "Critical
#- Applications"). Customer assumes the sole risk and
#- liability of any use of Xilinx products in Critical
#- Applications, subject only to applicable laws and
#- regulations governing limitations on product liability.
#-
#- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
#- PART OF THIS FILE AT ALL TIMES.
#- ************************************************************************
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef X_HLS_STREAM_SIM_H
#define X_HLS_STREAM_SIM_H
/*
* This file contains a C++ model of hls::stream.
* It defines C simulation model.
*/
#ifndef __cplusplus
#error C++ is required to include this header file
#else
//////////////////////////////////////////////
// C level simulation models for hls::stream
//////////////////////////////////////////////
#include <queue>
#include <iostream>
#include <typeinfo>
#include <string>
#include <sstream>
#ifdef HLS_STREAM_THREAD_SAFE
#include <mutex>
#include <condition_variable>
#endif
#ifndef _MSC_VER
#include <cxxabi.h>
#include <stdlib.h>
#endif
namespace hls {
template<typename __STREAM_T__>
class stream
{
protected:
std::string _name;
std::deque<__STREAM_T__> _data; // container for the elements
#ifdef HLS_STREAM_THREAD_SAFE
std::mutex _mutex;
std::condition_variable _condition_var;
#endif
public:
/// Constructors
// Keep consistent with the synthesis model's constructors
stream() {
static unsigned _counter = 1;
std::stringstream ss;
#ifndef _MSC_VER
char* _demangle_name = abi::__cxa_demangle(typeid(*this).name(), 0, 0, 0);
if (_demangle_name) {
_name = _demangle_name;
free(_demangle_name);
}
else {
_name = "hls_stream";
}
#else
_name = typeid(*this).name();
#endif
ss << _counter++;
_name += "." + ss.str();
}
stream(const std::string name) {
// default constructor,
// capacity set to predefined maximum
_name = name;
}
/// Make copy constructor and assignment operator private
private:
stream(const stream< __STREAM_T__ >& chn):
_name(chn._name), _data(chn._data) {
}
stream& operator = (const stream< __STREAM_T__ >& chn) {
_name = chn._name;
_data = chn._data;
return *this;
}
public:
/// Overload >> and << operators to implement read() and write()
void operator >> (__STREAM_T__& rdata) {
read(rdata);
}
void operator << (const __STREAM_T__& wdata) {
write(wdata);
}
public:
/// Destructor
/// Check status of the queue
virtual ~stream() {
if (!_data.empty())
{
std::cout << "WARNING: Hls::stream '"
<< _name
<< "' contains leftover data,"
<< " which may result in RTL simulation hanging."
<< std::endl;
}
}
/// Status of the queue
bool empty() {
#ifdef HLS_STREAM_THREAD_SAFE
std::lock_guard<std::mutex> lg(_mutex);
#endif
return _data.empty();
}
bool full() const { return false; }
/// Blocking read
void read(__STREAM_T__& head) {
head = read();
}
#ifdef HLS_STREAM_THREAD_SAFE
__STREAM_T__ read() {
std::unique_lock<std::mutex> ul(_mutex);
while (_data.empty()) {
_condition_var.wait(ul);
}
__STREAM_T__ elem;
elem = _data.front();
_data.pop_front();
return elem;
}
#else
__STREAM_T__ read() {
__STREAM_T__ elem;
#ifdef HLS_STREAM_WAIT_FOR_DATA_IN_BLOCKING_READ
while(_data.empty())
;
#endif
if (_data.empty()) {
std::cout << "WARNING: Hls::stream '"
<< _name
<< "' is read while empty,"
<< " which may result in RTL simulation hanging."
<< std::endl;
elem = __STREAM_T__();
} else {
elem = _data.front();
_data.pop_front();
}
return elem;
}
#endif
/// Blocking write
void write(const __STREAM_T__& tail) {
#ifdef HLS_STREAM_THREAD_SAFE
std::unique_lock<std::mutex> ul(_mutex);
#endif
_data.push_back(tail);
#ifdef HLS_STREAM_THREAD_SAFE
_condition_var.notify_one();
#endif
}
/// Nonblocking read
bool read_nb(__STREAM_T__& head) {
#ifdef HLS_STREAM_THREAD_SAFE
std::lock_guard<std::mutex> lg(_mutex);
#endif
bool is_empty = _data.empty();
if (is_empty) {
head = __STREAM_T__();
} else {
__STREAM_T__ elem(_data.front());
_data.pop_front();
head = elem;
}
return !is_empty;
}
/// Nonblocking write
bool write_nb(const __STREAM_T__& tail) {
bool is_full = full();
write(tail);
return !is_full;
}
/// Fifo size
size_t size() {
return _data.size();
}
};
} // namespace hls
#endif // __cplusplus
#endif // X_HLS_STREAM_SIM_H

945
include/mpfr.h Normal file
View file

@ -0,0 +1,945 @@
/* mpfr.h -- Include file for mpfr.
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
Contributed by the Arenaire and Cacao projects, INRIA.
This file is part of the GNU MPFR Library.
The GNU MPFR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
The GNU MPFR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef __MPFR_H
#define __MPFR_H
/* Define MPFR version number */
#define MPFR_VERSION_MAJOR 3
#define MPFR_VERSION_MINOR 0
#define MPFR_VERSION_PATCHLEVEL 1
#define MPFR_VERSION_STRING "3.0.1-p4"
/* Macros dealing with MPFR VERSION */
#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
#define MPFR_VERSION \
MPFR_VERSION_NUM(MPFR_VERSION_MAJOR,MPFR_VERSION_MINOR,MPFR_VERSION_PATCHLEVEL)
/* Check if GMP is included, and try to include it (Works with local GMP) */
#ifndef __GMP_H__
# include <gmp.h>
#endif
/* Check if stdio.h is included or if the user wants FILE */
#if defined (_GMP_H_HAVE_FILE) || defined (MPFR_USE_FILE)
# define _MPFR_H_HAVE_FILE 1
#endif
#if defined (_GMP_H_HAVE_VA_LIST)
# define _MPFR_H_HAVE_VA_LIST 1
#endif
/* Check if <stdint.h> / <inttypes.h> is included or if the user
explicitly wants intmax_t. Automatical detection is done by
checking:
- INTMAX_C and UINTMAX_C, but not if the compiler is a C++ one
(as suggested by Patrick Pelissier) because the test does not
work well in this case. See:
http://websympa.loria.fr/wwsympa/arc/mpfr/2010-02/msg00025.html
We do not check INTMAX_MAX and UINTMAX_MAX because under Solaris,
these macros are always defined by <limits.h> (i.e. even when
<stdint.h> and <inttypes.h> are not included).
- _STDINT_H (defined by the glibc) and _STDINT_H_ (defined under
Mac OS X), but this test may not work with all implementations.
Portable software should not rely on these tests.
*/
#if (defined (INTMAX_C) && defined (UINTMAX_C) && !defined(__cplusplus)) || \
defined (MPFR_USE_INTMAX_T) || defined (_STDINT_H) || defined (_STDINT_H_)
# define _MPFR_H_HAVE_INTMAX_T 1
#endif
/* Avoid some problems with macro expansion if the user defines macros
with the same name as keywords. By convention, identifiers and macro
names starting with mpfr_ are reserved by MPFR. */
typedef void mpfr_void;
typedef int mpfr_int;
typedef unsigned int mpfr_uint;
typedef long mpfr_long;
typedef unsigned long mpfr_ulong;
typedef size_t mpfr_size_t;
/* Definition of rounding modes (DON'T USE MPFR_RNDNA!).
Warning! Changing the contents of this enum should be seen as an
interface change since the old and the new types are not compatible
(the integer type compatible with the enumerated type can even change,
see ISO C99, 6.7.2.2#4), and in Makefile.am, AGE should be set to 0.
MPFR_RNDU must appear just before MPFR_RNDD (see
MPFR_IS_RNDUTEST_OR_RNDDNOTTEST in mpfr-impl.h).
MPFR_RNDF has been added, though not implemented yet, in order to avoid
to break the ABI once faithful rounding gets implemented.
If you change the order of the rounding modes, please update the routines
in texceptions.c which assume 0=RNDN, 1=RNDZ, 2=RNDU, 3=RNDD, 4=RNDA.
*/
typedef enum {
MPFR_RNDN=0, /* round to nearest, with ties to even */
MPFR_RNDZ, /* round toward zero */
MPFR_RNDU, /* round toward +Inf */
MPFR_RNDD, /* round toward -Inf */
MPFR_RNDA, /* round away from zero */
MPFR_RNDF, /* faithful rounding (not implemented yet) */
MPFR_RNDNA=-1 /* round to nearest, with ties away from zero (mpfr_round) */
} mpfr_rnd_t;
/* kept for compatibility with MPFR 2.4.x and before */
#define GMP_RNDN MPFR_RNDN
#define GMP_RNDZ MPFR_RNDZ
#define GMP_RNDU MPFR_RNDU
#define GMP_RNDD MPFR_RNDD
/* Define precision : 1 (short), 2 (int) or 3 (long) (DON'T USE IT!)*/
#ifndef _MPFR_PREC_FORMAT
# if __GMP_MP_SIZE_T_INT == 1
# define _MPFR_PREC_FORMAT 2
# else
# define _MPFR_PREC_FORMAT 3
# endif
#endif
/* Let's make mpfr_prec_t signed in order to avoid problems due to the
usual arithmetic conversions when mixing mpfr_prec_t and mpfr_exp_t
in an expression (for error analysis) if casts are forgotten. */
#if _MPFR_PREC_FORMAT == 1
typedef short mpfr_prec_t;
typedef unsigned short mpfr_uprec_t;
#elif _MPFR_PREC_FORMAT == 2
typedef int mpfr_prec_t;
typedef unsigned int mpfr_uprec_t;
#elif _MPFR_PREC_FORMAT == 3
typedef long mpfr_prec_t;
typedef unsigned long mpfr_uprec_t;
#else
# error "Invalid MPFR Prec format"
#endif
/* Definition of precision limits without needing <limits.h> */
/* Note: the casts allows the expression to yield the wanted behavior
for _MPFR_PREC_FORMAT == 1 (due to integer promotion rules). */
#define MPFR_PREC_MIN 2
#define MPFR_PREC_MAX ((mpfr_prec_t)((mpfr_uprec_t)(~(mpfr_uprec_t)0)>>1))
/* Definition of sign */
typedef int mpfr_sign_t;
/* Definition of the exponent: same as in GMP. */
typedef mp_exp_t mpfr_exp_t;
/* Definition of the standard exponent limits */
#define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((mpfr_ulong) 1 << 30) - 1))
#define MPFR_EMIN_DEFAULT (-(MPFR_EMAX_DEFAULT))
/* Definition of the main structure */
typedef struct {
mpfr_prec_t _mpfr_prec;
mpfr_sign_t _mpfr_sign;
mpfr_exp_t _mpfr_exp;
mp_limb_t *_mpfr_d;
} __mpfr_struct;
/* Compatibility with previous types of MPFR */
#ifndef mp_rnd_t
# define mp_rnd_t mpfr_rnd_t
#endif
#ifndef mp_prec_t
# define mp_prec_t mpfr_prec_t
#endif
/*
The represented number is
_sign*(_d[k-1]/B+_d[k-2]/B^2+...+_d[0]/B^k)*2^_exp
where k=ceil(_mp_prec/GMP_NUMB_BITS) and B=2^GMP_NUMB_BITS.
For the msb (most significant bit) normalized representation, we must have
_d[k-1]>=B/2, unless the number is singular.
We must also have the last k*GMP_NUMB_BITS-_prec bits set to zero.
*/
typedef __mpfr_struct mpfr_t[1];
typedef __mpfr_struct *mpfr_ptr;
typedef __gmp_const __mpfr_struct *mpfr_srcptr;
/* For those who need a direct and fast access to the sign field.
However it is not in the API, thus use it at your own risk: it might
not be supported, or change name, in further versions!
Unfortunately, it must be defined here (instead of MPFR's internal
header file mpfr-impl.h) because it is used by some macros below.
*/
#define MPFR_SIGN(x) ((x)->_mpfr_sign)
/* Stack interface */
typedef enum {
MPFR_NAN_KIND = 0,
MPFR_INF_KIND = 1, MPFR_ZERO_KIND = 2, MPFR_REGULAR_KIND = 3
} mpfr_kind_t;
/* GMP defines:
+ size_t: Standard size_t
+ __GMP_ATTRIBUTE_PURE Attribute for math functions.
+ __GMP_NOTHROW For C++: can't throw .
+ __GMP_EXTERN_INLINE Attribute for inline function.
* __gmp_const const (Supports for K&R compiler only for mpfr.h).
+ __GMP_DECLSPEC_EXPORT compiling to go into a DLL
+ __GMP_DECLSPEC_IMPORT compiling to go into a application
*/
/* Extra MPFR defines */
#define __MPFR_SENTINEL_ATTR
#if defined (__GNUC__)
# if __GNUC__ >= 4
# undef __MPFR_SENTINEL_ATTR
# define __MPFR_SENTINEL_ATTR __attribute__ ((sentinel))
# endif
#endif
/* Prototypes: Support of K&R compiler */
#if defined (__GMP_PROTO)
# define _MPFR_PROTO __GMP_PROTO
#elif defined (__STDC__) || defined (__cplusplus)
# define _MPFR_PROTO(x) x
#else
# define _MPFR_PROTO(x) ()
#endif
/* Support for WINDOWS Dll:
Check if we are inside a MPFR build, and if so export the functions.
Otherwise does the same thing as GMP */
#if defined(__MPFR_WITHIN_MPFR) && __GMP_LIBGMP_DLL
# define __MPFR_DECLSPEC __GMP_DECLSPEC_EXPORT
#else
# define __MPFR_DECLSPEC __GMP_DECLSPEC
#endif
/* Note: In order to be declared, some functions need a specific
system header to be included *before* "mpfr.h". If the user
forgets to include the header, the MPFR function prototype in
the user object file is not correct. To avoid wrong results,
we raise a linker error in that case by changing their internal
name in the library (prefixed by __gmpfr instead of mpfr). See
the lines of the form "#define mpfr_xxx __gmpfr_xxx" below. */
#if defined (__cplusplus)
extern "C" {
#endif
__MPFR_DECLSPEC __gmp_const char * mpfr_get_version _MPFR_PROTO ((void));
__MPFR_DECLSPEC __gmp_const char * mpfr_get_patches _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_buildopt_tls_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_buildopt_decimal_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_set_emin _MPFR_PROTO ((mpfr_exp_t));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin_min _MPFR_PROTO ((void));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emin_max _MPFR_PROTO ((void));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_set_emax _MPFR_PROTO ((mpfr_exp_t));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax_min _MPFR_PROTO ((void));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_emax_max _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_set_default_rounding_mode _MPFR_PROTO((mpfr_rnd_t));
__MPFR_DECLSPEC mpfr_rnd_t mpfr_get_default_rounding_mode _MPFR_PROTO((void));
__MPFR_DECLSPEC __gmp_const char *
mpfr_print_rnd_mode _MPFR_PROTO((mpfr_rnd_t));
__MPFR_DECLSPEC void mpfr_clear_flags _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_clear_underflow _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_clear_overflow _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_clear_nanflag _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_clear_inexflag _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_clear_erangeflag _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_set_underflow _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_set_overflow _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_set_nanflag _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_set_inexflag _MPFR_PROTO ((void));
__MPFR_DECLSPEC void mpfr_set_erangeflag _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_underflow_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_overflow_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_nanflag_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_inexflag_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_erangeflag_p _MPFR_PROTO ((void));
__MPFR_DECLSPEC int
mpfr_check_range _MPFR_PROTO ((mpfr_ptr, int, mpfr_rnd_t));
__MPFR_DECLSPEC void mpfr_init2 _MPFR_PROTO ((mpfr_ptr, mpfr_prec_t));
__MPFR_DECLSPEC void mpfr_init _MPFR_PROTO ((mpfr_ptr));
__MPFR_DECLSPEC void mpfr_clear _MPFR_PROTO ((mpfr_ptr));
__MPFR_DECLSPEC void
mpfr_inits2 _MPFR_PROTO ((mpfr_prec_t, mpfr_ptr, ...)) __MPFR_SENTINEL_ATTR;
__MPFR_DECLSPEC void
mpfr_inits _MPFR_PROTO ((mpfr_ptr, ...)) __MPFR_SENTINEL_ATTR;
__MPFR_DECLSPEC void
mpfr_clears _MPFR_PROTO ((mpfr_ptr, ...)) __MPFR_SENTINEL_ATTR;
__MPFR_DECLSPEC int
mpfr_prec_round _MPFR_PROTO ((mpfr_ptr, mpfr_prec_t, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_can_round _MPFR_PROTO ((mpfr_srcptr, mpfr_exp_t, mpfr_rnd_t, mpfr_rnd_t,
mpfr_prec_t));
__MPFR_DECLSPEC mpfr_prec_t mpfr_min_prec _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_exp _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_set_exp _MPFR_PROTO ((mpfr_ptr, mpfr_exp_t));
__MPFR_DECLSPEC mpfr_prec_t mpfr_get_prec _MPFR_PROTO((mpfr_srcptr));
__MPFR_DECLSPEC void mpfr_set_prec _MPFR_PROTO((mpfr_ptr, mpfr_prec_t));
__MPFR_DECLSPEC void mpfr_set_prec_raw _MPFR_PROTO((mpfr_ptr, mpfr_prec_t));
__MPFR_DECLSPEC void mpfr_set_default_prec _MPFR_PROTO((mpfr_prec_t));
__MPFR_DECLSPEC mpfr_prec_t mpfr_get_default_prec _MPFR_PROTO((void));
__MPFR_DECLSPEC int mpfr_set_d _MPFR_PROTO ((mpfr_ptr, double, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_set_flt _MPFR_PROTO ((mpfr_ptr, float, mpfr_rnd_t));
#ifdef MPFR_WANT_DECIMAL_FLOATS
__MPFR_DECLSPEC int mpfr_set_decimal64 _MPFR_PROTO ((mpfr_ptr, _Decimal64,
mpfr_rnd_t));
#endif
__MPFR_DECLSPEC int
mpfr_set_ld _MPFR_PROTO ((mpfr_ptr, long double, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_z _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_z_2exp _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, mpfr_exp_t, mpfr_rnd_t));
__MPFR_DECLSPEC void mpfr_set_nan _MPFR_PROTO ((mpfr_ptr));
__MPFR_DECLSPEC void mpfr_set_inf _MPFR_PROTO ((mpfr_ptr, int));
__MPFR_DECLSPEC void mpfr_set_zero _MPFR_PROTO ((mpfr_ptr, int));
__MPFR_DECLSPEC int
mpfr_set_f _MPFR_PROTO ((mpfr_ptr, mpf_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_get_f _MPFR_PROTO ((mpf_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_set_si _MPFR_PROTO ((mpfr_ptr, long, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_ui _MPFR_PROTO ((mpfr_ptr, unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_si_2exp _MPFR_PROTO ((mpfr_ptr, long, mpfr_exp_t, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_ui_2exp _MPFR_PROTO ((mpfr_ptr,unsigned long,mpfr_exp_t,mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_q _MPFR_PROTO ((mpfr_ptr, mpq_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_init_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int,
mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set4 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t, int));
__MPFR_DECLSPEC int
mpfr_abs _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_neg _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_signbit _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int
mpfr_setsign _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, int, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_copysign _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t));
#ifdef _MPFR_H_HAVE_INTMAX_T
#define mpfr_set_sj __gmpfr_set_sj
#define mpfr_set_sj_2exp __gmpfr_set_sj_2exp
#define mpfr_set_uj __gmpfr_set_uj
#define mpfr_set_uj_2exp __gmpfr_set_uj_2exp
#define mpfr_get_sj __gmpfr_mpfr_get_sj
#define mpfr_get_uj __gmpfr_mpfr_get_uj
__MPFR_DECLSPEC int mpfr_set_sj _MPFR_PROTO ((mpfr_t, intmax_t, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_sj_2exp _MPFR_PROTO ((mpfr_t, intmax_t, intmax_t, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_set_uj _MPFR_PROTO ((mpfr_t, uintmax_t, mpfr_rnd_t));
__MPFR_DECLSPEC int
mpfr_set_uj_2exp _MPFR_PROTO ((mpfr_t, uintmax_t, intmax_t, mpfr_rnd_t));
__MPFR_DECLSPEC intmax_t mpfr_get_sj _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC uintmax_t mpfr_get_uj _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
#endif
__MPFR_DECLSPEC mpfr_exp_t mpfr_get_z_2exp _MPFR_PROTO ((mpz_ptr, mpfr_srcptr));
__MPFR_DECLSPEC float mpfr_get_flt _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC double mpfr_get_d _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
#ifdef MPFR_WANT_DECIMAL_FLOATS
__MPFR_DECLSPEC _Decimal64 mpfr_get_decimal64 _MPFR_PROTO ((mpfr_srcptr,
mpfr_rnd_t));
#endif
__MPFR_DECLSPEC long double mpfr_get_ld _MPFR_PROTO ((mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC double mpfr_get_d1 _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC double mpfr_get_d_2exp _MPFR_PROTO ((long*, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC long double mpfr_get_ld_2exp _MPFR_PROTO ((long*, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC long mpfr_get_si _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC unsigned long mpfr_get_ui _MPFR_PROTO ((mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC char*mpfr_get_str _MPFR_PROTO ((char*, mpfr_exp_t*, int, size_t,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_get_z _MPFR_PROTO ((mpz_ptr z, mpfr_srcptr f,
mpfr_rnd_t));
__MPFR_DECLSPEC void mpfr_free_str _MPFR_PROTO ((char *));
__MPFR_DECLSPEC int mpfr_urandom _MPFR_PROTO ((mpfr_ptr, gmp_randstate_t,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_urandomb _MPFR_PROTO ((mpfr_ptr, gmp_randstate_t));
__MPFR_DECLSPEC void mpfr_nextabove _MPFR_PROTO ((mpfr_ptr));
__MPFR_DECLSPEC void mpfr_nextbelow _MPFR_PROTO ((mpfr_ptr));
__MPFR_DECLSPEC void mpfr_nexttoward _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr));
#ifdef _MPFR_H_HAVE_FILE
#define mpfr_inp_str __gmpfr_inp_str
#define mpfr_out_str __gmpfr_out_str
__MPFR_DECLSPEC size_t mpfr_inp_str _MPFR_PROTO ((mpfr_ptr, FILE*, int,
mpfr_rnd_t));
__MPFR_DECLSPEC size_t mpfr_out_str _MPFR_PROTO ((FILE*, int, size_t,
mpfr_srcptr, mpfr_rnd_t));
#define mpfr_fprintf __gmpfr_fprintf
__MPFR_DECLSPEC int mpfr_fprintf _MPFR_PROTO ((FILE*, __gmp_const char*,
...));
#endif
__MPFR_DECLSPEC int mpfr_printf _MPFR_PROTO ((__gmp_const char*, ...));
__MPFR_DECLSPEC int mpfr_asprintf _MPFR_PROTO ((char**, __gmp_const char*,
...));
__MPFR_DECLSPEC int mpfr_sprintf _MPFR_PROTO ((char*, __gmp_const char*,
...));
__MPFR_DECLSPEC int mpfr_snprintf _MPFR_PROTO ((char*, size_t,
__gmp_const char*, ...));
#ifdef _MPFR_H_HAVE_VA_LIST
#ifdef _MPFR_H_HAVE_FILE
#define mpfr_vfprintf __gmpfr_vfprintf
__MPFR_DECLSPEC int mpfr_vfprintf _MPFR_PROTO ((FILE*, __gmp_const char*,
va_list));
#endif /* _MPFR_H_HAVE_FILE */
#define mpfr_vprintf __gmpfr_vprintf
#define mpfr_vasprintf __gmpfr_vasprintf
#define mpfr_vsprintf __gmpfr_vsprintf
#define mpfr_vsnprintf __gmpfr_vsnprintf
__MPFR_DECLSPEC int mpfr_vprintf _MPFR_PROTO ((__gmp_const char*, va_list));
__MPFR_DECLSPEC int mpfr_vasprintf _MPFR_PROTO ((char**, __gmp_const char*,
va_list));
__MPFR_DECLSPEC int mpfr_vsprintf _MPFR_PROTO ((char*, __gmp_const char*,
va_list));
__MPFR_DECLSPEC int mpfr_vsnprintf _MPFR_PROTO ((char*, size_t,
__gmp_const char*, va_list));
#endif /* _MPFR_H_HAVE_VA_LIST */
__MPFR_DECLSPEC int mpfr_pow _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_pow_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_pow_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_ui_pow_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int,
unsigned long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_ui_pow _MPFR_PROTO ((mpfr_ptr, unsigned long int,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_pow_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpz_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sqrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sqrt_ui _MPFR_PROTO ((mpfr_ptr, unsigned long,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_rec_sqrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_add _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sub _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_add_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sub_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_ui_sub _MPFR_PROTO ((mpfr_ptr, unsigned long,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_ui_div _MPFR_PROTO ((mpfr_ptr, unsigned long,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_add_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sub_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_si_sub _MPFR_PROTO ((mpfr_ptr, long int,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long int, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_si_div _MPFR_PROTO ((mpfr_ptr, long int,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_add_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
double, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sub_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
double, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_d_sub _MPFR_PROTO ((mpfr_ptr, double,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
double, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_d _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
double, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_d_div _MPFR_PROTO ((mpfr_ptr, double,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sqr _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_const_pi _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_const_log2 _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_const_euler _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_const_catalan _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_agm _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_log _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_log2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_log10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_log1p _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_exp2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_exp10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_expm1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_eint _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_li2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cmp _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_cmp3 _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr, int));
__MPFR_DECLSPEC int mpfr_cmp_d _MPFR_PROTO ((mpfr_srcptr, double));
__MPFR_DECLSPEC int mpfr_cmp_ld _MPFR_PROTO ((mpfr_srcptr, long double));
__MPFR_DECLSPEC int mpfr_cmpabs _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_cmp_ui _MPFR_PROTO ((mpfr_srcptr, unsigned long));
__MPFR_DECLSPEC int mpfr_cmp_si _MPFR_PROTO ((mpfr_srcptr, long));
__MPFR_DECLSPEC int mpfr_cmp_ui_2exp _MPFR_PROTO ((mpfr_srcptr, unsigned long,
mpfr_exp_t));
__MPFR_DECLSPEC int mpfr_cmp_si_2exp _MPFR_PROTO ((mpfr_srcptr, long,
mpfr_exp_t));
__MPFR_DECLSPEC void mpfr_reldiff _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_eq _MPFR_PROTO((mpfr_srcptr, mpfr_srcptr,
unsigned long));
__MPFR_DECLSPEC int mpfr_sgn _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_mul_2exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_2exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul_2ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_2ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul_2si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_2si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
long, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_rint _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_round _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_trunc _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_ceil _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_floor _MPFR_PROTO((mpfr_ptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_rint_round _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_rint_trunc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_rint_ceil _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_rint_floor _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_frac _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_modf _MPFR_PROTO ((mpfr_ptr, mpfr_ptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_remquo _MPFR_PROTO ((mpfr_ptr, long*, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_remainder _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fmod _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_ulong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_slong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_uint_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_sint_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_ushort_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_sshort_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_uintmax_p _MPFR_PROTO((mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fits_intmax_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC void mpfr_extract _MPFR_PROTO ((mpz_ptr, mpfr_srcptr,
unsigned int));
__MPFR_DECLSPEC void mpfr_swap _MPFR_PROTO ((mpfr_ptr, mpfr_ptr));
__MPFR_DECLSPEC void mpfr_dump _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_nan_p _MPFR_PROTO((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_inf_p _MPFR_PROTO((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_number_p _MPFR_PROTO((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_integer_p _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_zero_p _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_regular_p _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_greater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_greaterequal_p _MPFR_PROTO ((mpfr_srcptr,
mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_less_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_lessequal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_lessgreater_p _MPFR_PROTO((mpfr_srcptr,mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_equal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_unordered_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr));
__MPFR_DECLSPEC int mpfr_atanh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_acosh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_asinh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cosh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sinh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_tanh _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sinh_cosh _MPFR_PROTO ((mpfr_ptr, mpfr_ptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sech _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_csch _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_coth _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_acos _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_asin _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_atan _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sin _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sin_cos _MPFR_PROTO ((mpfr_ptr, mpfr_ptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cos _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_tan _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_atan2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sec _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_csc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_hypot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_erf _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_erfc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cbrt _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_root _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,unsigned long,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_gamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_lngamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_lgamma _MPFR_PROTO((mpfr_ptr,int*,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_digamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_zeta _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_zeta_ui _MPFR_PROTO ((mpfr_ptr,unsigned long,mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fac_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_j0 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_j1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_jn _MPFR_PROTO ((mpfr_ptr, long, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_y0 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_y1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_yn _MPFR_PROTO ((mpfr_ptr, long, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_ai _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_min _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_max _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_dim _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_mul_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpz_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpz_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_add_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpz_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sub_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpz_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cmp_z _MPFR_PROTO ((mpfr_srcptr, mpz_srcptr));
__MPFR_DECLSPEC int mpfr_mul_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpq_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_div_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpq_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_add_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpq_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sub_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,
mpq_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_cmp_q _MPFR_PROTO ((mpfr_srcptr, mpq_srcptr));
__MPFR_DECLSPEC int mpfr_cmp_f _MPFR_PROTO ((mpfr_srcptr, mpf_srcptr));
__MPFR_DECLSPEC int mpfr_fma _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_fms _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_sum _MPFR_PROTO ((mpfr_ptr, mpfr_ptr *__gmp_const,
unsigned long, mpfr_rnd_t));
__MPFR_DECLSPEC void mpfr_free_cache _MPFR_PROTO ((void));
__MPFR_DECLSPEC int mpfr_subnormalize _MPFR_PROTO ((mpfr_ptr, int,
mpfr_rnd_t));
__MPFR_DECLSPEC int mpfr_strtofr _MPFR_PROTO ((mpfr_ptr, __gmp_const char *,
char **, int, mpfr_rnd_t));
__MPFR_DECLSPEC size_t mpfr_custom_get_size _MPFR_PROTO ((mpfr_prec_t));
__MPFR_DECLSPEC void mpfr_custom_init _MPFR_PROTO ((void *, mpfr_prec_t));
__MPFR_DECLSPEC void * mpfr_custom_get_significand _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC mpfr_exp_t mpfr_custom_get_exp _MPFR_PROTO ((mpfr_srcptr));
__MPFR_DECLSPEC void mpfr_custom_move _MPFR_PROTO ((mpfr_ptr, void *));
__MPFR_DECLSPEC void mpfr_custom_init_set _MPFR_PROTO ((mpfr_ptr, int,
mpfr_exp_t, mpfr_prec_t, void *));
__MPFR_DECLSPEC int mpfr_custom_get_kind _MPFR_PROTO ((mpfr_srcptr));
#if defined (__cplusplus)
}
#endif
/* DON'T USE THIS! (For MPFR-public macros only, see below.)
The mpfr_sgn macro uses the fact that __MPFR_EXP_NAN and __MPFR_EXP_ZERO
are the smallest values.
FIXME: In the following macros, the cast of an unsigned type with MSB set
to the signed type mpfr_exp_t yields an integer overflow, which can give
unexpected results with future compilers and aggressive optimisations.
Why not working only with signed types, using INT_MIN and LONG_MIN? */
#if __GMP_MP_SIZE_T_INT
#define __MPFR_EXP_NAN ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+2))
#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+1))
#define __MPFR_EXP_INF ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+3))
#else
#define __MPFR_EXP_NAN ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+2))
#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+1))
#define __MPFR_EXP_INF ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+3))
#endif
/* Define MPFR_USE_EXTENSION to avoid "gcc -pedantic" warnings. */
#ifndef MPFR_EXTENSION
# if defined(MPFR_USE_EXTENSION)
# define MPFR_EXTENSION __extension__
# else
# define MPFR_EXTENSION
# endif
#endif
/* Warning! This macro doesn't work with K&R C (e.g., compare the "gcc -E"
output with and without -traditional) and shouldn't be used internally.
For public use only, but see the MPFR manual. */
#define MPFR_DECL_INIT(_x, _p) \
MPFR_EXTENSION mp_limb_t __gmpfr_local_tab_##_x[((_p)-1)/GMP_NUMB_BITS+1]; \
MPFR_EXTENSION mpfr_t _x = {{(_p),1,__MPFR_EXP_NAN,__gmpfr_local_tab_##_x}}
/* Fast access macros to replace function interface.
If the USER don't want to use the macro interface, let him make happy
even if it produces faster and smaller code. */
#ifndef MPFR_USE_NO_MACRO
/* Inlining theses functions is both faster and smaller */
#define mpfr_nan_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_NAN)
#define mpfr_inf_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_INF)
#define mpfr_zero_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_ZERO)
#define mpfr_regular_p(_x) ((_x)->_mpfr_exp > __MPFR_EXP_INF)
#define mpfr_sgn(_x) \
((_x)->_mpfr_exp < __MPFR_EXP_INF ? \
(mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \
MPFR_SIGN (_x))
/* Prevent them from using as lvalues */
#define MPFR_VALUE_OF(x) (0 ? (x) : (x))
#define mpfr_get_prec(_x) MPFR_VALUE_OF((_x)->_mpfr_prec)
#define mpfr_get_exp(_x) MPFR_VALUE_OF((_x)->_mpfr_exp)
/* Note: if need be, the MPFR_VALUE_OF can be used for other expressions
(of any type). Thanks to Wojtek Lerch and Tim Rentsch for the idea. */
#define mpfr_round(a,b) mpfr_rint((a), (b), MPFR_RNDNA)
#define mpfr_trunc(a,b) mpfr_rint((a), (b), MPFR_RNDZ)
#define mpfr_ceil(a,b) mpfr_rint((a), (b), MPFR_RNDU)
#define mpfr_floor(a,b) mpfr_rint((a), (b), MPFR_RNDD)
#define mpfr_cmp_ui(b,i) mpfr_cmp_ui_2exp((b),(i),0)
#define mpfr_cmp_si(b,i) mpfr_cmp_si_2exp((b),(i),0)
#define mpfr_set(a,b,r) mpfr_set4(a,b,r,MPFR_SIGN(b))
#define mpfr_abs(a,b,r) mpfr_set4(a,b,r,1)
#define mpfr_copysign(a,b,c,r) mpfr_set4(a,b,r,MPFR_SIGN(c))
#define mpfr_setsign(a,b,s,r) mpfr_set4(a,b,r,(s) ? -1 : 1)
#define mpfr_signbit(x) (MPFR_SIGN(x) < 0)
#define mpfr_cmp(b, c) mpfr_cmp3(b, c, 1)
#define mpfr_mul_2exp(y,x,n,r) mpfr_mul_2ui((y),(x),(n),(r))
#define mpfr_div_2exp(y,x,n,r) mpfr_div_2ui((y),(x),(n),(r))
/* When using GCC, optimize certain common comparisons and affectations.
+ Remove ICC since it defines __GNUC__ but produces a
huge number of warnings if you use this code.
VL: I couldn't reproduce a single warning when enabling these macros
with icc 10.1 20080212 on Itanium. But with this version, __ICC isn't
defined (__INTEL_COMPILER is, though), so that these macros are enabled
anyway. Checking with other ICC versions is needed. Possibly detect
whether warnings are produced or not with a configure test.
+ Remove C++ too, since it complains too much. */
/* Added casts to improve robustness in case of undefined behavior and
compiler extensions based on UB (in particular -fwrapv). MPFR doesn't
use such extensions, but these macros will be used by 3rd-party code,
where such extensions may be required.
Moreover casts to unsigned long have been added to avoid warnings in
programs that use MPFR and are compiled with -Wconversion; such casts
are OK since if X is a constant expression, then (unsigned long) X is
also a constant expression, so that the optimizations still work. The
warnings are probably related to the following two bugs:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4210
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470 (possibly a variant)
and the casts could be removed once these bugs are fixed.
Casts shouldn't be used on the generic calls (to the ..._2exp functions),
where implicit conversions are performed. Indeed, having at least one
implicit conversion in the macro allows the compiler to emit diagnostics
when normally expected, for instance in the following call:
mpfr_set_ui (x, "foo", MPFR_RNDN);
If this is not possible (for future macros), one of the tricks described
on http://groups.google.com/group/comp.std.c/msg/e92abd24bf9eaf7b could
be used. */
#if defined (__GNUC__) && !defined(__ICC) && !defined(__cplusplus)
#if (__GNUC__ >= 2)
#undef mpfr_cmp_ui
/* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0.
But warning! mpfr_sgn is specified as a macro in the API, thus the macro
mustn't be used if side effects are possible, like here. */
#define mpfr_cmp_ui(_f,_u) \
(__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ? \
(mpfr_sgn) (_f) : \
mpfr_cmp_ui_2exp ((_f), (_u), 0))
#undef mpfr_cmp_si
#define mpfr_cmp_si(_f,_s) \
(__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
mpfr_cmp_ui ((_f), (mpfr_ulong) (mpfr_long) (_s)) : \
mpfr_cmp_si_2exp ((_f), (_s), 0))
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
#undef mpfr_set_ui
#define mpfr_set_ui(_f,_u,_r) \
(__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ? \
__extension__ ({ \
mpfr_ptr _p = (_f); \
_p->_mpfr_sign = 1; \
_p->_mpfr_exp = __MPFR_EXP_ZERO; \
(mpfr_void) (_r); 0; }) : \
mpfr_set_ui_2exp ((_f), (_u), 0, (_r)))
#endif
#undef mpfr_set_si
#define mpfr_set_si(_f,_s,_r) \
(__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
mpfr_set_ui ((_f), (mpfr_ulong) (mpfr_long) (_s), (_r)) : \
mpfr_set_si_2exp ((_f), (_s), 0, (_r)))
#endif
#endif
/* Macro version of mpfr_stack interface for fast access */
#define mpfr_custom_get_size(p) ((mpfr_size_t) \
(((p)+GMP_NUMB_BITS-1)/GMP_NUMB_BITS*sizeof (mp_limb_t)))
#define mpfr_custom_init(m,p) do {} while (0)
#define mpfr_custom_get_significand(x) ((mpfr_void*)((x)->_mpfr_d))
#define mpfr_custom_get_exp(x) ((x)->_mpfr_exp)
#define mpfr_custom_move(x,m) do { ((x)->_mpfr_d = (mp_limb_t*)(m)); } while (0)
#define mpfr_custom_init_set(x,k,e,p,m) do { \
mpfr_ptr _x = (x); \
mpfr_exp_t _e; \
mpfr_kind_t _t; \
mpfr_int _s, _k; \
_k = (k); \
if (_k >= 0) { \
_t = (mpfr_kind_t) _k; \
_s = 1; \
} else { \
_t = (mpfr_kind_t) -k; \
_s = -1; \
} \
_e = _t == MPFR_REGULAR_KIND ? (e) : \
_t == MPFR_NAN_KIND ? __MPFR_EXP_NAN : \
_t == MPFR_INF_KIND ? __MPFR_EXP_INF : __MPFR_EXP_ZERO; \
_x->_mpfr_prec = (p); \
_x->_mpfr_sign = _s; \
_x->_mpfr_exp = _e; \
_x->_mpfr_d = (mp_limb_t*) (m); \
} while (0)
#define mpfr_custom_get_kind(x) \
( (x)->_mpfr_exp > __MPFR_EXP_INF ? \
(mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (x) \
: (x)->_mpfr_exp == __MPFR_EXP_INF ? \
(mpfr_int) MPFR_INF_KIND * MPFR_SIGN (x) \
: (x)->_mpfr_exp == __MPFR_EXP_NAN ? (mpfr_int) MPFR_NAN_KIND \
: (mpfr_int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
#endif /* MPFR_USE_NO_MACRO */
/* Theses are defined to be macros */
#define mpfr_init_set_si(x, i, rnd) \
( mpfr_init(x), mpfr_set_si((x), (i), (rnd)) )
#define mpfr_init_set_ui(x, i, rnd) \
( mpfr_init(x), mpfr_set_ui((x), (i), (rnd)) )
#define mpfr_init_set_d(x, d, rnd) \
( mpfr_init(x), mpfr_set_d((x), (d), (rnd)) )
#define mpfr_init_set_ld(x, d, rnd) \
( mpfr_init(x), mpfr_set_ld((x), (d), (rnd)) )
#define mpfr_init_set_z(x, i, rnd) \
( mpfr_init(x), mpfr_set_z((x), (i), (rnd)) )
#define mpfr_init_set_q(x, i, rnd) \
( mpfr_init(x), mpfr_set_q((x), (i), (rnd)) )
#define mpfr_init_set(x, y, rnd) \
( mpfr_init(x), mpfr_set((x), (y), (rnd)) )
#define mpfr_init_set_f(x, y, rnd) \
( mpfr_init(x), mpfr_set_f((x), (y), (rnd)) )
/* Compatibility layer -- obsolete functions and macros */
#define mpfr_cmp_abs mpfr_cmpabs
#define mpfr_round_prec(x,r,p) mpfr_prec_round(x,p,r)
#define __gmp_default_rounding_mode (mpfr_get_default_rounding_mode())
#define __mpfr_emin (mpfr_get_emin())
#define __mpfr_emax (mpfr_get_emax())
#define __mpfr_default_fp_bit_precision (mpfr_get_default_fp_bit_precision())
#define MPFR_EMIN_MIN mpfr_get_emin_min()
#define MPFR_EMIN_MAX mpfr_get_emin_max()
#define MPFR_EMAX_MIN mpfr_get_emax_min()
#define MPFR_EMAX_MAX mpfr_get_emax_max()
#define mpfr_version (mpfr_get_version())
#ifndef mpz_set_fr
# define mpz_set_fr mpfr_get_z
#endif
#define mpfr_add_one_ulp(x,r) \
(mpfr_sgn (x) > 0 ? mpfr_nextabove (x) : mpfr_nextbelow (x))
#define mpfr_sub_one_ulp(x,r) \
(mpfr_sgn (x) > 0 ? mpfr_nextbelow (x) : mpfr_nextabove (x))
#define mpfr_get_z_exp mpfr_get_z_2exp
#define mpfr_custom_get_mantissa mpfr_custom_get_significand
#endif /* __MPFR_H*/