C++ program compiled for x64 is slower than complied for x86
http://c-vision.com.ua/?p=1116
u/bnolsen Feb 13 '12
I just ran the code compiled 64bit only (apparently it's a PITA for me to cross compile 32bit).
gcc -std=c++0x -march=native -O3 -ftree-vectorize -o sse sse.cpp -lstdc++ (gcc version 4.6.2 20120120)
It seems your hand rolled SSE loop is slower than the compiler optimized version (I'm frankly not surprised though).
Dot product double - 0.0228735 Dot product SIMD double - 0.0240497
7
u/00kyle00 Feb 13 '12
Why guess, when you may know for sure? objdump/vc disasm both and see for yourself.
2
-1
u/zfxvxr Feb 24 '12
The whole 64bit thing is a scam. The pointers are getting bigger and the CPU's workload is twice as heavy.
2
u/TheCoelacanth Feb 27 '12
Enjoy your 4GB address space. I'll be over here with my 16 GB of memory.
2
Mar 05 '12
And your extra 8 general purpose registers, and your much faster standard calling convention on POSIX systems, in the case of x86-64.
-10
u/MarkTraceur Feb 13 '12
compiled....complied
Well, there's your problem. I can fix 'er, but it'll take a course in basic English.
5
u/jacekplacek Feb 13 '12
Oh, you've never made a typo?
9
u/MarkTraceur Feb 13 '12 edited Feb 13 '12
Not to my nkowledge.
EDIT: For posterity, I want everyone to know that I love Reddit's sense of humour: downvote me to oblivion for pointing out a typo, but upvote 7 times for satirically insulting people who make them. Bravo, guys!
7
u/Rhomboid Feb 13 '12
Using gcc 4.5 and -O3 -march=native, I get the following (normalized):
I'm not too surprised, as one of the quirks of gcc is that to use the xmmintrin.h intrinsics you have to enable SSE2, but if you enable SSE2 it's going to auto-vectorize your code, so both versions are using SIMD. All this shows is that the compiler is better at it than doing it by hand.
There should be little advantage to 64 bit mode here. I would expect it to have inlined most of the function calls, so the improved calling convention overhead isn't too much of a win, and all the work is being done in SIMD registers so the extra general purpose registers aren't too much of a win either. There really aren't many pointers so the extra memory is negligible as well.