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