1 /* $Id: string.h,v 1.36 2001/12/21 00:54:31 davem Exp $
2 * string.h: External definitions for optimized assembly string
3 * routines for the Linux Kernel.
5 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 #ifndef __SPARC_STRING_H__
10 #define __SPARC_STRING_H__
14 /* Really, userland/ksyms should not see any of this stuff. */
18 extern void __memmove(void *,const void *,__kernel_size_t
);
19 extern __kernel_size_t
__memcpy(void *,const void *,__kernel_size_t
);
20 extern __kernel_size_t
__memset(void *,int,__kernel_size_t
);
22 #ifndef EXPORT_SYMTAB_STROPS
24 /* First the mem*() things. */
25 #define __HAVE_ARCH_BCOPY
26 #define __HAVE_ARCH_MEMMOVE
28 #define memmove(_to, _from, _n) \
31 __memmove(_t, (_from), (_n)); \
35 #define __HAVE_ARCH_MEMCPY
37 static inline void *__constant_memcpy(void *to
, const void *from
, __kernel_size_t n
)
39 extern void __copy_1page(void *, const void *);
42 __builtin_memcpy(to
, from
, n
);
46 __copy_1page(to
, from
);
49 __memcpy(to
, from
, n
);
56 static inline void *__nonconstant_memcpy(void *to
, const void *from
, __kernel_size_t n
)
58 __memcpy(to
, from
, n
);
63 #define memcpy(t, f, n) \
64 (__builtin_constant_p(n) ? \
65 __constant_memcpy((t),(f),(n)) : \
66 __nonconstant_memcpy((t),(f),(n)))
68 #define __HAVE_ARCH_MEMSET
70 static inline void *__constant_c_and_count_memset(void *s
, char c
, __kernel_size_t count
)
72 extern void bzero_1page(void *);
73 extern __kernel_size_t
__bzero(void *, __kernel_size_t
);
76 if(count
== PAGE_SIZE
)
81 __memset(s
, c
, count
);
86 static inline void *__constant_c_memset(void *s
, char c
, __kernel_size_t count
)
88 extern __kernel_size_t
__bzero(void *, __kernel_size_t
);
93 __memset(s
, c
, count
);
97 static inline void *__nonconstant_memset(void *s
, char c
, __kernel_size_t count
)
99 __memset(s
, c
, count
);
104 #define memset(s, c, count) \
105 (__builtin_constant_p(c) ? (__builtin_constant_p(count) ? \
106 __constant_c_and_count_memset((s), (c), (count)) : \
107 __constant_c_memset((s), (c), (count))) \
108 : __nonconstant_memset((s), (c), (count)))
110 #define __HAVE_ARCH_MEMSCAN
113 #define memscan(__arg0, __char, __arg2) \
115 extern void *__memscan_zero(void *, size_t); \
116 extern void *__memscan_generic(void *, int, size_t); \
117 void *__retval, *__addr = (__arg0); \
118 size_t __size = (__arg2); \
120 if(__builtin_constant_p(__char) && !(__char)) \
121 __retval = __memscan_zero(__addr, __size); \
123 __retval = __memscan_generic(__addr, (__char), __size); \
128 #define __HAVE_ARCH_MEMCMP
129 extern int memcmp(const void *,const void *,__kernel_size_t
);
131 /* Now the str*() stuff... */
132 #define __HAVE_ARCH_STRLEN
133 extern __kernel_size_t
strlen(const char *);
135 #define __HAVE_ARCH_STRNCMP
137 extern int __strncmp(const char *, const char *, __kernel_size_t
);
139 static inline int __constant_strncmp(const char *src
, const char *dest
, __kernel_size_t count
)
144 case 1: return (src
[0] - dest
[0]);
145 case 2: retval
= (src
[0] - dest
[0]);
146 if(!retval
&& src
[0])
147 retval
= (src
[1] - dest
[1]);
149 case 3: retval
= (src
[0] - dest
[0]);
150 if(!retval
&& src
[0]) {
151 retval
= (src
[1] - dest
[1]);
152 if(!retval
&& src
[1])
153 retval
= (src
[2] - dest
[2]);
156 case 4: retval
= (src
[0] - dest
[0]);
157 if(!retval
&& src
[0]) {
158 retval
= (src
[1] - dest
[1]);
159 if(!retval
&& src
[1]) {
160 retval
= (src
[2] - dest
[2]);
161 if (!retval
&& src
[2])
162 retval
= (src
[3] - dest
[3]);
166 case 5: retval
= (src
[0] - dest
[0]);
167 if(!retval
&& src
[0]) {
168 retval
= (src
[1] - dest
[1]);
169 if(!retval
&& src
[1]) {
170 retval
= (src
[2] - dest
[2]);
171 if (!retval
&& src
[2]) {
172 retval
= (src
[3] - dest
[3]);
173 if (!retval
&& src
[3])
174 retval
= (src
[4] - dest
[4]);
180 retval
= (src
[0] - dest
[0]);
181 if(!retval
&& src
[0]) {
182 retval
= (src
[1] - dest
[1]);
183 if(!retval
&& src
[1]) {
184 retval
= (src
[2] - dest
[2]);
185 if(!retval
&& src
[2])
186 retval
= __strncmp(src
+3,dest
+3,count
-3);
194 #define strncmp(__arg0, __arg1, __arg2) \
195 (__builtin_constant_p(__arg2) ? \
196 __constant_strncmp(__arg0, __arg1, __arg2) : \
197 __strncmp(__arg0, __arg1, __arg2))
199 #endif /* !EXPORT_SYMTAB_STROPS */
201 #endif /* __KERNEL__ */
203 #endif /* !(__SPARC_STRING_H__) */