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 andq $0xff,%rax 12 movq %rdx,%rcx 13 movq %rdi,%r11 14 15 /* 16 * if the string is too short, it's really not worth the overhead 17 * of aligning to word boundaries, etc. So we jump to a plain 18 * unaligned set. 19 */ 20 cmpq $0x0f,%rcx 21 jle L1 22 23 movb %al,%ah /* copy char to all bytes in word */ 24 movl %eax,%edx 25 sall $16,%eax 26 orl %edx,%eax 27 28 movl %eax,%edx 29 salq $32,%rax 30 orq %rdx,%rax 31 32 movq %rdi,%rdx /* compute misalignment */ 33 negq %rdx 34 andq $7,%rdx 35 movq %rcx,%r8 36 subq %rdx,%r8 37 38 movq %rdx,%rcx /* set until word aligned */ 39 rep 40 stosb 41 42 movq %r8,%rcx 43 shrq $3,%rcx /* set by words */ 44 rep 45 stosq 46 47 movq %r8,%rcx /* set remainder by bytes */ 48 andq $7,%rcx 49L1: rep 50 stosb 51 movq %r11,%rax 52 53 ret 54