在iOS ARM设备(iPhone 4)上支持非正常IEEE 754浮点数

在iOS ARM设备(iPhone 4)上支持非正常IEEE 754浮点数,第1张

概述在将应用程序从 Linux x86移植到iOS ARM(iPhone 4)时,我发现了 浮点运算和小值行为的差异. 64bits floating point numbers (double)小于[/-]2.2250738585072014E-308在IEEE 754-1985/IEEE 754-2008标准中称为denormal/denormalized/subnormal号. 在iPhone 在将应用程序从 Linux x86移植到iOS ARM(iPhone 4)时,我发现了
浮点运算和小值行为的差异.

64bits floating point numbers (double)小于[/-]2.2250738585072014E-308在IEEE 754-1985/IEEE 754-2008标准中称为denormal/denormalized/subnormal号.

在iPhone 4上,这么小的数字被视为零(0),而在x86上,可以使用次正规数字进行计算.

对于Apple的文档Mac OS X Manual Page For float(3),我无法找到符合IEEE-754标准的任何解释.

但是,由于Stack Overflow(flush-to-zero behavior in floating-point arithmetic,Double vs float on the iPhone)的一些答案,我发现了一些线索.

根据一些搜索,似乎沿着ARM内核使用的VFP(或NEON)数学协处理器正在使用Flush-To-Zero(FTZ)模式(例如,在输出时将次正规值转换为0)和Denormals-Are-Zero DAZ)模式(例如,当用作输入参数时,将非正规值转换为0),以提供快速硬件处理的IEEE 754计算.

Full IEEE754 compliance with ARM support code Run-Fast mode for near IEEE754 compliance (harDWare only)

对自由贸易区和大都市的一个很好的解释可以在这里找到
x87 and SSE Floating Point Assists in IA-32: Flush-To-Zero (FTZ) and Denormals-Are-Zero (DAZ):

FTZ and DAZ modes both handle the cases when invalID floating-point data occurs or is
processed with underflow or denormal conditions. […]. The difference between a number
that is handled by FTZ and DAZ is very subtle. FTZ handles underflow conditions while
DAZ handles denormals. An underflow condition occurs when a computation results in a
denormal. In this case,FTZ mode sets the output to zero. DAZ fixes the cases when
denormals are used as input,either as constants or by reading invalID memory into
registers. DAZ mode sets the inputs of the calculation to zero before computation. FTZ
can then be saID to handle [output] while DAZ handles [input].

关于自由贸易区在苹果开发商网站上唯一的事情似乎是在iOS ABI Function Call Guide :

VFP status register |
FPSCR |
Special |
Condition code bits (28-31) and saturation bits (0-4) are not preserved by function calls. Exception control (8-12),rounding mode (22-23),and flush-to-zero (24) bits should be modifIEd only by specific routines that affect the application state (including framework API functions). Short vector length (16-18) and strIDe (20-21) bits must be zero on function entry and exit. All other bits must not be modifIEd.

根据ARM1176JZF-S Technical Reference Manual,18.5
Modes of operation(第一个iPhone处理器),VFP可以配置为完全支持IEEE 754(子正常算术),但在这种情况下,它将需要一些软件支持(陷入内核以在软件中进行计算).

注意:我也读过Debian的ARM Hard Float Port和VFP comparison页.

我的问题是:

>哪些人可以在iOS设备上找到关于超常数字处理的明确答案?
>可以将iOS系统设置为提供对正常数量的支持,而不要求编译器仅生成完整的软件浮点代码?

谢谢.

解决方法

Can one set the iOS system to provIDe support for subnormal number without asking the compiler to produce only full software floating point code?

是.这可以通过将FPSCR中的FZ位设置为零来实现:

static inline voID disableFZ( ){    __asm__ volatile("vmrs r0,fpscr\n"                     "bic r0,$(1 << 24)\n"                     "vmsr fpscr,r0" : : : "r0");}

请注意,当遇到可观量的非正常值时,这可能会导致应用程序性能的显着下降.您可以(并且应该)恢复默认浮点状态,然后再调用任何不使ABI保证在非默认模式下正常工作的代码:

static inline voID RestoreFZ( ) {    __asm__ volatile("vmrs r0,fpscr\n"                     "orr r0,r0" : : : "r0");}

请提交bug report请求,为iOS中的FP *** 作模式提供更好的文档.

总结

以上是内存溢出为你收集整理的在iOS ARM设备(iPhone 4)上支持非正常IEEE 754浮点数全部内容,希望文章能够帮你解决在iOS ARM设备(iPhone 4)上支持非正常IEEE 754浮点数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1096535.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存