Home | History | Annotate | Download | only in string
      1 /*	$OpenBSD: memset.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */
      2 /*
      3  * Written by J.T. Conklin <jtc (at) netbsd.org>.
      4  * Public domain.
      5  */
      6 
      7 #include <machine/asm.h>
      8 
      9 ENTRY(memset)
     10 	pushl	%edi
     11 	pushl	%ebx
     12 	movl	12(%esp),%edi
     13 	movzbl	16(%esp),%eax		/* unsigned char, zero extend */
     14 	movl	20(%esp),%ecx
     15 	pushl	%edi			/* push address of buffer */
     16 
     17 	cld				/* set fill direction forward */
     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 	cmpl	$0x0f,%ecx
     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	%edi,%edx		/* compute misalignment */
     33 	negl	%edx
     34 	andl	$3,%edx
     35 	movl	%ecx,%ebx
     36 	subl	%edx,%ebx
     37 
     38 	movl	%edx,%ecx		/* set until word aligned */
     39 	rep
     40 	stosb
     41 
     42 	movl	%ebx,%ecx
     43 	shrl	$2,%ecx			/* set by words */
     44 	rep
     45 	stosl
     46 
     47 	movl	%ebx,%ecx		/* set remainder by bytes */
     48 	andl	$3,%ecx
     49 L1:	rep
     50 	stosb
     51 
     52 	popl	%eax			/* pop address of buffer */
     53 	popl	%ebx
     54 	popl	%edi
     55 	ret
     56