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