#!/bin/bash rm -f bench.bin core core.* if [ "$1" = "-new" -o "$1" = "-clean" ] ; then rm -f cache.txt [ "$1" = "-clean" ] && exit 0 elif [ "$1" != "-resume" ] ; then echo "Usage: $0 { -new | -resume | -clean } [ compiler ]" exit 1 fi compiler=${2:-gcc} declare -a options=() did_new_tests=1 tryit() { thisval=$( egrep "^[0-9]+: $*\$" cache.txt 2> /dev/null | cut -f1 -d: ) [ -z "$thisval" ] || return tmp=`mktemp` echo -e "\nTesting: $* ..." if ! $* *.c *.cc bzlib/*.c -lstdc++ -lm -Ibzlib -o bench.bin &> $tmp || [ -s $tmp ] then cat $tmp ; rm $tmp ; thisval=0 echo "Compiler returned an error!" echo "0: $*" >> cache.txt return fi if ! ./bench.bin > $tmp || [ ! -s $tmp ] then rm $tmp ; thisval=0 echo "Benchmark returned an error!" echo "0: $*" >> cache.txt return fi thisval=$( cat $tmp ) echo "$thisval: $*" >> cache.txt did_new_tests=1 rm $tmp } try() { bestval=0 ; best="" for x in "" "$@" ; do options[options_counter]="$x" tryit $compiler ${options[*]} if [ $thisval -gt $bestval ] ; then bestval=$thisval ; best="$x" fi done options[options_counter]="$best" (( options_counter++ )) } while [ $did_new_tests -eq 1 ] do options_counter=0 did_new_tests=0 try -march={i386,i486,i586,i686,pentium{-mmx,2,3,4}} \ -march={k6,k6-2,k6-3,athlon,athlon-{tbird,4,xp,mp}} # Options from -O1 # try -fmerge-constants try -fdefer-pop try -fthread-jumps try -fdelayed-branch try -fomit-frame-pointer try -fguess-branch-prob try -fcprop-registers # Options from -O2 # # Note: -fschedule-insns2 is not used in -O2 # try -foptimize-sibling-calls try -fcse-follow-jumps try -fcse-skip-blocks try -fgcse try -fexpensive-optimizations try -fstrength-reduce try -frerun-cse-after-loop try -frerun-loop-opt try -fcaller-saves try -fforce-mem try -fpeephole2 try -fschedule-insns -fschedule-insns2 try -fregmove try -fstrict-aliasing try -fdelete-null-pointer-checks try -freorder-blocks # Options from -O3 # try -finline-functions try -frename-registers # Options from -Os # try -fmerge-constants try -falign-loops try -falign-jumps try -falign-labels try -falign-functions # Other nice options # try -fforce-addr try -funroll-loops -funroll-all-loops try -maccumulate-outgoing-args -mno-push-args try -preferred-stack-boundary={2,3,4} try -fprefetch-loop-arrays try -fmove-all-movables try -freduce-all-givs # Dangerous options which are not included by default # # try -malign-double # Options from -ffast-math # # try -funsafe-math-optimizations # try -fno-math-errno # try -fno-trapping-math # Other floating point math options # # try -mfpmath=387 # try -mfpmath=sse # try -mfpmath=sse,387 # try -mieee-fp done rm -f bench.bin core core.* echo -e "\nCompiler benchmark finished. Best results with:" echo "$compiler" ${options[*]} ; echo