[PATCH, i386]: Insert "cld" via optimize mode switching

Michael Matz matz@suse.de
Mon Dec 4 14:59:00 GMT 2006


Hi,

On Mon, 4 Dec 2006, Uros Bizjak wrote:

> On 12/4/06, Michael Matz <matz@suse.de> wrote:
> 
> > > I think it would have been good that the ABI mandated that the flag be
> > > cleared...
> >
> > It does, on function entry and exit (i386 and x86-64 ABI).
> 
> The we in fact need cld insn only after asm statements. MODE_ENTRY can
> be set to CLD_FLAG_SET (actually CLD_FLAG_CLEARED...) and call insns
> wouldn't set MODE_UNINITIALIZED anymore. If we specify MODE_EXIT as
> CLD_FLAG_CLEARED, then optimize_mode_switching pass will automatically
> emmit cld after every asm statement, fulfilling ABI requirement about
> exit mode.
> 
> Is this thinking pushing cld optimization too far?

No, I think that's exactly the right approach.  The only problem I could 
see are functions written completely in asm, where the author did STD and 
forgot about the ABI (i.e. didn't CLD before exit).  They happen to work 
right now, but will fail working with those changes.  IMHO such routines 
would be extremely rare, if they exist at all, so that shouldn't hinder 
full progress by using mode switching for the direction flag.


Ciao,
Michael.



More information about the Gcc-patches mailing list