diff options
author | Matthew Cline <zelgadis@sourceforge.net> | 2009-10-17 20:22:24 -0700 |
---|---|---|
committer | Matthew Cline <zelgadis@sourceforge.net> | 2009-10-17 20:22:24 -0700 |
commit | 43873ef0ff403a6bc0242f8cc8510060127abde3 (patch) | |
tree | 8718f8c5a614efbba8722e7efb0696a76b7d40b7 /crawl-ref/source/util | |
parent | f923d3b75a2d9dc0e5b8953b0021832b76c65081 (diff) | |
download | crawl-ref-43873ef0ff403a6bc0242f8cc8510060127abde3.tar.gz crawl-ref-43873ef0ff403a6bc0242f8cc8510060127abde3.zip |
makefile: Automatically optimize for your machine
Setting the makefile variable AUTO_OPT_GCC will give GCC a list of
optimization flags suited for the machine make is run on. It does this
using util/auto-opt.sh. "-march=native -mtune=native" are always
outputted, which causes GCC to detect the CPU type you use and generate
code for that. On Linux systems it also looks at the flags line of
/proc/cpuinfo to pick x86 optimization flags.
Diffstat (limited to 'crawl-ref/source/util')
-rwxr-xr-x | crawl-ref/source/util/auto-opt.sh | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/crawl-ref/source/util/auto-opt.sh b/crawl-ref/source/util/auto-opt.sh new file mode 100755 index 0000000000..8f4aa185cb --- /dev/null +++ b/crawl-ref/source/util/auto-opt.sh @@ -0,0 +1,50 @@ +#!/bin/bash --noprofile + +######################################################################### +# Called by the makefile if AUTO_OPT_GCC is true, outputs the list of CPU +# specific optimization flags that should be used. +######################################################################### + +#TODO: Detect extra compiler options for: +# +# * Non-gcc compilers. +# * CYGWIN. +# * Mac OS X. +# * Non-x86 Linux systems. + +######################################################################### + +# This line makes GCC automatically detect the CPU architecture to use. Also +# might cause the use of some of the "-m" options we use down below, +# but GCC doesn't complain about an "-m" option being used repeatedly. +OUT="-mtune=native -march=native" + +if [ -f /proc/cpuinfo ]; then + # On Linux system, the "flags: " line of /proc/cpuinfo indicates which + # extended instruction sets are available (among other things), so we + # can use that to detect what to use. + + # Only get info for the first CPU; assumes that all CPUs in the system + # are the same + INFO=`cat /proc/cpuinfo | grep '^flags.*:' | head -n 1` + + # These are currently all x86 specific. + for flag in cx16 mmx sse sse2 sse3 sse4.1 sse4.2 sse4 sse4a 3dnow abm; do + # Put a space on either side of the flag name, so that it won't + # match in the middle of a flag. + if [[ $INFO == *\ $flag\ * ]] ; then + OUT="$OUT -m$flag" + fi + done + + if [[ $INFO == *\ lahf_lm\ * ]]; then + OUT="$OUT -msahf" + fi + + # Any available SSE lets us use -mfpmath=sse + if [[ $INFO == *\ sse* ]]; then + OUT="$OUT -mfpmath=sse" + fi +fi + +echo "$OUT" |