Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will enabling -msse, -msse2 and -mfpmath=sse always make my program run faster?

Tags:

c++

gcc

g++

I have a C++ program that is doing a lot of math (mostly calls to sin(), sqrt() and so regular operations). I know that in theory enabling -msse, -msse2, and -mfpmath=sse should expose more registers for GCC/G++ to use therefor potentially making my program run faster, in practice will it always do so? In the worst case could it make my code run slower?

like image 926
WirthLuce Avatar asked Jun 08 '11 22:06

WirthLuce


2 Answers

When worried about performance, you should always profile.

SSE instructions use different CPU resources, so they could cause a decrease in performance (e.g. because those resources are not available for Hyperthreading), but in real life this should be very rare indeed.

like image 76
Ben Voigt Avatar answered Nov 11 '22 02:11

Ben Voigt


Nope: it will not always make the program faster.

Though it could, I wouldn't really expect much slowdown in pathetic cases; however, as mentioned by Ben, profile, profile profile.

Your luck may vary. Also, using -march=native is usually better if you are compiling on the same type of CPU that will run the code.

In particular with SIMD instructions, watch alignment and processor affinity (i.e. the effects on cache locality)

like image 43
sehe Avatar answered Nov 11 '22 01:11

sehe