Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_SH_STRING_H
3#define __ASM_SH_STRING_H
4
5/*
6 * Copyright (C) 1999 Niibe Yutaka
7 * But consider these trivial functions to be public domain.
8 */
9
10#define __HAVE_ARCH_STRCPY
11static inline char *strcpy(char *__dest, const char *__src)
12{
13 register char *__xdest = __dest;
14 unsigned long __dummy;
15
16 __asm__ __volatile__("1:\n\t"
17 "mov.b @%1+, %2\n\t"
18 "mov.b %2, @%0\n\t"
19 "cmp/eq #0, %2\n\t"
20 "bf/s 1b\n\t"
21 " add #1, %0\n\t"
22 : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
23 : "0" (__dest), "1" (__src)
24 : "memory", "t");
25
26 return __xdest;
27}
28
29#define __HAVE_ARCH_STRCMP
30static inline int strcmp(const char *__cs, const char *__ct)
31{
32 register int __res;
33 unsigned long __dummy;
34
35 __asm__ __volatile__(
36 "mov.b @%1+, %3\n"
37 "1:\n\t"
38 "mov.b @%0+, %2\n\t"
39 "cmp/eq #0, %3\n\t"
40 "bt 2f\n\t"
41 "cmp/eq %2, %3\n\t"
42 "bt/s 1b\n\t"
43 " mov.b @%1+, %3\n\t"
44 "add #-2, %1\n\t"
45 "mov.b @%1, %3\n\t"
46 "sub %3, %2\n"
47 "2:"
48 : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
49 : "0" (__cs), "1" (__ct)
50 : "t");
51
52 return __res;
53}
54
55#define __HAVE_ARCH_STRNCMP
56static inline int strncmp(const char *__cs, const char *__ct, size_t __n)
57{
58 register int __res;
59 unsigned long __dummy;
60
61 if (__n == 0)
62 return 0;
63
64 __asm__ __volatile__(
65 "mov.b @%1+, %3\n"
66 "1:\n\t"
67 "mov.b @%0+, %2\n\t"
68 "cmp/eq %6, %0\n\t"
69 "bt/s 2f\n\t"
70 " cmp/eq #0, %3\n\t"
71 "bt/s 3f\n\t"
72 " cmp/eq %3, %2\n\t"
73 "bt/s 1b\n\t"
74 " mov.b @%1+, %3\n\t"
75 "add #-2, %1\n\t"
76 "mov.b @%1, %3\n"
77 "2:\n\t"
78 "sub %3, %2\n"
79 "3:"
80 :"=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
81 : "0" (__cs), "1" (__ct), "r" (__cs+__n)
82 : "t");
83
84 return __res;
85}
86
87#define __HAVE_ARCH_MEMSET
88extern void *memset(void *__s, int __c, size_t __count);
89
90#define __HAVE_ARCH_MEMCPY
91extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
92
93#define __HAVE_ARCH_MEMMOVE
94extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
95
96#define __HAVE_ARCH_MEMCHR
97extern void *memchr(const void *__s, int __c, size_t __n);
98
99#define __HAVE_ARCH_STRLEN
100extern size_t strlen(const char *);
101
102#endif /* __ASM_SH_STRING_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_SH_STRING_H
3#define __ASM_SH_STRING_H
4
5#ifdef __KERNEL__
6
7/*
8 * Copyright (C) 1999 Niibe Yutaka
9 * But consider these trivial functions to be public domain.
10 */
11
12#define __HAVE_ARCH_STRCPY
13static inline char *strcpy(char *__dest, const char *__src)
14{
15 register char *__xdest = __dest;
16 unsigned long __dummy;
17
18 __asm__ __volatile__("1:\n\t"
19 "mov.b @%1+, %2\n\t"
20 "mov.b %2, @%0\n\t"
21 "cmp/eq #0, %2\n\t"
22 "bf/s 1b\n\t"
23 " add #1, %0\n\t"
24 : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
25 : "0" (__dest), "1" (__src)
26 : "memory", "t");
27
28 return __xdest;
29}
30
31#define __HAVE_ARCH_STRNCPY
32static inline char *strncpy(char *__dest, const char *__src, size_t __n)
33{
34 register char *__xdest = __dest;
35 unsigned long __dummy;
36
37 if (__n == 0)
38 return __xdest;
39
40 __asm__ __volatile__(
41 "1:\n"
42 "mov.b @%1+, %2\n\t"
43 "mov.b %2, @%0\n\t"
44 "cmp/eq #0, %2\n\t"
45 "bt/s 2f\n\t"
46 " cmp/eq %5,%1\n\t"
47 "bf/s 1b\n\t"
48 " add #1, %0\n"
49 "2:"
50 : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
51 : "0" (__dest), "1" (__src), "r" (__src+__n)
52 : "memory", "t");
53
54 return __xdest;
55}
56
57#define __HAVE_ARCH_STRCMP
58static inline int strcmp(const char *__cs, const char *__ct)
59{
60 register int __res;
61 unsigned long __dummy;
62
63 __asm__ __volatile__(
64 "mov.b @%1+, %3\n"
65 "1:\n\t"
66 "mov.b @%0+, %2\n\t"
67 "cmp/eq #0, %3\n\t"
68 "bt 2f\n\t"
69 "cmp/eq %2, %3\n\t"
70 "bt/s 1b\n\t"
71 " mov.b @%1+, %3\n\t"
72 "add #-2, %1\n\t"
73 "mov.b @%1, %3\n\t"
74 "sub %3, %2\n"
75 "2:"
76 : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
77 : "0" (__cs), "1" (__ct)
78 : "t");
79
80 return __res;
81}
82
83#define __HAVE_ARCH_STRNCMP
84static inline int strncmp(const char *__cs, const char *__ct, size_t __n)
85{
86 register int __res;
87 unsigned long __dummy;
88
89 if (__n == 0)
90 return 0;
91
92 __asm__ __volatile__(
93 "mov.b @%1+, %3\n"
94 "1:\n\t"
95 "mov.b @%0+, %2\n\t"
96 "cmp/eq %6, %0\n\t"
97 "bt/s 2f\n\t"
98 " cmp/eq #0, %3\n\t"
99 "bt/s 3f\n\t"
100 " cmp/eq %3, %2\n\t"
101 "bt/s 1b\n\t"
102 " mov.b @%1+, %3\n\t"
103 "add #-2, %1\n\t"
104 "mov.b @%1, %3\n"
105 "2:\n\t"
106 "sub %3, %2\n"
107 "3:"
108 :"=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
109 : "0" (__cs), "1" (__ct), "r" (__cs+__n)
110 : "t");
111
112 return __res;
113}
114
115#define __HAVE_ARCH_MEMSET
116extern void *memset(void *__s, int __c, size_t __count);
117
118#define __HAVE_ARCH_MEMCPY
119extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
120
121#define __HAVE_ARCH_MEMMOVE
122extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
123
124#define __HAVE_ARCH_MEMCHR
125extern void *memchr(const void *__s, int __c, size_t __n);
126
127#define __HAVE_ARCH_STRLEN
128extern size_t strlen(const char *);
129
130#endif /* __KERNEL__ */
131
132#endif /* __ASM_SH_STRING_H */