Linux 内核中是否使用了扩展指令集(SSE、MMX)?
好吧,它们带来(至少应该带来)性能的巨大提升,不是吗?
所以,我还没有看到任何 Linux 内核源代码,但很想问:它们是否以某种方式使用? (在这种情况下,对于没有此类指令的系统,必须有一些特殊的“代码上限”?)
Well, they bring (should bring at least) great increase in performance, isn’t it?
So, I haven’t seen any Linux kernel sources, but ‘d love to ask: are they used somehow? (In this case – there must be some special “code-cap” for system that has no such instructions?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
SSE 和 MMX 指令集在音频/视频和游戏工作之外的价值有限。您可能会在内核的黑暗角落中发现一些明确的用途,但我不会指望它。一般情况下的答案是“不,它们没有被使用”,它们也没有在大多数非内核/用户空间应用程序中使用。
内核有时确实可以选择使用特定于某些 CPU 的某些 x86 指令(例如,存在于某些 AMD 或 Intel 型号上,但不是全部,反之亦然),例如 syscall ,但这些指令不同于您所指的 SIMD 指令集,并且不属于更广泛的类似主题扩展集的一部分。
马克回答后,我去寻找。我唯一可以轻松识别它们正在使用的地方是 RAID 6 库(它还支持 AltiVec,即 PowerPC SIMD 指令集)。
(在 grep 树时要小心,有很多地方内核“知道”SSE/MMX 来支持用户空间应用程序,但实际上并没有使用它。还有一些不幸的变量名称的情况,它们绝对具有与 SSE 无关,例如在 SCTP 实现中。)
The SSE and MMX instruction sets have limited value outside of audio/video and gaming work. You might find a few explicit uses in dark corners of the kernel, but I wouldn't count on it. The answer in the general case is "no, they are not used", nor are they used in most non-kernel/userspace applications.
The kernel does sometimes optionally use certain x86 instructions that are specific to certain CPUs (e.g. present on some AMD or Intel models but not all, nor vice-versa), such as
syscall
, but these are different from the SIMD instruction sets you're referring to, and are not part of some wider set of similarly-themed extensions.After Mark's answer, I went looking. The only place I could easily identify them being used is in the RAID 6 library (which also has support for AltiVec, which is the PowerPC SIMD instruction set).
(Be wary just grepping the tree, there are a lot of spots where the kernel "knows" about SSE/MMX to support user-space applications, but isn't actually using it. Also a couple cases of unfortunate variable names that have absolutely nothing to do with SSE, e.g. in the SCTP implementation.)
在内核代码中使用向量寄存器和浮点寄存器有严格的限制。例如,参见“不同 C++ 编译器和操作系统的调用约定”的第 6.3 章。 http://www.agner.org/optimize/#manuals
There are severe restrictions on using vector registers and floating point registers in kernel code. See e.g. chapter 6.3 of "Calling conventions for different C++ compilers and operating systems". http://www.agner.org/optimize/#manuals
它们在内核中用于一些用途,例如
但是,我相信它总是首先检查它们的存在。
They are used in the kernel for a few things, such as
However, I believe it always checks their presence first.
“cpu simd 指令使用 FPU”
呃,不,不是我所理解的。它们在某种程度上是 FPU 指令的现代且(更)高效的替代品,但 SIMD 指令集的很大一部分处理整数运算。
我从来没有仔细研究过它,但我想(好吧,希望)最近的 gcc 版本生成的 SIMD 代码不会破坏任何寄存器或状态。
"cpu simd instructions use FPU"
erm, no, not as I understand it. They're in part a modern and (much) more efficient replacement for FPU instructions, but a large part of the SIMD instruction set deals with integer operations.
I've never looked very hard at it, but I suppose (ok, hope) that SIMD code generated by a recent gcc version will not clobber any registers or state.