Hi,
I'm working on an LPC4357 with MCUXpresso v10.2.1, using Redlib and the single precision floating point unit.
The code I'm working on makes extensive use of powf(), but unfortunately it is causing problems because the current implementation of this function uses double precision instructions, e.g.:
1a00b4ce: bl 0x1a00be70 <__aeabi_f2d>
1a00b4d2: add r3, pc, #484 ; (adr r3, 0x1a00b6b8 <powf+648>)
1a00b4d4: ldrd r2, r3, [r3]
1a00b4d8: mov r7, r1
1a00b4da: mov r6, r0
1a00b4dc: bl 0x1a00bdbc <__aeabi_dcmple>
This means that the computation doesn't go through the FPU, creating unacceptable delays.
I can't switch to Newlib easily as the system is already in production.
Does anyone know of any fix or workaround?
Solved! Go to Solution.
Both the Redlib and Newlib implementations of powf still make some use of double precision math - so you will see some calls like this into the double precision FP library code when linking regardless of which C library you have selected. However a lot of the math is still single precision, so if you look further through the disassembly you will see quite a lot of single precision FP instructions being used - as long as you are building with FP enabled.
You may want to consider implementing your own bespoke "fast" version of the function - though whether this is possible may depend upon the actual values you expect to pass into it (as such algorithms will often have restrictions on inputs or accuracy). I would suggest you do an internet search for "fast powf C function", or similar.
Regards,
MCUXpresso IDE Support
Thank you for the reply.
I checked and, indeed, the Newlib implementation of powf() uses double precision maths as well.
Fortunately, both logf and expf use single precision instructions, so I was able to write my crude implementation of powf by exploiting the fact that a^b = exp(log(a) * b).
The problematic routine is now an order of magnitude faster with the help of the single precision FPU.
Cheers!
Both the Redlib and Newlib implementations of powf still make some use of double precision math - so you will see some calls like this into the double precision FP library code when linking regardless of which C library you have selected. However a lot of the math is still single precision, so if you look further through the disassembly you will see quite a lot of single precision FP instructions being used - as long as you are building with FP enabled.
You may want to consider implementing your own bespoke "fast" version of the function - though whether this is possible may depend upon the actual values you expect to pass into it (as such algorithms will often have restrictions on inputs or accuracy). I would suggest you do an internet search for "fast powf C function", or similar.
Regards,
MCUXpresso IDE Support