xref: /linux/arch/s390/include/asm/string.h (revision e0bf6c5ca2d3281f231c5f0c9bf145e9513644de)
1 /*
2  *  S390 version
3  *    Copyright IBM Corp. 1999
4  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
5  */
6 
7 #ifndef _S390_STRING_H_
8 #define _S390_STRING_H_
9 
10 #ifndef _LINUX_TYPES_H
11 #include <linux/types.h>
12 #endif
13 
14 #define __HAVE_ARCH_MEMCHR	/* inline & arch function */
15 #define __HAVE_ARCH_MEMCMP	/* arch function */
16 #define __HAVE_ARCH_MEMCPY	/* gcc builtin & arch function */
17 #define __HAVE_ARCH_MEMSCAN	/* inline & arch function */
18 #define __HAVE_ARCH_MEMSET	/* gcc builtin & arch function */
19 #define __HAVE_ARCH_STRCAT	/* inline & arch function */
20 #define __HAVE_ARCH_STRCMP	/* arch function */
21 #define __HAVE_ARCH_STRCPY	/* inline & arch function */
22 #define __HAVE_ARCH_STRLCAT	/* arch function */
23 #define __HAVE_ARCH_STRLCPY	/* arch function */
24 #define __HAVE_ARCH_STRLEN	/* inline & arch function */
25 #define __HAVE_ARCH_STRNCAT	/* arch function */
26 #define __HAVE_ARCH_STRNCPY	/* arch function */
27 #define __HAVE_ARCH_STRNLEN	/* inline & arch function */
28 #define __HAVE_ARCH_STRRCHR	/* arch function */
29 #define __HAVE_ARCH_STRSTR	/* arch function */
30 
31 /* Prototypes for non-inlined arch strings functions. */
32 extern int memcmp(const void *, const void *, size_t);
33 extern void *memcpy(void *, const void *, size_t);
34 extern void *memset(void *, int, size_t);
35 extern int strcmp(const char *,const char *);
36 extern size_t strlcat(char *, const char *, size_t);
37 extern size_t strlcpy(char *, const char *, size_t);
38 extern char *strncat(char *, const char *, size_t);
39 extern char *strncpy(char *, const char *, size_t);
40 extern char *strrchr(const char *, int);
41 extern char *strstr(const char *, const char *);
42 
43 #undef __HAVE_ARCH_MEMMOVE
44 #undef __HAVE_ARCH_STRCHR
45 #undef __HAVE_ARCH_STRNCHR
46 #undef __HAVE_ARCH_STRNCMP
47 #undef __HAVE_ARCH_STRPBRK
48 #undef __HAVE_ARCH_STRSEP
49 #undef __HAVE_ARCH_STRSPN
50 
51 #if !defined(IN_ARCH_STRING_C)
52 
53 static inline void *memchr(const void * s, int c, size_t n)
54 {
55 	register int r0 asm("0") = (char) c;
56 	const void *ret = s + n;
57 
58 	asm volatile(
59 		"0:	srst	%0,%1\n"
60 		"	jo	0b\n"
61 		"	jl	1f\n"
62 		"	la	%0,0\n"
63 		"1:"
64 		: "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
65 	return (void *) ret;
66 }
67 
68 static inline void *memscan(void *s, int c, size_t n)
69 {
70 	register int r0 asm("0") = (char) c;
71 	const void *ret = s + n;
72 
73 	asm volatile(
74 		"0:	srst	%0,%1\n"
75 		"	jo	0b\n"
76 		: "+a" (ret), "+&a" (s) : "d" (r0) : "cc");
77 	return (void *) ret;
78 }
79 
80 static inline char *strcat(char *dst, const char *src)
81 {
82 	register int r0 asm("0") = 0;
83 	unsigned long dummy;
84 	char *ret = dst;
85 
86 	asm volatile(
87 		"0:	srst	%0,%1\n"
88 		"	jo	0b\n"
89 		"1:	mvst	%0,%2\n"
90 		"	jo	1b"
91 		: "=&a" (dummy), "+a" (dst), "+a" (src)
92 		: "d" (r0), "0" (0) : "cc", "memory" );
93 	return ret;
94 }
95 
96 static inline char *strcpy(char *dst, const char *src)
97 {
98 	register int r0 asm("0") = 0;
99 	char *ret = dst;
100 
101 	asm volatile(
102 		"0:	mvst	%0,%1\n"
103 		"	jo	0b"
104 		: "+&a" (dst), "+&a" (src) : "d" (r0)
105 		: "cc", "memory");
106 	return ret;
107 }
108 
109 static inline size_t strlen(const char *s)
110 {
111 	register unsigned long r0 asm("0") = 0;
112 	const char *tmp = s;
113 
114 	asm volatile(
115 		"0:	srst	%0,%1\n"
116 		"	jo	0b"
117 		: "+d" (r0), "+a" (tmp) :  : "cc");
118 	return r0 - (unsigned long) s;
119 }
120 
121 static inline size_t strnlen(const char * s, size_t n)
122 {
123 	register int r0 asm("0") = 0;
124 	const char *tmp = s;
125 	const char *end = s + n;
126 
127 	asm volatile(
128 		"0:	srst	%0,%1\n"
129 		"	jo	0b"
130 		: "+a" (end), "+a" (tmp) : "d" (r0)  : "cc");
131 	return end - s;
132 }
133 #else /* IN_ARCH_STRING_C */
134 void *memchr(const void * s, int c, size_t n);
135 void *memscan(void *s, int c, size_t n);
136 char *strcat(char *dst, const char *src);
137 char *strcpy(char *dst, const char *src);
138 size_t strlen(const char *s);
139 size_t strnlen(const char * s, size_t n);
140 #endif /* !IN_ARCH_STRING_C */
141 
142 #endif /* __S390_STRING_H_ */
143