Home | History | Annotate | Line # | Download | only in string
memset.S revision 1.1
      1 /*
      2  * Written by J.T. Conklin <jtc (at) NetBSD.org>.
      3  * Public domain.
      4  * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl (at) wasabisystems.com>
      5  */
      6 
      7 #include <machine/asm.h>
      8 
      9 #if defined(LIBC_SCCS)
     10 	RCSID("$NetBSD: memset.S,v 1.1 2005/12/20 19:28:51 christos Exp $")
     11 #endif
     12 
     13 ENTRY(memset)
     14 	movq	%rsi,%rax
     15 	andq	$0xff,%rax
     16 	movq	%rdx,%rcx
     17 	movq	%rdi,%r11
     18 
     19 	cld				/* set fill direction forward */
     20 
     21 	/*
     22 	 * if the string is too short, it's really not worth the overhead
     23 	 * of aligning to word boundries, etc.  So we jump to a plain
     24 	 * unaligned set.
     25 	 */
     26 	cmpq	$0x0f,%rcx
     27 	jle	L1
     28 
     29 	movb	%al,%ah			/* copy char to all bytes in word */
     30 	movl	%eax,%edx
     31 	sall	$16,%eax
     32 	orl	%edx,%eax
     33 
     34 	movl	%eax,%edx
     35 	salq	$32,%rax
     36 	orq	%rdx,%rax
     37 
     38 	movq	%rdi,%rdx		/* compute misalignment */
     39 	negq	%rdx
     40 	andq	$7,%rdx
     41 	movq	%rcx,%r8
     42 	subq	%rdx,%r8
     43 
     44 	movq	%rdx,%rcx		/* set until word aligned */
     45 	rep
     46 	stosb
     47 
     48 	movq	%r8,%rcx
     49 	shrq	$3,%rcx			/* set by words */
     50 	rep
     51 	stosq
     52 
     53 	movq	%r8,%rcx		/* set remainder by bytes */
     54 	andq	$7,%rcx
     55 L1:	rep
     56 	stosb
     57 	movq	%r11,%rax
     58 
     59 	ret
     60