1 /* Multiple versions of memcpy.
2 All versions must be listed in ifunc-impl-list.c.
3 Copyright (C) 2017-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 /* Redefine memcpy so that the compiler won't complain about the type
22 mismatch with the IFUNC selector in strong_alias, below. */
24 # define memcpy __redirect_memcpy
27 # include <ifunc-init.h>
28 # include <riscv-ifunc.h>
29 # include <sys/hwprobe.h>
31 extern __typeof (__redirect_memcpy
) __libc_memcpy
;
33 extern __typeof (__redirect_memcpy
) __memcpy_generic attribute_hidden
;
34 extern __typeof (__redirect_memcpy
) __memcpy_noalignment attribute_hidden
;
36 static inline __typeof (__redirect_memcpy
) *
37 select_memcpy_ifunc (uint64_t dl_hwcap
, __riscv_hwprobe_t hwprobe_func
)
39 unsigned long long int v
;
40 if (__riscv_hwprobe_one (hwprobe_func
, RISCV_HWPROBE_KEY_CPUPERF_0
, &v
) == 0
41 && (v
& RISCV_HWPROBE_MISALIGNED_MASK
) == RISCV_HWPROBE_MISALIGNED_FAST
)
42 return __memcpy_noalignment
;
44 return __memcpy_generic
;
47 riscv_libc_ifunc (__libc_memcpy
, select_memcpy_ifunc
);
50 strong_alias (__libc_memcpy
, memcpy
);
52 __hidden_ver1 (memcpy
, __GI_memcpy
, __redirect_memcpy
)
53 __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memcpy
);
56 # include <string/memcpy.c>