1 /*
2 Copyright (c) 1990 The Regents of the University of California.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms and that any documentation,
8 and/or other materials related to such
9 distribution and use acknowledge that the software was developed
10 by the University of California, Berkeley. The name of the
11 University may not be used to endorse or promote products derived
12 from this software without specific prior written permission.
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17 /*
18 * C library strlen routine
19 *
20 * This routine has been optimized for the CPU32+.
21 * It should run on all 68k machines.
22 *
23 * W. Eric Norum
24 * Saskatchewan Accelerator Laboratory
25 * University of Saskatchewan
26 * Saskatoon, Saskatchewan, CANADA
27 * eric@skatter.usask.ca
28 */
29
30 #include <string.h>
31
32 /*
33 * Test bytes using CPU32+ loop mode if possible.
34 */
35 size_t
strlen(const char * str)36 strlen (const char *str)
37 {
38 unsigned int n = ~0;
39 const char *cp = str;
40
41 __asm__ volatile ("1:\n"
42 "\ttst.b (%0)+\n"
43 #if defined(__mcpu32__)
44 "\tdbeq %1,1b\n"
45 #endif
46 "\tbne.b 1b\n" :
47 "=a" (cp), "=d" (n) :
48 "0" (cp), "1" (n) :
49 "cc");
50 return (cp - str) - 1;
51 }
52