1 /* Optimized, inlined string functions. S/390 version.
2 Copyright (C) 2000, 2001, 2007 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # error "Never use <bits/string.h> directly; include <string.h> instead."
25 /* The s390 processors can access unaligned multi-byte variables. */
26 #define _STRING_ARCH_unaligned 1
28 /* We only provide optimizations if the user selects them and if
30 #if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
31 && defined __GNUC__ && __GNUC__ >= 2
33 #ifndef __STRING_INLINE
34 # ifndef __extern_inline
35 # define __STRING_INLINE inline
37 # define __STRING_INLINE __extern_inline
41 #define _HAVE_STRING_ARCH_strlen 1
42 #ifndef _FORCE_INLINES
43 __STRING_INLINE
size_t
44 strlen (__const
char *__str
)
49 __tmp
= (char *) __str
;
50 __asm__
__volatile__ (" la 0,0\n"
53 : "+&a" (__ptr
), "+&a" (__tmp
) :
54 : "cc", "memory", "0" );
55 return (size_t) (__ptr
- __str
);
59 /* Copy SRC to DEST. */
60 #define _HAVE_STRING_ARCH_strcpy 1
61 #ifndef _FORCE_INLINES
62 __STRING_INLINE
char *
63 strcpy (char *__dest
, __const
char *__src
)
67 __asm__
__volatile__ (" la 0,0\n"
70 : "+&a" (__dest
), "+&a" (__src
) :
71 : "cc", "memory", "0" );
76 #define _HAVE_STRING_ARCH_strncpy 1
77 #ifndef _FORCE_INLINES
78 __STRING_INLINE
char *
79 strncpy (char *__dest
, __const
char *__src
, size_t __n
)
86 __diff
= (size_t) (__dest
- __src
);
87 __ptr
= (char *) __src
;
88 __asm__
__volatile__ (" j 1f\n"
93 #if defined(__s390x__)
101 #if defined(__s390x__)
107 : "+&a" (__ptr
), "+&a" (__n
) : "a" (__diff
)
108 : "cc", "memory", "0" );
114 /* Append SRC onto DEST. */
115 #define _HAVE_STRING_ARCH_strcat 1
116 #ifndef _FORCE_INLINES
117 __STRING_INLINE
char *
118 strcat(char *__dest
, const char *__src
)
120 char *__ret
= __dest
;
123 /* Move __ptr to the end of __dest. */
126 __asm__
__volatile__ (" la 0,0\n"
129 : "+&a" (__ptr
), "+&a" (__tmp
) :
132 /* Now do the copy. */
133 __asm__
__volatile__ (" la 0,0\n"
136 : "+&a" (__ptr
), "+&a" (__src
) :
137 : "cc", "memory", "0" );
142 /* Append no more than N characters from SRC onto DEST. */
143 #define _HAVE_STRING_ARCH_strncat 1
144 #ifndef _FORCE_INLINES
145 __STRING_INLINE
char *
146 strncat (char *__dest
, __const
char *__src
, size_t __n
)
148 char *__ret
= __dest
;
153 /* Move __ptr to the end of __dest. */
156 __asm__
__volatile__ (" la 0,0\n"
159 : "+&a" (__ptr
), "+&a" (__tmp
) :
160 : "cc", "memory", "0" );
162 __diff
= (size_t) (__ptr
- __src
);
163 __tmp
= (char *) __src
;
164 __asm__
__volatile__ (" j 1f\n"
169 #if defined(__s390x__)
177 : "+&a" (__tmp
), "+&a" (__n
) : "a" (__diff
)
178 : "cc", "memory", "0" );
185 /* Search N bytes of S for C. */
186 #define _HAVE_STRING_ARCH_memchr 1
187 #ifndef _FORCE_INLINES
188 __STRING_INLINE
void *
189 memchr (__const
void *__str
, int __c
, size_t __n
)
193 __tmp
= (char *) __str
;
194 __ptr
= (char *) __tmp
+ __n
;
195 __asm__
__volatile__ (" lhi 0,0xff\n"
202 : "+&a" (__ptr
), "+&a" (__tmp
) : "d" (__c
)
203 : "cc", "memory", "0" );
208 /* Search N bytes of S for C. */
209 #define _HAVE_STRING_ARCH_memchr 1
210 #ifndef _FORCE_INLINES
212 strcmp (__const
char *__s1
, __const
char *__s2
)
217 __p1
= (char *) __s1
;
218 __p2
= (char *) __s2
;
219 __asm__
__volatile__ (" slr 0,0\n"
224 : "=d" (__ret
), "+&a" (__p1
), "+&a" (__p2
) :
225 : "cc", "memory", "0" );
226 __ret
= (__ret
== 0) ? 0 : (__ret
== 1) ? -1 : 1;
231 #endif /* Use string inlines && GNU CC. */