ARM - Unwanted local variable stored in VFP register
Thu Jul 2 08:32:09 GMT 2020
On Thu, 2 Jul 2020, Jiri Dobry via Gcc-help wrote:
> we are found that GCC >= 9 uses ARM VFP registers to store local function
> variables instead of stack. It looks like a smart idea, because access to
> the VFP register is faster than access to stack, but there is one serious
> problem. We need to disable this optimization and we don't know how to do
> Problem is simple. We have MCU with VFP unit and real-time operating
> system. Problem is that save/restore complete VFP unit state on every
> context switch is very time expensive (33 DWORDs on stack). And most
> processes don't need VFP operations. Therefore we enable/disable VFP unit
> depending on the process setting. In other words we need to have VFP
> operations only on functions where there are float point operations.
This notion becomes ill-defined when you consider inlining, and LTO might
make it possible that VFP-using functions are candidates for inlining into
a larger function that does not have VFP enabled throughout.
There's -mgeneral-regs-only command-line option that disallows use of VFP
(please see GCC manual for further info), so you can move functions that
need VFP to separate translation units, and pass the option to the rest.
AFAICT this will work with LTO as well (GCC will consider functions
without the flag as not eligible for inlining into functions with it),
but you might want to work out an explicit way to prevent inlining if you
don't want to rely on this implicit (and undocumented) behavior.
More information about the Gcc-help