1 /* $Id: string.h,v 1.17 2000/06/19 06:24:58 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,1999 Jakub Jelinek (jakub@redhat.com)
9 #ifndef __SPARC64_STRING_H__
10 #define __SPARC64_STRING_H__
12 /* 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
__memcpy_short(void *,const void *,__kernel_size_t
,long,long);
21 extern __kernel_size_t
__memcpy_entry(void *,const void *,__kernel_size_t
,long,long);
22 extern __kernel_size_t
__memcpy_16plus(void *,const void *,__kernel_size_t
,long,long);
23 extern __kernel_size_t
__memcpy_384plus(void *,const void *,__kernel_size_t
,long,long);
24 extern void *__memset(void *,int,__kernel_size_t
);
25 extern void *__builtin_memcpy(void *,const void *,__kernel_size_t
);
26 extern void *__builtin_memset(void *,int,__kernel_size_t
);
28 #ifndef EXPORT_SYMTAB_STROPS
30 /* First the mem*() things. */
31 #define __HAVE_ARCH_BCOPY
32 #define __HAVE_ARCH_MEMMOVE
35 #define memmove(_to, _from, _n) \
38 __memmove(_t, (_from), (_n)); \
42 #define __HAVE_ARCH_MEMCPY
44 static inline void *__constant_memcpy(void *to
, const void *from
, __kernel_size_t n
)
48 __builtin_memcpy(to
, from
, n
);
50 __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_memset(void *s
, int c
, __kernel_size_t count
)
72 extern __kernel_size_t
__bzero(void *, __kernel_size_t
);
78 return __memset(s
, c
, count
);
82 #define memset(s, c, count) \
83 ((__builtin_constant_p(count) && (count) <= 32) ? \
84 __builtin_memset((s), (c), (count)) : \
85 (__builtin_constant_p(c) ? \
86 __constant_memset((s), (c), (count)) : \
87 __memset((s), (c), (count))))
89 #define __HAVE_ARCH_MEMSCAN
92 #define memscan(__arg0, __char, __arg2) \
94 extern void *__memscan_zero(void *, size_t); \
95 extern void *__memscan_generic(void *, int, size_t); \
96 void *__retval, *__addr = (__arg0); \
97 size_t __size = (__arg2); \
99 if(__builtin_constant_p(__char) && !(__char)) \
100 __retval = __memscan_zero(__addr, __size); \
102 __retval = __memscan_generic(__addr, (__char), __size); \
107 #define __HAVE_ARCH_MEMCMP
109 /* Now the str*() stuff... */
110 #define __HAVE_ARCH_STRLEN
112 extern __kernel_size_t
__strlen(const char *);
114 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)
115 extern __kernel_size_t
strlen(const char *);
117 /* Ugly but it works around a bug in our original sparc64-linux-gcc. */
119 #define strlen(__arg0) \
120 ({ int __strlen_res = __strlen(__arg0) + 1; \
126 #define __HAVE_ARCH_STRNCMP
128 extern int __strncmp(const char *, const char *, __kernel_size_t
);
130 static inline int __constant_strncmp(const char *src
, const char *dest
, __kernel_size_t count
)
135 case 1: return (src
[0] - dest
[0]);
136 case 2: retval
= (src
[0] - dest
[0]);
137 if(!retval
&& src
[0])
138 retval
= (src
[1] - dest
[1]);
140 case 3: retval
= (src
[0] - dest
[0]);
141 if(!retval
&& src
[0]) {
142 retval
= (src
[1] - dest
[1]);
143 if(!retval
&& src
[1])
144 retval
= (src
[2] - dest
[2]);
147 case 4: retval
= (src
[0] - dest
[0]);
148 if(!retval
&& src
[0]) {
149 retval
= (src
[1] - dest
[1]);
150 if(!retval
&& src
[1]) {
151 retval
= (src
[2] - dest
[2]);
152 if (!retval
&& src
[2])
153 retval
= (src
[3] - dest
[3]);
157 case 5: retval
= (src
[0] - dest
[0]);
158 if(!retval
&& src
[0]) {
159 retval
= (src
[1] - dest
[1]);
160 if(!retval
&& src
[1]) {
161 retval
= (src
[2] - dest
[2]);
162 if (!retval
&& src
[2]) {
163 retval
= (src
[3] - dest
[3]);
164 if (!retval
&& src
[3])
165 retval
= (src
[4] - dest
[4]);
171 retval
= (src
[0] - dest
[0]);
172 if(!retval
&& src
[0]) {
173 retval
= (src
[1] - dest
[1]);
174 if(!retval
&& src
[1]) {
175 retval
= (src
[2] - dest
[2]);
176 if(!retval
&& src
[2])
177 retval
= __strncmp(src
+3,dest
+3,count
-3);
185 #define strncmp(__arg0, __arg1, __arg2) \
186 (__builtin_constant_p(__arg2) ? \
187 __constant_strncmp(__arg0, __arg1, __arg2) : \
188 __strncmp(__arg0, __arg1, __arg2))
190 #endif /* !EXPORT_SYMTAB_STROPS */
192 #endif /* __KERNEL__ */
194 #endif /* !(__SPARC64_STRING_H__) */