1 /* SPDX-License-Identifier: GPL-2.0 */
3 * String handling functions.
5 * Copyright IBM Corp. 2012
8 #include <linux/linkage.h>
9 #include <asm/export.h>
10 #include <asm/nospec-insn.h>
15 * void *memmove(void *dest, const void *src, size_t n)
30 jz .Lmemmove_forward_remainder
31 .Lmemmove_forward_loop:
35 brctg %r0,.Lmemmove_forward_loop
36 .Lmemmove_forward_remainder:
37 larl %r5,.Lmemmove_mvc
44 brctg %r4,.Lmemmove_reverse
50 EXPORT_SYMBOL(memmove)
53 * memset implementation
55 * This code corresponds to the C construct below. We do distinguish
56 * between clearing (c == 0) and setting a memory array (c != 0) simply
57 * because nearly all memset invocations in the kernel clear memory and
58 * the xc instruction is preferred in such cases.
60 * void *memset(void *s, int c, size_t n)
63 * return __builtin_memset(s, 0, n);
64 * return __builtin_memset(s, c, n);
76 jz .Lmemset_clear_remainder
80 brctg %r3,.Lmemset_clear_loop
81 .Lmemset_clear_remainder:
94 jz .Lmemset_fill_remainder
98 brctg %r3,.Lmemset_fill_loop
99 .Lmemset_fill_remainder:
100 larl %r3,.Lmemset_mvc
108 EXPORT_SYMBOL(memset)
111 * memcpy implementation
113 * void *memcpy(void *dest, const void *src, size_t n)
124 larl %r5,.Lmemcpy_mvc
129 mvc 0(256,%r1),0(%r3)
132 brctg %r5,.Lmemcpy_loop
136 EXPORT_SYMBOL(memcpy)