现实世界中是否有 CPU 不使用 IEEE 754?

发布于 2024-08-21 01:27:41 字数 705 浏览 2 评论 0原文

我正在优化数字/统计库的排序函数,基于这样的假设:在过滤掉任何 NaN 并进行一些调整后,浮点数可以与 32 位整数进行比较,而不会更改结果,而双精度数可以与64 位整数。

这似乎可以将这些数组的排序速度加快 40% 左右,而且只要浮点数的位级表示是 IEEE 754,我的假设就成立。人们实际使用的 CPU 是否存在(不包括在嵌入式设备中(该库不针对该设备)使用可能会打破此假设的其他表示形式?


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?


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掩于岁月 2024-08-28 01:27:42

除了有缺陷的 Pentium 之外,任何基于 x86 或 x64 的 CPU 都使用 IEEE 754 作为其浮点算术标准。

以下是 FPA 标准及其采用的简要概述。

IEEE 754:       Intel x86, and all RISC systems (IBM Power
                and PowerPC, Compaq/DEC Alpha, HP PA-RISC,
                Motorola 68xxx and 88xxx, SGI (MIPS) R-xxxx,
                Sun SPARC, and others);

VAX:            Compaq/DEC

IBM S/390:      IBM (however, in 1998, IBM added an IEEE 754
                option to S/390)

Cray:           X-MP, Y-MP, C-90; other Cray models have been
                based on Alpha and SPARC processors with
                IEEE-754 arithmetic.

除非您计划在相当奇特的 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.

IEEE 754:       Intel x86, and all RISC systems (IBM Power
                and PowerPC, Compaq/DEC Alpha, HP PA-RISC,
                Motorola 68xxx and 88xxx, SGI (MIPS) R-xxxx,
                Sun SPARC, and others);

VAX:            Compaq/DEC

IBM S/390:      IBM (however, in 1998, IBM added an IEEE 754
                option to S/390)

Cray:           X-MP, Y-MP, C-90; other Cray models have been
                based on Alpha and SPARC processors with
                IEEE-754 arithmetic.

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.

枫以 2024-08-28 01:27:42

这取决于你在“现实世界”和想象世界之间的界限。

  1. Alpha 机器仍然支持 Vax G 格式(HP 表示他们将至少支持到 2013 年)。
  2. IBM z 系列大型机仍然支持 IBM 十六进制 FP。他们添加了 IEEE 二进制和十进制支持,但据我所知,它们很少被使用,因为十六进制 FP 速度要快得多(IBM 已经对其进行了大约 45 年的优化......)

直到最近, 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.

  1. Vax G format is still supported on Alpha machines (which HP says they will support through at least 2013).
  2. IBM hexadecimal FP is still supported by IBM z-series mainframes. They've added IEEE binary and decimal support, but from what I've heard they're rarely used, because the hexadecimal FP is quite a bit faster (IBM's been optimizing it for about 45 years now...)

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).

倦话 2024-08-28 01:27:42

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...

巨坚强 2024-08-28 01:27:42

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.

遥远的她 2024-08-28 01:27:42

许多现实世界的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文