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)
31 jz .Lmemmove_forward_remainder
32 .Lmemmove_forward_loop:
36 brctg %r0,.Lmemmove_forward_loop
37 .Lmemmove_forward_remainder:
38 larl %r5,.Lmemmove_mvc
45 brctg %r4,.Lmemmove_reverse
52 EXPORT_SYMBOL(memmove)
55 * memset implementation
57 * This code corresponds to the C construct below. We do distinguish
58 * between clearing (c == 0) and setting a memory array (c != 0) simply
59 * because nearly all memset invocations in the kernel clear memory and
60 * the xc instruction is preferred in such cases.
62 * void *memset(void *s, int c, size_t n)
65 * return __builtin_memset(s, 0, n);
66 * return __builtin_memset(s, c, n);
79 jz .Lmemset_clear_remainder
83 brctg %r3,.Lmemset_clear_loop
84 .Lmemset_clear_remainder:
96 jz .Lmemset_fill_remainder
101 brctg %r5,.Lmemset_fill_loop
102 .Lmemset_fill_remainder:
104 larl %r5,.Lmemset_mvc
115 EXPORT_SYMBOL(memset)
118 * memcpy implementation
120 * void *memcpy(void *dest, const void *src, size_t n)
132 larl %r5,.Lmemcpy_mvc
137 mvc 0(256,%r1),0(%r3)
140 brctg %r5,.Lmemcpy_loop
145 EXPORT_SYMBOL(memcpy)
150 * void *__memset16(uint16_t *s, uint16_t v, size_t count)
151 * void *__memset32(uint32_t *s, uint32_t v, size_t count)
152 * void *__memset64(uint64_t *s, uint64_t v, size_t count)
154 .macro __MEMSET bits,bytes,insn
157 jz .L__memset_exit\bits
159 je .L__memset_store\bits
164 jz .L__memset_remainder\bits
165 .L__memset_loop\bits:
167 mvc \bytes(256-\bytes,%r1),0(%r1)
169 brctg %r5,.L__memset_loop\bits
170 .L__memset_remainder\bits:
172 larl %r5,.L__memset_mvc\bits
175 .L__memset_store\bits:
177 .L__memset_exit\bits:
180 mvc \bytes(1,%r1),0(%r1)
181 ENDPROC(__memset\bits)
185 EXPORT_SYMBOL(__memset16)
188 EXPORT_SYMBOL(__memset32)
191 EXPORT_SYMBOL(__memset64)