现实世界中是否有 CPU 不使用 IEEE 754?
我正在优化数字/统计库的排序函数,基于这样的假设:在过滤掉任何 NaN 并进行一些调整后,浮点数可以与 32 位整数进行比较,而不会更改结果,而双精度数可以与64 位整数。
这似乎可以将这些数组的排序速度加快 40% 左右,而且只要浮点数的位级表示是 IEEE 754,我的假设就成立。人们实际使用的 CPU 是否存在(不包括在嵌入式设备中(该库不针对该设备)使用可能会打破此假设的其他表示形式?
- https://en.wikipedia.org/wiki/Single- precision_floating-point_format
(binary32,在使用 IEEE754 的系统中又称为float
) - https:// /en.wikipedia.org/wiki/Double- precision_floating-point_format
(binary64,在使用 IEEE754 的系统中又称为double
)
I'm optimizing a sorting function for a numerics/statistics library based on the assumption that, after filtering out any NaNs and doing a little bit twiddling, floats can be compared as 32-bit ints without changing the result and doubles can be compared as 64-bit ints.
This seems to speed up sorting these arrays by somewhere on the order of 40%, and my assumption holds as long as the bit-level representation of floating point numbers is IEEE 754. Are there any real-world CPUs that people actually use (excluding in embedded devices, which this library doesn't target) that use some other representation that might break this assumption?
- https://en.wikipedia.org/wiki/Single-precision_floating-point_format
(binary32, akafloat
in systems that use IEEE754) - https://en.wikipedia.org/wiki/Double-precision_floating-point_format
(binary64, akadouble
in systems that use IEEE754)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
除了有缺陷的 Pentium 之外,任何基于 x86 或 x64 的 CPU 都使用 IEEE 754 作为其浮点算术标准。
以下是 FPA 标准及其采用的简要概述。
除非您计划在相当奇特的 CPU 架构上支持您的库,否则可以安全地假设目前 99% 的 CPU 都符合 IEEE 754。
Other than flawed Pentiums, any x86 or x64-based CPU is using IEEE 754 as their floating-point arithmetic standard.
Here are a brief overview of the FPA standards and their adoptions.
Unless your planning on supporting your library on fairly exotic CPU architectures, it is safe to assume that for now 99% of CPUs are IEEE 754 compliant.
这取决于你在“现实世界”和想象世界之间的界限。
直到最近, Unisys 仍然销售支持 Burroughs FP 格式的 ClearPath IX 服务器和支持 Univac FP 格式的 ClearPath MCP 机器。我相信这些现在只能在仿真中运行(在 Xeon 上),但从软件的角度来看,它们可能会继续活跃使用十年或更长时间。
甚至还有少数人仍在使用DtCyber 在(模拟)控制数据大型机上运行 Plato,具有独特的浮点格式。 (抱歉,但我的第一个严肃的编程是在 CDC Cyber 机器上进行的,所以我忍不住提起它,即使它已经不是“现实世界”几十年了)。
It depends on where you draw the line between the "real world" and the imaginary one.
Until fairly recently, Unisys still sold ClearPath IX servers that supported the Burroughs FP format, and ClearPath MCP machines that supported the Univac FP format. I believe those are now only run in emulation (on Xeons) but from a software viewpoint, they'll probably continue in active use for another decade or more.
There are even a few people still using DtCyber to run Plato on (emulated) Control Data mainframes, with their unique floating point format. (Sorry, but my first serious programming was on a CDC Cyber machine, so I couldn't resist bringing it up, even if it hasn't been "real world" for decades).
Cell 处理器的 SPU 在几个方面有所不同(例如缺少 INF 和 NAN),但我认为这些差异不会打破您的假设......
The Cell Processor's SPUs differ in a few ways (like lack of INF and NANs), but I don't think there are differences would break your assumptions...
PowerPC 处理器(大约 2006-2007 年之前的 Mac,目前大量的 IBM 服务器)使用由两个双精度型长双精度型组成的 128 位格式,而不是 IEEE 754 扩展格式。
然而,在 C 或 Objective-C 中,没有可移植的方法将 32 位或 64 位浮点数解释为整数(假设 float 和 uint32_t,或 double 和 uint64_t 具有相同的位数)。当我需要做这类事情时,我必须根据编译器编写不同的代码(一个是使用联合,一个是将 double* 转换为 long long*)。不知道 C++ 中的重新解释是否可以移植。
PowerPC processors (Macs until about 2006-2007, tons of current IBM servers) use a 128 bit format consisting of two doubles for long double, instead if the IEEE 754 extended format.
However, in C or Objective-C, there is no portable way to interpret a 32 bit or 64 bit floating point number as an integer (assuming float and uint32_t, or double and uint64_t have the same number of bits). When I needed to do that kind of thing, I had to write different code depending on the compiler (one was using a union, one was by casting double* to long long*). No idea whether a reinterpretcast in C++ will do it portably.
许多现实世界的 CPU 没有任何本机浮点格式。此类 CPU 的许多 C 语言和其他语言的实现捆绑了使用 IEEE-754 单精度和双精度格式的库,并省略了扩展精度格式,尽管其他格式更适合多种用途。
Many real-world CPUs don't have any native floating-point format. Many implementations of C and other languages for such CPUs bundle libraries that use IEEE-754 single and double-precision formats and omit the extended-precision format despite the fact that other formats would be more suitable for many purposes.