1 /* Optimized unaligned memcpy implementation using basic LoongArch instructions.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <https://www.gnu.org/licenses/>. */
21 #include <sys/regdef.h>
26 # define MEMCPY_NAME __memcpy_unaligned
28 # define LD_64(reg, n) \
30 ld.d t1, reg, n + 8; \
31 ld.d t2, reg, n + 16; \
32 ld.d t3, reg, n + 24; \
33 ld.d t4, reg, n + 32; \
34 ld.d t5, reg, n + 40; \
35 ld.d t6, reg, n + 48; \
38 # define ST_64(reg, n) \
40 st.d t1, reg, n + 8; \
41 st.d t2, reg, n + 16; \
42 st.d t3, reg, n + 24; \
43 st.d t4, reg, n + 32; \
44 st.d t5, reg, n + 40; \
45 st.d t6, reg, n + 48; \
52 bge a6, a2, L(less_16bytes)
55 blt a6, a2, L(long_bytes)
57 blt a6, a2, L(more_64bytes)
60 blt a6, a2, L(more_32bytes)
99 blt zero, a7, L(loop_32)
138 beqz a6, L(less_8bytes)
149 beqz a6, L(less_4bytes)
160 beqz a6, L(less_2bytes)
170 beqz a2, L(less_1bytes)
192 blt a5, t8, L(align_end_proc)
201 bge a5, t8, L(loop_128)
246 libc_hidden_builtin_def (MEMCPY_NAME)