61e0427b5c9050273cacec8bcf9b37cada4dc8b9
[dragonfly.git] / lib / libc / amd64 / string / bzero.S
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  * $NetBSD: bzero.S,v 1.2 2003/07/26 19:24:38 salo Exp $
7  * $FreeBSD: src/lib/libc/amd64/string/bzero.S,v 1.3 2008/11/02 01:10:54 peter Exp $
8  */
9
10 #include <machine/asm.h>
11
12 ENTRY(bzero)
13         cld                             /* set fill direction forward */
14         xorq    %rax,%rax               /* set fill data to 0 */
15
16         /*
17          * if the string is too short, it's really not worth the overhead
18          * of aligning to word boundries, etc.  So we jump to a plain
19          * unaligned set.
20          */
21         cmpq    $16,%rsi
22         jb      L1
23
24         movq    %rdi,%rcx               /* compute misalignment */
25         negq    %rcx
26         andq    $7,%rcx
27         subq    %rcx,%rsi
28         rep                             /* zero until word aligned */
29         stosb
30
31         movq    %rsi,%rcx               /* zero by words */
32         shrq    $3,%rcx
33         andq    $7,%rsi
34         rep
35         stosq
36
37 L1:     movq    %rsi,%rcx               /* zero remainder by bytes */
38         rep
39         stosb
40
41         ret
42 END(bzero)