source: trunk/libs/newlib/src/newlib/libc/machine/x86_64/memset.S @ 690

Last change on this file since 690 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.7 KB
Line 
1/*
2 * ====================================================
3 * Copyright (C) 2007 by Ellips BV. All rights reserved.
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software is freely granted, provided that this notice
7 * is preserved.
8 * ====================================================
9 */
10
11  #include "x86_64mach.h"
12
13  .global SYM (memset)
14  SOTYPE_FUNCTION(memset)
15
16SYM (memset):
17  movq    rdi, r9                 /* Save return value */
18  movq    rsi, rax
19  movq    rdx, rcx
20  cmpq    $16, rdx
21  jb      byte_set
22
23  movq    rdi, r8                 /* Align on quad word boundary */
24  andq    $7, r8
25  jz      quadword_aligned
26  movq    $8, rcx
27  subq    r8, rcx
28  subq    rcx, rdx
29  rep     stosb
30  movq    rdx, rcx
31
32quadword_aligned:
33  movabs  $0x0101010101010101, r8
34  movzbl  sil, eax
35  imul    r8, rax
36  cmpq    $256, rdx
37  jb      quadword_set
38
39  shrq    $7, rcx                 /* Store 128 bytes at a time with minimum cache polution */
40
41  .p2align 4
42loop:
43  movntiq rax,     (rdi)
44  movntiq rax,   8 (rdi)
45  movntiq rax,  16 (rdi)
46  movntiq rax,  24 (rdi)
47  movntiq rax,  32 (rdi)
48  movntiq rax,  40 (rdi)
49  movntiq rax,  48 (rdi)
50  movntiq rax,  56 (rdi)
51  movntiq rax,  64 (rdi)
52  movntiq rax,  72 (rdi)
53  movntiq rax,  80 (rdi)
54  movntiq rax,  88 (rdi)
55  movntiq rax,  96 (rdi)
56  movntiq rax, 104 (rdi)
57  movntiq rax, 112 (rdi)
58  movntiq rax, 120 (rdi)
59
60  leaq    128 (rdi), rdi
61
62  dec     rcx
63  jnz     loop
64
65  sfence
66  movq    rdx, rcx
67  andq    $127, rcx
68  rep     stosb
69  movq    r9, rax
70  ret
71
72
73byte_set:
74  rep     stosb
75  movq    r9, rax
76  ret
77
78
79quadword_set:
80  shrq    $3, rcx
81  .p2align 4
82  rep     stosq
83  movq    rdx, rcx
84  andq    $7, rcx
85  rep     stosb                   /* Store the remaining bytes */
86  movq    r9, rax
87  ret
88
Note: See TracBrowser for help on using the repository browser.