[PATCH, i386]: Implement -mcmpxchg16b and -msahf options

Michael Meissner michael.meissner@amd.com
Fri Mar 30 21:03:00 GMT 2007

On Thu, Mar 08, 2007 at 09:53:25PM +0100, Uros Bizjak wrote:
> H. J. Lu wrote:
> >-march=nocona shouldn't use sahf. However, -machine=native should
> >check the lahf_lm bit.
> >  
> Attached patch implements processor specific compile options 
> -mcmpxchg16b and -msahf that instructs the compiler to generate these 
> instructions in asm code. The compiler driver is further enhanced to 
> detect availability of these instructions through cpuid query in order 
> to set appropriate compiler flags for -march=native compilations.
> Due to this change, X86_TUNE_USE_SAHF flag can be set also for 
> m_GENERIC64. sahf generation itself is disabled by default, but can be 
> enabled by -msahf - either manually or via -arch=native. When enabled, 
> it should be used as it results in smaller, but equivalently fast code 
> on all 64bit processors. The same logic applies to m_NOCONA (as reported 
> by Jan). sahf generation is disabled by default for march=nocona, but if 
> -march=native detects availability of instruction, it enables it via -msahf.
> As far as the implementation of compile option handling is concerned, I 
> would like to point out that we ran out of target mask flags for i386, 
> so "normal" variables have to be used. Also, options are marked as 
> RejectNegative, as they only override default setting [false].
> 2007-03-08  Uros Bizjak  <ubizjak@gmail.com>
>        * config/i386/i386.opt (mcmpxchg16b, msahf): New options.
>        * config/i386/i386.c (x86_cmpxchg16b, x86_sahf): Remove.
>        (ix86_tune_features) [X86_TUNE_USE_SAHF]: Enable for m_GENERIC.
>        * config/i386/driver-i386.c (bit_LAHF_LM): New define.
>        (host_detect_local_cpu): Detect cmpxchgb16b and lahf_lm cpuid
>        bits.  Output -mcmpxchg16b and -msahf options when corresponding
>        bit is set.
>        * doc/invoke.texi (i386 and x86-64 Options): Document -mcmpxchg16b
>        and -msahf options.
> Patch was bootstrapped on x86_64 (core2) using "-O2 -march=native" and 
> regression tested for all default languages. OK for mainline?

If early Intel 64-bit machines did not have SAHF, then generic should not be
turning it on, unless we know that none of the machines are in use anymore.
Otherwise you might get random segment faults if you bring up Linux, BSD, or
one of the OSes compiled with GCC using the default -mtune=generic.

On a similar note, it would be nice if we could assume all computers have BSWAP
and MMX, but the original i386 does not have those instructions, and so by
default generic can't generate them.

Michael Meissner, AMD
90 Central Street, MS 83-29, Boxborough, MA, 01719, USA

More information about the Gcc-patches mailing list