https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113155
Bug ID: 113155
Summary: large overhead for cast float to uint64_t. Arm
cortex-m4 (ARMv7E-M, fpv4-sp-d16, ieee 754). Compiler:
arm-none-eabi-gcc
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: kirdyankinsp at gmail dot com
Target Milestone: ---
To cast float to uint64 the initial value first converted to double. Cortex-M4
does not have hardware support for "double". Therefore, such an implementation
adds several kilobytes of code, which is unacceptable for embeded systems with
limited resources. In addition, increasing the code size is, of course, low
performance.
I think it is necessary to separate the softfloat functions for platforms that
have hardware "float" support and do not have a hardware "double". The current
version cannot be used for embedded systems. Additional functions need to be
written.
Below is the __aeabi_f2ulz code for fpv4-sp-d16 (ieee 754):
uint64_t __aeabi_f2ulz(float f)
{
uint32_t result = *((uint32_t*) &f);
uint32_t exp;
result &= (~0x80000000);
exp = result >> 23;
result &= 0x7FFFFF;
result |= 0x800000;
#if CHECK_UB
if (exp == 0xFF) // if NaN or inf
{
return 0x8000000000000000; // ????????
}
if(exp > (0x96 + 40)) // if the variable value is too large
{
return 0x8000000000000000; // ????????
}
#endif
if (exp < 0x7F)
{
return 0;
}
if (exp <= 0x96U)
{
exp = 0x96 - exp;
result >>= exp;
return (uint64_t) result;
}
exp -= 0x96U;
return (uint64_t) result << exp;
}