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