Home | History | Annotate | Line # | Download | only in string
memset.S revision 1.2
      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.2        ad 	RCSID("$NetBSD: memset.S,v 1.2 2007/11/12 18:41:59 ad 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 	/*
     20  1.1  christos 	 * if the string is too short, it's really not worth the overhead
     21  1.1  christos 	 * of aligning to word boundries, etc.  So we jump to a plain
     22  1.1  christos 	 * unaligned set.
     23  1.1  christos 	 */
     24  1.1  christos 	cmpq	$0x0f,%rcx
     25  1.1  christos 	jle	L1
     26  1.1  christos 
     27  1.1  christos 	movb	%al,%ah			/* copy char to all bytes in word */
     28  1.1  christos 	movl	%eax,%edx
     29  1.1  christos 	sall	$16,%eax
     30  1.1  christos 	orl	%edx,%eax
     31  1.1  christos 
     32  1.1  christos 	movl	%eax,%edx
     33  1.1  christos 	salq	$32,%rax
     34  1.1  christos 	orq	%rdx,%rax
     35  1.1  christos 
     36  1.1  christos 	movq	%rdi,%rdx		/* compute misalignment */
     37  1.1  christos 	negq	%rdx
     38  1.1  christos 	andq	$7,%rdx
     39  1.1  christos 	movq	%rcx,%r8
     40  1.1  christos 	subq	%rdx,%r8
     41  1.1  christos 
     42  1.1  christos 	movq	%rdx,%rcx		/* set until word aligned */
     43  1.1  christos 	rep
     44  1.1  christos 	stosb
     45  1.1  christos 
     46  1.1  christos 	movq	%r8,%rcx
     47  1.1  christos 	shrq	$3,%rcx			/* set by words */
     48  1.1  christos 	rep
     49  1.1  christos 	stosq
     50  1.1  christos 
     51  1.1  christos 	movq	%r8,%rcx		/* set remainder by bytes */
     52  1.1  christos 	andq	$7,%rcx
     53  1.1  christos L1:	rep
     54  1.1  christos 	stosb
     55  1.1  christos 	movq	%r11,%rax
     56  1.1  christos 
     57  1.1  christos 	ret
     58