Reputation: 13
Environment Details:
Machine: Core i5 M540 processor running Centos 64 bits in a virtual machine in VMware player. GCC: 4.8.2 built from source tar.
Issue: I am trying to learn more about SIMD functions in C/C++ and for that I created the following helloworld program.
#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.
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.
Thanks you!!
Upvotes: 1
Views: 102
Reputation: 3736
It looks like your compiler is optimizing away the calls to _mm_foo_epi32
, since all the values are known. Try taking all the relevant inputs from the user and see what happens.
Alternately, compile with -O0
instead of -O3
and see what happens.
Upvotes: 2