From: Norbert Kamenicky <noro@xmedia.sk>
To: gentoo-dev@gentoo.org
Cc: Tavis Ormandy <taviso@gentoo.org>
Subject: Re: [gentoo-dev] Script to test instruction set.
Date: Tue, 12 Aug 2003 16:13:32 +0200 [thread overview]
Message-ID: <3F38F60C.8080102@xmedia.sk> (raw)
In-Reply-To: <20030812115517.GA18146@sdf.lonestar.org>
I tested your script on P4 and Athlon XP Gentoo machines
built from stage1 with these CFLAGS:
P4 CFLAGS="-march=i686 -O3 -pipe"
AMD-XP CFLAGS="-march=athlon-xp -O3 -pipe"
Received the same answer:
$ bin/analyse-x86 /bin/bash
Checking vendor_id string... GenuineIntel ( or AuthenticAMD )
Disassembling /bin/bash, please wait...
i486: 0 i586: 0 mmx: 0 sse: 0 3dnow: 0 ext3dnow: 0
/bin/bash will run on 80386 or compatible (i386) or higher processor.
So something is wrong ...
noro
Tavis Ormandy wrote:
>Hey, this is an x86 port of a script i wrote (with some help from
>wwoods) to identify what processor an alpha binary would work on.
>
>I think its pretty cool, and had some good feedback so im posting it
>here :)
>
>Example:
>
>$ ./analyse-x86 /bin/ls
>Checking vendor_id string...GenuineIntel
>Disassembling /bin/ls, please wait...
>i486: 0 i586: 0 ppro: 15 mmx: 0 sse: 8 sse2: 0
>/bin/ls will run on Pentium III (pentium3) or higher processor.
>
>
>
>------------------------------------------------------------------------
>
>#!/bin/sh
># Tavis Ormandy <taviso@gentoo.org> 2003
># Improvments by Will Woods <wwoods@gentoo.org>
>#
># Identify instruction set used in binary.
>#
>
># initialize everything to zero.
>eval {i486,i586,ppro,mmx,sse,sse2,amd,amd2,cpuid}=0
>
># unfortunately there are mnemonic collissions between vendor sets
># so check vendor_id string, and enable relevant sets.
>printf "Checking vendor_id string..."
>if ! test "${1%=*}" == "--vendor"; then
> case "`grep -Em1 '^vendor_id.*: ' /proc/cpuinfo | cut -d" " -f2`" in
> *GenuineIntel*) vendor=intel; printf "GenuineIntel\n";;
> *AuthenticAMD*) vendor=amd; printf "AuthenticAMD\n";;
> *CyrixInstead*) vendor=cyrix; printf "CyrixInstead\n";;
> *GenuineTMx86*) vendor=transmeta; printf "GenuineTMx86\n";;
> *) vendor=other; printf "other\n";;
> esac
>else
> # allow vendor to be overridden
> vendor=${1#*=}; shift
> printf "%s\n" $vendor
>fi
>
># quick sanity tests.
>if ! test "$1"; then
> printf "usage: %s [--vendor=intel|amd|cyrix|transmeta] /path/to/binary\n" $0 1>&2
> exit 1
>elif ! test -e "$1"; then
> printf "error: %s does not exist.\n" "$1" 1>&2
> exit 1
>elif ! test -r "$1"; then
> printf "error: cant read %s.\n" "$1" 1>&2
> exit 1
>fi
>
>printf "Disassembling %s, please wait...\n" $1
>
># initialize screen output
>case "$vendor" in
> *intel*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \
> $i486 $i586 $ppro $mmx $sse $sse2;;
> *amd*) printf "i486: %4u i586: %4u mmx: %4u sse: %4u 3dnow: %4u ext3dnow: %4u\r" \
> $i486 $i586 $mmx $sse $amd $amd2;;
> *cyrix*) printf "i486: %4u i586: %4u mmx: %4u\r" \
> $i486 $i586 $mmx;;
> *transmeta*) printf "i486: %4u i586: %4u mmx: %4u\r" \
> $i486 $i586 $mmx;;
> *) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \
> $i486 $i586 $ppro $mmx $sse $sse2;;
>esac
>
># do the disassembling.
>objdump -d $1 | cut -f3 | cut -d" " -f1 | (
> while read instruction; do
> case "$instruction" in
> "cmpxchg"|"xadd"|"bswap"|"invd"|"wbinvd"|"invlpg") let ++i486; print=1;;
> "rdmsr"|"wrmsr"|"rdtsc"|"cmpxch8B"|"rsm") let ++i586; print=1;;
> "cmovcc"|"fcmovcc"|"fcomi"|"fcomip"|"fucomi"|"fucomip"|"rdpmc"|"ud2") let ++ppro; print=1;;
> "emms"|"movd"|"movq"|"packsswb"|"packssdw"|"packuswb"|"paddb"|"paddw"|"paddd"|"paddsb"|"paddsw"|"paddusb"|"paddusw"|"pand"|"pandn"|"pcmpeqb"|"pcmpeqw"|"pcmpeqd"|"pcmpgtb"|"pcmpgtw"|"pcmpgtd"|"pmaddwd"|"pmulhw"|"pmullw"|"por"|"psllw"|"pslld"|"psllq"|"psraw"|"psrad"|"psrlw"|"psrld"|"psrlq"|"psubb"|"psubw"|"psubd"|"psubsb"|"psubsw"|"psubusb"|"psubusw"|"punpckhbw"|"punpckhwd"|"punpckhdq"|"punpcklbw"|"punpcklwd"|"punpckldq"|"pxor") let ++mmx; print=1;;
> "addps"|"addss"|"andnps"|"andps"|"cmpps"|"cmpss"|"comiss"|"cvtpi2ps"|"cvtps2pi"|"cvtsi2ss"|"cvtss2si"|"cvttps2pi"|"cvttss2si"|"divps"|"divss"|"fxrstor"|"fxsave"|"ldmxcsr"|"maxps"|"maxss"|"minps"|"minss"|"movaps"|"movhlps"|"movhps"|"movlhps"|"movlps"|"movmskps"|"movss"|"movups"|"mulps"|"mulss"|"orps"|"pavgb"|"pavgw"|"psadbw"|"rcpps"|"rcpss"|"rsqrtps"|"rsqrtss"|"shufps"|"sqrtps"|"sqrtss"|"stmxcsr"|"subps"|"subss"|"ucomiss"|"unpckhps"|"unpcklps"|"xorps"|"pextrw"|"pinsrw"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhuw"|"pshufw"|"maskmovq"|"movntps"|"movntq"|"prefetch"|"sfence") let ++sse; print=1;;
> "addpd"|"addsd"|"andnpd"|"andpd"|"clflush"|"cmppd"|"cmpsd"|"comisd"|"cvtdq2pd"|"cvtdq2ps"|"cvtpd2pi"|"cvtpd2pq"|"cvtpd2ps"|"cvtpi2pd"|"cvtps2dq"|"cvtps2pd"|"cvtsd2si"|"cvtsd2ss"|"cvtsi2sd"|"cvtss2sd"|"cvttpd2pi"|"cvttpd2dq"|"cvttps2dq"|"cvttsd2si"|"divpd"|"divsd"|"lfence"|"maskmovdqu"|"maxpd"|"maxsd"|"mfence"|"minpd"|"minsd"|"movapd"|"movd"|"movdq2q"|"movdqa"|"movdqu"|"movhpd"|"movlpd"|"movmskpd"|"movntdq"|"movnti"|"movntpd"|"movq"|"movq2dq"|"movsd"|"movupd"|"mulpd"|"mulsd"|"orpd"|"packsswb"|"packssdw"|"packuswb"|"paddb"|"paddw"|"paddd"|"paddq"|"paddq"|"paddsb"|"paddsw"|"paddusb"|"paddusw"|"pand"|"pandn"|"pause"|"pavgb"|"pavgw"|"pcmpeqb"|"pcmpeqw"|"pcmpeqd"|"pcmpgtb"|"pcmpgtw"|"pcmpgtd"|"pextrw"|"pinsrw"|"pmaddwd"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhw"|"pmulhuw"|"pmullw"|"pmuludq"|"pmuludq"|"por"|"psadbw"|"pshufd"|"pshufhw"|"pshuflw"|"pslldq"|"psllw"|"pslld"|"psllq"|"psraw"|"psrad"|"psrldq"|"psrlw"|"psrld"|"psrlq"|"psubb"|"psubw"|"psubd"|"psubq"|"psubq"|"psubsb"|"psubsw"|"psubusb"|"psubusw"|"psubsb"|"punpckhbw"|"punpckhwd"|"punpckhdq"|"punpckhqdq"|"punpcklbw"|"punpcklwd"|"punpckldq"|"punpcklqdq"|"pxor"|"shufpd"|"sqrtpd"|"sqrtsd"|"subpd"|"subsd"|"ucomisd"|"unpckhpd"|"unpcklpd"|"xorpd") let ++sse2; print=1;;
> "pavgusb"|"pfadd"|"pfsub"|"pfsubr"|"pfacc"|"pfcmpge"|"pfcmpgt"|"pfcmpeq"|"pfmin"|"pfmax"|"pi2fw"|"pi2fd"|"pf2iw"|"pf2id"|"pfrcp"|"pfrsqrt"|"pfmul"|"pfrcpit1"|"pfrsqit1"|"pfrcpit2"|"pmulhrw"|"pswapw"|"femms"|"prefetch") let ++amd; print=1;;
> "pf2iw"|"pfnacc"|"pfpnacc"|"pi2fw"|"pswapd"|"maskmovq"|"movntq"|"pavgb"|"pavgw"|"pextrw"|"pinsrw"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhuw"|"prefetchnta"|"prefetcht0"|"prefetcht1"|"prefetcht2"|"psadbw"|"pshufw"|"sfence") let ++amd2; print=1;;
> "cpuid") let ++cpuid ++i586; print=1;;
> esac
> # check if screen needs updating.
> if test "$print"; then
> case "$vendor" in
> *intel*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \
> $i486 $i586 $ppro $mmx $sse $sse2;;
> *amd*) printf "i486: %4u i586: %4u mmx: %4u sse: %4u 3dnow: %4u ext3dnow: %4u\r" \
> $i486 $i586 $mmx $sse $amd $amd2;;
> *cyrix*) printf "i486: %4u i586: %4u mmx: %4u\r" \
> $i486 $i586 $mmx;;
> *transmeta*) printf "i486: %4u i586: %4u mmx: %4u\r" \
> $i486 $i586 $mmx;;
> *) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \
> $i486 $i586 $ppro $mmx $sse $sse2;;
> esac
> unset print
> fi
> done
>
># print a newline
>echo
>
># cpuid instruction could mean the application checks to see
># if an instruction is supported before executing it. This might
># mean it will work on anything over a pentium.
>if test $cpuid -gt 0; then
> printf "\nThis binary was found to contain the cpuid instruction.\n"
> printf "It may be able to conditionally execute instructions if\n"
> printf "they are supported on the host (i586+).\n\n"
>fi
>
># print minimum required processor, if there are collissions
># use the vendor to decide what to print.
>if test $sse2 -gt 0; then
> subarch="Pentium IV (pentium4)"
>elif test $sse -gt 0; then
> if test "$vendor" == "intel"; then
> subarch="Pentium III (pentium3)"
> elif test "$vendor" == "amd"; then
> subarch="AMD Athlon 4 (athlon-4)"
> else
> subarch="Pentium III (pentium3)"
> fi
>elif test "$vendor" == "amd" -a $amd2 -gt 0; then
> subarch="AMD Athlon (athlon)"
>elif test "$vendor" == "amd" -a $amd -gt 0; then
> subarch="AMD K6 III (k6-3)"
>elif test $mmx -gt 0; then
> if test "$vendor" == "intel"; then
> if $ppro -gt 0; then
> subarch="Pentium II (pentium2)"
> else
> subarch="Intel Pentium MMX [P55C] (pentium-mmx)"
> fi
> elif test "$vendor" == "amd"; then
> subarch="AMD K6 (k6)"
> elif test "$vendor" == "cyrix"; then
> subarch="Cyrix 6x86MX / MII (pentium-mmx)"
> else
> subarch="Intel Pentium MMX [P55C] (pentium-mmx)"
> fi
>elif test $ppro -gt 0; then
> subarch="Pentium Pro (i686 or pentiumpro)"
>elif test $i586 -gt 0; then
> subarch="Pentium or compatible (i586) (i586 or pentium)"
>elif test $i486 -gt 0; then
> subarch="80486 or comaptible (i486)"
>else
> subarch="80386 or compatible (i386)"
>fi
>
># print message and exit.
>printf "%s will run on %s or higher processor.\n" "$1" "$subarch"; )
>
>
>
>------------------------------------------------------------------------
>
>--
>gentoo-dev@gentoo.org mailing list
>
--
gentoo-dev@gentoo.org mailing list
next prev parent reply other threads:[~2003-08-12 14:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-12 11:55 [gentoo-dev] Script to test instruction set Tavis Ormandy
2003-08-12 14:13 ` Norbert Kamenicky [this message]
2003-08-12 14:45 ` Tavis Ormandy
2003-08-12 14:26 ` Philippe Lafoucrière
2003-08-12 14:43 ` Tavis Ormandy
2003-08-12 15:37 ` Ned Ludd
2003-08-12 18:23 ` Georgi Georgiev
2003-08-13 5:04 ` Joerg Plate
2003-08-13 8:08 ` Georgi Georgiev
2003-08-13 8:24 ` Georgi Georgiev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3F38F60C.8080102@xmedia.sk \
--to=noro@xmedia.sk \
--cc=gentoo-dev@gentoo.org \
--cc=taviso@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox