pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: devel/cpuflags delivers wrong value on macppc (Power Mac G4)



On Wed, 3 Nov 2004, Timo Schöler wrote:

hi,

running cpuflags on my Power Mac G4 (dmesg output below, [1]) gives following value back:

-mcpu=740

this is not true. as can be seen e.g. at [2], the PowerPC 740 is kind of PowerPC 750 lacking (any) L2 Cache, as where the CPU built into the Power Mac G4 (Yikes and Sawtooth series; not the following 466, 533 MHz series, which sported the 7410 already) is definitely a PowerPC/MPC7400 processor.

the wrong output of cpuflags leads to false optimization in case they're utilized e.g. via /etc/mk.conf.

is this a ``known bug'' or should i file a PR?

        Those entried were probably added before gcc 3.1.x and the support
        for the -mcpu=7400 and -mcpu=7450

        Could you try the attached?

        It falls back to -mcpu=740 for versions of gcc before -mcpu=7400 and
        -mcpu=7450. Do you know of a better option?
        http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#SEC32

--
                David/absolute       -- www.NetBSD.org: No hype required --
#!/bin/sh
# $NetBSD: cpuflags.NetBSD,v 1.55 2004/09/23 11:41:10 abs Exp $
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH

if [ "$1" = -v ] ; then
    shift
    opt_v=1
fi
if [ -n "$1" ]; then
    CC=$1
else
    CC=gcc
fi

display_hw_details()
    {
    echo "  OS              : '$(uname)'"
    echo "  hw.model        : '$hw_model'"
    echo "  hw.machine      : '$hw_machine'"
    echo "  hw.machine_arch : '$hw_machine_arch'"
    echo "  cpu details     :"
    sed -n -e 's/^/    /' -e '/^    cpu/p' /var/run/dmesg.boot
    }

hw_model=$(sysctl -n hw.model)
hw_machine=$(sysctl -n hw.machine)
hw_machine_arch=$(sysctl -n hw.machine_arch)

# We're almost certainly crosscompiling
if [ -n "$MACHINE" -a $hw_machine != "$MACHINE" ]; then
    echo
    exit
fi

# When adding $hw_model tests use maximum context (such as trailing space)
case $hw_machine_arch in

    alpha)
        # cpu0 at mainbus0: ID 0 (primary), 21164A-0 (unknown ...
        case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
            *[\(\ ]2106[46][-A\ \)]*)   FLAGS="-mcpu=21064"     ;;
            *[\(\ ]21164[-\ \)]*)       FLAGS="-mcpu=21164"     ;;
            *[\(\ ]21164A[-\ \)]*)      FLAGS="-mcpu=21164a"    ;;
            *[\(\ ]21264[-\ \)]*)       FLAGS="-mcpu=21264"     ;;
            *[\(\ ]21264[AB][-\ \)]*)   FLAGS="-mcpu=21264a"    ;;
            *\ PCA56-2)                 FLAGS="-mcpu=21164pc"   ;;
        esac
        ;;

    arm | arm32) case $hw_model in
        ARM610*)                FLAGS="-mcpu=arm610"            ;; # risc pc
        ARM710*)                FLAGS="-mcpu=arm710"            ;; # risc pc
        i80321\ *)              FLAGS="-mcpu=xscale"            ;; # iyonix
        SA-110*)        
            case $hw_machine in                  # arm32 split post 1.5
                cats|shark|hpcarm|netwinder)
                    FLAGS="-mcpu=strongarm110" ;;
                acorn32)
                    FLAGS="-march=armv3m -mtune=strongarm" ;;
                *)
                    # memorybus in strongarm risc pc machines cannot support
                    # certain strongarm instructions, but in 1.5 and earlier
                    # all strongarm machines are 'arm32', so uname and sysctl
                    # no use
                    if egrep -q 'ofbus0|footbridge0' /var/run/dmesg.boot \
                                                            2>/dev/null ; then
                        FLAGS="-mcpu=strongarm110"                 # shark/cats
                    else
                        FLAGS="-march=armv3m -mtune=strongarm"     # risc pc
                    fi
            esac ;;
        esac ;;

    i386) case $hw_model in
        *Intel\ Pentium/MMX\ *)         FLAGS='-march=pentium-mmx'      ;;
        *Intel\ Pentium\ II\ *)         FLAGS='-march=pentium2'         ;;
        *Intel\ Pentium\ III\ *)        FLAGS='-march=pentium3'         ;;
        *Intel\ Mobile\ Pentium\ III\ *) FLAGS='-march=pentium3'        ;;
        *Intel\ Celeron\ \(Mendocino\)\ *) FLAGS='-march=pentium3 -mno-sse' ;;
        *Intel\ Pentium\ M\ *)          FLAGS='-march=pentium3m'        ;;
        *Intel\ Mobile\ Pentium\ 4\ *)  FLAGS='-march=pentium4m'        ;;
        *Intel\ Pentium\ 4\ *)          FLAGS='-march=pentium4'         ;;
        *VIA\ C3*\ Samuel*)             FLAGS='-march=c3'               ;;
        *AMD\ K6-III*)                  FLAGS='-march=k6-3'             ;;
        *AMD\ K6-2*)                    FLAGS='-march=k6-2'             ;;
        *AMD\ K6*)                      FLAGS='-march=k6'               ;;
        *AMD\ Duron*)                   FLAGS='-march=athlon'           ;;
        *AMD\ Athlon\ 4*)               FLAGS='-march=athlon-4'         ;;
        *AMD\ Athlon\ MP*)              FLAGS='-march=athlon-mp'        ;;
        *AMD\ K7\ \(Athlon\)\ XP\ *)    FLAGS='-march=athlon-xp'        ;;
        *AMD\ Athlon\ XP\ *)            FLAGS='-march=athlon-xp'        ;;
        *AMD\ K7*|*AMD\ Athlon*)        FLAGS='-march=athlon'           ;;
        *386-class*)                    FLAGS='-march=i386'             ;;
        *486-class*)                    FLAGS='-march=i486'             ;;
        *586-class*)                    FLAGS='-march=pentium'          ;;
        *686-class*)                    FLAGS='-march=pentiumpro'       ;;
    esac
    ;;

    m68k) case $hw_model in                                # Examples
        *\(68020*|*\ MC68020\ *) FLAGS='-m68020'        ;; # Untested
        *\(68030*|*\ MC68030\ *) FLAGS='-m68030'        ;; # Mac LC III
        *\(68040*|*\ MC68040\ *) FLAGS='-m68040'        ;; # Untested
        *\(68060*|*\ MC68060\ *) FLAGS='-m68060'        ;; # Upgr amiga 3000
    esac
    case "$(egrep '^fpu0 ' /var/run/dmesg.boot)" in
        *\(emulator\)*)         FLAGS="$FLAGS -msoft-float" ;; 
        *\(no\ math\ support\)*) FLAGS="$FLAGS -msoft-float" ;; 
    esac
    ;;

    mipseb|mipsel)
        # cpu0 at mainbus0: QED R4600 Orion CPU (0x2020) Rev. 2.0 with ...
        case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
            *\ MIPS\ R2000\ *)  FLAGS="-march=r2000"       ;;
            *\ MIPS\ R3000\ *)  FLAGS="-march=r3000"       ;;
            *\ MIPS\ R3000A\ *) FLAGS="-march=r3000"       ;;
            *\ Toshiba\ TX3912\ *)    FLAGS="-march=r3900"  ;;
            *\ Toshiba\ TX392[27]\ *) FLAGS="-march=r3900"  ;;
            *\ MIPS\ R4000\ *)  FLAGS="-mtune=r4000 -mips2" ;; # really mips3
            *\ MIPS\ R4400\ *)  FLAGS="-mtune=r4400 -mips2" ;; # really mips3
            *\ NEC\ VR4100\ *)  FLAGS="-mtune=r4100 -mips2" ;; # really mips3
            *\ NEC\ VR4300\ *)  FLAGS="-mtune=r4300 -mips2" ;; # really mips3
            *\ QED\ R4600\ *)   FLAGS="-mtune=r4600 -mips2" ;; # really mips3
            *\ MIPS\ R5000\ *)  FLAGS="-mtune=r5000 -mips2" ;; # really mips4
            *\ QED\ RM5200\ *)  FLAGS="-mtune=r5000 -mips2" ;; # really mips4
            *\ MIPS\ R6000\ *)  FLAGS="-mtune=r6000 -mips2" ;;
            *\ MIPS\ R8000\ *)  FLAGS="-mtune=r8000 -mips2" ;; # really mips4
        esac
        ;;

    powerpc) case $hw_model in                             # Examples
        601\ *)                 FLAGS='-mcpu=601'       ;; # Untested
        602\ *)                 FLAGS='-mcpu=602'       ;; # Untested
        603\ *)                 FLAGS='-mcpu=603'       ;; # Untested
        603e\ *|603ev\ *)       FLAGS='-mcpu=603e'      ;; # Umax C500 / PM4400
        604\ *)                 FLAGS='-mcpu=604'       ;; # Mac 8500
        604ev\ *)               FLAGS='-mcpu=604e'      ;; # upgr B&W G3
        620\ *)                 FLAGS='-mcpu=620'       ;; # Untested
        7400\ *)                FLAGS='-mcpu=7400'      ;; # AGP G4/400 Mac
        740\ *)                 FLAGS='-mcpu=740'       ;; # Untested
        7450\ *)                FLAGS='-mcpu=7450'      ;; # tibook 550
        750\ *)                 FLAGS='-mcpu=750'       ;; # Untested
    esac ;;

    sparc | sparc64) case " $hw_model" in                          # Examples
        *[\ \(]MB86900/1A*)     FLAGS='-mcpu=cypress'           ;; # ss1+
        *[\ \(]L64811*)         FLAGS='-mcpu=cypress'           ;; # sun4/sun4c
        *[\ \(]CY7C601*)        FLAGS='-mcpu=cypress'           ;; # ss2
        *[\ \(]W8601/8701*)     FLAGS='-mcpu=cypress'           ;; # elc
        *[\ \(]MB86904*)        FLAGS='-mcpu=supersparc'        ;; # ss5 usparc
        *[\ \(]MB86907*)        FLAGS='-mcpu=supersparc'        ;; # ss5 usparc
        *[\ \(]TMS390S10*)      FLAGS='-mcpu=supersparc'        ;; # classic  "
        *[\ \(]TMS390Z50*)      FLAGS='-mcpu=supersparc'        ;; # ss10/ss20
        *[\ \(]RT620/625*)      FLAGS='-mcpu=hypersparc'        ;; # ss20 ross
        *[\ \(]MB86930*)        FLAGS='-mcpu=sparclite'         ;; # from gcc
        *[\ \(]MB86934*)        FLAGS='-mcpu=sparclite'         ;; # from gcc
        # under 1.5.1 -mcpu=ultrasparc chokes egcs-2.91.66 compiling perl
        *[\ \(]SUNW,UltraSPARC*) FLAGS='-mcpu=v9'               ;; # Ultra
    esac ;;

    x86_64) # No x86_64 specific gcc optimisations yet
        NONE=1
        ;;

    vax) # No VAX specific gcc optimisations available
        NONE=1
        ;;

esac

############
# Everything from this point common between all cpuflags variants.

if [ -n "$opt_v" ] ; then
    if [ -z "$NONE" ] ; then
        echo "CPUFLAGS=Unknown"
    else
        echo "CPUFLAGS=None"
    fi
    display_hw_details
    exit
fi
if [ -z "$FLAGS" -a -z "$NONE" ] ; then
    echo 'Unknown machine - please send details to abs%netbsd.org@localhost'    
>&2
    display_hw_details                                                  >&2
fi

# Fixup options for older gccs.
# Entries can be recursive - eg:
#   -march=k6-3 -> -march=k6 -> -march=pentium -> -march=i486
#
# The format of table is
#   gcc_version_in_which_option_was_introduced  new_option  old_option

if [ -n "$FLAGS" ]; then
    gcc_ver=`${CC} -dumpversion | sed 's/^egcs-//'`
    FLAGS=`awk -F: -v "flags=$FLAGS" -v "gcc_ver=$gcc_ver" '
        { if (gcc_ver < $1){map[$2] = ""$3} }
        END { while (flags in map) {flags = map[flags]} print flags }
        ' <<EOD
2.90:-march=i386:-mno-486
2.90:-march=i486:-m486
2.90:-march=pentium:-m486
2.90:-march=pentiumpro:-m486
2.90:-mcpu=21164a:
2.90:-mcpu=arm610:-m6
2.90:-mcpu=arm710:-m6
2.90:-mcpu=cypress:-mcypress
2.90:-mcpu=sparclite:-msparclite
2.90:-mcpu=strongarm110:-m6
2.90:-mcpu=supersparc:-msupersparc
2.90:-mcpu=v9:-mv8
2.95:-march=k6:-march=pentium
3.0:-march=athlon:-march=pentiumpro
3.1:-march=athlon-4:-march=athlon
3.1:-march=athlon-mp:-march=athlon
3.1:-march=athlon-tbird:-march=athlon
3.1:-march=athlon-xp:-march=athlon
3.1:-march=k6-2:-march=k6
3.1:-march=k6-3:-march=k6
3.1:-march=pentium-mmx:-march=pentium
3.1:-march=pentium2:-march=pentiumpro
3.1:-march=pentium3 -mno-sse:-march=pentiumpro
3.1:-march=pentium3:-march=pentiumpro
3.1:-march=pentium4:-march=pentiumpro
3.1:-march=r2000:-cpu=r2000
3.1:-march=r3000:-cpu=r3000
3.1:-march=r3900:-cpu=r3900
3.1:-march=r4000:-cpu=r4000
3.1:-march=r4100:-cpu=r4100
3.1:-march=r4300:-cpu=r4300
3.1:-march=r4400:-cpu=r4400
3.1:-march=r4600:-cpu=r4600
3.1:-march=r5000:-cpu=r5000
3.1:-march=r6000:-cpu=r6000
3.1:-march=r8000:-cpu=r8000
3.1:-mcpu=21264a:-mcpu=21264
3.1:-mcpu=7400:-mcpu=740
3.1:-mcpu=7450:-mcpu=740
3.1:-mtune=r2000:-cpu=r2000
3.1:-mtune=r3000:-cpu=r3000
3.1:-mtune=r3900:-cpu=r3900
3.1:-mtune=r4000:-cpu=r4000
3.1:-mtune=r4100:-cpu=r4100
3.1:-mtune=r4300:-cpu=r4300
3.1:-mtune=r4400:-cpu=r4400
3.1:-mtune=r4600:-cpu=r4600
3.1:-mtune=r5000:-cpu=r5000
3.1:-mtune=r6000:-cpu=r6000
3.1:-mtune=r8000:-cpu=r8000
3.3:-march=c3:-march=i586
3.3:-march=winchip-c6:-march=i586
3.3:-march=winchip2:-march=i586
3.4:-march=athlon-fx:-march=athlon-xp
3.4:-march=athlon64:-march=athlon-xp
3.4:-march=c3-2:-march=c3
3.4:-march=k8:-march=athlon-xp
3.4:-march=nocona:-march=pentium4
3.4:-march=opteron:-march=athlon-xp
3.4:-march=pentium-m:-march=pentium3
3.4:-march=pentium3m:-march=pentium3
3.4:-march=pentium4m:-march=pentium4
3.4:-march=prescott:-march=pentium4
EOD
`
fi

echo $FLAGS

exit 0


Home | Main Index | Thread Index | Old Index