When 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.
As per the Arm Architecture Reference Manual:
"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.
There is no currently known way to direct GCC ARM FPU conversions, so assembly must be used in this case.
Round to Zero is used because the C specification states that truncation (round to zero) is sufficient for the conversion, as per section 6.3.1.4 of the C programming language standard.
"When a value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero)."
As an example, the following code makes use of inline assembly to use VCVTR instruction:
AR# 61480 | |
---|---|
日期 | 06/08/2018 |
状态 | Active |
Type | 综合文章 |
Tools |