64位浮点移植问题 [英] 64 bit floating point porting issues

查看:228
本文介绍了64位浮点移植问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序移植从32位到64位。目前,code这两种体系结构下的编译,但是结果是不同的。由于种种原因,我用浮漂,而不是双打。我认为有一些隐含的上变频,从浮到双发生在一台机器,而不是其他。有没有办法来控制这一点,或特定的陷阱我应该寻找?

I'm porting my application from 32 bit to 64 bit. Currently, the code compiles under both architectures, but the results are different. For various reasons, I'm using floats instead of doubles. I assume that there is some implicit upconverting from float to double happening on one machine and not the other. Is there a way to control for this, or specific gotchas I should be looking for?

编辑补充:

32位平台

 gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)
 Dual-Core AMD Opteron(tm) Processor 2218 HE

64位平台

64 bit platform

 gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
 Intel(R) Xeon(R) CPU

运用-mfpmath = 387帮助一些,1迭代算法的值相同后,但除此之外,他们出现不一致的现象了。

Applying the -mfpmath=387 helps somewhat, after 1 iteration of the algorithm the values are the same, but beyond that they fall out of sync again.

我还要补充一点,我关心的不是,结果是不相同的,那就是移植到64位平台已经发现了一个32位的依赖,而我不知道。

I should also add that my concern isn't that the results aren't identical, it's that porting to a 64 bit platform has uncovered a 32 bit dependency of which I was not aware.

推荐答案

有没有内在的需要和双精度浮点数来表现不同的32位和64位code,但他们经常做的。在回答你的问题将是平台和编译器特定的,所以你需要说什么平台,你是从移植和你移植到什么平台。

There is no inherent need for floats and doubles to behave differently between 32-bit and 64-bit code but frequently they do. The answer to your question is going to be platform and compiler specific so you need to say what platform you are porting from and what platform you are porting to.

在英特尔的x86平台上的32位code经常使用的x87协处理器指令集和浮点寄存器堆栈而在amb64 / x86_64的平台提供最大的兼容性,上证所*说明和XMM *寄存器,往往替代使用。这些有不同的precision特点。

On intel x86 platforms 32-bit code often uses the x87 co-processor instruction set and floating-point register stack for maximum compatibility whereas on amb64/x86_64 platforms, the SSE* instructions and xmm* registers and are often used instead. These have different precision characteristics.

帖子编辑:

由于您的平台,你可能要考虑尝试在你的x86_64的版本所-mfpmath = 387(默认为i386的GCC),看看这解释了不同的结果。您可能也想看看所有-fmath- *编译器开关的设置,以确保它们符合您希望在这两个构建什么。

Given your platform, you might want to consider trying the -mfpmath=387 (the default for i386 gcc) on your x86_64 build to see if this explains the differing results. You may also want to look at the settings for all the -fmath-* compiler switches to ensure that they match what you want in both builds.

这篇关于64位浮点移植问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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