Gentoo Archives: gentoo-dev

From: "Diego 'Flameeyes' Pettenò" <flameeyes@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Replacing cpu-feature USE flags
Date: Thu, 06 Jul 2006 10:59:13
Message-Id: 200607061252.33028@enterprise.flameeyes.is-a-geek.org
1 So, I've been drafting this up in my blog[1], and it is a simple way to
2 replace the CPU feature useflags. Let's try to summarise:
3
4 Right now we have mmx, 3dnow, 3dnowex, sse, sse2 and so on useflags present in
5 the tree, almost never used to get new dependencies, but usually used to
6 supply econf switches.
7
8 This works as long as the user enable the flags, but for AMD64 the story was,
9 until now, that we simply enabled them when they worked, because we had some
10 minimum support available. Unfortunately this became a problem with the
11 introduction of nocona, because that is an amd64-like system but with no
12 3dnow. And there is the problem that sse3 is supported only in later versions
13 of Athlon64 and so on.
14
15 To try to clean up this mess, and to make it simpler to work in
16 cross-compilation, I thought of using the definitions created by the C
17 Preprocessor (CPP) by default for the given CFLAGS. Basically when
18 using -march=athlon64, the preprocessor will enable a few definitions that
19 tells the availability of MMX, 3dNOW, SSE and so on... if we wrap that
20 around, we can use it to know if it's the case of enabling something or not.
21 This is customisable by the user by setting the CFLAGS themselves. If one does
22 not want MMX instructions to be generated, but still want the rest of
23 Athlon64 optimisations, it's simply the matter of
24 using "-march=athlon64 -mno-mmx".
25
26 So, rather than the functions proposed in [1], I've sampled today the
27 following function:
28
29 has_cpuset() {
30 local def hasfeat
31
32 while [[ -n $1 ]]; do
33 case $1 in
34 mmx)
35 def="__MMX__" ;;
36 3dnow)
37 def="__3dNOW__" ;;
38 3dnowex)
39 def="__3dNOW_A__" ;;
40 sse)
41 def="__SSE__" ;;
42 sse2)
43 def="__SSE2__" ;;
44 sse3)
45 def="__SSE3__" ;;
46 altivec)
47 def="__ALTIVEC__" ;;
48 *)
49 ewarn "Instruction set $1 not supported."
50 die "Instruction set not supported."
51 esac
52
53 echo | $(tc-getCC) ${CFLAGS} -dM -E - 2>/dev/null | grep -q ${def} ||
54 hasfeat="no"
55 shift
56 done
57
58 if [[ ${hasfeat} == "no" ]]; then
59 return 1
60 else
61 return 0
62 fi
63 }
64
65 that can be tested easily with the following code:
66
67 yesno() {
68 if "$@"; then
69 echo "yes"
70 else
71 echo "no"
72 fi
73 }
74
75 echo "Does it have 3dnow mmx sse2?"
76 yesno has_cpuset 3dnow mmx sse2
77 echo "Does it have mmx sse sse3?"
78 yesno has_cpuset mmx sse sse3
79 echo "Does it have altivec?"
80 yesno has_cpuset altivec
81
82
83 Note that you need to set your CFLAGS corretly or it will, by default, tell
84 you that everything is disabled.
85
86 Thoughts? Comments?
87
88 SPARC team: I'd like to know if VIS does a similar thing, would make simpler
89 for instance its handling in xine-lib ebuild.
90
91 [1]
92 http://farragut.flameeyes.is-a-geek.org/articles/2006/06/24/crazy-idea-an-alternative-to-cpu-features-useflags
93 --
94 Diego "Flameeyes" Pettenò - http://farragut.flameeyes.is-a-geek.org/
95 Gentoo/Alt lead, Gentoo/FreeBSD, Video, AMD64, Sound, PAM, KDE

Replies

Subject Author
Re: [gentoo-dev] Replacing cpu-feature USE flags Stuart Herbert <stuart.herbert@×××××.com>
Re: [gentoo-dev] Replacing cpu-feature USE flags Ioannis Aslanidis <aslanidis@×××××.com>
Re: [gentoo-dev] Replacing cpu-feature USE flags Donnie Berkholz <spyderous@g.o>
Re: [gentoo-dev] Replacing cpu-feature USE flags Ciaran McCreesh <ciaran.mccreesh@×××××××××××××.uk>
Re: [gentoo-dev] Replacing cpu-feature USE flags "Kevin F. Quinn" <kevquinn@g.o>
Re: [gentoo-dev] Replacing cpu-feature USE flags Luca Barbato <lu_zero@g.o>
Re: [gentoo-dev] Replacing cpu-feature USE flags "Kevin F. Quinn" <kevquinn@g.o>
Re: [gentoo-dev] Replacing cpu-feature USE flags Luca Barbato <lu_zero@g.o>
Re: [gentoo-dev] Replacing cpu-feature USE flags Richard Fish <bigfish@××××××××××.org>