如何测试你的 Linux 是否支持 SSE2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4203235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:00:27  来源:igfitidea点击:

How to test if your Linux Support SSE2

linuxunixcompiler-constructionsse2itanium

提问by neversaint

Actually I have 2 questions:

其实我有2个问题:

  1. Is SSE2 Compatibility a CPU issue or Compiler issue?
  2. How to check if your CPU or Compiler support SSE2?
  1. SSE2 兼容性是 CPU 问题还是编译器问题?
  2. 如何检查您的 CPU 或编译器是否支持 SSE2?

I am using GCC Version:

我正在使用 GCC 版本:

gcc (GCC) 4.5.1

When I tried to compile a code it give me this error:

当我尝试编译代码时,它给了我这个错误:

$ gcc -O3 -msse2 -fno-strict-aliasing -DHAVE_SSE2=1 -DMEXP=19937 -o test-sse2-M19937 test.c
cc1: error: unrecognized command line option "-msse2"

And cpuinfoshowed this:

cpuinfo展示了这一点:

processor  : 0
vendor     : GenuineIntel
arch       : IA-64
family     : 32
model      : 1
model name : Dual-Core Intel(R) Itanium(R) Processor 9140M
revision   : 1
archrev    : 0
features   : branchlong, 16-byte atomic ops
cpu number : 0
cpu regs   : 4
cpu MHz    : 1669.000503
itc MHz    : 416.875000
BogoMIPS   : 3325.95
siblings   : 2
physical id: 0
core id    : 0
thread id  : 0

采纳答案by thkala

  1. It's both. The compiler/assembler need to be able to emit/handle SSE2 instructions, and then the CPU needs to support them. If your binary has SSE2 instructions with no conditions attached and you try to run it on a Pentium II you are out of luck.

  2. The best way is to check your GCC manual. For example my GCC manpage refers to the -msse2 option which will allow you to explicitly enable SSE2 instructions in the binaries. Any relatively recent GCC or ICC should support it. As for your cpu, check the flags line in /proc/cpuinfo.

  1. 两者都是。编译器/汇编器需要能够发出/处理 SSE2 指令,然后 CPU 需要支持它们。如果您的二进制文件包含没有附加条件的 SSE2 指令,而您尝试在 Pentium II 上运行它,那您就不走运了。

  2. 最好的方法是检查您的 GCC 手册。例如,我的 GCC 联机帮助页引用了 -msse2 选项,该选项将允许您在二进制文件中显式启用 SSE2 指令。任何相对较新的 GCC 或 ICC 都应该支持它。至于您的 CPU,请检查 /proc/cpuinfo 中的标志行。

It would be best, though, to have checks in your code using cpuid etc, so that SSE2 sections can be disabled in CPUs that do not support it and your code can fall back on a more common instruction set.

但是,最好使用 cpuid 等检查您的代码,以便可以在不支持它的 CPU 中禁用 SSE2 部分,并且您的代码可以回退到更常见的指令集。

EDIT:

编辑:

Note that your compiler needs to either be a native compiler running on a x86 system, or a cross-compiler for x86. Otherwise it will not have the necessary options to compile binaries for x86 processors, which includes anything with SSE2.

请注意,您的编译器需要是在 x86 系统上运行的本机编译器,或者是 x86 的交叉编译器。否则它将没有必要的选项来为 x86 处理器编译二进制文件,其中包括任何与 SSE2 相关的内容。

In your case the CPU does not support x86 at all. Depending on your Linux distribution, there might be packages with the Intel IA32EL emulation layer for x86-software-on-IA64, which may allow you to run x86 software.

在您的情况下,CPU 根本不支持 x86。根据您的 Linux 发行版,可能存在带有用于 x86-software-on-IA64 的 Intel IA32EL 仿真层的软件包,这可能允许您运行 x86 软件。

Therefore you have the following options:

因此,您有以下选择:

  • Use a cross-compiler that will run on IA64 and produce binaries for x86. Cross-compiler toolchains are not an easy thing to setup though, because you need way more than just the compiler (binutils, libraries etc).

  • Use Intel IA32EL to run a native x86 compiler. I don't know how you would go about installing a native x86 toolchain and all the libraries that your project needs in your distributions does not support it directly. Perhaps a full-blown chroot'ed installation of an x86 distribution ?

  • 使用将在 IA64 上运行并为 x86 生成二进制文件的交叉编译器。但是,交叉编译器工具链并不是一件容易设置的事情,因为您需要的不仅仅是编译器(binutils、库等)。

  • 使用英特尔 IA32EL 运行原生 x86 编译器。我不知道您将如何安装本机 x86 工具链,并且您的项目在您的发行版中需要的所有库都不直接支持它。也许是 x86 发行版的完整 chroot 安装?

Then if you want to test your build on this system you haveto install Intel's IA32EL for Linux.

然后如果你想在这个系统上测试你的构建,你必须为 Linux 安装英特尔的 IA32EL。

EDIT2:

编辑2:

I suppose you could also run a full x86 linux distribution on an emulator like Bochs or QEMU (with no virtualization of course). You are definitely notgoing to be dazzled by the resulting speeds though.

我想你也可以在像 Bochs 或 QEMU 这样的模拟器上运行完整的 x86 linux 发行版(当然没有虚拟化)。不过,您绝对不会对由此产生的速度感到眼花缭乱。

回答by Gunther Piez

The CPU needs to be able to execute SSE2 instrcutions, and the compiler needs to be able to generate them.

CPU 需要能够执行 SSE2 指令,编译器需要能够生成它们。

To check if your cpu supports SSE2:

要检查您的 CPU 是否支持 SSE2:

# cat /proc/cpuinfo

It will be somewhere under "flags" if it is supported.

如果支持,它将位于“标志”下的某个位置。

Update: So you cpu doesn't support it.

更新:所以你的 CPU 不支持它。

For the compiler:

对于编译器:

# gcc -dumpmachine
# gcc --version

Target of your compiler needs to a kind of x86*, since only this cpus support sse2, which is part of the x86 instruction set

编译器的目标需要一种 x86*,因为只有这个 CPU 支持 sse2,它是 x86 指令集的一部分

AND

gcc version needs to be >= 3.1 (most likely, since this is about 10 years old or something) for supporting SSE2.

gcc 版本需要 >= 3.1(很可能,因为它已经有大约 10 年的历史了)才能支持 SSE2。

Update: So your compiler doesn't support it on this target, it will if you are using it as a cross compiler for x86.

更新:所以你的编译器在这个目标上不支持它,如果你将它用作 x86 的交叉编译器,它会支持。

回答by Nico Huysamen

Try running:

尝试运行:

lshw -class processor | grep -w sse2

and look under the processor section.

并查看处理器部分。

回答by prgbenz

use asm to check the existence of sse2

使用 asm 检查 sse2 是否存在

enter code here
static
bool HaveSSE2()
{
    return false;
    __asm mov EAX,1              ;
    __asm cpuid                  ;
    __asm test EDX, 4000000h     ;test whether bit 26 is set
    __asm jnz yes                ;yes
    return false;
yes:
    return true;
}

回答by dentad

Another trick not yet mentioned is do:

另一个尚未提到的技巧是:

gcc -march=native -dM -E - </dev/null | grep SSE2

and get:

并得到:

#define __SSE2_MATH__ 1
#define __SSE2__ 1

With -march=native you are checking both your compiler and your CPU. If you give a different -march for a specific CPU, like -march=bonnell you can check for that CPU.

使用 -march=native 您可以同时检查编译器和 CPU。如果您为特定 CPU 提供不同的 -march,例如 -march=bonnell,您可以检查该 CPU。

Consult your gcc docs for the correct version of gcc:

请查阅您的 gcc 文档以获得正确的 gcc 版本:

https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Submodel-Options.html

https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Submodel-Options.html