3
# Check cpu of current machine and find the
4
# best compiler optimization flags for gcc
5
# Will return result in:
6
# cpu_arg : Type of CPU
7
# check_cpu_args : Arguments for GCC compiler settings
12
if test -n "$TEST_CPUINFO" ; then
15
if test -r "$CPUINFO" -a "$CPUINFO" != " " ; then
16
# on Linux (and others?) we can get detailed CPU information out of /proc
17
cpuinfo="cat $CPUINFO"
20
cpu_family=`$cpuinfo | grep 'family' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1`
21
if test -z "$cpu_family" ; then
22
cpu_family=`$cpuinfo | grep 'cpu' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1`
25
# detect CPU vendor and model
26
cpu_vendor=`$cpuinfo | grep 'vendor_id' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1`
27
model_name=`$cpuinfo | grep 'model name' | cut -d ':' -f 2 | head -1`
28
if test -z "$model_name" ; then
29
model_name=`$cpuinfo | grep 'cpu model' | cut -d ':' -f 2 | head -1`
32
# fallback: get CPU model from uname output
33
if test -z "$model_name" ; then
38
for flag in `$cpuinfo | grep '^flags' | sed -e 's/^flags.*: //' -e 's/[^a-zA-Z0-9_ ]/_/g'`; do
39
eval cpu_flag_$flag=yes
42
# Fallback when there is no /proc/cpuinfo
46
cpu_family=`uname -m`;
47
model_name=`sysctl -n hw.model`
54
cpu_family=`uname -m`;
55
model_name=`uname -p`;
60
# detect CPU shortname as used by gcc options
61
# this list is not complete, feel free to add further entries
63
case "$cpu_family--$model_name" in
69
*Intel*Core*|*X[eE][oO][nN]*)
70
# a Xeon is just another pentium4 ...
71
# ... unless it has the "lm" (long-mode) flag set,
72
# in that case it's a Xeon with EM64T support
73
# If SSE3 support exists it is a Core2 Duo or newer
75
if [ -z "$cpu_flag_lm" ]; then
80
if test -z "$cpu_flag_ssse3" ; then
104
*Celeron*Coppermine*)
157
if test -z "$cpu_arg" ; then
158
if test "$CPUINFO" != " " ; then
159
# fallback to uname if necessary
165
echo "BUILD/check-cpu: Oops, could not find out what kind of cpu this machine is using." >&2
170
# different compiler versions have different option names
171
# for CPU specific command line options
172
if test -z "$CC" ; then
178
cc_ver=`$cc --version | sed 1q`
179
cc_verno=`echo $cc_ver | sed -e 's/^.*gcc/gcc/g; s/[^0-9. ]//g; s/^ *//g; s/ .*//g'`
180
set -- `echo $cc_verno | tr '.' ' '`
184
cc_comp=`expr $cc_major '*' 100 '+' $cc_minor`
186
case "$cc_ver--$cc_verno" in
188
# different gcc backends (and versions) have different CPU flags
189
case `gcc -dumpmachine` in
191
if test "$cc_comp" -lt 304 ; then
192
check_cpu_cflags="-mcpu=${cpu_arg}"
193
elif test "$cc_comp" -ge 402 ; then
194
check_cpu_cflags="-mtune=native"
196
check_cpu_cflags="-mtune=${cpu_arg}"
200
check_cpu_cflags="-mcpu=${cpu_arg} -mtune=${cpu_arg}"
209
# GCC 2.95 doesn't expose its name in --version output
210
check_cpu_cflags="-m${cpu_arg}"
218
# now we check whether the compiler really understands the cpu type
221
if test "x$core2" = "xyes" ; then
224
while [ "$cpu_arg" ] ; do
225
printf "testing $cpu_arg ... " >&2
228
eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null
229
if test "x$?" = "x0" ; then