c++ - Arbitrary Precision Floating Point library for High Level Synthesis -
i trying make template based arbitrary precision floating point library in c++ supports variable exponents , variable mantissa can specified template arguments. have developed template based fixed point library. type of implementation want :
template<int exponent_bits, int mantissa_bits> struct fp_float { <some_data_type_to_store_exponent_and_mantissa_values>; };
i unable find suitable datatype store exponents don't use more bits needed code. thought of using intn_t
n = {8, 16, 32, 64}
if declare fp_float<3,11>
use 8
bits exponent
, 16
bits mantissa
.
hence makes entire library useless uses more resources ought specified precision.
i know if there other arbitrary precision data-type serves purpose.
i did come across few arbitrary precision libraries these libraries have code structure cannot synthesized hardware descriptions using high level synthesis (which reason making library).
is valid solution you? base_int_t trait type gives basic type used in subsequent bitfield definition. code below missing specializations n > 2
// gives integer type fitting in n bytes template <int n> struct base_int_t { typedef int type; }; // specializations template <> struct base_int_t<1> { typedef unsigned char type; }; template <> struct base_int_t<2> { typedef unsigned short type; }; // add suitable definitions n = 3,4...8. n = 3 , 4 type unsigned int template <int exp_bits, int mantissa_bits> struct fp_float { // template argument number of bytes required typedef typename base_int_t<(exp_bits + mantissa_bits + 7) / 8>::type type; type mantissa : mantissa_bits; type exponent : exp_bits; }; typedef fp_float<3, 11> fp_3_11_t; fp_3_11_t fp;
Comments
Post a Comment