在XCode中将denormal flush设置为零(FTZ)

前端之家收集整理的这篇文章主要介绍了在XCode中将denormal flush设置为零(FTZ)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_6@ 我正在使用XCode在OS X Mountain Lion上使用C进行开发,以便在本地计算机上运行.我遇到与非正规数有关的性能问题,我希望设置FTZ标志,以便将它们刷新为零. (我已经检查过denormals确实是问题,将它们刷新为零不会导致我的情况下的准确性问题.)但是,我找不到任何关于如何在XCode中实现这一点的信息.这是我可以在构建设置中更改的选项吗?或者我应该在某处输入一些代码?任何帮助将非常感激.

解决方法

如果我理解“/usr/include/fenv.h”中的注释,

#include <fenv.h>
fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV);

应该做你想做的事.

    FE_DFL_DISABLE_SSE_DENORMS_ENV

    A pointer to a fenv_t object with the default floating-point state modifed
    to set the DAZ and FZ bits in the SSE status/control register.  When using
    this environment,denormals encountered by SSE based calculation (which
    normally should be all single and double precision scalar floating point
    calculations,and all SSE/SSE2/SSE3 computation) will be treated as zero.
    Calculation results that are denormals will also be truncated to zero.

设置此选项可将程序的运行时间从Why does changing 0.1f to 0 slow down performance by 10x?减少(@Mysticial在其评论中给出的链接)从27秒减少到0.3秒(MacBook Pro,2.5 GHz Intel Core 2 Duo).

猜你在找的Xcode相关文章