ARM NEON convert f32 to s32 rounded to even

Are there any functions that control the vcvt_s32_f32 intrinsic rounding mode? I want to use round so instead of rounding towards negative infinity.



source to share

1 answer

No, you cannot change the rounding mode.

NEON is designed for performance, not accuracy, and therefore is limited in comparison to VFP. Unlike VFP, this is not a complete implementation of IEEE 754 and is hardcoded to specific settings - quoting from ARM ARM:

  • denormalized numbers are reset to zero
  • only standard NaNs are supported
  • round and closest * rounding mode selected
  • excluded exception handling selected for all floating point exceptions

The specific case of floating point to integer conversion is somewhat different in that the command behavior VCVT

in this case (for both VFP and NEON) is to ignore the selected rounding mode and always round to zero. The instruction VCVTR

that uses the selected rounding mode is only available in VFP.

The ARMv8 architecture has introduced a whole bunch of rounding and converting commands to use specific rounding modes, but I suspect there isn't much help in this particular case. If you want to do conversions in a different rounding mode on ARMv7 and earlier, you will have to either use VFP (if available) or a hacky bit to implement it manually.

* ARM ARM uses IEEE 754-1985 terminology, so it is more accurate to round to the nearest, even



All Articles