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>
12 * void *memmove(void *dest, const void *src, size_t n)
27 jz .Lmemmove_forward_remainder
28 .Lmemmove_forward_loop:
32 brctg %r0,.Lmemmove_forward_loop
33 .Lmemmove_forward_remainder:
34 larl %r5,.Lmemmove_mvc
40 brctg %r4,.Lmemmove_reverse
46 EXPORT_SYMBOL(memmove)
49 * memset implementation
51 * This code corresponds to the C construct below. We do distinguish
52 * between clearing (c == 0) and setting a memory array (c != 0) simply
53 * because nearly all memset invocations in the kernel clear memory and
54 * the xc instruction is preferred in such cases.
56 * void *memset(void *s, int c, size_t n)
59 * return __builtin_memset(s, 0, n);
60 * return __builtin_memset(s, c, n);
72 jz .Lmemset_clear_remainder
76 brctg %r3,.Lmemset_clear_loop
77 .Lmemset_clear_remainder:
88 jz .Lmemset_fill_remainder
93 brctg %r5,.Lmemset_fill_loop
94 .Lmemset_fill_remainder:
106 EXPORT_SYMBOL(memset)
109 * memcpy implementation
111 * void *memcpy(void *dest, const void *src, size_t n)
122 larl %r5,.Lmemcpy_mvc
126 mvc 0(256,%r1),0(%r3)
129 brctg %r5,.Lmemcpy_loop
133 EXPORT_SYMBOL(memcpy)
138 * void *__memset16(uint16_t *s, uint16_t v, size_t count)
139 * void *__memset32(uint32_t *s, uint32_t v, size_t count)
140 * void *__memset64(uint64_t *s, uint64_t v, size_t count)
142 .macro __MEMSET bits,bytes,insn
147 je .L__memset_exit\bits
152 jz .L__memset_remainder\bits
153 .L__memset_loop\bits:
155 mvc \bytes(256-\bytes,%r1),0(%r1)
157 brctg %r5,.L__memset_loop\bits
158 .L__memset_remainder\bits:
160 larl %r5,.L__memset_mvc\bits
163 .L__memset_exit\bits:
167 mvc \bytes(1,%r1),0(%r1)
171 EXPORT_SYMBOL(__memset16)
174 EXPORT_SYMBOL(__memset32)
177 EXPORT_SYMBOL(__memset64)