[英]Issues with SIMD functions in GNU c & c++
Environment Details: 环境详细信息:
Machine: Core i5 M540 processor running Centos 64 bits in a virtual machine in VMware player. 计算机:在VMware Player中的虚拟机中运行Centos 64位的Core i5 M540处理器。 GCC: 4.8.2 built from source tar. GCC:4.8.2从源tar构建。
Issue: I am trying to learn more about SIMD functions in C/C++ and for that I created the following helloworld program. 问题:我试图了解有关C / C ++中SIMD函数的更多信息,为此,我创建了以下helloworld程序。
#include <iostream>
#include <pmmintrin.h>
int main(void){
__m128i a, b, c;
a = _mm_set_epi32(1, 1, 1, 1);
b = _mm_set_epi32(2, 3, 4, 5);
c = _mm_add_epi32(a,b);
std::cout << "Value of first int: " << c[0];
}
When I look at the assembly output for it using the following command I do not see the SIMD instructions. 当我使用以下命令查看程序集输出时,看不到SIMD指令。
g++ -S -I/usr/local/include/c++/4.8.2 -msse3 -O3 hello.cpp
Sample of the assembly generated: 生成的程序集样本:
movl $.LC2, %esi
movl $_ZSt4cout, %edi
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movabsq $21474836486, %rsi
movq %rax, %rdi
call _ZNSo9_M_insertIxEERSoT_
xorl %eax, %eax
Please advise the correct way of writing or compiling the SIMD code. 请提供正确的方式编写或编译SIMD代码。
Thanks you!! 谢谢!!
It looks like your compiler is optimizing away the calls to _mm_foo_epi32
, since all the values are known. 似乎您的编译器正在优化对_mm_foo_epi32
的调用,因为所有值都是已知的。 Try taking all the relevant inputs from the user and see what happens. 尝试从用户那里获取所有相关输入,然后看看会发生什么。
Alternately, compile with -O0
instead of -O3
and see what happens. 或者,使用-O0
而不是-O3
编译,然后看看会发生什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.