QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1022|回复: 7

CFLAGS自由选择:)

[复制链接]
发表于 2005-3-9 22:05:40 | 显示全部楼层 |阅读模式
稍微比较快的 CFLAGS (建议那些以稳定为诉求的使用者使用):

o   -march=<cpu-type> -mtune=<cpu-type> -O2 -pipe -fomit-frame-pointer

·         注重执行时期效能使用的 CFLAGS (建议需要快速运算的软件使用):

o   -march=<cpu-type> -mtune=<cpu-type> -mfpmath=sse,387 [-mmmx -msse -msse2 -msse3 -m3dnow] -minline-all-stringops -pipe -O3 -fomit-frame-pointer -fforce-addr -finline-functions -finline-limit=800 -fmove-all-movables -freduce-all-givs -freorder-blocks -freorder-functions -fexpensive-optimizations -falign-functions -falign-labels -falign-loops -falign-jumps -frename-registers -fweb -funit-at-a-time -funroll-loops -fprefetch-loop-arrays -ffunction-sections -fdata-sections -fbranch-target-load-optimize -fbranch-target-load-optimize2

·         注重档案大小与加载速度的 CFLAGS (建议需要常常被启动的程序使用):

o   -march=<cpu-type> -mtune=<cpu-type> -mfpmath=sse,387 [-mmmx -msse -msse2 -msse3 -m3dnow] -maccumulate-outgoing-args -malign-stringops -pipe -Os -fomit-frame-pointer -fforce-addr -finline-functions -finline-limit=400 -fmove-all-movables -freduce-all-givs -freorder-blocks -freorder-functions -fexpensive-optimizations -frename-registers -fweb -funit-at-a-time -fbranch-target-load-optimize -fbranch-target-load-optimize2

         折衷 CFLAGS (从加载速度跟执行效能折衷出来的 CFLAGS,大部份的人可能会想用这个):

o   -march=<cpu-type> -mtune=<cpu-type> -mfpmath=sse,387 [-mmmx -msse -msse2 -msse3 -m3dnow] -pipe -Os -fomit-frame-pointer -fforce-addr -finline-functions -finline-limit=400 -fmove-all-movables -freduce-all-givs -freorder-blocks -freorder-functions -fexpensive-optimizations -falign-functions -falign-labels -falign-loops -falign-jumps -frename-registers -fweb -funit-at-a-time -fbranch-target-load-optimize -fbranch-target-load-optimize2

请注意,这里列出的 CFLAGS 并不是最好的,也永远不会有最好的 CFLAGS。
发表于 2005-3-9 22:54:59 | 显示全部楼层
唉,网络帖子一大抄

到处转,转来转去的
回复

使用道具 举报

发表于 2005-3-10 16:56:47 | 显示全部楼层
这帖不就在精华里呢嘛。
回复

使用道具 举报

 楼主| 发表于 2005-3-11 07:31:12 | 显示全部楼层
还以为大家不知道,发出来给大家共享下.我真的是孤陋寡闻.看来以后我不用发这种贴子.斑主删了该贴吧!
回复

使用道具 举报

发表于 2005-3-11 07:54:00 | 显示全部楼层
没事没事

不要打击大家的积极性嘛
回复

使用道具 举报

发表于 2005-3-11 07:54:22 | 显示全部楼层
我一般都用-O3
回复

使用道具 举报

发表于 2005-3-12 06:48:02 | 显示全部楼层
在gentoo论坛上有个自动决定CFLAG的帖子,试试看。

http://forums.gentoo.org/viewtopic-t-53602.html

[code:1]
#!/bin/sh

# Author: pixelbeat

#This script is Linux specific
#It should work on any gcc >= 2.95 at least

#these apply to any arch (just here for reference)
unsafe_math_opts="-ffast-math -fno-math-errno -funsafe-math-optimizations -fno-trapping-math"

gcc_version=`gcc -dumpversion | sed 's/\([0-9]\{1,\}\.[0-9]\{1,\}\)\.*\([0-9]\{1,\}\)\{0,1\}/\1\2/'`

IFS=":"
while read name value; do
    unset IFS
    name=`echo $name`
    value=`echo $value`
    IFS=":"
    if [ "$name" == "vendor_id" ]; then
        vendor_id="$value"
    elif [ "$name" == "cpu family" ]; then
        cpu_family="$value"
    elif [ "$name" == "model" ]; then
        cpu_model="$value"
    elif [ "$name" == "flags" ]; then
        flags="$value"
    fi
done < /proc/cpuinfo
unset IFS

if [ "$vendor_id" == "AuthenticAMD" ]; then
    if [ "$cpu_family" == "4" ]; then
        _CFLAGS="$_CFLAGS -march=i486"
    elif [ "$cpu_family" == "5" ]; then
        if [ "$cpu_model" -lt "4" ]; then
            _CFLAGS="$_CFLAGS -march=pentium"
        elif [ "$cpu_model" == "6" ] || [ "$cpu_model" == "7" ]; then
            _CFLAGS="$_CFLAGS -march=k6"
        elif [ "$cpu_model" == "8" ] || [ "$cpu_model" == "12" ]; then
            if expr $gcc_version '>=' 3.1 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=k6-2"
            else
                _CFLAGS="$_CFLAGS -march=k6"
            fi
        elif [ "$cpu_model" == "9" ] || [ "$cpu_model" == "13" ]; then
            if expr $gcc_version '>=' 3.1 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=k6-3"
            else
                _CFLAGS="$_CFLAGS -march=k6"
            fi
        fi
    elif [ "$cpu_family" == "6" ]; then
        if [ "$cpu_model" -le "3" ]; then
            if expr $gcc_version '>=' 3.0 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=athlon"
            else
                _CFLAGS="$_CFLAGS -march=k6"
            fi
        elif [ "$cpu_model" == "4" ]; then
            if expr $gcc_version '>=' 3.1 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=athlon-tbird"
            elif expr $gcc_version '>=' 3.0 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=athlon"
            else
                _CFLAGS="$_CFLAGS -march=k6"
            fi
        elif [ "$cpu_model" -ge "6" ]; then #athlon-{4,xp,mp}
            if expr $gcc_version '>=' 3.1 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=athlon-xp"
            elif expr $gcc_version '>=' 3.0 >/dev/null; then
                _CFLAGS="$_CFLAGS -march=athlon"
            else
                _CFLAGS="$_CFLAGS -march=k6"
            fi
        fi
    fi
else #everything else "GenuineIntel"
    if [ "$cpu_family" == "3" ]; then
        _CFLAGS="$_CFLAGS -march=i386"
    elif [ "$cpu_family" == "4" ]; then
        _CFLAGS="$_CFLAGS -march=i486"
    elif [ "$cpu_family" == "5" ] && expr $gcc_version '<' 3.1 >/dev/null; then
        _CFLAGS="$_CFLAGS -march=pentium"
    elif [ "$cpu_family" -ge "6" ] && expr $gcc_version '<' 3.1 >/dev/null; then        _CFLAGS="$_CFLAGS -march=pentiumpro"
    elif [ "$cpu_family" == "5" ]; then
        if [ "$cpu_model" != "4" ]; then
            _CFLAGS="$_CFLAGS -march=pentium"
        else
            _CFLAGS="$_CFLAGS -march=pentium-mmx" #No overlap with other vendors        fi
    elif [ "$cpu_family" == "6" ]; then
        if echo "$flags" | grep -vq cmov; then #gcc incorrectly assumes i686 always has cmov
            _CFLAGS="$_CFLAGS -march=pentium -mcpu=pentiumpro" #VIA CPUs exhibit this
        else
            if [ "$cpu_model" == "0" ] || [ "$cpu_model" == "1" ]; then
                _CFLAGS="$_CFLAGS -march=pentiumpro"
            elif [ "$cpu_model" -ge "3" ] && [ "$cpu_model" -le "6" ]; then #4=TM5600 at least
                _CFLAGS="$_CFLAGS -march=pentium2"
            elif [ "$cpu_model" -ge "7" ] && [ "$cpu_model" -le "11" ]; then #9 invalid
                _CFLAGS="$_CFLAGS -march=pentium3"
            fi
        fi
    elif [ "$cpu_family" == "15" ]; then
        _CFLAGS="$_CFLAGS -march=pentium4"
    fi
fi

if expr $gcc_version '>=' 3.1 >/dev/null; then
    if echo "$flags" | grep -q sse2; then
        _CFLAGS="$_CFLAGS -mfpmath=sse -msse2"
    elif echo "$flags" | grep -q sse; then
        _CFLAGS="$_CFLAGS -mfpmath=sse -msse"
    fi
    if echo "$flags" | grep -q mmx; then
        _CFLAGS="$_CFLAGS -mmmx"
    fi
    if echo "$flags" | grep -q 3dnow; then
        _CFLAGS="$_CFLAGS -m3dnow"
    fi
fi

echo "$_CFLAGS"
[/code:1]
回复

使用道具 举报

发表于 2005-3-12 23:41:31 | 显示全部楼层
http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=91776
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-10-5 02:28 , Processed in 0.040804 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表