1/* 2 * Written by J.T. Conklin <jtc@netbsd.org>. 3 * Public domain. 4 */ 5 6#include <machine/asm.h> 7 8#if defined(LIBC_SCCS) 9 .text 10 .asciz "$OpenBSD: memset.S,v 1.2 1996/08/19 08:13:09 tholo Exp $" 11#endif 12 13ENTRY(memset) 14 pushl %edi 15 pushl %ebx 16 movl 12(%esp),%edi 17 movzbl 16(%esp),%eax /* unsigned char, zero extend */ 18 movl 20(%esp),%ecx 19 pushl %edi /* push address of buffer */ 20 21 cld /* set fill direction forward */ 22 23 /* 24 * if the string is too short, it's really not worth the overhead 25 * of aligning to word boundries, etc. So we jump to a plain 26 * unaligned set. 27 */ 28 cmpl $0x0f,%ecx 29 jle L1 30 31 movb %al,%ah /* copy char to all bytes in word */ 32 movl %eax,%edx 33 sall $16,%eax 34 orl %edx,%eax 35 36 movl %edi,%edx /* compute misalignment */ 37 negl %edx 38 andl $3,%edx 39 movl %ecx,%ebx 40 subl %edx,%ebx 41 42 movl %edx,%ecx /* set until word aligned */ 43 rep 44 stosb 45 46 movl %ebx,%ecx 47 shrl $2,%ecx /* set by words */ 48 rep 49 stosl 50 51 movl %ebx,%ecx /* set remainder by bytes */ 52 andl $3,%ecx 53L1: rep 54 stosb 55 56 popl %eax /* pop address of buffer */ 57 popl %ebx 58 popl %edi 59 ret 60