If the ELF is viewed with the FPU enabled, GCC will use the VCVT instruction when a floating-point variable is assigned (and hence converted) to an integer.
To use another rounding mode (for example Round to Nearest (RN) mode) the VCVTR instruction should be used instead of VCVT.
If R is specified, the operation uses the rounding mode specified by the FPSCR.
From the ARM:
The floating-point to integer operation normally uses the Round towards Zero rounding mode, but can optionally use the rounding mode specified by the FPSCR.
The FPSCR Register bit function FPSCR[23:22] defines different rounding modes.
When FPSCR[23:22] = 0b00, Round to Nearest (RN) mode is set.
Is it possible to set the compiler to use the VCVTR instruction?
There is no currently known way to direct GCC ARM FPU conversions, so assembly must be used in this case.
A synchronization barrier (ISB) is also required after modifying the rounding configuration register.Round to Zero is used because the C specification states that truncation (round to zero) is sufficient for the conversion.