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

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

问题描述

我正在将我的应用程序从 32 位移植到 64 位.目前,代码在两种架构下都可以编译,但结果不同.出于各种原因,我使用浮点数而不是双精度数.我假设在一台机器上而不是另一台机器上发生了一些从 float 到 double 的隐式上转换.有没有办法控制这个,或者我应该寻找特定的陷阱?

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 位平台

 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 位代码之间表现出不同的行为,但它们经常这样做.您的问题的答案将是特定于平台和编译器的,因此您需要说明您要从哪个平台移植以及要移植到哪个平台.

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 位代码通常使用 x87 协处理器指令集和浮点寄存器堆栈以实现最大兼容性,而在 amb64/x86_64 平台上,SSE* 指令和 xmm* 寄存器通常被用作替代.它们具有不同的精度特性.

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天全站免登陆