如何测试你的Linux支持SSE2 [英] How to test if your Linux Support SSE2

查看:2051
本文介绍了如何测试你的Linux支持SSE2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我有两个问题:


  1. SSE2兼容性是CPU问题还是编译器问题?

  2. <如何检查您的CPU或编译器是否支持SSE2?

我正在使用GCC版本:

  gcc(GCC)4.5.1 

当我试图编译一个代码,它给我这个错误:

  $ gcc -O3 -msse2 -fno-strict- aliasing -DHAVE_SSE2 = 1 -DMEXP = 19937 -o test-sse2-M19937 test.c 
cc1:错误:无法识别的命令行选项-msse2

并且 cpuinfo 显示:

 处理器:0 
供应商:GenuineIntel
arch:IA-64
系列:32
型号:1
型号名称:双核英特尔(R)Itanium(R)处理器9140M
修订版本:1
archrev:0
特性:branchlong,16字节原子操作
cpu数字:0
cpu regs :4
cpu MHz:1669.000503
itc MHz:416.875000
BogoMIPS:3325.95
siblings:2
物理ID:0
核心ID:0
thread id:0


解决方案


  1. 这是两个。编译器/汇编器需要能够发出/处理SSE2指令,然后CPU需要支持它们。如果你的二进制程序没有附加条件的SSE2指令,并且试图在奔腾II上运行它,你就不幸运。


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


在您的代码使用cpuid等检查,以便SSE2部分可以在不支持它的CPU中禁用,您的代码可以落回一个更常见的指令集。



EDIT:



请注意,编译器需要是在x86系统上运行的本机编译器,或者是x86的交叉编译器。否则,它不会有必要的选项来编译x86处理器的二进制文件,包括任何带有SSE2的文件。



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



您有以下选项:




  • 使用将在IA64上运行并为x86生成二进制文件的交叉编译器。


  • 使用英特尔IA32EL时,交叉编译器工具链并不是一件容易的事情,因为你需要的不仅仅是编译器(binutils,运行本机x86编译器。我不知道你将如何去安装一个原生的x86工具链,你的项目在你的发行版中需要的所有库不直接支持它。也许一个完整的chroot安装的x86分发?




然后如果你想测试你的构建


$ b


$ b

我想你也可以在仿真器上运行一个完整的x86 linux发行版,如Bochs或QEMU(当然没有虚拟化)。你肯定不会因为速度而感到眩目。


Actually I have 2 questions:

  1. Is SSE2 Compatibility a CPU issue or Compiler issue?
  2. How to check if your CPU or Compiler support SSE2?

I am using GCC Version:

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 cpuinfo showed this:

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

解决方案

  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.

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.

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.

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.

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 ?

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

EDIT2:

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 not going to be dazzled by the resulting speeds though.

这篇关于如何测试你的Linux支持SSE2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆