是SSE浮点运算重现? [英] Is SSE floating-point arithmetic reproducible?

查看:302
本文介绍了是SSE浮点运算重现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的的x87 FPU值得注意的是使用内部80位precision模式,这往往导致跨越编译器和机器意想不到和unreproducible结果。 <一href="http://stackoverflow.com/questions/14864238/coercing-floating-point-to-be-deterministic-in-net">In我的搜索对.NET重现的浮点运算,我发现.NET(微软和Mono)的两个主要实现方式发出SSE指令,而不是在的x87 64位模式。

SSE(2)严格使用32位寄存器的32位浮点数,以及严格的64位寄存器,用于64位浮点数。非规格化可以选择通过设置href="http://msdn.microsoft.com/en-us/library/vstudio/c9676k6h.aspx" rel="nofollow">适当的控制字的

因此​​,看来该证不会从的x87的precision有关的问题受到影响,并且该唯一的变量是反常值的行为,它可以被控制。

撇开超越函数(这本身不上证所不同的x87提供),并使用SSE此事保证在机器和编译器的可重复的结果?难道编译器优化,例如,翻译成不同的结果?我发现了一些不同意见:

  

如果您有SSE2,使用它,从此过上幸福生活。 SSE2支持   既32b和64b的操作和中间结果的   操作数的大小。     - 贝纳Kreinin http://www.yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

...

  

SSE2指令(...)是完全符合IEEE754-1985,他们   允许更好的重现性(由于采用了静态取整   precision)和便携性与其它平台。 Muller等aliis   <一href="http://books.google.ca/books?id=VDJVFM8WyzsC&pg=PA106&lpg=PA106&dq=SSE2%20ieee754&source=bl&ots=qmU1JKLLkX&sig=Wes4oPcxucRbX2WQm2pz41yhH-o&hl=fr&sa=X&ei=4-AvUd6RDoKsywHns4HADA&ved=0CFAQ6AEwAw#v=onepage&q=SSE2%20ieee754&f=false"相对=nofollow>手册浮点运算 - 第107页

不过:<​​/ P>

  

此外,您不能使用SSE或SSE2浮点,因为它太   下指定为确定性的。 - 约翰Watte    http://www.gamedev.net/topic/499435-floating-点决定/#entry4259411

解决方案

SSE完全指定*。穆勒是在浮点运算方面的专家;谁是你要相信,他还是一个gamedev论坛上一些人?

(*),实际上有几个例外为非IEEE-754的操作,如rsqrtss,其中英特尔从未完全指定的行为,但是,这并不影响的IEEE-754的基本操作,和更重要的是它们的行为可以'牛逼其实在这一点改变,因为它会打破东西太多了二进制兼容性,所以他们规定好。

The x87 FPU is notable for using an internal 80-bit precision mode, which often leads to unexpected and unreproducible results across compilers and machines. In my search for reproducible floating-point math on .NET, I discovered that both major implementations of .NET (Microsoft's and Mono) emit SSE instructions rather than x87 in 64-bit mode.

SSE(2) uses strictly 32-bit registers for 32-bit floats, and strictly 64-bit registers for 64-bit floats. Denormals can optionally be flushed to zero by setting the appropriate control word.

It would therefore appear that SSE does not suffer from the precision-related issues of x87, and that the only variable is the denormal behavior, which can be controlled.

Leaving aside the matter of transcendental functions (which are not natively provided by SSE unlike x87), does using SSE guarantee reproducible results across machines and compilers? Could compiler optimizations, for instance, translate into different results? I found some conflicting opinions:

If you have SSE2, use it and live happily ever after. SSE2 supports both 32b and 64b operations and the intermediate results are of the size of the operands. - Yossi Kreinin, http://www.yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

...

The SSE2 instructions (...) are fully IEEE754-1985 compliant, and they permit better reproducibility (thanks to the static rounding precision) and portability with other platforms. Muller et aliis, Handbook of Floating-Point Arithmetic - p.107

however:

Also, you can't use SSE or SSE2 for floating point, because it's too under-specified to be deterministic. - John Watte http://www.gamedev.net/topic/499435-floating-point-determinism/#entry4259411

解决方案

SSE is fully specified*. Muller is an expert in floating point arithmetic; who are you going to trust, him or some guy on a gamedev forum?

(*) there are actually a few exceptions for non-IEEE-754 operations like rsqrtss, where Intel never fully specified the behavior, but that doesn't effect the IEEE-754 basic operations, and more importantly their behavior can't actually change at this point because it would break binary compatibility for too many things, so they're as good as specified.

这篇关于是SSE浮点运算重现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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