xref: /linux/arch/s390/lib/mem.S (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1/*
2 * String handling functions.
3 *
4 * Copyright IBM Corp. 2012
5 */
6
7#include <linux/linkage.h>
8
9/*
10 * memset implementation
11 *
12 * This code corresponds to the C construct below. We do distinguish
13 * between clearing (c == 0) and setting a memory array (c != 0) simply
14 * because nearly all memset invocations in the kernel clear memory and
15 * the xc instruction is preferred in such cases.
16 *
17 * void *memset(void *s, int c, size_t n)
18 * {
19 *	if (likely(c == 0))
20 *		return __builtin_memset(s, 0, n);
21 *	return __builtin_memset(s, c, n);
22 * }
23 */
24ENTRY(memset)
25	ltgr	%r4,%r4
26	bzr	%r14
27	ltgr	%r3,%r3
28	jnz	.Lmemset_fill
29	aghi	%r4,-1
30	srlg	%r3,%r4,8
31	ltgr	%r3,%r3
32	lgr	%r1,%r2
33	jz	.Lmemset_clear_rest
34.Lmemset_clear_loop:
35	xc	0(256,%r1),0(%r1)
36	la	%r1,256(%r1)
37	brctg	%r3,.Lmemset_clear_loop
38.Lmemset_clear_rest:
39	larl	%r3,.Lmemset_xc
40	ex	%r4,0(%r3)
41	br	%r14
42.Lmemset_fill:
43	stc	%r3,0(%r2)
44	cghi	%r4,1
45	lgr	%r1,%r2
46	ber	%r14
47	aghi	%r4,-2
48	srlg	%r3,%r4,8
49	ltgr	%r3,%r3
50	jz	.Lmemset_fill_rest
51.Lmemset_fill_loop:
52	mvc	1(256,%r1),0(%r1)
53	la	%r1,256(%r1)
54	brctg	%r3,.Lmemset_fill_loop
55.Lmemset_fill_rest:
56	larl	%r3,.Lmemset_mvc
57	ex	%r4,0(%r3)
58	br	%r14
59.Lmemset_xc:
60	xc	0(1,%r1),0(%r1)
61.Lmemset_mvc:
62	mvc	1(1,%r1),0(%r1)
63
64/*
65 * memcpy implementation
66 *
67 * void *memcpy(void *dest, const void *src, size_t n)
68 */
69ENTRY(memcpy)
70	ltgr	%r4,%r4
71	bzr	%r14
72	aghi	%r4,-1
73	srlg	%r5,%r4,8
74	ltgr	%r5,%r5
75	lgr	%r1,%r2
76	jnz	.Lmemcpy_loop
77.Lmemcpy_rest:
78	larl	%r5,.Lmemcpy_mvc
79	ex	%r4,0(%r5)
80	br	%r14
81.Lmemcpy_loop:
82	mvc	0(256,%r1),0(%r3)
83	la	%r1,256(%r1)
84	la	%r3,256(%r3)
85	brctg	%r5,.Lmemcpy_loop
86	j	.Lmemcpy_rest
87.Lmemcpy_mvc:
88	mvc	0(1,%r1),0(%r3)
89