This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH, i386]: Emit cld instruction when stringops are used
Let's not muddy the water by dragging an irrelevant topic (inline asm)
into the discussion.
On Fri, 7 Mar 2008, Chris Lattner wrote:
> >Because it relies on the direction flag clear which is neither
> >guaranteed by the ABI, nor was ensured by GCC in previous releases.
> You seem confused. The i386 psABI explicitly states:
No he isn't. The DF flag is clear on entry and exit of functions. How it
behaves inside the function is of no concern to the ABI. Inline asm is
completely outside the scope, and instead is of interest to the code
generator of GCC only. Inline asm authors simply have to cope with that,
and they do.
There are no documented guarantees on how DF is set or not set on entry of
asm blocks, hence there are none. The most conservative assumption for
asm authors would be to not touch the flag at all, the next (still
working) guidance would to leave asms with DF clear. But GCC won't ever
prevent you from doing otherwise and shooting yourself, like it won't
prevent you from or taking care of clobbering the PIC register in inline
If inline asm authors want to rely on DF being clear on function entry
they have to write their asms at the start of a function, and even then
they won't have this guarantee (as GCC is free to emit whatever code it
wants to between entry point and asm start, that is true also for volatile
asm). The only way for asm authors to exploit the ABI guarantee at all is
by writing naked asm functions without prologue, at which point it makes
more sense to just write them in an .S file yourself. Then you can enjoy
the ABI guarantees, but also need to take care to not break them.