Main Page | Alphabetical List | Class List | File List | Class Members | File Members

strlen.h

Go to the documentation of this file.
00001 #ifndef _STRLEN_H_
00002 #define _STRLEN_H_
00003 
00004 #include <nlibc.h>
00005 #include <stddef.h>     /* for size_t */
00006 
00007 /*----------------------------------------------------------------------
00008 |  NAME
00009 |         strlen - calculate the length of a string
00010 |  
00011 |  SYNOPSIS
00012 |         #include <string.h>
00013 |  
00014 |         size_t strlen(const char *s);
00015 |  
00016 |  DESCRIPTION
00017 |         The  strlen() function calculates the length of the string
00018 |         s, not including the terminating `\0' character.
00019 |  
00020 |  RETURN VALUE
00021 |         The strlen() function returns the number of characters  in
00022 |         s.
00023 |  
00024 |  CONFORMING TO
00025 |         SVID 3, POSIX, BSD 4.3, ISO 9899
00026 |  
00027 |  SEE ALSO
00028 |         string(3)
00029 |  
00030 +----------------------------------------------------------------------*/
00031 #ifndef __HAS_MAIN
00032 extern size_t strlen( const char *s );
00033 #else
00034 #if !defined(__cflow_processed) || defined(_uses_strlen_strlen_h)
00035 size_t strlen( const char *s )
00036 {
00037   vector unsigned *p = (vector unsigned *) s;
00038   int cr = 0;
00039   vector unsigned a, c;
00040     
00041   a = *p;
00042   if (!a.lo)
00043     return 0;
00044 
00045   do {
00046     unsigned mask = 0xff;
00047     c = 0;
00048     do { 
00049       register int shft= -8;
00050       register vector unsigned u = a & mask;
00051       #pragma vectorcond
00052       where (u) 
00053         c++;
00054       mask >>= shft;
00055     } while (mask);
00056 
00057     a = *(++p);
00058     {  
00059       register int hi,lo; 
00060       asm("\tlutcross.L %0 %1\n\tatr.H %0 $ZERO" : "=r" (hi) : "r" (c));
00061       asm("\tlutmove.L %0 %1\n\tatr.H %0 $ZERO" : "=r" (lo) : "r" (c));
00062       cr += hi + lo;
00063     }
00064   } while (a);
00065 
00066   return cr;
00067 }
00068 #endif
00069 #endif // Has Main
00070 
00071 #endif

Generated on Fri Jul 14 10:51:32 2006 for nlibc by doxygen 1.3.5