fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / include / asm-sparc / string.h
blobcb1e923356c61a7855ac824f54ace382955f9dc9
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)
7 */
9 #ifndef __SPARC_STRING_H__
10 #define __SPARC_STRING_H__
12 #include <asm/page.h>
14 /* Really, userland/ksyms should not see any of this stuff. */
16 #ifdef __KERNEL__
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
26 #undef memmove
27 #define memmove(_to, _from, _n) \
28 ({ \
29 void *_t = (_to); \
30 __memmove(_t, (_from), (_n)); \
31 _t; \
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 *);
40 if(n <= 32) {
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);
45 } else {
46 switch(n) {
47 case PAGE_SIZE:
48 __copy_1page(to, from);
49 break;
50 default:
51 __memcpy(to, from, n);
52 break;
55 return to;
58 static inline void *__nonconstant_memcpy(void *to, const void *from, __kernel_size_t n)
60 __memcpy(to, from, n);
61 return to;
64 #undef memcpy
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);
77 if(!c) {
78 if(count == PAGE_SIZE)
79 bzero_1page(s);
80 else
81 __bzero(s, count);
82 } else {
83 __memset(s, c, count);
85 return s;
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);
92 if(!c)
93 __bzero(s, count);
94 else
95 __memset(s, c, count);
96 return s;
99 static inline void *__nonconstant_memset(void *s, char c, __kernel_size_t count)
101 __memset(s, c, count);
102 return s;
105 #undef memset
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
114 #undef memscan
115 #define memscan(__arg0, __char, __arg2) \
116 ({ \
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); \
124 else \
125 __retval = __memscan_generic(__addr, (__char), __size); \
127 __retval; \
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)
143 register int retval;
144 switch(count) {
145 case 0: return 0;
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]);
150 return retval;
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]);
157 return retval;
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]);
167 return retval;
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]);
180 return retval;
181 default:
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);
191 return retval;
195 #undef strncmp
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__) */