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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-m68knommu/] [string.h] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#ifndef _M68K_STRING_H_
2
#define _M68K_STRING_H_
3
 
4
#include <linux/config.h>
5
#include <asm/page.h>
6
 
7
#if 0
8
 
9
#define __HAVE_ARCH_STRCPY
10
extern inline char * strcpy(char * dest,const char *src)
11
{
12
  char *xdest = dest;
13
 
14
  __asm__ __volatile__
15
       ("1:\tmoveb %1@+,%0@+\n\t"
16
        "jne 1b"
17
        : "=a" (dest), "=a" (src)
18
        : "0" (dest), "1" (src) : "memory");
19
  return xdest;
20
}
21
 
22
#define __HAVE_ARCH_STRNCPY
23
extern inline char * strncpy(char *dest, const char *src, size_t n)
24
{
25
  char *xdest = dest;
26
 
27
  if (n == 0)
28
    return xdest;
29
 
30
  __asm__ __volatile__
31
       ("1:\tmoveb %1@+,%0@+\n\t"
32
        "jeq 2f\n\t"
33
        "subql #1,%2\n\t"
34
        "jne 1b\n\t"
35
        "2:"
36
        : "=a" (dest), "=a" (src), "=d" (n)
37
        : "0" (dest), "1" (src), "2" (n)
38
        : "memory");
39
  return xdest;
40
}
41
 
42
#define __HAVE_ARCH_STRCAT
43
extern inline char * strcat(char * dest, const char * src)
44
{
45
        char *tmp = dest;
46
 
47
        while (*dest)
48
                dest++;
49
        while ((*dest++ = *src++))
50
                ;
51
 
52
        return tmp;
53
}
54
 
55
#define __HAVE_ARCH_STRNCAT
56
extern inline char * strncat(char *dest, const char *src, size_t count)
57
{
58
        char *tmp = dest;
59
 
60
        if (count) {
61
                while (*dest)
62
                        dest++;
63
                while ((*dest++ = *src++)) {
64
                        if (--count == 0) {
65
                                *dest++='\0';
66
                                break;
67
                        }
68
                }
69
        }
70
 
71
        return tmp;
72
}
73
 
74
#define __HAVE_ARCH_STRCHR
75
extern inline char * strchr(const char * s, int c)
76
{
77
  const char ch = c;
78
 
79
  for(; *s != ch; ++s)
80
    if (*s == '\0')
81
      return( NULL );
82
  return( (char *) s);
83
}
84
 
85
#define __HAVE_ARCH_STRPBRK
86
extern inline char * strpbrk(const char * cs,const char * ct)
87
{
88
  const char *sc1,*sc2;
89
 
90
  for( sc1 = cs; *sc1 != '\0'; ++sc1)
91
    for( sc2 = ct; *sc2 != '\0'; ++sc2)
92
      if (*sc1 == *sc2)
93
        return((char *) sc1);
94
  return( NULL );
95
}
96
 
97
#define __HAVE_ARCH_STRSPN
98
extern inline size_t strspn(const char *s, const char *accept)
99
{
100
  const char *p;
101
  const char *a;
102
  size_t count = 0;
103
 
104
  for (p = s; *p != '\0'; ++p)
105
    {
106
      for (a = accept; *a != '\0'; ++a)
107
        if (*p == *a)
108
          break;
109
      if (*a == '\0')
110
        return count;
111
      else
112
        ++count;
113
    }
114
 
115
  return count;
116
}
117
 
118
#define __HAVE_ARCH_STRTOK
119
extern inline char * strtok(char * s,const char * ct)
120
{
121
  char *sbegin, *send;
122
 
123
  sbegin  = s ? s : ___strtok;
124
  if (!sbegin) {
125
          return NULL;
126
  }
127
  sbegin += strspn(sbegin,ct);
128
  if (*sbegin == '\0') {
129
    ___strtok = NULL;
130
    return( NULL );
131
  }
132
  send = strpbrk( sbegin, ct);
133
  if (send && *send != '\0')
134
    *send++ = '\0';
135
  ___strtok = send;
136
  return (sbegin);
137
}
138
 
139
/* strstr !! */
140
 
141
#define __HAVE_ARCH_STRLEN
142
extern inline size_t strlen(const char * s)
143
{
144
  const char *sc;
145
  for (sc = s; *sc != '\0'; ++sc) ;
146
  return(sc - s);
147
}
148
 
149
/* strnlen !! */
150
 
151
#define __HAVE_ARCH_STRCMP
152
extern inline int strcmp(const char * cs,const char * ct)
153
{
154
  char __res;
155
 
156
  __asm__
157
       ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
158
        "cmpb %1@+,%2\n\t"      /* compare a byte */
159
        "jne  2f\n\t"           /* not equal, break out */
160
        "tstb %2\n\t"           /* at end of cs? */
161
        "jne  1b\n\t"           /* no, keep going */
162
        "jra  3f\n\t"           /* strings are equal */
163
        "2:\tsubb %1@-,%2\n\t"  /* *cs - *ct */
164
        "3:"
165
        : "=a" (cs), "=a" (ct), "=d" (__res)
166
        : "0" (cs), "1" (ct));
167
  return __res;
168
}
169
 
170
#define __HAVE_ARCH_STRNCMP
171
extern inline int strncmp(const char * cs,const char * ct,size_t count)
172
{
173
  char __res;
174
 
175
  if (!count)
176
    return 0;
177
  __asm__
178
       ("1:\tmovb %0@+,%3\n\t"          /* get *cs */
179
        "cmpb   %1@+,%3\n\t"            /* compare a byte */
180
        "jne    3f\n\t"                 /* not equal, break out */
181
        "tstb   %3\n\t"                 /* at end of cs? */
182
        "jeq    4f\n\t"                 /* yes, all done */
183
        "subql  #1,%2\n\t"              /* no, adjust count */
184
        "jne    1b\n\t"                 /* more to do, keep going */
185
        "2:\tmoveq #0,%3\n\t"           /* strings are equal */
186
        "jra    4f\n\t"
187
        "3:\tsubb %1@-,%3\n\t"          /* *cs - *ct */
188
        "4:"
189
        : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
190
        : "0" (cs), "1" (ct), "2" (count));
191
  return __res;
192
}
193
 
194
#define __HAVE_ARCH_MEMSET
195
/*
196
 * This is really ugly, but its highly optimizatiable by the
197
 * compiler and is meant as compensation for gcc's missing
198
 * __builtin_memset(). For the 680[23]0 it might be worth considering
199
 * the optimal number of misaligned writes compared to the number of
200
 * tests'n'branches needed to align the destination address. The
201
 * 680[46]0 doesn't really care due to their copy-back caches.
202
 *                                              10/09/96 - Jes Sorensen
203
 */
204
extern inline void * __memset_g(void * s, int c, size_t count)
205
{
206
  void *xs = s;
207
  size_t temp;
208
 
209
  if (!count)
210
    return xs;
211
 
212
  c &= 0xff;
213
  c |= c << 8;
214
  c |= c << 16;
215
 
216
  if (count < 36){
217
          long *ls = s;
218
 
219
          switch(count){
220
          case 32: case 33: case 34: case 35:
221
                  *ls++ = c;
222
          case 28: case 29: case 30: case 31:
223
                  *ls++ = c;
224
          case 24: case 25: case 26: case 27:
225
                  *ls++ = c;
226
          case 20: case 21: case 22: case 23:
227
                  *ls++ = c;
228
          case 16: case 17: case 18: case 19:
229
                  *ls++ = c;
230
          case 12: case 13: case 14: case 15:
231
                  *ls++ = c;
232
          case 8: case 9: case 10: case 11:
233
                  *ls++ = c;
234
          case 4: case 5: case 6: case 7:
235
                  *ls++ = c;
236
                  break;
237
          default:
238
                  break;
239
          }
240
          s = ls;
241
          if (count & 0x02){
242
                  short *ss = s;
243
                  *ss++ = c;
244
                  s = ss;
245
          }
246
          if (count & 0x01){
247
                  char *cs = s;
248
                  *cs++ = c;
249
                  s = cs;
250
          }
251
          return xs;
252
  }
253
 
254
  if ((long) s & 1)
255
    {
256
      char *cs = s;
257
      *cs++ = c;
258
      s = cs;
259
      count--;
260
    }
261
  if (count > 2 && (long) s & 2)
262
    {
263
      short *ss = s;
264
      *ss++ = c;
265
      s = ss;
266
      count -= 2;
267
    }
268
  temp = count >> 2;
269
  if (temp)
270
    {
271
      long *ls = s;
272
      temp--;
273
      do
274
        *ls++ = c;
275
      while (temp--);
276
      s = ls;
277
    }
278
  if (count & 2)
279
    {
280
      short *ss = s;
281
      *ss++ = c;
282
      s = ss;
283
    }
284
  if (count & 1)
285
    {
286
      char *cs = s;
287
      *cs = c;
288
    }
289
  return xs;
290
}
291
 
292
/*
293
 * __memset_page assumes that data is longword aligned. Most, if not
294
 * all, of these page sized memsets are performed on page aligned
295
 * areas, thus we do not need to check if the destination is longword
296
 * aligned. Of course we suffer a serious performance loss if this is
297
 * not the case but I think the risk of this ever happening is
298
 * extremely small. We spend a lot of time clearing pages in
299
 * get_empty_page() so I think it is worth it anyway. Besides, the
300
 * 680[46]0 do not really care about misaligned writes due to their
301
 * copy-back cache.
302
 *
303
 * The optimized case for the 680[46]0 is implemented using the move16
304
 * instruction. My tests showed that this implementation is 35-45%
305
 * faster than the original implementation using movel, the only
306
 * caveat is that the destination address must be 16-byte aligned.
307
 *                                            01/09/96 - Jes Sorensen
308
 */
309
extern inline void * __memset_page(void * s,int c,size_t count)
310
{
311
  unsigned long data, tmp;
312
  void *xs, *sp;
313
 
314
  xs = sp = s;
315
 
316
  c = c & 255;
317
  data = c | (c << 8);
318
  data |= data << 16;
319
 
320
#if defined(CONFIG_OPTIMIZE_040) || defined(CONFIG_OPTIMIZE_060)
321
 
322
  if (((unsigned long) s) & 0x0f)
323
          memset(s, c, count);
324
  else{
325
          *((unsigned long *)(s))++ = data;
326
          *((unsigned long *)(s))++ = data;
327
          *((unsigned long *)(s))++ = data;
328
          *((unsigned long *)(s))++ = data;
329
 
330
          __asm__ __volatile__("1:\t"
331
                               "move16 %2@+,%0@+\n\t"
332
                               "subqw  #8,%2\n\t"
333
                               "subqw  #8,%2\n\t"
334
                               "subql  #1,%1\n\t"
335
                               "bne    1b\n\t"
336
                               : "=a" (s), "=d" (tmp)
337
                               : "a" (sp), "0" (s), "1" ((count - 16) / 16)
338
                               );
339
  }
340
 
341
#else
342
  __asm__ __volatile__("1:\t"
343
                       "movel %2,%0@+\n\t"
344
                       "movel %2,%0@+\n\t"
345
                       "movel %2,%0@+\n\t"
346
                       "movel %2,%0@+\n\t"
347
                       "movel %2,%0@+\n\t"
348
                       "movel %2,%0@+\n\t"
349
                       "movel %2,%0@+\n\t"
350
                       "movel %2,%0@+\n\t"
351
                       "subql #1,%1\n\t"
352
                       "bne   1b\n\t"
353
                       : "=a" (s), "=d" (tmp)
354
                       : "d" (data), "0" (s), "1" (count / 32)
355
                       );
356
#endif
357
 
358
  return xs;
359
}
360
 
361
#define __memset_const(s,c,count) \
362
((count==PAGE_SIZE) ? \
363
  __memset_page((s),(c),(count)) : \
364
  __memset_g((s),(c),(count)))
365
 
366
#define memset(s, c, count) \
367
(__builtin_constant_p(count) ? \
368
 __memset_const((s),(c),(count)) : \
369
 memset((s),(c),(count)))
370
 
371
#define __HAVE_ARCH_MEMCPY
372
/*
373
 * __builtin_memcpy() does not handle page-sized memcpys very well,
374
 * thus following the same assumptions as for page-sized memsets, this
375
 * function copies page-sized areas using an unrolled loop, without
376
 * considering alignment.
377
 *
378
 * For the 680[46]0 only kernels we use the move16 instruction instead
379
 * as it writes through the data-cache, invalidating the cache-lines
380
 * touched. In this way we do not use up the entire data-cache (well,
381
 * half of it on the 68060) by copying a page. An unrolled loop of two
382
 * move16 instructions seem to the fastest. The only caveat is that
383
 * both source and destination must be 16-byte aligned, if not we fall
384
 * back to the generic memcpy function.  - Jes
385
 */
386
extern inline void * __memcpy_page(void * to, const void * from, size_t count)
387
{
388
  unsigned long tmp;
389
  void *xto = to;
390
 
391
#if defined(CONFIG_OPTIMIZE_040) || defined(CONFIG_OPTIMIZE_060)
392
 
393
  if (((unsigned long) to | (unsigned long) from) & 0x0f)
394
          return memcpy(to, from, count);
395
 
396
  __asm__ __volatile__("1:\t"
397
                       "move16 %1@+,%0@+\n\t"
398
                       "move16 %1@+,%0@+\n\t"
399
                       "subql  #1,%2\n\t"
400
                       "bne    1b\n\t"
401
                       : "=a" (to), "=a" (from), "=d" (tmp)
402
                       : "0" (to), "1" (from) , "2" (count / 32)
403
                       );
404
#else
405
  __asm__ __volatile__("1:\t"
406
                       "movel %1@+,%0@+\n\t"
407
                       "movel %1@+,%0@+\n\t"
408
                       "movel %1@+,%0@+\n\t"
409
                       "movel %1@+,%0@+\n\t"
410
                       "movel %1@+,%0@+\n\t"
411
                       "movel %1@+,%0@+\n\t"
412
                       "movel %1@+,%0@+\n\t"
413
                       "movel %1@+,%0@+\n\t"
414
                       "subql #1,%2\n\t"
415
                       "bne   1b\n\t"
416
                       : "=a" (to), "=a" (from), "=d" (tmp)
417
                       : "0" (to), "1" (from) , "2" (count / 32)
418
                       );
419
#endif
420
  return xto;
421
}
422
 
423
#define __memcpy_const(to, from, n) \
424
((n==PAGE_SIZE) ? \
425
  __memcpy_page((to),(from),(n)) : \
426
  __builtin_memcpy((to),(from),(n)))
427
 
428
#define memcpy(to, from, n) \
429
(__builtin_constant_p(n) ? \
430
 __memcpy_const((to),(from),(n)) : \
431
 memcpy((to),(from),(n)))
432
 
433
#define __HAVE_ARCH_MEMMOVE
434
extern inline void * memmove(void * dest,const void * src, size_t n)
435
{
436
  void *xdest = dest;
437
  size_t temp;
438
 
439
  if (!n)
440
    return xdest;
441
 
442
  if (dest < src)
443
    {
444
      if ((long) dest & 1)
445
        {
446
          char *cdest = dest;
447
          const char *csrc = src;
448
          *cdest++ = *csrc++;
449
          dest = cdest;
450
          src = csrc;
451
          n--;
452
        }
453
      if (n > 2 && (long) dest & 2)
454
        {
455
          short *sdest = dest;
456
          const short *ssrc = src;
457
          *sdest++ = *ssrc++;
458
          dest = sdest;
459
          src = ssrc;
460
          n -= 2;
461
        }
462
      temp = n >> 2;
463
      if (temp)
464
        {
465
          long *ldest = dest;
466
          const long *lsrc = src;
467
          temp--;
468
          do
469
            *ldest++ = *lsrc++;
470
          while (temp--);
471
          dest = ldest;
472
          src = lsrc;
473
        }
474
      if (n & 2)
475
        {
476
          short *sdest = dest;
477
          const short *ssrc = src;
478
          *sdest++ = *ssrc++;
479
          dest = sdest;
480
          src = ssrc;
481
        }
482
      if (n & 1)
483
        {
484
          char *cdest = dest;
485
          const char *csrc = src;
486
          *cdest = *csrc;
487
        }
488
    }
489
  else
490
    {
491
      dest = (char *) dest + n;
492
      src = (const char *) src + n;
493
      if ((long) dest & 1)
494
        {
495
          char *cdest = dest;
496
          const char *csrc = src;
497
          *--cdest = *--csrc;
498
          dest = cdest;
499
          src = csrc;
500
          n--;
501
        }
502
      if (n > 2 && (long) dest & 2)
503
        {
504
          short *sdest = dest;
505
          const short *ssrc = src;
506
          *--sdest = *--ssrc;
507
          dest = sdest;
508
          src = ssrc;
509
          n -= 2;
510
        }
511
      temp = n >> 2;
512
      if (temp)
513
        {
514
          long *ldest = dest;
515
          const long *lsrc = src;
516
          temp--;
517
          do
518
            *--ldest = *--lsrc;
519
          while (temp--);
520
          dest = ldest;
521
          src = lsrc;
522
        }
523
      if (n & 2)
524
        {
525
          short *sdest = dest;
526
          const short *ssrc = src;
527
          *--sdest = *--ssrc;
528
          dest = sdest;
529
          src = ssrc;
530
        }
531
      if (n & 1)
532
        {
533
          char *cdest = dest;
534
          const char *csrc = src;
535
          *--cdest = *--csrc;
536
        }
537
    }
538
  return xdest;
539
}
540
 
541
#define __HAVE_ARCH_MEMCMP
542
#define memcmp(cs, ct, n) \
543
(__builtin_constant_p(n) ? \
544
 __builtin_memcmp((cs),(ct),(n)) : \
545
 memcmp((cs),(ct),(n)))
546
 
547
#endif
548
 
549
#endif /* _M68K_STRING_H_ */

powered by: WebSVN 2.1.0

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