Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
compiling for machines with different CPU features
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
mrsaccess
n00b
n00b


Joined: 03 Sep 2005
Posts: 30
Location: Greece

PostPosted: Mon Jun 04, 2012 3:32 pm    Post subject: compiling for machines with different CPU features Reply with quote

I have two systems and both are running Gentoo. I want to compile my programs once for both machines.

The problem is that despite both machines having a Core 2 Duo processor, one is a Penryn version with SSE 4.1 instructions and the other a Merom version without SSE 4.1.

So the question is: How can I set my make.conf so that GCC will create code that will take advantage of SSE 4.1 if it is available but work even if it isn't present?

Maybe it is simple but I haven't find an answer googling around for some time now.

PS. Also a thing about setiing -march=core2 is that it doesn't enable SSE4.1 according to GCC's manual.
_________________
Hardware: The parts of your pc you can kick.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21607

PostPosted: Tue Jun 05, 2012 1:22 am    Post subject: Reply with quote

As far as I know, what you want is not supported via a simple command line switch. The point of the new instructions is to perform certain operations quickly. If the CPU does not support the operation, then the code must either jump to an alternate block that does the same work without hardware assistance or it must execute the unsupported opcode, take a CPU fault, and hope that the kernel can emulate the requested operation. The former increases code size and may have negative impact on cache prediction. The latter is extremely expensive when it works at all, and requires kernel support. I am not aware of any kernel support for emulating SSE instructions.

With regard to -march=core2, that seems correct given your earlier statement that some Core 2 Duo processors do not understand SSE4.1 instructions.
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9523
Location: beyond the rim

PostPosted: Tue Jun 05, 2012 8:29 am    Post subject: Reply with quote

Note that there aren't many cases where the compiler would use those instructions anyway, and they may actually decrease performance (see http://www.phoronix.com/scan.php?page=article&item=intel_avx_gcc)
Back to top
View user's profile Send private message
mrsaccess
n00b
n00b


Joined: 03 Sep 2005
Posts: 30
Location: Greece

PostPosted: Tue Jun 05, 2012 11:03 am    Post subject: Reply with quote

Thanks!

I knew that SSE 4.1 doesn't help most applications. I was wondering for those few task intensive applications that can take advantage of it.
After a bit more search, it seems almost none uses SSE 4.1 and those who need it, should be set up by their developers (I guess asm blocks in the code, instructions in the makefile) to be able to detect it at runtime.

What initially confused me was that many binaries compiled for my Penryn machine, wouldn't run on my Merom machine, even Xorg or awk. I guess when SSE 4.1 gets enabled (with march=native for example), GCC will use it for much more programs than those that actually can take advantage of it.

Will stay with march=core2 mtune=native for now, since I want my apps to run as good as they can on my main machine, yet still be compatible with the second one. :D
_________________
Hardware: The parts of your pc you can kick.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum