Skip to content

Commit 1edad85

Browse files
heicarstMartin Schwidefsky
authored andcommitted
[S390] use compiler builtin versions of strlen/strcpy/strcat
Use builtin variants if gcc 4 or newer is used to compile the kernel. Generates better code than the asm variants. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 504665a commit 1edad85

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎arch/s390/include/asm/string.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static inline char *strcat(char *dst, const char *src)
100100

101101
static inline char *strcpy(char *dst, const char *src)
102102
{
103+
#if __GNUC__ < 4
103104
register int r0 asm("0") = 0;
104105
char *ret = dst;
105106

@@ -109,10 +110,14 @@ static inline char *strcpy(char *dst, const char *src)
109110
: "+&a" (dst), "+&a" (src) : "d" (r0)
110111
: "cc", "memory");
111112
return ret;
113+
#else
114+
return __builtin_strcpy(dst, src);
115+
#endif
112116
}
113117

114118
static inline size_t strlen(const char *s)
115119
{
120+
#if __GNUC__ < 4
116121
register unsigned long r0 asm("0") = 0;
117122
const char *tmp = s;
118123

@@ -121,6 +126,9 @@ static inline size_t strlen(const char *s)
121126
" jo 0b"
122127
: "+d" (r0), "+a" (tmp) : : "cc");
123128
return r0 - (unsigned long) s;
129+
#else
130+
return __builtin_strlen(s);
131+
#endif
124132
}
125133

126134
static inline size_t strnlen(const char * s, size_t n)

‎arch/s390/lib/string.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ static inline char *__strnend(const char *s, size_t n)
4444
*/
4545
size_t strlen(const char *s)
4646
{
47+
#if __GNUC__ < 4
4748
return __strend(s) - s;
49+
#else
50+
return __builtin_strlen(s);
51+
#endif
4852
}
4953
EXPORT_SYMBOL(strlen);
5054

@@ -70,6 +74,7 @@ EXPORT_SYMBOL(strnlen);
7074
*/
7175
char *strcpy(char *dest, const char *src)
7276
{
77+
#if __GNUC__ < 4
7378
register int r0 asm("0") = 0;
7479
char *ret = dest;
7580

@@ -78,6 +83,9 @@ char *strcpy(char *dest, const char *src)
7883
: "+&a" (dest), "+&a" (src) : "d" (r0)
7984
: "cc", "memory" );
8085
return ret;
86+
#else
87+
return __builtin_strcpy(dest, src);
88+
#endif
8189
}
8290
EXPORT_SYMBOL(strcpy);
8391

0 commit comments

Comments
 (0)