summaryrefslogtreecommitdiff
path: root/devel/cpuflags/files/subr_FreeBSD
blob: f95b6fc9f0a5bdb6312b2093450295917bdbf0ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# $NetBSD: subr_FreeBSD,v 1.4 2010/12/05 11:19:39 abs Exp $

AWK=awk
SED=sed

display_hw_details()
    {
    cat <<END
OS		: '$(uname)'
hw.model	: '$hw_model'
hw.machine	: '$hw_machine'
hw.machine_arch : '$hw_machine_arch'
cpu details	:
END
    $SED -n '/^CPU:/{N;N;N;N;N;N;N;s/\n[^ ].*//g;/\n /p;}' \
     /var/run/dmesg.boot 2>/dev/null
    }

extract_hw_details()
    {
    hw_model=$(sysctl -n hw.model | $SED 's/(R)//g;s/([tT][mM])//g')
    hw_machine=$(sysctl -n hw.machine)
    hw_machine_arch=$(sysctl -n hw.machine_arch)

    # We're almost certainly crosscompiling
    if [ -n "$MACHINE" -a "$hw_machine" != "$MACHINE" ]; then
	echo
	exit
    fi
    }

determine_arch()
    {
    ARCH=
    # When adding $hw_model tests use maximum context (such as trailing space)
    case $hw_machine_arch in
    i386) case $hw_model in
	Pentium\ II*)			ARCH='-march=pentium2'		;;
	Intel\ Pentium\ III\ *)		ARCH='-march=pentium3'		;;
	Intel\ Pentium\ 4\ *)		ARCH='-march=pentium4'		;;
	Intel\ Core2\ *)		ARCH='-march=core2'		;;
	AMD\ Athlon\ XP*)		ARCH='-march=athlon-xp'		;;
	AMD\ Sempron\ Processor\ *)	ARCH='-march=athlon-xp'		;;
	# last resort:
	*386-class*)			ARCH='-march=i386'		;;
	*486-class*)			ARCH='-march=i486'		;;
	*586-class*)			ARCH='-march=pentium'		;;
	*686-class*)			ARCH='-march=pentiumpro'	;;
    esac ;;
    amd64) case $hw_model in
	AMD\ Sempron\ Processor\ *)	ARCH='-march=athlon64'		;;
    esac ;;
    esac

    echo $ARCH
    }

determine_features()
    {
    FEATURES=
    dmesg_features=$(echo $($SED -n \
's/.* Features[0-9]\{0,1\}=0x[0-9a-f]\{1,\}<\(.*\)>$/\1/p' \
/var/run/dmesg.boot 2>/dev/null | $SED 's/,/ /g'))

    case $hw_machine_arch in
	i386 | amd64) case " $dmesg_features " in
	    *" SSE3 "*)		FEATURES="-mfpmath=sse -msse3"		;;
	    *" SSE2 "*)		FEATURES="-mfpmath=sse -msse2"		;;
	    *" SSE "*)		FEATURES="-mfpmath=sse -msse"		;;
	    *" MMX "*)		FEATURES="-mmmx"			;;
	esac
	if [ -z "$FEATURES" ]; then	# FEATURES empty: jail?
	    # failover: try sse from sysctl db
	    if [ "$(sysctl -n hw.instruction_sse 2>/dev/null)" = 1 ]; then
		FEATURES="-mfpmath=sse -msse"
	    fi
	fi
    esac

    echo $FEATURES
    }