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_MEMMOVE
27 #define memmove(_to, _from, _n) \
30 __memmove(_t, (_from), (_n)); \
34 #define __HAVE_ARCH_MEMCPY
36 static inline void *__constant_memcpy(void *to
, const void *from
, __kernel_size_t n
)
38 extern void __copy_1page(void *, const void *);
41 __builtin_memcpy(to
, from
, n
);
42 } else if (((unsigned int) to
& 7) != 0) {
43 /* Destination is not aligned on the double-word boundary */
44 __memcpy(to
, from
, n
);
48 __copy_1page(to
, from
);
51 __memcpy(to
, from
, n
);
58 static inline void *__nonconstant_memcpy(void *to
, const void *from
, __kernel_size_t n
)
60 __memcpy(to
, from
, n
);
65 #define memcpy(t, f, n) \
66 (__builtin_constant_p(n) ? \
67 __constant_memcpy((t),(f),(n)) : \
68 __nonconstant_memcpy((t),(f),(n)))
70 #define __HAVE_ARCH_MEMSET
72 static inline void *__constant_c_and_count_memset(void *s
, char c
, __kernel_size_t count
)
74 extern void bzero_1page(void *);
75 extern __kernel_size_t
__bzero(void *, __kernel_size_t
);
78 if(count
== PAGE_SIZE
)
83 __memset(s
, c
, count
);
88 static inline void *__constant_c_memset(void *s
, char c
, __kernel_size_t count
)
90 extern __kernel_size_t
__bzero(void *, __kernel_size_t
);
95 __memset(s
, c
, count
);
99 static inline void *__nonconstant_memset(void *s
, char c
, __kernel_size_t count
)
101 __memset(s
, c
, count
);
106 #define memset(s, c, count) \
107 (__builtin_constant_p(c) ? (__builtin_constant_p(count) ? \
108 __constant_c_and_count_memset((s), (c), (count)) : \
109 __constant_c_memset((s), (c), (count))) \
110 : __nonconstant_memset((s), (c), (count)))
112 #define __HAVE_ARCH_MEMSCAN
115 #define memscan(__arg0, __char, __arg2) \
117 extern void *__memscan_zero(void *, size_t); \
118 extern void *__memscan_generic(void *, int, size_t); \
119 void *__retval, *__addr = (__arg0); \
120 size_t __size = (__arg2); \
122 if(__builtin_constant_p(__char) && !(__char)) \
123 __retval = __memscan_zero(__addr, __size); \
125 __retval = __memscan_generic(__addr, (__char), __size); \
130 #define __HAVE_ARCH_MEMCMP
131 extern int memcmp(const void *,const void *,__kernel_size_t
);
133 /* Now the str*() stuff... */
134 #define __HAVE_ARCH_STRLEN
135 extern __kernel_size_t
strlen(const char *);
137 #define __HAVE_ARCH_STRNCMP
139 extern int __strncmp(const char *, const char *, __kernel_size_t
);
141 static inline int __constant_strncmp(const char *src
, const char *dest
, __kernel_size_t count
)
146 case 1: return (src
[0] - dest
[0]);
147 case 2: retval
= (src
[0] - dest
[0]);
148 if(!retval
&& src
[0])
149 retval
= (src
[1] - dest
[1]);
151 case 3: retval
= (src
[0] - dest
[0]);
152 if(!retval
&& src
[0]) {
153 retval
= (src
[1] - dest
[1]);
154 if(!retval
&& src
[1])
155 retval
= (src
[2] - dest
[2]);
158 case 4: retval
= (src
[0] - dest
[0]);
159 if(!retval
&& src
[0]) {
160 retval
= (src
[1] - dest
[1]);
161 if(!retval
&& src
[1]) {
162 retval
= (src
[2] - dest
[2]);
163 if (!retval
&& src
[2])
164 retval
= (src
[3] - dest
[3]);
168 case 5: retval
= (src
[0] - dest
[0]);
169 if(!retval
&& src
[0]) {
170 retval
= (src
[1] - dest
[1]);
171 if(!retval
&& src
[1]) {
172 retval
= (src
[2] - dest
[2]);
173 if (!retval
&& src
[2]) {
174 retval
= (src
[3] - dest
[3]);
175 if (!retval
&& src
[3])
176 retval
= (src
[4] - dest
[4]);
182 retval
= (src
[0] - dest
[0]);
183 if(!retval
&& src
[0]) {
184 retval
= (src
[1] - dest
[1]);
185 if(!retval
&& src
[1]) {
186 retval
= (src
[2] - dest
[2]);
187 if(!retval
&& src
[2])
188 retval
= __strncmp(src
+3,dest
+3,count
-3);
196 #define strncmp(__arg0, __arg1, __arg2) \
197 (__builtin_constant_p(__arg2) ? \
198 __constant_strncmp(__arg0, __arg1, __arg2) : \
199 __strncmp(__arg0, __arg1, __arg2))
201 #endif /* !EXPORT_SYMTAB_STROPS */
203 #endif /* __KERNEL__ */
205 #endif /* !(__SPARC_STRING_H__) */