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