[PATCH, i386]: Add arch flag for sahf instruction

Uros Bizjak ubizjak@gmail.com
Thu Mar 8 11:40:00 GMT 2007

On 3/7/07, Richard Henderson <rth@redhat.com> wrote:

> This is not something appropriate for tune, because it
> does *not* work for a subset of the 64-bit chips.  It
> would have to be an arch switch instead.

Attached patch adds arch flag for sahf instruction. in x86_64, I
propose following:

gcc -march=(any 64bit arch) generates sahf instruction depending on tune flags.
gcc -mtune=(any 64bit arch) does not generate sahf instruction.

This solves the problem of supporting very old x86_64 prototypes. gcc
does not generate sahf by default, but -march= switch implies that
user has recent enough processor. However, there is no problem to
switch sahf off on a per-processor basis by adding TARGET_NO_SAHF to
affected processor flags.

Also, this patch cleans handling of TARGET_USE_SAHF flag through the sources.

2007-03-08  Uros Bizjak  <ubizjak@gmail.com>

	* config/i386/i386.h (TARGET_SAHF): New define.
        * config/i386/i386.c (ix86_tune_features) [X86_TUNE_USE_SAHF]:
	Also enable for m_K8, m_AMDFAM10 and m_CORE2.
	(x86_sahf): New global variable.
	(override_options): Add PTA_NO_SAHF to pta_flags enum.  Recode
	pta_flags masks using shifts.  Add PTA_NO_SAHF to x86_64 processor
	flags. Set x86_sahf when PTA_NO_SAHF is not set in processor flags.
	Do not unconditionally disable TARGET_USE_SAHF for 64-bit.
	(ix86_fp_comparison_sahf_cost): Return high value for !TARGET_SAHF.
	(ix86_expand_fp_compare): Check for TARGET_CMOVE or TARGET_SAHF
	when expanding fcomi/sahf based tests.
	(ix86_emit_fp_unordered_jump): Check for TARGET_SAHF when
	expanding sahf based alternative. Emit sahf based sequence when
	optimizing for code size.
	* config/i386/i386.md (x86_sahf_1): Do not disable for
	TARGET_64BIT, enable for TARGET_SAHF.

Patch was regression tested on i686-pc-linux-gnu for all default
languages. OK for mainline?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: i386-sahf-2.diff
Type: application/octet-stream
Size: 5129 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070308/b6f0b5b5/attachment.obj>

More information about the Gcc-patches mailing list