fpu 单精度和双精度_FPU的精度,蝙蝠侠!

fpu 单精度和双精度

One of our customers found an interesting bug the other day: embedding Unity Web Player into a web page makes some javascript animation libraries not work correctly. For example, script.aculo.us or Dojo Toolkit would stop doing some of their tasks. But only on Windows, and only on some browsers (Firefox and Safari).

我们的一位客户前几天发现了一个有趣的错误:将Unity Web Player嵌入到网页中会使某些javascript动画库无法正常工作。 例如, script.aculo.usDojo Toolkit将停止执行其某些任务。 但仅在Windows上,并且仅在某些浏览器(Firefox和Safari)上。

Wait a moment… Unity plugin makes nice wobbling web page elements not wobble anymore!? Sounds like an interesting issue…

等等... Unity插件使摆动的网页元素变得不再摆动! 听起来像是一个有趣的问题……

So I prepared for a debug session and tried the usual “divide by two until you locate the problem” approach.

因此,我准备了一个调试会话,并尝试了通常的“一分为二,直到找到问题”的方法。

  • Unity Web Player is composed of two parts: a small browser plugin, and the actual “engine” (let’s call it “runtime”). First I change the plugin so that it only loads the data, but never loads or starts the runtime. Everything works. So the problem is not in the plugin. Good.

    Unity Web Player由两部分组成:一个小的浏览器插件和实际的“引擎”(我们称其为“运行时”)。 首先,我更改插件,使其仅加载数据,而从不加载或启动运行时。 一切正常。 因此,问题不在插件中。

  • Load the runtime and fully initialize everything, but never actually start playing the content – the bug appears! By now I know that the problem is somewhere in the initialization.

    加载运行时并完全初始化所有内容,但从未真正开始播放内容–出现错误! 现在我知道问题出在什么地方初始化。

Initialization reads some settings from the data file, creates some “manager objects” for the runtime, initializes graphics device, loads first game “level” and then the game can play.

初始化从数据文件中读取一些设置,为运行时创建一些“管理器对象”,初始化图形设备,加载第一个游戏“关卡”,然后游戏就可以玩了。

What of the above could cause something inside browser’s JavaScript engine stop working? And do that only on Windows, and only on some browsers? My first guess was the most platform-specific part: intialization of the graphics device, which on Windows usually happens to be Direct3D.

以上哪种情况可能会导致浏览器JavaScript引擎内部的某些功能停止工作? 并且仅在Windows和某些浏览器上这样做吗? 我的第一个猜测是最特定于平台的部分:图形设备的初始化,在Windows上通常是Direct3D。

So I continued:

所以我继续:

  • “A-ha!” moment: tell Direct3D to not change floating point precision (via a create flag). Voilà, everything works!

    “啊哈!” 时刻:告诉Direct3D不要更改浮点精度(通过create flag )。 Voilà,一切正常!

I don’t know how I actually came up with the idea of testing floating point precision flag. Maybe I remembered some related problems we had a while ago, where Direct3D would cause timing calculations be “off”, if the user’s machine was not rebooted for a couple of weeks or more. That time around we properly changed our timing code to use 64 bit integers, but left Direct3D precision setting intact.

我不知道我实际上是如何想到测试浮点精度标志的。 也许我还记得我们前段时间遇到的一些相关问题,如果用户的计算机在几周或更长时间内没有重新启动,Direct3D将导致计时计算“关闭”。 那个时候,我们适当地更改了时序代码以使用64位整数,但保留了Direct3D精度设置。

Side note: Intel x86 floating point unit (FPU) can operate in various precision modes, usually 32, 64 or 80 bit. By default Direct3D 9 sets FPU precision to 32 bit (i.e. single precision). Telling D3D to not change FPU settings could lower performance somewhat, but in my tests it did not have any noticeable impact.

旁注:英特尔x86浮点单元(FPU)可以在各种精度模式下运行 ,通常为32、64或80位。 默认情况下,Direct3D 9将FPU精度设置为32位(即单精度)。 告诉D3D不更改FPU设置可能会降低性能,但是在我的测试中,它没有任何明显的影响。

So there it was. A debugging session, one line of change in the code, and fancy javascript webpage animations work on Windows in Firefox and Safari. This is coming out in Unity 2.0.2 update soon.

就是这样。 调试会话,代码中的一行更改以及精美的javascript网页动画可在Firefox和Safari的Windows上运行。 这将很快在Unity 2.0.2更新中推出。

The moral? Something in one place can affect seemingly completely unrelated things in another place!

道德? 一个地方的东西可能会影响另一个地方看似完全无关的事物!

翻译自: https://blogs.unity3d.com/2008/01/22/holy-fpu-precision-batman/

fpu 单精度和双精度

相关文章: