about summary refs log tree commit diff
path: root/sysdeps/x86_64/multiarch/memset-avx2.S
blob: 0de08002d78e6cc8921b8ddc639a720f12390688 (plain) (blame)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* memset with AVX2
   Copyright (C) 2014 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <sysdep.h>

#if IS_IN (libc)

#include "asm-syntax.h"
#ifndef MEMSET
# define MEMSET	__memset_avx2
# define MEMSET_CHK	__memset_chk_avx2
#endif

	.section .text.avx2,"ax",@progbits
#if defined PIC
ENTRY (MEMSET_CHK)
	cmpq	%rdx, %rcx
	jb	HIDDEN_JUMPTARGET (__chk_fail)
END (MEMSET_CHK)
#endif

ENTRY (MEMSET)
	vpxor	%xmm0, %xmm0, %xmm0
	vmovd	%esi, %xmm1
	lea	(%rdi, %rdx), %rsi
	mov	%rdi, %rax
	vpshufb	%xmm0, %xmm1, %xmm0
	cmp	$16, %rdx
	jb	L(less_16bytes)
	cmp	$256, %rdx
	jae	L(256bytesormore)
	cmp	$128, %dl
	jb	L(less_128bytes)
	vmovdqu	%xmm0, (%rdi)
	vmovdqu %xmm0, 0x10(%rdi)
	vmovdqu %xmm0, 0x20(%rdi)
	vmovdqu %xmm0, 0x30(%rdi)
	vmovdqu %xmm0, 0x40(%rdi)
	vmovdqu %xmm0, 0x50(%rdi)
	vmovdqu %xmm0, 0x60(%rdi)
	vmovdqu %xmm0, 0x70(%rdi)
	vmovdqu %xmm0, -0x80(%rsi)
	vmovdqu %xmm0, -0x70(%rsi)
	vmovdqu %xmm0, -0x60(%rsi)
	vmovdqu %xmm0, -0x50(%rsi)
	vmovdqu %xmm0, -0x40(%rsi)
	vmovdqu %xmm0, -0x30(%rsi)
	vmovdqu %xmm0, -0x20(%rsi)
	vmovdqu %xmm0, -0x10(%rsi)
	ret

	.p2align 4
L(less_128bytes):
	cmp	$64, %dl
	jb	L(less_64bytes)
	vmovdqu %xmm0, (%rdi)
	vmovdqu %xmm0, 0x10(%rdi)
	vmovdqu %xmm0, 0x20(%rdi)
	vmovdqu %xmm0, 0x30(%rdi)
	vmovdqu %xmm0, -0x40(%rsi)
	vmovdqu %xmm0, -0x30(%rsi)
	vmovdqu %xmm0, -0x20(%rsi)
	vmovdqu %xmm0, -0x10(%rsi)
	ret

	.p2align 4
L(less_64bytes):
	cmp	$32, %dl
	jb	L(less_32bytes)
	vmovdqu %xmm0, (%rdi)
	vmovdqu %xmm0, 0x10(%rdi)
	vmovdqu %xmm0, -0x20(%rsi)
	vmovdqu %xmm0, -0x10(%rsi)
	ret

	.p2align 4
L(less_32bytes):
	vmovdqu %xmm0, (%rdi)
	vmovdqu %xmm0, -0x10(%rsi)
	ret

	.p2align 4
L(less_16bytes):
	cmp	$8, %dl
	jb	L(less_8bytes)
	vmovq %xmm0, (%rdi)
	vmovq %xmm0, -0x08(%rsi)
	ret

	.p2align 4
L(less_8bytes):
	vmovd	%xmm0, %ecx
	cmp	$4, %dl
	jb	L(less_4bytes)
	mov	%ecx, (%rdi)
	mov	%ecx, -0x04(%rsi)
	ret

	.p2align 4
L(less_4bytes):
	cmp	$2, %dl
	jb	L(less_2bytes)
	mov	%cx, (%rdi)
	mov	%cx, -0x02(%rsi)
	ret

	.p2align 4
L(less_2bytes):
	cmp	$1, %dl
	jb	L(less_1bytes)
	mov	%cl, (%rdi)
L(less_1bytes):
	ret

	.p2align 4
L(256bytesormore):
	vinserti128 $1, %xmm0, %ymm0, %ymm0
	and	$-0x20, %rdi
	add	$0x20, %rdi
	vmovdqu	%ymm0, (%rax)
	sub	%rdi, %rax
	lea	-0x80(%rax, %rdx), %rcx
	cmp	$4096, %rcx
	ja	L(gobble_data)
L(gobble_128_loop):
	vmovdqa	%ymm0, (%rdi)
	vmovdqa	%ymm0, 0x20(%rdi)
	vmovdqa	%ymm0, 0x40(%rdi)
	vmovdqa	%ymm0, 0x60(%rdi)
	sub	$-0x80, %rdi
	add	$-0x80, %ecx
	jb	L(gobble_128_loop)
	mov	%rsi, %rax
	vmovdqu	%ymm0, -0x80(%rsi)
	vmovdqu	%ymm0, -0x60(%rsi)
	vmovdqu	%ymm0, -0x40(%rsi)
	vmovdqu	%ymm0, -0x20(%rsi)
	sub	%rdx, %rax
	vzeroupper
	ret

	.p2align 4
L(gobble_data):
	sub	$-0x80, %rcx
	vmovd	%xmm0, %eax
	rep	stosb
	mov	%rsi, %rax
	sub	%rdx, %rax
	vzeroupper
	ret

END (MEMSET)
#endif