* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / include / asm-sparc64 / string.h
blobc1a67071f46776682b56f86ed21bdee4480b4322
1 /* $Id: string.h,v 1.14 1998/10/20 03:09:18 jj 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 __SPARC64_STRING_H__
10 #define __SPARC64_STRING_H__
12 /* Really, userland/ksyms should not see any of this stuff. */
14 #ifdef __KERNEL__
16 #include <asm/asi.h>
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 __kernel_size_t __memset(void *,int,__kernel_size_t);
26 #ifndef EXPORT_SYMTAB_STROPS
28 /* First the mem*() things. */
29 #define __HAVE_ARCH_BCOPY
30 #define __HAVE_ARCH_MEMMOVE
32 #undef memmove
33 #define memmove(_to, _from, _n) \
34 ({ \
35 void *_t = (_to); \
36 __memmove(_t, (_from), (_n)); \
37 _t; \
40 #define __HAVE_ARCH_MEMCPY
42 extern inline void *__constant_memcpy(void *to, const void *from, __kernel_size_t n)
44 if(n) {
45 if(n <= 32) {
46 __builtin_memcpy(to, from, n);
47 } else {
48 __memcpy(to, from, n);
51 return to;
54 extern inline void *__nonconstant_memcpy(void *to, const void *from, __kernel_size_t n)
56 __memcpy(to, from, n);
57 return to;
60 #undef memcpy
61 #define memcpy(t, f, n) \
62 (__builtin_constant_p(n) ? \
63 __constant_memcpy((t),(f),(n)) : \
64 __nonconstant_memcpy((t),(f),(n)))
66 #define __HAVE_ARCH_MEMSET
68 extern inline void *__constant_memset(void *s, char c, __kernel_size_t count)
70 extern __kernel_size_t __bzero(void *, __kernel_size_t);
72 if(!c)
73 __bzero(s, count);
74 else
75 __memset(s, c, count);
76 return s;
79 extern inline void *__nonconstant_memset(void *s, char c, __kernel_size_t count)
81 __memset(s, c, count);
82 return s;
85 #undef memset
86 #define memset(s, c, count) \
87 (__builtin_constant_p(c) ? \
88 __constant_memset((s), (c), (count)) : \
89 __nonconstant_memset((s), (c), (count)))
91 #define __HAVE_ARCH_MEMSCAN
93 #undef memscan
94 #define memscan(__arg0, __char, __arg2) \
95 ({ \
96 extern void *__memscan_zero(void *, size_t); \
97 extern void *__memscan_generic(void *, int, size_t); \
98 void *__retval, *__addr = (__arg0); \
99 size_t __size = (__arg2); \
101 if(__builtin_constant_p(__char) && !(__char)) \
102 __retval = __memscan_zero(__addr, __size); \
103 else \
104 __retval = __memscan_generic(__addr, (__char), __size); \
106 __retval; \
109 #define __HAVE_ARCH_MEMCMP
111 /* Now the str*() stuff... */
112 #define __HAVE_ARCH_STRLEN
114 extern __kernel_size_t __strlen(const char *);
116 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 91
117 extern __kernel_size_t strlen(const char *);
118 #else /* !EGCS */
119 /* Ugly but it works around a bug in our original sparc64-linux-gcc. */
120 #undef strlen
121 #define strlen(__arg0) \
122 ({ int __strlen_res = __strlen(__arg0) + 1; \
123 __strlen_res -= 1; \
124 __strlen_res; \
126 #endif /* !EGCS */
128 #define __HAVE_ARCH_STRNCMP
130 extern int __strncmp(const char *, const char *, __kernel_size_t);
132 extern inline int __constant_strncmp(const char *src, const char *dest, __kernel_size_t count)
134 register int retval;
135 switch(count) {
136 case 0: return 0;
137 case 1: return (src[0] - dest[0]);
138 case 2: retval = (src[0] - dest[0]);
139 if(!retval && src[0])
140 retval = (src[1] - dest[1]);
141 return retval;
142 case 3: retval = (src[0] - dest[0]);
143 if(!retval && src[0]) {
144 retval = (src[1] - dest[1]);
145 if(!retval && src[1])
146 retval = (src[2] - dest[2]);
148 return retval;
149 case 4: 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]);
154 if (!retval && src[2])
155 retval = (src[3] - dest[3]);
158 return retval;
159 case 5: retval = (src[0] - dest[0]);
160 if(!retval && src[0]) {
161 retval = (src[1] - dest[1]);
162 if(!retval && src[1]) {
163 retval = (src[2] - dest[2]);
164 if (!retval && src[2]) {
165 retval = (src[3] - dest[3]);
166 if (!retval && src[3])
167 retval = (src[4] - dest[4]);
171 return retval;
172 default:
173 retval = (src[0] - dest[0]);
174 if(!retval && src[0]) {
175 retval = (src[1] - dest[1]);
176 if(!retval && src[1]) {
177 retval = (src[2] - dest[2]);
178 if(!retval && src[2])
179 retval = __strncmp(src+3,dest+3,count-3);
182 return retval;
186 #undef strncmp
187 #define strncmp(__arg0, __arg1, __arg2) \
188 (__builtin_constant_p(__arg2) ? \
189 __constant_strncmp(__arg0, __arg1, __arg2) : \
190 __strncmp(__arg0, __arg1, __arg2))
192 #endif /* !EXPORT_SYMTAB_STROPS */
194 #endif /* __KERNEL__ */
196 #endif /* !(__SPARC64_STRING_H__) */