Optimize code compilation using GCCCPU parameters in Linux

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.