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
|
/*
Copyright 2022 Gabriel Jensen
This file is part of rgo.
rgo is free software: you can reaxstribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
rgo 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 rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
.global rgo_memcpy
rgo_memcpy:
/*
void const * in
size_t num
void * out
*/
#if defined(__i386__)
/* eax: Address of the current input element. */
movl 0x4(%esp),%eax
/* ecx: Number of remaining elements. */
movl 0x8(%esp),%ecx
/* edx: Address of the current output element. */
movl 0xC(%esp),%edx
/* ebx: Current element. */
pushl %ebx /* ebx must be restored. */
/* xmm0: Current element. */
/* ymm0: Current element. */
#if defined(__AVX__)
.big256cpy:
cmpl $0x20,%ecx
#if defined(__SSE__)
jl .big128cpy
#else
jl .wrdcpy
#endif
vmovdqu (%eax),%ymm0
vmovdqu %ymm0,(%edx)
addl $0x20,%eax
addl $0x20,%edx
subl $0x20,%ecx
jmp .big256cpy
#endif
#if defined(__SSE__)
.big128cpy:
cmpl $0x10,%ecx
jl .wrdcpy
#if defined(__SSE2__)
movdqu (%eax),%xmm0
movdqu %xmm0,(%edx)
#else
movups (%eax),%xmm0
movups %xmm0,(%edx)
#endif
addl $0x10,%eax
addl $0x10,%edx
subl $0x10,%ecx
jmp .big128cpy
#endif
.wrdcpy:
cmpl $0x4,%ecx
jl .bytecpy
movl (%eax),%ebx
movl %ebx,(%edx)
addl $0x4,%eax
addl $0x4,%edx
subl $0x4,%ecx
jmp .wrdcpy
.bytecpy:
testl %ecx,%ecx
jz .done
movb (%eax),%bl
movb %bl,(%edx)
incl %eax
incl %edx
decl %ecx
jmp .bytecpy
.done:
popl %ebx
ret
#elif defined(__x86_64__)
/* rdi: Address of the current input element. */
/* rsi: Number of remaining elements. */
/* rdx: Address of the current output element. */
/* rcx: Current element. */
/* xmm0: Current element. */
/* ymm0: Current element. */
#if defined(__AVX__)
.big256cpy:
cmpq $0x20,%rsi
jl .big128cpy
vmovups (%rdi),%ymm0
vmovups %ymm0,(%rdx)
addq $0x20,%rdi
addq $0x20,%rdx
subq $0x20,%rsi
jmp .big256cpy
#endif
.big128cpy:
cmpq $0x10,%rsi
jl .wrdcpy
movdqu (%rdi),%xmm0
movdqu %xmm0,(%rdx)
addq $0x10,%rdi
addq $0x10,%rdx
subq $0x10,%rsi
jmp .big128cpy
.wrdcpy:
cmpq $0x8,%rsi
jl .bytecpy
movq (%rdi),%rcx
movq %rcx,(%rdx)
addq $0x8,%rdi
addq $0x8,%rdx
subq $0x8,%rsi
jmp .wrdcpy
.bytecpy:
testq %rsi,%rsi
jz .done
movb (%rdi),%cl
movb %cl,(%rdx)
incq %rdi
incq %rdx
decq %rsi
jmp .bytecpy
.done:
ret
#endif
|