diff options
author | Steven Noonan <steven@uplinklabs.net> | 2009-10-18 03:29:19 -0700 |
---|---|---|
committer | Steven Noonan <steven@uplinklabs.net> | 2009-10-18 03:30:18 -0700 |
commit | 6aec5ed01c4d4c41d1b94ae3f275d788b734719e (patch) | |
tree | 9e516dd32935ba8e322e39bc303543bec6738eb0 /crawl-ref/source/util/gcc-opt-x86.pl | |
parent | 0b1a6a2371cb0b4ffe55dd8b708fc4211b0b6ccc (diff) | |
download | crawl-ref-6aec5ed01c4d4c41d1b94ae3f275d788b734719e.tar.gz crawl-ref-6aec5ed01c4d4c41d1b94ae3f275d788b734719e.zip |
AUTO_OPT: add a bit of flexibility for future porting, Mac OS X support
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Diffstat (limited to 'crawl-ref/source/util/gcc-opt-x86.pl')
-rwxr-xr-x | crawl-ref/source/util/gcc-opt-x86.pl | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/crawl-ref/source/util/gcc-opt-x86.pl b/crawl-ref/source/util/gcc-opt-x86.pl new file mode 100755 index 0000000000..808eecac2d --- /dev/null +++ b/crawl-ref/source/util/gcc-opt-x86.pl @@ -0,0 +1,104 @@ +#!/usr/bin/perl +# +# GCC optimization flag generator +# + +use strict; +use warnings; + +my $gcc = $ARGV[0]; +my $cpuinfo = $ARGV[1]; + +if ( ! $gcc ) { + die "Can't generate optimization flags (no compiler specified)\n"; +} + +if ( ! `which $gcc 2> /dev/null` ) { + die "Can't generate optimization flags ($gcc is missing?)\n"; +} + +# +# We allow people to provide their own cpuinfo-compatible +# descriptor. This may be useful later if we want to have +# specific architecture-specific optimizations for release +# builds or something. +# +if ( ! $cpuinfo ) { + $cpuinfo = "/proc/cpuinfo"; +} + +my %features; +my $family; +my $uname_S = `uname -s`; + +# +# Collect CPU feature list +# + +# The Linux way +if ( -e $cpuinfo ) { + open(FH, "< $cpuinfo"); + my @cpuinfo = <FH>; + close FH; + + my @familyline = grep(/^cpu family/, @cpuinfo); + $familyline[0] =~ s/^cpu[ ]family[ \t]*[:][ ]*//; + $family = $familyline[0]; + + my @flags = grep(/^flags/, @cpuinfo); + $flags[0] =~ s/^flags[ \t]*[:][ \t]*//; + @flags = split(' ',$flags[0]); + foreach (@flags) { + $features{$_} = 1; + } +} + +# The Mac OS X way +if ( $uname_S =~ /^Darwin/ ) { + # All released Intel macs have CMOV, and + # sysctl doesn't provide this one. + $features{"cmov"} = 1; + + $features{"mmx"} = `sysctl -n hw.optional.mmx`; + $features{"sse"} = `sysctl -n hw.optional.sse`; + $features{"sse2"} = `sysctl -n hw.optional.sse2`; + $features{"pni"} = `sysctl -n hw.optional.sse3`; + $features{"ssse3"} = `sysctl -n hw.optional.supplementalsse3`; +} + +# +# Check the minimum march/mtune value +# +my $march = "i386"; +my $fpmath; + +if ( $features{"cmov"} && $features{"mmx"} ) { + $march = "pentium2"; +} +if ( $features{"sse"} ) { + $march = "pentium3"; + $fpmath = "sse" +} +if ( $features{"sse2"} ) { + $march = "pentium-m"; +} +if ( $features{"pni"} ) { + $march = "prescott"; +} + +# It's important to specify 'march=pentium4' for the +# Pentium 4, because it has vastly different optimization +# rules than other x86 processors. What's optimal for the +# Pentium 3 is extremely sub-optimal for the Pentium 4. +if ( $family == 15 ) { + $march = "pentium4"; +} + +print "-march=$march -mtune=$march"; +if ( $fpmath ) { + print " -mfpmath=$fpmath"; +} + +print "\n"; + +exit 0 |