Welcome to mirror list, hosted at ThFree Co, Russian Federation.

memset.S « x86_64 « machine « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ba53e3c821e68d6632ea6d85b838110cbc13621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * ====================================================
 * Copyright (C) 2007 by Ellips BV. All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

  #include "x86_64mach.h"

  .global SYM (memset)
  SOTYPE_FUNCTION(memset)

SYM (memset):
  movq    rdi, r9                 /* Save return value */
  movq    rsi, rax
  movq    rdx, rcx
  cmpq    $16, rdx
  jb      byte_set

  movq    rdi, r8                 /* Align on quad word boundary */
  andq    $7, r8
  jz      quadword_aligned
  movq    $8, rcx
  subq    r8, rcx
  subq    rcx, rdx
  rep     stosb
  movq    rdx, rcx

quadword_aligned:
  movabs  $0x0101010101010101, r8
  movzbl  sil, eax
  imul    r8, rax
  cmpq    $256, rdx
  jb      quadword_set

  shrq    $7, rcx                 /* Store 128 bytes at a time with minimum cache polution */

  .p2align 4
loop:
  movntiq rax,     (rdi)
  movntiq rax,   8 (rdi)
  movntiq rax,  16 (rdi)
  movntiq rax,  24 (rdi)
  movntiq rax,  32 (rdi)
  movntiq rax,  40 (rdi)
  movntiq rax,  48 (rdi)
  movntiq rax,  56 (rdi)
  movntiq rax,  64 (rdi)
  movntiq rax,  72 (rdi)
  movntiq rax,  80 (rdi)
  movntiq rax,  88 (rdi)
  movntiq rax,  96 (rdi)
  movntiq rax, 104 (rdi)
  movntiq rax, 112 (rdi)
  movntiq rax, 120 (rdi)

  leaq    128 (rdi), rdi

  dec     rcx
  jnz     loop

  sfence
  movq    rdx, rcx
  andq    $127, rcx
  rep     stosb
  movq    r9, rax
  ret


byte_set:
  rep     stosb
  movq    r9, rax
  ret


quadword_set:
  shrq    $3, rcx
  .p2align 4
  rep     stosq
  movq    rdx, rcx
  andq    $7, rcx
  rep     stosb                   /* Store the remaining bytes */
  movq    r9, rax
  ret