From patchwork Sat Aug 11 02:20:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [wwwdocs] Document Runtime CPU detection builtins Date: Fri, 10 Aug 2012 16:20:17 -0000 From: Sriraman Tallam X-Patchwork-Id: 176656 Message-Id: To: GCC Patches Cc: Gerald Pfeifer , "H.J. Lu" Hi, I have added a release note for x86 builtins __builtin_cpu_is and __builtin_cpu_supports. They were checked in to trunk in rev. 186789. Is this ok to submit? Thanks, -Sri. Index: changes.html =================================================================== RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.8/changes.html,v retrieving revision 1.10 diff -u -u -p -r1.10 changes.html --- changes.html 10 Aug 2012 16:25:46 -0000 1.10 +++ changes.html 11 Aug 2012 02:14:13 -0000 @@ -92,6 +92,69 @@ by this change.

wrong results. You must build all modules with -mpreferred-stack-boundary=3, including any libraries. This includes the system libraries and startup modules. +
  • New builtin functions to detect run-time CPU type and ISA:
    +
      +
    • Builtin __builtin_cpu_is has been added to detect if + the run-time CPU is of a particular type. The builtin returns a postive + integer on a match and zero otherwise. The builtin accepts one string + literal argument, the CPU name. For example, + __builtin_cpu_is("westmere") returns a postive integer if + the run-time CPU is an Intel Corei7 Westmere processor. The following + are the CPU names recognized by __builtin_cpu_is: +
        +
      • amd
      • +
      • intel
      • +
      • atom
      • +
      • core2
      • +
      • corei7
      • +
      • nehalem
      • +
      • westmere
      • +
      • sandybridge
      • +
      • amdfam10h
      • +
      • barcelona
      • +
      • shanghai
      • +
      • istanbul
      • +
      • bdver1
      • +
      • bdver2
      • +
      • btver2
      • +
    • +
    • Builtin __builtin_cpu_supports has been added to detect + if the run-time CPU supports a particular ISA feature. The builtin + returns a postive integer on a match and zero otherwise. The builtin + accepts one string literal argument, the ISA feature. + For example, __builtin_cpu_supports("ssse3") returns a + positive integer if the run-time CPU supports SSSE3 instructions. The + following are the ISA features recognized by + __builtin_cpu_supports: +
        +
      • cmov
      • +
      • mmx
      • +
      • popcnt
      • +
      • sse
      • +
      • sse2
      • +
      • sse3
      • +
      • ssse3
      • +
      • sse4.1
      • +
      • sse4.2
      • +
      • avx
      • +
      • avx2
      • +
    • +
    +

    Caveat: If the above builtins are called before any constructors are + invoked, like during IFUNC initialization, then the CPU detection + initialization must be explicity run using this newly provided + builtin, __builtin_cpu_init. The initialization needs to + be done only once. For example, this is how the invocation would look + like inside an IFUNC initializer:

    + + static void (*some_ifunc_resolver(void))(void)
    + {
    +    __builtin_cpu_init();
    +    if (__builtin_cpu_is("amdfam10h") ...
    +    if (__builtin_cpu_supports("popcnt") ...
    + } +
    +
  • MIPS