在linux中计算结果为非正规数时,刷新为零 [英] Flush to Zero when a computation results in a denormal number in linux

查看:144
本文介绍了在linux中计算结果为非正规数时,刷新为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C代码计算正在产生一个逐渐下溢,当它发生的程序终止与SIGFPE。当一个渐进下溢(Denormal)结果来自一个计算,并且不终止执行时,我怎样才能将结果清零? (我正在使用redhat linux机器)。谢谢。

解决方案

您还没有指定架构 - 我会猜测这是一个相对较新的x86 [在这种情况下,您可以使用 _mm_getcsr _mm_setcsr 来操作SSE控制寄存器c $ c>< xmmintrin.h> (或< immintrin.h> )标题。 b $ b

'flush-to-zero'位设置为0x8000,'denormals-are-zero'(对于输入/ src)设置为0x0040。
$ b $ < pmmintrin.h> (SSE3) _mm_setcsr(_mm_getcsr()| 0x8040) :



_mm_setcsr(_mm_getcsr()|(_MM_FLUSH_ZERO_ON | _MM_DENORMALS_ZERO_ON));


这可能会更容易确定下溢的源头,但不应将其视为解决方案,因为FP环境不再符合IEEE-754标准。

A computation in my C code is producing a gradual underflow, and when it happens the program is terminating with SIGFPE. How can I flush the result to zero when a gradual underflow (Denormal) results from a computation, and not terminate the execution? (I am working on a redhat linux machine). Thanks.

解决方案

You haven't specified the architecture - I'm going to take a guess that it's a relatively recent x86[-64], in which case you can manipulate the SSE control register using _mm_getcsr, _mm_setcsr, specified in the <xmmintrin.h> (or <immintrin.h>) header.

The 'flush-to-zero' bit is set with 0x8000, and 'denormals-are-zero' (for inputs / src) is set with 0x0040.

_mm_setcsr(_mm_getcsr() | 0x8040); or with <pmmintrin.h> (SSE3) :

_mm_setcsr(_mm_getcsr() | (_MM_FLUSH_ZERO_ON | _MM_DENORMALS_ZERO_ON));

This might make it easier to determine the source of the underflow, but it shouldn't be considered a solution, since the FP environment is no longer IEEE-754 compliant.

这篇关于在linux中计算结果为非正规数时,刷新为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆