Article title: Optimize code compilation using GCCCPU parameters in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Using specific GCC parameters can greatly improve the execution efficiency of compiled programs. The details are as follows:
1. optimization principle:
During program compilation, the gcc parameters matching the system CPU are used by passing parameters. the compiled program is optimized for the system CPU, therefore, the execution speed and efficiency will be the best.
2. Notes
(1) after a large number of tests, it is found that in RedHat and CentOS systems, compilation and optimization can only be performed through the method passed by parameters. of course, if you are willing to modify the MakeFile of the program, you can achieve this effect, but it is complicated and requires a lot of work. Other methods widely circulated on the Internet (for example, declaring the parameter system variables directly through. bashrc,/etc/profile, and writing/etc/make. conf) have no effect after testing.
(2) for Gentoo Linux or FreeBSD, you can add parameters by modifying/etc/make. conf without passing parameters.
3. optimization steps:
(1) determine the system CPU type:
# Cat/proc/cpuinfo | grep "model name"
After running the command, you will see the specific CPU model in the system. write down the CPU model.
(2) compile using the parameter transfer method: (take Pentium4 CPU as an example)
Here we will compile Apache as an example to illustrate how to use parameter passing:
# Tar xzvf httpd-2.0.55.tar.gz
# Cd httpd-2.0.55
CHOST = "i686-pc-linux-gnu "\
CFLAGS = "-O3 \
-Msse2 \
-Mmmx \
-Mfpmath = sse \
-Mcpu = pentium4 \
-March = pentium4 \
-Pipe \
-Fomit-frame-pointer "\
CXXFLAGS = "-O3 \
-Msse2 \
-Mmmx \
-Mfpmath = sse \
-Funroll-loops \
-Mcpu = pentium4 \
-March = pentium4 \
-Pipe \
-Fomit-frame-pointer "\
./Configure ......
# Make
# Make install
[1] [2] [3] Next page