1 /* memcpy for RISC-V, ignoring buffer alignment
2 Copyright (C) 2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
22 /* void *memcpy(void *, const void *, size_t) */
23 ENTRY (__memcpy_noalignment)
24 move t6, a0 /* Preserve return value */
29 /* Jump to byte copy if size < SZREG */
33 /* Round down to the nearest "page" size */
34 andi a4, a2, ~((16*SZREG)-1)
38 /* Copy the first word to get dest word aligned */
44 /* Align dst up to a word, move src and size as well. */
46 andi t6, t6, ~(SZREG-1)
51 /* Recompute page count */
52 andi a4, a2, ~((16*SZREG)-1)
56 /* Copy "pages" (chunks of 16 registers) */
77 REG_L a4, 10*SZREG(a1)
78 REG_L a5, 11*SZREG(a1)
79 REG_L a6, 12*SZREG(a1)
80 REG_L a7, 13*SZREG(a1)
81 REG_L t0, 14*SZREG(a1)
82 REG_L t1, 15*SZREG(a1)
84 REG_S a4, 10*SZREG(t6)
85 REG_S a5, 11*SZREG(t6)
86 REG_S a6, 12*SZREG(t6)
87 REG_S a7, 13*SZREG(t6)
88 REG_S t0, 14*SZREG(t6)
89 REG_S t1, 15*SZREG(t6)
92 andi a2, a2, (16*SZREG)-1 /* Update count */
95 /* Remainder is smaller than a page, compute native word count */
97 andi a5, a2, ~(SZREG-1)
98 andi a2, a2, (SZREG-1)
100 /* Jump directly to last word if no words. */
104 /* Use single native register copy */
111 /* Jump directly out if no more bytes */
115 /* Copy the last word unaligned */
123 /* Copy bytes when the total copy is <SZREG */
136 END (__memcpy_noalignment)