Changing the width of the Mantissa in a non-IEEE floating point implementation
I have a gcc cross compiler on an 18 bit soft core target processor which has the following datatypes: Integer 18 bit long 36 bit and float 36 bit (single precision). I am currently focusing on working with floating point. Since the width is non-standard (36 bits), I have the following scheme: 27 bits for Mantissa (value), 8 bits for exponents, and 1 bit for sign. I can see that the width is defined in the float.h file. of interest to me are the following: FLT_MANT_DIG and FLT_DIG. They are defined as:
FLT_MANT_DIG 24 FLT_DIG 6
I changed them to
FLT_MANT_DIG 28 FLT_DIG 9
As per my requirements in float.h and then build the gcc compiler. But still I am getting 32 bit floating point output. Does anyone have experience implementing non-standard single precision floating point numbers and / or know a workaround?
source to share
Effective floating point math requires hardware designed to support the exact floating point formats that are used. In the absence of such hardware, subroutines that are designed around a specific floating point format will be much more efficient than subroutines that easily adapt to other formats. The GCC compiler and supplied libraries are designed to work efficiently with IEEE-754 floating point types and cannot be adapted to any others. The aforementioned headers do not allow the programmer to request a specific floating point format, but simply to notify the code which format will be used.
If you don't want 72-bit floating point types, and if the compiler's type double
will do 64-bit math in something akin to sane style, even if it long
's 36 bits instead of 32, you might be able to order things so that the values are float
unboxed in four words double
, doing calculations with that, and then swapping the bits double
to get float
. Also, you can write or find 36 bit floating point libraries. I wouldn't really expect GCC or its libraries to include such a thing, since 36-bit processors are pretty rare these days.
source to share