当前位置: 动力学知识库 > 问答 > 编程问答 >

ARM NEON convert f32 to s32 with round toward even

问题描述:

Is there any functions that controls rounding mode of vcvt_s32_f32 intrinsic? I want to use round toward even instead of round toward negative infinity.

Thanks.

网友答案:

No, you can't change the rounding mode.

NEON is designed for performance rather than precision, and thus is restricted compared to VFP. Unlike VFP, it's not a full IEEE 754 implementation, and is hardwired to certain settings - quoting from the ARM ARM:

  • denormalized numbers are flushed to zero
  • only default NaNs are supported
  • the Round to Nearest* rounding mode selected
  • untrapped exception handling selected for all floating-point exceptions

The specific case of floating-point to integer conversion is slightly different in that the behaviour of the VCVT instruction in this case (for both VFP and NEON) is to ignore the selected rounding mode and always round towards zero. The VCVTR instruction which does use the selected rounding mode is only available in VFP.

The ARMv8 architecture introduced a whole bunch of rounding and conversion instructions for using specific rounding modes, but I suspect that's not much help in this particular case. If you want to do conversions under a different rounding mode on ARMv7 and earlier, you'll either have to use VFP (if available) or some bit-hacking to implement it manually.

* The ARM ARM uses IEEE 754-1985 terminology, so more precisely this is round to nearest, ties to even

分享给朋友:
您可能感兴趣的文章:
随机阅读: