LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-20-2007, 10:36 AM   #1
MS3FGX
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
Compiling from source with optimizations


First I should apologize for my likely naive questions, but I have only started playing with actual optimizations in the last week or so; I have always just compiled with the defaults before.

Anyway, I have recently been playing with compiler flags through the use od SlackBuild scripts, and had a few questions and thoughts that I would like cleared up.

1. I have read in the GCC documentation that -march implies -mtune to the same CPU type. But I have seen many scripts specifying both. Is it alright that I am just using -march?

2. In the official Slackware build scripts, the following is added to ./configure:

Code:
--build=$ARCH-slackware-linux
Now, since $ARCH is also used when it names the package, I have been using "i786", even though I use "pentium4" for -march. Is this correct? I assume so, because when I give --build "pentium4", the response I get back is still:

Code:
checking build system type... i786-slackware-linux-gnu
3. Since I mainly compile my packages on a centralized server and then push them out to my machines, should I be using --host rather than --build when optimizing for a specific CPU (one which the server does not have)? At the very least I know I am misrepresenting the build machine (does this matter?), though the host machine does show up as i786 in the ./configure output.

4. Finally, I have noticed that when I build a package that should be compiled only for Pentium 4 (if I am doing it right), I am able to run the binaries on the server. I had got the impression that once they were compiled for a specific CPU, that was it, and they would not run on a different chip (the server has an AMD XP 1500+, and my desktop has a 2.4 GHz P4). So this has gotten me thinking that I have either done something wrong and they are not fully optimized for Pentium 4, or that I was a little too gullible with what I read online about CPU optimizations.

Again, I am sorry if a lot of this is very obvious, but I have not been able to find clear explanations for some of these issues, and it seems like the kind of thing were you really want to hear other's first hand accounts to make sure you are getting the best performance. I should also note that I do "feel" a considerable performance boost in some applications (most notably, Wine) so I must be doing something right.

Last edited by MS3FGX; 08-20-2007 at 10:42 AM.
 
Old 08-20-2007, 11:10 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,745
Blog Entries: 1

Rep: Reputation: 224Reputation: 224Reputation: 224
Not that I'm any kind of expert, but....

1. It shouldn't hurt. I specify both in my build flags and haven't had any problems.

2. i786 is the technology used in Intel's Pentium 4 chips.

3. --build=build-type is the machine that you are configuring and building the package on (your server)
--host=host-type is the machine that will run the resulting binaries. By default it is the same as build. Specify both --build and --host to cross-compile.
--target=target-type is the type of machine that any compiler tools in the package will produce code. By
default, it is the same as host.

4. Optimized, not exclusive. It will still run on x86 architectures, just not optimally.

Last edited by weibullguy; 08-20-2007 at 11:12 AM.
 
Old 08-20-2007, 05:11 PM   #3
MS3FGX
Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Original Poster
Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
Quote:
2. i786 is the technology used in Intel's Pentium 4 chips.
I am aware of this, but the i786 is still a generic CPU type. The GCC documentation lists 3 separate versions of the Pentium 4 (not counting the 64 bit extended version) for cpu_type, and I obviously only want to optimize for just one of them.

Quote:
3. --build=build-type is the machine that you are configuring and building the package on (your server)
--host=host-type is the machine that will run the resulting binaries. By default it is the same as build. Specify both --build and --host to cross-compile.
I'll play with this a bit more then, but in my quick tests, I got a number of errors from ./configure's output when specifying i786 for --host.

Quote:
4. Optimized, not exclusive. It will still run on x86 architectures, just not optimally.
This is very interesting, since it is the complete opposite of what I have read online (from sources such as the Gentoo docs). Basically my understanding was that -march would target the code only for the specified CPU or newer (not maintaining any backwards compatibility), while -mtune would optimize lightly enough that it would still run on generic CPUs.

From Gentoo handbook:

Quote:
On x86 and x86-64 CPUs, -march will generate code specifically for that CPU using all its available instruction sets and the correct ABI; it will have no backwards compatibility for older/different CPUs. If you don't need to execute code on anything other than the system you're running Gentoo on, continue to use -march. You should only consider using -mtune when you need to generate code for older CPUs such as i386 and i486. -mtune produces more generic code than -march; though it will tune code for a certain CPU, it doesn't take into account available instruction sets and ABI. Don't use -mtune on x86 or x86-64 systems, as it is deprecated for those arches.
I also see this in the official Slackware build scripts, which specify "-march=i486 -mtune=i686" which equates to (if I have the concept right): "Optimize for i686 so long as it doesn't keep the code from running on a i486".

But even with -march, I have gone so far as to run Pentium 4 optimized binaries on a Pentium 3 and have not had problems, to say nothing of the AMD XP. But perhaps the code I was optimizing was too simplistic for the optimizations to make that much of an impact on the resulting binary, I was only using simple programs to test.
 
  


Reply

Tags
optimization, slackbuild


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling apt from source - where's the source? stynhx9000 Ubuntu 2 12-01-2005 07:32 AM
Compiling Firefox with i686 optimizations? Jacksteruk309 Linux - Newbie 3 10-19-2005 12:22 PM
compiling from source with i686 optimizations ganja_guru Linux - Software 6 11-08-2004 09:26 AM
Slack optimizations? bluenirve Slackware 4 09-20-2004 06:58 AM
compiling software from source...how do i delete the folder w/ source? webazoid Linux - Software 2 07-01-2004 09:09 PM


All times are GMT -5. The time now is 05:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration