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