This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
How to use higher ISA's while restraining GCC to lower ISA's
- From: Jeffrey Walton <noloader at gmail dot com>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 22 May 2017 02:46:49 -0400
- Subject: How to use higher ISA's while restraining GCC to lower ISA's
- Authentication-results: sourceware.org; auth=none
- Reply-to: noloader at gmail dot com
I'm testing some code that wants to use SSE2 and above. The code is
guarded by runtime CPU checks. The options used to compile are
minimal. For example, Debian will effectively compile with only
-mcpu=i686 even though MMX and SSE are ubiquitous since the late
1990s/early 2000's.
According to https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes,
I access different ISA's with the target attribute:
__attribute__ ((__target__ ("sse4_2")))
int main(int argc, char* argv[])
{
if (HasSSE4())
{
// use SSE4
}
else if (HasSSE2())
{
// use SSE2
}
else
{
// use C or C++
}
return 0;
}
Debian packagers will compile the code with, say, `gcc -mcpu=i686
...`. (I believe they omit the -march=X and -mcpu=X, which effectively
targets a machine without MMX, SSE and friends).
Does GCC restrict itself to i686 when it selects instructions? If not,
then how do I ensure GCC only uses i686 or x86_64 when it selects
instructions?
Jeff