[ros-kernel] new strlen (correct)

Waldo Alvarez wac at ghost.matcom.uh.cu
Fri Dec 19 13:04:55 CET 2003

Hi ppl:

I found how to fix this file after deling with it some time, I use a 
previous alignment and now I save ebx, I still beleive some ticks can be 
saved by means of a better scheduling inside the inner loop.

The file goes to lib\string\i386

The speed increase is huge in everythig you do, I beleive is because 
the use of all those Debug Prints. It makes me think about chasing other 
functions. BTW this function appears in the maps of ntoskrnl, ntdll, 
msvcrt and crtdll. Why don't you make at least msvcrt and crtdll call the 
one in ntdll. Some other string functions go to all of them too.

Best Regards
Waldo Alvarez
-------------- next part --------------
/* $Id: tcslen.h,v 1.1 2003/07/06 23:04:19 hyperion Exp $


/* Synopsis:  returns length of passed string

 * Author(s): based on optimized Strlen by 

 *            Agner Fog (agner at agner.org) http://www.agner.org

 *            modified by Jeremy Collake (lowercase code) to force dword alignment.

 *            Jeremy Collake (collake at charter.net) http://www.collakesoftware.com

 *            Adapted to ReactOS by Waldo Alvarez Ca?izares (wac at ghost.matcom.uh.cu)

 * Notes:

 * Todo:     Apply this to the unicode version


#include "tchar.h"

.globl	_tcslen


#ifdef _UNICODE

 push   %edi

 mov    0x8(%esp), %edi

 xor    %eax, %eax

 mov    $0xffffffff, %ecx


 mov    %ecx, %edx


 repne _tscas

 not    %ecx

 pop    %edi

 dec    %ecx

 mov    %ecx, %eax




 push    %ebx

 mov     0x8(%esp), %eax


 mov     %eax,%edx

 inc     %edx

 test    $3,%eax

 je      L1

// align memory


 mov     (%eax),%bl

 add     $1,%eax

 test    %bl,%bl

 je      L4

 test    $3,%eax

 jne     L0


 add     $2,%edx


 mov     (%eax),%ebx            // read first 4 bytes

 add     $4,%eax                // increment pointer

 lea     0xfefefeff(%ebx),%ecx  // substract 1 from each byte

 not     %ebx                   // invert all bytes

 and     %ebx,%ecx              // and these two

 and     $0x80808080,%ecx       // test all sign bits

 jz      L2

 test    $0x8080,%ecx           // test first two bytes

 jnz     L3

 shr     $0x10,%ecx             // not in the first 2 bytes

 add     $2,%eax


 shl     %cl                    // use carry flag to avoid branch


 sbb     %edx,%eax              // compute length


 pop     %ebx




/* EOF */

More information about the Ros-kernel mailing list