How to use higher ISA's while restraining GCC to lower ISA's

Jeffrey Walton noloader@gmail.com
Mon May 22 06:46:00 GMT 2017


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



More information about the Gcc-help mailing list