This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, i386]: Emit cld instruction when stringops are used


On Mar 6, 2008, at 7:55 AM, Uros Bizjak wrote:

Hello!

This patch adds back generation of cld instructions when stringops are
used in the function. cld insn is emitted as unspec volatile at the
end of function prologue. Currently, patched gcc emits cld when
"-mcld" is added to compile flags.

Currently, there is no configure-time support, I think we should first
reach a consensus on how to configure this. We can

If I understand the issue correctly, this patch is insufficient. You should also have GCC emit a cld instruction before any inline asm. Do you think it's a good idea to add a 52 cycle delay (on the P4) to any function that uses inline asm?


-Chris



./configure --with-cld (or something), where no cld generation is default.

Anyway the code for:

--cut here--
extern void *memcpy (void *, const void *, __SIZE_TYPE__);

int foo[10];
int bar[10];

char baz[15];
char quux[15];

void
do_copy ()
{
 memcpy (foo, bar, sizeof foo);
 memcpy (baz, quux, sizeof baz);
}
--cut here--

now generates (gcc -Os):

do_copy:
       pushl   %ebp
       movl    %esp, %ebp
       pushl   %edi
       pushl   %esi
       subl    $8, %esp
       cld                                       <- here
       movl    $foo, %edi
       movl    $bar, %esi
       movl    $10, %ecx
       rep movsl
       movl    $baz, %edi
       movl    $quux, %esi
       movb    $15, %cl
       rep movsb
       popl    %eax
       popl    %edx
       popl    %esi
       popl    %edi
       popl    %ebp
       ret

2008-03-06 Uros Bizjak <ubizjak@gmail.com>

	* config/i386/i386.h (TARGET_CLD): New define.
	(struct machine_function): Add needs_cld field.
	(ix86_current_function_needs_cld): New define.
	* config/i386/i386.md (UNSPEC_CLD): New unspec volatile constant.
	("cld"): New isns pattern.
	("strmov_singleop"): Set ix86_current_function_needs_cld flag.
	("rep_mov"): Ditto.
	("strset_singleop"): Ditto.
	("rep_stos"): Ditto.
	("cmpstrnqi_nz_1"): Ditto.
	("cmpstrnqi_1"): Ditto.
	("strlenqi_1"): Ditto.
	* config/i386/i386.opt (mcld): New option.
	* config/i386/i386.c (ix86_expand_prologue): Emit cld insn for
	TARGET_CLD when ix86_current_function_needs_cld is set.

The patch was bootstrapped on i686-pc-linux-gnu, regression test with
-mcld is in progress.

Uros.
<p.diff.txt>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]