OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [i386/] [bits/] [string.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Optimized, inlined string functions.  i386 version.
2
   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
#ifndef _STRING_H
21
# error "Never use <bits/string.h> directly; include <string.h> instead."
22
#endif
23
 
24
/* The ix86 processors can access unaligned multi-byte variables.  */
25
#define _STRING_ARCH_unaligned  1
26
 
27
 
28
/* We only provide optimizations if the user selects them and if
29
   GNU CC is used.  */
30
#if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
31
    && defined __GNUC__ && __GNUC__ >= 2 && !__BOUNDED_POINTERS__
32
 
33
#ifndef __STRING_INLINE
34
# ifdef __cplusplus
35
#  define __STRING_INLINE inline
36
# else
37
#  define __STRING_INLINE extern __inline
38
# endif
39
#endif
40
 
41
 
42
/* Copy N bytes of SRC to DEST.  */
43
#define _HAVE_STRING_ARCH_memcpy 1
44
#define memcpy(dest, src, n) \
45
  (__extension__ (__builtin_constant_p (n)                                    \
46
                  ? __memcpy_c (dest, src, n)                                 \
47
                  : memcpy (dest, src, n)))
48
/* This looks horribly ugly, but the compiler can optimize it totally,
49
   as the count is constant.  */
50
__STRING_INLINE void *__memcpy_c (void *__dest, __const void *__src,
51
                                  size_t __n);
52
 
53
__STRING_INLINE void *
54
__memcpy_c (void *__dest, __const void *__src, size_t __n)
55
{
56
  register unsigned long int __d0, __d1, __d2;
57
  union {
58
    unsigned int __ui;
59
    unsigned short int __usi;
60
    unsigned char __uc;
61
  } *__u = __dest;
62
  switch (__n)
63
    {
64
    case 0:
65
      return __dest;
66
    case 1:
67
      __u->__uc = *(const unsigned char *) __src;
68
      return __dest;
69
    case 2:
70
      __u->__usi = *(const unsigned short int *) __src;
71
      return __dest;
72
    case 3:
73
      __u->__usi = *(const unsigned short int *) __src;
74
      __u = (void *) __u + 2;
75
      __u->__uc = *(2 + (const unsigned char *) __src);
76
      return __dest;
77
    case 4:
78
      __u->__ui = *(const unsigned int *) __src;
79
      return __dest;
80
    case 6:
81
      __u->__ui = *(const unsigned int *) __src;
82
      __u = (void *) __u + 4;
83
      __u->__usi = *(2 + (const unsigned short int *) __src);
84
      return __dest;
85
    case 8:
86
      __u->__ui = *(const unsigned int *) __src;
87
      __u = (void *) __u + 4;
88
      __u->__ui = *(1 + (const unsigned int *) __src);
89
      return __dest;
90
    case 12:
91
      __u->__ui = *(const unsigned int *) __src;
92
      __u = (void *) __u + 4;
93
      __u->__ui = *(1 + (const unsigned int *) __src);
94
      __u = (void *) __u + 4;
95
      __u->__ui = *(2 + (const unsigned int *) __src);
96
      return __dest;
97
    case 16:
98
      __u->__ui = *(const unsigned int *) __src;
99
      __u = (void *) __u + 4;
100
      __u->__ui = *(1 + (const unsigned int *) __src);
101
      __u = (void *) __u + 4;
102
      __u->__ui = *(2 + (const unsigned int *) __src);
103
      __u = (void *) __u + 4;
104
      __u->__ui = *(3 + (const unsigned int *) __src);
105
      return __dest;
106
    case 20:
107
      __u->__ui = *(const unsigned int *) __src;
108
      __u = (void *) __u + 4;
109
      __u->__ui = *(1 + (const unsigned int *) __src);
110
      __u = (void *) __u + 4;
111
      __u->__ui = *(2 + (const unsigned int *) __src);
112
      __u = (void *) __u + 4;
113
      __u->__ui = *(3 + (const unsigned int *) __src);
114
      __u = (void *) __u + 4;
115
      __u->__ui = *(4 + (const unsigned int *) __src);
116
      return __dest;
117
    }
118
#define __COMMON_CODE(x) \
119
  __asm__ __volatile__                                                        \
120
    ("cld\n\t"                                                                \
121
     "rep; movsl"                                                             \
122
     x                                                                        \
123
     : "=&c" (__d0), "=&D" (__d1), "=&S" (__d2)                               \
124
     : "0" (__n / 4), "1" (&__u->__uc), "2" (__src)                            \
125
     : "memory");
126
 
127
  switch (__n % 4)
128
    {
129
    case 0:
130
      __COMMON_CODE ("");
131
      break;
132
    case 1:
133
      __COMMON_CODE ("\n\tmovsb");
134
      break;
135
    case 2:
136
      __COMMON_CODE ("\n\tmovsw");
137
      break;
138
    case 3:
139
      __COMMON_CODE ("\n\tmovsw\n\tmovsb");
140
      break;
141
  }
142
  return __dest;
143
#undef __COMMON_CODE
144
}
145
 
146
 
147
/* Copy N bytes of SRC to DEST, guaranteeing
148
   correct behavior for overlapping strings.  */
149
#define _HAVE_STRING_ARCH_memmove 1
150
#ifndef _FORCE_INLINES
151
__STRING_INLINE void *
152
memmove (void *__dest, __const void *__src, size_t __n)
153
{
154
  register unsigned long int __d0, __d1, __d2;
155
  if (__dest < __src)
156
    __asm__ __volatile__
157
      ("cld\n\t"
158
       "rep\n\t"
159
       "movsb"
160
       : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
161
       : "0" (__n), "1" (__src), "2" (__dest)
162
       : "memory");
163
  else
164
    __asm__ __volatile__
165
      ("std\n\t"
166
       "rep\n\t"
167
       "movsb\n\t"
168
       "cld"
169
       : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
170
       : "0" (__n), "1" (__n - 1 + (const char *) __src),
171
         "2" (__n - 1 + (char *) __dest)
172
       : "memory");
173
  return __dest;
174
}
175
#endif
176
 
177
/* Set N bytes of S to C.  */
178
#define _HAVE_STRING_ARCH_memset 1
179
#define _USE_STRING_ARCH_memset 1
180
#define memset(s, c, n) \
181
  (__extension__ (__builtin_constant_p (c)                                    \
182
                  ? (__builtin_constant_p (n)                                 \
183
                     ? __memset_cc (s, 0x01010101UL * (unsigned char) (c), n) \
184
                     : __memset_cg (s, 0x01010101UL * (unsigned char) (c), n))\
185
                  : __memset_gg (s, c, n)))
186
 
187
__STRING_INLINE void *__memset_cc (void *__s, unsigned long int __pattern,
188
                                   size_t __n);
189
 
190
__STRING_INLINE void *
191
__memset_cc (void *__s, unsigned long int __pattern, size_t __n)
192
{
193
  register unsigned long int __d0, __d1;
194
  union {
195
    unsigned int __ui;
196
    unsigned short int __usi;
197
    unsigned char __uc;
198
  } *__u = __s;
199
  switch (__n)
200
    {
201
    case 0:
202
      return __s;
203
    case 1:
204
      __u->__uc = __pattern;
205
      return __s;
206
    case 2:
207
      __u->__usi = __pattern;
208
      return __s;
209
    case 3:
210
      __u->__usi = __pattern;
211
      __u = __extension__ ((void *) __u + 2);
212
      __u->__uc = __pattern;
213
      return __s;
214
    case 4:
215
      __u->__ui = __pattern;
216
      return __s;
217
        }
218
#define __COMMON_CODE(x) \
219
  __asm__ __volatile__                                                        \
220
    ("cld\n\t"                                                                \
221
     "rep; stosl"                                                             \
222
     x                                                                        \
223
     : "=&c" (__d0), "=&D" (__d1)                                             \
224
     : "a" (__pattern), "0" (__n / 4), "1" (&__u->__uc)                        \
225
     : "memory")
226
 
227
  switch (__n % 4)
228
    {
229
    case 0:
230
      __COMMON_CODE ("");
231
      break;
232
    case 1:
233
      __COMMON_CODE ("\n\tstosb");
234
      break;
235
    case 2:
236
      __COMMON_CODE ("\n\tstosw");
237
      break;
238
    case 3:
239
      __COMMON_CODE ("\n\tstosw\n\tstosb");
240
      break;
241
    }
242
  return __s;
243
#undef __COMMON_CODE
244
}
245
 
246
__STRING_INLINE void *__memset_cg (void *__s, unsigned long __c, size_t __n);
247
 
248
__STRING_INLINE void *
249
__memset_cg (void *__s, unsigned long __c, size_t __n)
250
{
251
  register unsigned long int __d0, __d1;
252
  __asm__ __volatile__
253
    ("cld\n\t"
254
     "rep; stosl\n\t"
255
     "testb     $2,%b3\n\t"
256
     "je        1f\n\t"
257
     "stosw\n"
258
     "1:\n\t"
259
     "testb     $1,%b3\n\t"
260
     "je        2f\n\t"
261
     "stosb\n"
262
     "2:"
263
     : "=&c" (__d0), "=&D" (__d1)
264
     : "a" (__c), "q" (__n), "0" (__n / 4), "1" (__s)
265
     : "memory");
266
  return __s;
267
}
268
 
269
__STRING_INLINE void *__memset_gg (void *__s, char __c, size_t __n);
270
 
271
__STRING_INLINE void *
272
__memset_gg (void *__s, char __c, size_t __n)
273
{
274
  register unsigned long int __d0, __d1;
275
  __asm__ __volatile__
276
    ("cld\n\t"
277
     "rep; stosb"
278
     : "=&D" (__d0), "=&c" (__d1)
279
     : "a" (__c), "0" (__s), "1" (__n)
280
     : "memory");
281
  return __s;
282
}
283
 
284
 
285
 
286
 
287
/* Search N bytes of S for C.  */
288
#define _HAVE_STRING_ARCH_memchr 1
289
#ifndef _FORCE_INLINES
290
__STRING_INLINE void *
291
memchr (__const void *__s, int __c, size_t __n)
292
{
293
  register unsigned long int __d0;
294
  register void *__res;
295
  if (__n == 0)
296
    return NULL;
297
  __asm__ __volatile__
298
    ("cld\n\t"
299
     "repne; scasb\n\t"
300
     "je 1f\n\t"
301
     "movl $1,%0\n"
302
     "1:"
303
     : "=D" (__res), "=&c" (__d0)
304
     : "a" (__c), "0" (__s), "1" (__n)
305
     : "cc");
306
  return __res - 1;
307
}
308
#endif
309
 
310
#define _HAVE_STRING_ARCH_memrchr 1
311
#ifndef _FORCE_INLINES
312
__STRING_INLINE void *
313
__memrchr (__const void *__s, int __c, size_t __n)
314
{
315
  register unsigned long int __d0;
316
  register void *__res;
317
  if (__n == 0)
318
    return NULL;
319
  __asm__ __volatile__
320
    ("std\n\t"
321
     "repne; scasb\n\t"
322
     "je 1f\n\t"
323
     "orl $-1,%0\n"
324
     "1:\tcld"
325
     : "=D" (__res), "=&c" (__d0)
326
     : "a" (__c), "0" (__s + __n - 1), "1" (__n)
327
     : "cc");
328
  return __res + 1;
329
}
330
# ifdef __USE_GNU
331
#  define memrchr(s, c, n) __memrchr (s, c, n)
332
# endif
333
#endif
334
 
335
/* Return the length of S.  */
336
#define _HAVE_STRING_ARCH_strlen 1
337
#ifndef _FORCE_INLINES
338
__STRING_INLINE size_t
339
strlen (__const char *__str)
340
{
341
  register unsigned long int __d0;
342
  register size_t __res;
343
  __asm__ __volatile__
344
    ("cld\n\t"
345
     "repne; scasb\n\t"
346
     "notl %0"
347
     : "=c" (__res), "=&D" (__d0)
348
     : "1" (__str), "a" (0), "0" (0xffffffff)
349
     : "cc");
350
  return __res - 1;
351
}
352
#endif
353
 
354
/* Copy SRC to DEST.  */
355
#define _HAVE_STRING_ARCH_strcpy 1
356
#ifndef _FORCE_INLINES
357
__STRING_INLINE char *
358
strcpy (char *__dest, __const char *__src)
359
{
360
  register unsigned long int __d0, __d1;
361
  __asm__ __volatile__
362
    ("cld\n"
363
     "1:\n\t"
364
     "lodsb\n\t"
365
     "stosb\n\t"
366
     "testb     %%al,%%al\n\t"
367
     "jne       1b"
368
     : "=&S" (__d0), "=&D" (__d1)
369
     : "0" (__src), "1" (__dest)
370
     : "ax", "memory", "cc");
371
  return __dest;
372
}
373
#endif
374
 
375
/* Copy no more than N characters of SRC to DEST.  */
376
#define _HAVE_STRING_ARCH_strncpy 1
377
#ifndef _FORCE_INLINES
378
__STRING_INLINE char *
379
strncpy (char *__dest, __const char *__src, size_t __n)
380
{
381
  register unsigned long int __d0, __d1, __d2;
382
  __asm__ __volatile__
383
    ("cld\n"
384
     "1:\n\t"
385
     "decl      %2\n\t"
386
     "js        2f\n\t"
387
     "lodsb\n\t"
388
     "stosb\n\t"
389
     "testb     %%al,%%al\n\t"
390
     "jne       1b\n\t"
391
     "rep; stosb\n"
392
     "2:"
393
     : "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
394
     : "0" (__src), "1" (__dest), "2" (__n)
395
     : "ax", "memory", "cc");
396
  return __dest;
397
}
398
#endif
399
 
400
/* Append SRC onto DEST.  */
401
#define _HAVE_STRING_ARCH_strcat 1
402
#ifndef _FORCE_INLINES
403
__STRING_INLINE char *
404
strcat (char *__dest, __const char *__src)
405
{
406
  register unsigned long int __d0, __d1, __d2, __d3;
407
  __asm__ __volatile__
408
    ("cld\n\t"
409
     "repne; scasb\n\t"
410
     "decl      %1\n"
411
     "1:\n\t"
412
     "lodsb\n\t"
413
     "stosb\n\t"
414
     "testb     %%al,%%al\n\t"
415
     "jne       1b"
416
     : "=&S" (__d0), "=&D" (__d1), "=&c" (__d2), "=&a" (__d3)
417
     : "0" (__src), "1" (__dest), "2" (0xffffffff), "3" (0)
418
     : "memory", "cc");
419
  return __dest;
420
}
421
#endif
422
 
423
/* Append no more than N characters from SRC onto DEST.  */
424
#define _HAVE_STRING_ARCH_strncat 1
425
#ifndef _FORCE_INLINES
426
__STRING_INLINE char *
427
strncat (char *__dest, __const char *__src, size_t __n)
428
{
429
  register unsigned long int __d0, __d1, __d2, __d3;
430
  __asm__ __volatile__
431
    ("cld\n\t"
432
     "repne; scasb\n\t"
433
     "decl      %1\n\t"
434
     "movl      %4,%2\n"
435
     "1:\n\t"
436
     "decl      %2\n\t"
437
     "js        2f\n\t"
438
     "lodsb\n\t"
439
     "stosb\n\t"
440
     "testb     %%al,%%al\n\t"
441
     "jne       1b\n\t"
442
     "jmp       3f\n"
443
     "2:\n\t"
444
     "xorl      %3,%3\n\t"
445
     "stosb\n"
446
     "3:"
447
     : "=&S" (__d0), "=&D" (__d1), "=&c" (__d2), "=&a" (__d3)
448
     : "g" (__n), "0" (__src), "1" (__dest), "2" (0xffffffff), "3" (0)
449
     : "memory", "cc");
450
  return __dest;
451
}
452
#endif
453
 
454
/* Compare S1 and S2.  */
455
#define _HAVE_STRING_ARCH_strcmp 1
456
#ifndef _FORCE_INLINES
457
__STRING_INLINE int
458
strcmp (__const char *__s1, __const char *__s2)
459
{
460
  register unsigned long int __d0, __d1;
461
  register int __res;
462
  __asm__ __volatile__
463
    ("cld\n"
464
     "1:\n\t"
465
     "lodsb\n\t"
466
     "scasb\n\t"
467
     "jne       2f\n\t"
468
     "testb     %%al,%%al\n\t"
469
     "jne       1b\n\t"
470
     "xorl      %%eax,%%eax\n\t"
471
     "jmp       3f\n"
472
     "2:\n\t"
473
     "sbbl      %%eax,%%eax\n\t"
474
     "orb       $1,%%al\n"
475
     "3:"
476
     : "=a" (__res), "=&S" (__d0), "=&D" (__d1)
477
     : "1" (__s1), "2" (__s2)
478
     : "cc");
479
  return __res;
480
}
481
#endif
482
 
483
/* Compare N characters of S1 and S2.  */
484
#define _HAVE_STRING_ARCH_strncmp 1
485
#ifndef _FORCE_INLINES
486
__STRING_INLINE int
487
strncmp (__const char *__s1, __const char *__s2, size_t __n)
488
{
489
  register unsigned long int __d0, __d1, __d2;
490
  register int __res;
491
  __asm__ __volatile__
492
    ("cld\n"
493
     "1:\n\t"
494
     "decl      %3\n\t"
495
     "js        2f\n\t"
496
     "lodsb\n\t"
497
     "scasb\n\t"
498
     "jne       3f\n\t"
499
     "testb     %%al,%%al\n\t"
500
     "jne       1b\n"
501
     "2:\n\t"
502
     "xorl      %%eax,%%eax\n\t"
503
     "jmp       4f\n"
504
     "3:\n\t"
505
     "sbbl      %%eax,%%eax\n\t"
506
     "orb       $1,%%al\n"
507
     "4:"
508
     : "=a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
509
     : "1" (__s1), "2" (__s2), "3" (__n)
510
     : "cc");
511
  return __res;
512
}
513
#endif
514
 
515
/* Find the first occurrence of C in S.  */
516
#define _HAVE_STRING_ARCH_strchr 1
517
#define _USE_STRING_ARCH_strchr 1
518
#define strchr(s, c) \
519
  (__extension__ (__builtin_constant_p (c)                                    \
520
                  ? __strchr_c (s, ((c) & 0xff) << 8)                         \
521
                  : __strchr_g (s, c)))
522
 
523
__STRING_INLINE char *__strchr_g (__const char *__s, int __c);
524
 
525
__STRING_INLINE char *
526
__strchr_g (__const char *__s, int __c)
527
{
528
  register unsigned long int __d0;
529
  register char *__res;
530
  __asm__ __volatile__
531
    ("cld\n\t"
532
     "movb      %%al,%%ah\n"
533
     "1:\n\t"
534
     "lodsb\n\t"
535
     "cmpb      %%ah,%%al\n\t"
536
     "je        2f\n\t"
537
     "testb     %%al,%%al\n\t"
538
     "jne       1b\n\t"
539
     "movl      $1,%1\n"
540
     "2:\n\t"
541
     "movl      %1,%0"
542
     : "=a" (__res), "=&S" (__d0)
543
     : "0" (__c), "1" (__s)
544
     : "cc");
545
  return __res - 1;
546
}
547
 
548
__STRING_INLINE char *__strchr_c (__const char *__s, int __c);
549
 
550
__STRING_INLINE char *
551
__strchr_c (__const char *__s, int __c)
552
{
553
  register unsigned long int __d0;
554
  register char *__res;
555
  __asm__ __volatile__
556
    ("cld\n\t"
557
     "1:\n\t"
558
     "lodsb\n\t"
559
     "cmpb      %%ah,%%al\n\t"
560
     "je        2f\n\t"
561
     "testb     %%al,%%al\n\t"
562
     "jne       1b\n\t"
563
     "movl      $1,%1\n"
564
     "2:\n\t"
565
     "movl      %1,%0"
566
     : "=a" (__res), "=&S" (__d0)
567
     : "0" (__c), "1" (__s)
568
     : "cc");
569
  return __res - 1;
570
}
571
 
572
 
573
/* Find the first occurrence of C in S or the final NUL byte.  */
574
#define _HAVE_STRING_ARCH_strchrnul 1
575
#define __strchrnul(s, c) \
576
  (__extension__ (__builtin_constant_p (c)                                    \
577
                  ? ((c) == '\0'                                              \
578
                     ? (char *) __rawmemchr (s, c)                            \
579
                     : __strchrnul_c (s, ((c) & 0xff) << 8))                  \
580
                  : __strchrnul_g (s, c)))
581
 
582
__STRING_INLINE char *__strchrnul_g (__const char *__s, int __c);
583
 
584
__STRING_INLINE char *
585
__strchrnul_g (__const char *__s, int __c)
586
{
587
  register unsigned long int __d0;
588
  register char *__res;
589
  __asm__ __volatile__
590
    ("cld\n\t"
591
     "movb      %%al,%%ah\n"
592
     "1:\n\t"
593
     "lodsb\n\t"
594
     "cmpb      %%ah,%%al\n\t"
595
     "je        2f\n\t"
596
     "testb     %%al,%%al\n\t"
597
     "jne       1b\n\t"
598
     "2:\n\t"
599
     "movl      %1,%0"
600
     : "=a" (__res), "=&S" (__d0)
601
     : "0" (__c), "1" (__s)
602
     : "cc");
603
  return __res - 1;
604
}
605
 
606
__STRING_INLINE char *__strchrnul_c (__const char *__s, int __c);
607
 
608
__STRING_INLINE char *
609
__strchrnul_c (__const char *__s, int __c)
610
{
611
  register unsigned long int __d0;
612
  register char *__res;
613
  __asm__ __volatile__
614
    ("cld\n\t"
615
     "1:\n\t"
616
     "lodsb\n\t"
617
     "cmpb      %%ah,%%al\n\t"
618
     "je        2f\n\t"
619
     "testb     %%al,%%al\n\t"
620
     "jne       1b\n\t"
621
     "2:\n\t"
622
     "movl      %1,%0"
623
     : "=a" (__res), "=&S" (__d0)
624
     : "0" (__c), "1" (__s)
625
     : "cc");
626
  return __res - 1;
627
}
628
#ifdef __USE_GNU
629
# define strchrnul(s, c) __strchrnul (s, c)
630
#endif
631
 
632
 
633
/* Return the length of the initial segment of S which
634
   consists entirely of characters not in REJECT.  */
635
#define _HAVE_STRING_ARCH_strcspn 1
636
#ifndef _FORCE_INLINES
637
# ifdef __PIC__
638
__STRING_INLINE size_t
639
strcspn (__const char *__s, __const char *__reject)
640
{
641
  register unsigned long int __d0, __d1, __d2;
642
  register char *__res;
643
  __asm__ __volatile__
644
    ("pushl     %%ebx\n\t"
645
     "cld\n\t"
646
     "movl      %4,%%edi\n\t"
647
     "repne; scasb\n\t"
648
     "notl      %%ecx\n\t"
649
     "decl      %%ecx\n\t"
650
     "movl      %%ecx,%%ebx\n"
651
     "1:\n\t"
652
     "lodsb\n\t"
653
     "testb     %%al,%%al\n\t"
654
     "je        2f\n\t"
655
     "movl      %4,%%edi\n\t"
656
     "movl      %%ebx,%%ecx\n\t"
657
     "repne; scasb\n\t"
658
     "jne       1b\n"
659
     "2:\n\t"
660
     "popl      %%ebx"
661
     : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
662
     : "d" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
663
     : "cc");
664
  return (__res - 1) - __s;
665
}
666
# else
667
__STRING_INLINE size_t
668
strcspn (__const char *__s, __const char *__reject)
669
{
670
  register unsigned long int __d0, __d1, __d2, __d3;
671
  register char *__res;
672
  __asm__ __volatile__
673
    ("cld\n\t"
674
     "movl      %5,%%edi\n\t"
675
     "repne; scasb\n\t"
676
     "notl      %%ecx\n\t"
677
     "decl      %%ecx\n\t"
678
     "movl      %%ecx,%%edx\n"
679
     "1:\n\t"
680
     "lodsb\n\t"
681
     "testb     %%al,%%al\n\t"
682
     "je        2f\n\t"
683
     "movl      %5,%%edi\n\t"
684
     "movl      %%edx,%%ecx\n\t"
685
     "repne; scasb\n\t"
686
     "jne       1b\n"
687
     "2:"
688
     : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
689
     : "g" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
690
     : "cc");
691
  return (__res - 1) - __s;
692
}
693
# endif
694
#endif
695
 
696
 
697
/* Return the length of the initial segment of S which
698
   consists entirely of characters in ACCEPT.  */
699
#define _HAVE_STRING_ARCH_strspn 1
700
#ifndef _FORCE_INLINES
701
# ifdef __PIC__
702
__STRING_INLINE size_t
703
strspn (__const char *__s, __const char *__accept)
704
{
705
  register unsigned long int __d0, __d1, __d2;
706
  register char *__res;
707
  __asm__ __volatile__
708
    ("pushl     %%ebx\n\t"
709
     "cld\n\t"
710
     "movl      %4,%%edi\n\t"
711
     "repne; scasb\n\t"
712
     "notl      %%ecx\n\t"
713
     "decl      %%ecx\n\t"
714
     "movl      %%ecx,%%ebx\n"
715
     "1:\n\t"
716
     "lodsb\n\t"
717
     "testb     %%al,%%al\n\t"
718
     "je        2f\n\t"
719
     "movl      %4,%%edi\n\t"
720
     "movl      %%ebx,%%ecx\n\t"
721
     "repne; scasb\n\t"
722
     "je        1b\n"
723
     "2:\n\t"
724
     "popl      %%ebx"
725
     : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
726
     : "r" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
727
     : "cc");
728
  return (__res - 1) - __s;
729
}
730
# else
731
__STRING_INLINE size_t
732
strspn (__const char *__s, __const char *__accept)
733
{
734
  register unsigned long int __d0, __d1, __d2, __d3;
735
  register char *__res;
736
  __asm__ __volatile__
737
    ("cld\n\t"
738
     "movl      %5,%%edi\n\t"
739
     "repne; scasb\n\t"
740
     "notl      %%ecx\n\t"
741
     "decl      %%ecx\n\t"
742
     "movl      %%ecx,%%edx\n"
743
     "1:\n\t"
744
     "lodsb\n\t"
745
     "testb     %%al,%%al\n\t"
746
     "je        2f\n\t"
747
     "movl      %5,%%edi\n\t"
748
     "movl      %%edx,%%ecx\n\t"
749
     "repne; scasb\n\t"
750
     "je        1b\n"
751
     "2:"
752
     : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
753
     : "g" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
754
     : "cc");
755
  return (__res - 1) - __s;
756
}
757
# endif
758
#endif
759
 
760
 
761
/* Find the first occurrence in S of any character in ACCEPT.  */
762
#define _HAVE_STRING_ARCH_strpbrk 1
763
#ifndef _FORCE_INLINES
764
# ifdef __PIC__
765
__STRING_INLINE char *
766
strpbrk (__const char *__s, __const char *__accept)
767
{
768
  unsigned long int __d0, __d1, __d2;
769
  register char *__res;
770
  __asm__ __volatile__
771
    ("pushl     %%ebx\n\t"
772
     "cld\n\t"
773
     "movl      %4,%%edi\n\t"
774
     "repne; scasb\n\t"
775
     "notl      %%ecx\n\t"
776
     "decl      %%ecx\n\t"
777
     "movl      %%ecx,%%ebx\n"
778
     "1:\n\t"
779
     "lodsb\n\t"
780
     "testb     %%al,%%al\n\t"
781
     "je        2f\n\t"
782
     "movl      %4,%%edi\n\t"
783
     "movl      %%ebx,%%ecx\n\t"
784
     "repne; scasb\n\t"
785
     "jne       1b\n\t"
786
     "decl      %0\n\t"
787
     "jmp       3f\n"
788
     "2:\n\t"
789
     "xorl      %0,%0\n"
790
     "3:\n\t"
791
     "popl      %%ebx"
792
     : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&D" (__d2)
793
     : "r" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
794
     : "cc");
795
  return __res;
796
}
797
# else
798
__STRING_INLINE char *
799
strpbrk (__const char *__s, __const char *__accept)
800
{
801
  register unsigned long int __d0, __d1, __d2, __d3;
802
  register char *__res;
803
  __asm__ __volatile__
804
    ("cld\n\t"
805
     "movl      %5,%%edi\n\t"
806
     "repne; scasb\n\t"
807
     "notl      %%ecx\n\t"
808
     "decl      %%ecx\n\t"
809
     "movl      %%ecx,%%edx\n"
810
     "1:\n\t"
811
     "lodsb\n\t"
812
     "testb     %%al,%%al\n\t"
813
     "je        2f\n\t"
814
     "movl      %5,%%edi\n\t"
815
     "movl      %%edx,%%ecx\n\t"
816
     "repne; scasb\n\t"
817
     "jne       1b\n\t"
818
     "decl      %0\n\t"
819
     "jmp       3f\n"
820
     "2:\n\t"
821
     "xorl      %0,%0\n"
822
     "3:"
823
     : "=&S" (__res), "=&a" (__d0), "=&c" (__d1), "=&d" (__d2), "=&D" (__d3)
824
     : "g" (__accept), "0" (__s), "1" (0), "2" (0xffffffff)
825
     : "cc");
826
  return __res;
827
}
828
# endif
829
#endif
830
 
831
 
832
/* Find the first occurrence of NEEDLE in HAYSTACK.  */
833
#define _HAVE_STRING_ARCH_strstr 1
834
#ifndef _FORCE_INLINES
835
# ifdef __PIC__
836
__STRING_INLINE char *
837
strstr (__const char *__haystack, __const char *__needle)
838
{
839
  register unsigned long int __d0, __d1, __d2;
840
  register char *__res;
841
  __asm__ __volatile__
842
    ("pushl     %%ebx\n\t"
843
     "cld\n\t" \
844
     "movl      %4,%%edi\n\t"
845
     "repne; scasb\n\t"
846
     "notl      %%ecx\n\t"
847
     "decl      %%ecx\n\t"      /* NOTE! This also sets Z if searchstring='' */
848
     "movl      %%ecx,%%ebx\n"
849
     "1:\n\t"
850
     "movl      %4,%%edi\n\t"
851
     "movl      %%esi,%%eax\n\t"
852
     "movl      %%ebx,%%ecx\n\t"
853
     "repe; cmpsb\n\t"
854
     "je        2f\n\t"         /* also works for empty string, see above */
855
     "xchgl     %%eax,%%esi\n\t"
856
     "incl      %%esi\n\t"
857
     "cmpb      $0,-1(%%eax)\n\t"
858
     "jne       1b\n\t"
859
     "xorl      %%eax,%%eax\n\t"
860
     "2:\n\t"
861
     "popl      %%ebx"
862
     : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
863
     : "r" (__needle), "0" (0), "1" (0xffffffff), "2" (__haystack)
864
     : "cc");
865
  return __res;
866
}
867
# else
868
__STRING_INLINE char *
869
strstr (__const char *__haystack, __const char *__needle)
870
{
871
  register unsigned long int __d0, __d1, __d2, __d3;
872
  register char *__res;
873
  __asm__ __volatile__
874
    ("cld\n\t" \
875
     "movl      %5,%%edi\n\t"
876
     "repne; scasb\n\t"
877
     "notl      %%ecx\n\t"
878
     "decl      %%ecx\n\t"      /* NOTE! This also sets Z if searchstring='' */
879
     "movl      %%ecx,%%edx\n"
880
     "1:\n\t"
881
     "movl      %5,%%edi\n\t"
882
     "movl      %%esi,%%eax\n\t"
883
     "movl      %%edx,%%ecx\n\t"
884
     "repe; cmpsb\n\t"
885
     "je        2f\n\t"         /* also works for empty string, see above */
886
     "xchgl     %%eax,%%esi\n\t"
887
     "incl      %%esi\n\t"
888
     "cmpb      $0,-1(%%eax)\n\t"
889
     "jne       1b\n\t"
890
     "xorl      %%eax,%%eax\n\t"
891
     "2:"
892
     : "=&a" (__res), "=&c" (__d0), "=&S" (__d1), "=&d" (__d2), "=&D" (__d3)
893
     : "g" (__needle), "0" (0), "1" (0xffffffff), "2" (__haystack)
894
     : "cc");
895
  return __res;
896
}
897
# endif
898
#endif
899
 
900
#ifndef _FORCE_INLINES
901
# undef __STRING_INLINE
902
#endif
903
 
904
#endif  /* use string inlines && GNU CC */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.