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
43 brctg %r4,.Lmemmove_reverse
49 EXPORT_SYMBOL(memmove)
52 * memset implementation
54 * This code corresponds to the C construct below. We do distinguish
55 * between clearing (c == 0) and setting a memory array (c != 0) simply
56 * because nearly all memset invocations in the kernel clear memory and
57 * the xc instruction is preferred in such cases.
59 * void *memset(void *s, int c, size_t n)
62 * return __builtin_memset(s, 0, n);
63 * return __builtin_memset(s, c, n);
75 jz .Lmemset_clear_remainder
79 brctg %r3,.Lmemset_clear_loop
80 .Lmemset_clear_remainder:
91 jz .Lmemset_fill_remainder
96 brctg %r5,.Lmemset_fill_loop
97 .Lmemset_fill_remainder:
109 EXPORT_SYMBOL(memset)
112 * memcpy implementation
114 * void *memcpy(void *dest, const void *src, size_t n)
125 larl %r5,.Lmemcpy_mvc
129 mvc 0(256,%r1),0(%r3)
132 brctg %r5,.Lmemcpy_loop
136 EXPORT_SYMBOL(memcpy)
141 * void *__memset16(uint16_t *s, uint16_t v, size_t count)
142 * void *__memset32(uint32_t *s, uint32_t v, size_t count)
143 * void *__memset64(uint64_t *s, uint64_t v, size_t count)
145 .macro __MEMSET bits,bytes,insn
150 je .L__memset_exit\bits
155 jz .L__memset_remainder\bits
156 .L__memset_loop\bits:
158 mvc \bytes(256-\bytes,%r1),0(%r1)
160 brctg %r5,.L__memset_loop\bits
161 .L__memset_remainder\bits:
163 larl %r5,.L__memset_mvc\bits
166 .L__memset_exit\bits:
170 mvc \bytes(1,%r1),0(%r1)
174 EXPORT_SYMBOL(__memset16)
177 EXPORT_SYMBOL(__memset32)
180 EXPORT_SYMBOL(__memset64)