ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÖÐʹÓÃGCC CPU²ÎÊýÓÅ»¯´úÂë±àÒë

·¢²¼Ê±¼ä:2007-09-05 15:41:30À´Ô´:ºìÁª×÷Õß:lication
ʹÓÃÌض¨µÄGCC²ÎÊý¿ÉÒÔʹ±àÒë³öµÄ³ÌÐòÖ´ÐÐЧÂÊÓнϴóÌáÉý¡£¾ßÌåÈçÏ£º

1¡¢ÓÅ»¯Ô­Àí£º
ÔÚ±àÒë³ÌÐòʱ£¬½èÖú²ÎÊý´«µÝµÄ·½·¨£¬Ê¹ÓÃÓëϵͳCPUÏàÆ¥ÅäµÄgcc²ÎÊý£¬±àÒë³öµÄ³ÌÐò¾ÍÊÇΪϵͳCPU¶ø½øÐÐÌض¨ÓÅ»¯¹ýµÄ£¬Òò¶øÖ´ÐÐËٶȺÍЧÂʶ¼»áÊÇ×îºÃ¡£

2¡¢×¢ÒâÊÂÏî
(1) ¾­¹ý´óÁ¿²âÊÔ·¢ÏÖ£¬ÔÚRedHat, CentOSϵͳÖÐͨ³£Ö»ÄÜͨ¹ý²ÎÊý´«µÝµÄ·½·¨½øÐбàÒëÓÅ»¯£¬µ±È»£¬Èç¹ûÔ¸Òâ²¢ÇÒÄܹ»Ð޸ijÌÐòµÄMakeFileÒ²¿ÉÒÔ´ïµ½ÕâһЧ¹û£¬Ö»²»¹ý±È½Ï¸´ÔÓ£¬¹¤×÷Á¿½Ï´ó¡£ÆäËûÔÚÍøÉϹãΪÁ÷´«µÄ·½·¨£¨ÀýÈ磺ֱ½Óͨ¹ý.bashrc, /etc/profileÉùÃ÷²ÎÊýϵͳ±äÁ¿¡¢Ð´Èë/etc/make.confµÈ£©¾­¹ý²âÊÔ¾ùûÓÐЧ¹û¡£

(2) ¶ÔÓÚGentoo Linux»òFreeBSD¿ÉÒÔͨ¹ýÐÞ¸Ä/etc/make.confÌí¼Ó²ÎÊýµÄ·½·¨À´ÊµÏÖ£¬¶ø²»±ØʹÓòÎÊý´«µÝ·¨¡£

3¡¢ÓÅ»¯²½Ö裺
£¨1£©È·¶¨ÏµÍ³CPUÀàÐÍ£º
# cat /proc/cpuinfo | grep "model name"
Ö´Ðкó»á¿´µ½ÏµÍ³ÖÐCPUµÄ¾ßÌåÐͺţ¬¼ÇÏÂCPUÐͺš£

£¨2£©Ê¹ÓòÎÊý´«µÝ·½·¨½øÐбàÒ룺£¨ÒÔPentium4 CPUΪÀý£©
´Ë´¦ÒÔ±àÒëApacheΪÀý˵Ã÷ÈçºÎʹÓòÎÊý´«µÝ£º
# 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

ÕâÑù¾Íͨ¹ýº¯Êý´«µÝ·½·¨ÊµÏÖÁ˱àÒëÓÅ»¯¡£ÏÂÃæ¶ÔÆäÖеÄһЩ²ÎÊý½øÐоßÌå˵Ã÷£º

-O3£ºÏà¶ÔÓÚ-O¡¢-O1¡¢-O2£¬-O3¿ªÆôÁËËùÓÐGCCÖ§³ÖµÄÓÅ»¯ÌØÐÔ£»
-msse2£º¿ªÆôCPUËùÖ§³ÖµÄsse2Ö¸Á£»
-mmmx£º²Î¿¼-msse2
-mfpmath=sse£ºÎªÖ¸¶¨Ö¸ÁÉú³É¸¡µãÔËËãÌØÐÔ£¨ÓÅ»¯¸¡µãÔËË㹦ÄÜ£©£»
-mcpu£ºÖ¸¶¨CPUÐͺţ»
-march£ºÖ¸¶¨CPUÐͺţ¬»ù±¾Í¬-mcpu£¬GCC¸ù¾Ý-marchÉ趨µÄCPUÐͺžö¶¨ÔÚÉú³É´úÂëʱ¿ÉÒÔʹÓÃÄÄЩÖÖÀàµÄÖ¸Áî¡££¨×¢Ò⣡-march²ÎÊýÔÚijЩCPUÐͺÅÖв»¿ÉÓã¡£©
-pipe£ºÊ¹ÓùܵÀ(pipe)·½·¨Ìæ´úÁÙʱÎļþ·½·¨ÔÚ±àÒëµÄ²»Í¬½×¶ÎÖ®¼ä½øÐÐͨѶ¡£

¸½£º³£¼ûCPUÓÅ»¯²ÎÊý
386£º
CHOST="i386-pc-linux-gnu"
CFLAGS="-march=i386 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=i386 -O3 -pipe -fomit-frame-pointer"
486£º
CHOST="i486-pc-linux-gnu"
CFLAGS="-march=i486 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=i486 -O3 -pipe -fomit-frame-pointer"
Pentium (Intel)£º
CHOST="i586-pc-linux-gnu"
CFLAGS="-march=pentium -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium -O3 -pipe -fomit-frame-pointer"
Pentium MMX (Intel)£º
CHOST="i586-pc-linux-gnu"
CFLAGS="-march=pentium-mmx -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium-mmx -O3 -pipe -fomit-frame-pointer"
Pentium PRO (Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentiumpro -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentiumpro -O3 -pipe -fomit-frame-pointer"
Pentium II (Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer"
Celeron (Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer"
Pentium III (Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
Celeron2 (Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
Celeron (Willamette-Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
Pentium 4 (Intel)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
K6 (AMD)£º
CHOST="i586-pc-linux-gnu"
CFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer"
K6-2 (AMD)£º
CHOST="i586-pc-linux-gnu"
CFLAGS="-march=k6-2 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=k6-2 -O3 -pipe -fomit-frame-pointer"
K6-3 (AMD)£º
CHOST="i586-pc-linux-gnu"
CFLAGS="-march=k6-3 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=k6-3 -O3 -pipe -fomit-frame-pointer"
Athlon (AMD)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=athlon -O3 -pipe -fomit-frame-pointer"
Athlon-tbird, aka K7 (AMD)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon-tbird -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=athlon-tbird -O3 -pipe -fomit-frame-pointer"
Athlon-tbird XP (AMD)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
Athlon 4(AMD)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon-4 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=athlon-4 -O3 -pipe -fomit-frame-pointer"
Athlon XP (AMD)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
Athlon MP (AMD)£º
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon-mp -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=athlon-mp -O3 -pipe -fomit-frame-pointer"
603 (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
603e (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
604 (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
604e (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
750 aka as G3 (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-mcpu=750 -O3 -pipe -fomit-frame-pointer -fsigned-char"
CXXFLAGS="-mcpu=750 -O3 -pipe -fomit-frame-pointer -fsigned-char"
7400, aka G4 (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-mcpu=7400 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec"
CXXFLAGS="-mcpu=7400 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec"
7450, aka G4 second generation (PowerPC)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-mcpu=7450 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec"
CXXFLAGS="-mcpu=7450 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec"
PowerPC (If you don't know which one)£º
CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
Sparc£º
CHOST="sparc-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer"
Sparc 64£º
CHOST="sparc64-unknown-linux-gnu"
CFLAGS="-O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer"
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ