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     unsigned *p = (unsigned *)s;
00038     int a,c,cr=0;
00039     unsigned mask;
00040     int one = 1,shft= -8;
00041     
00042     if( ! (a=*p) ) return 0;
00043 
00044     do {
00045         mask = 0xff;
00046         c=0;
00047         do { 
00048             unsigned u = a & mask;
00049             #pragma vectorcond
00050             where( u ) 
00051                c++;
00052             mask >>= shft;
00053         } while( mask );
00054         a = *(++p);
00055         {  
00056             int hi,lo; 
00057             asm("\tlutcross.L %0 %1\n\tatr.H %0 $ZERO" : "=r" (hi) : "r" (c));
00058             asm("\tlutmove.L %0 %1\n\tatr.H %0 $ZERO" : "=r" (lo) : "r" (c));
00059             cr += hi + lo;
00060         }
00061       } while( a );
00062       return cr;
00063 }
00064 #endif
00065 #endif // Has Main
00066 
00067 #endif

Generated on Tue Jan 10 12:43:39 2006 for nlibc by doxygen 1.3.5