[ros-kernel] Can someone give me a hand in here

Waldo Alvarez wac at ghost.matcom.uh.cu
Wed Dec 17 13:21:01 CET 2003


Hello:

I was changing this file in ROS to speedup strlen but ReactOS 
crashes with a page fault very quick since strlen is used almost 
everywhere. But I'm not used to this kind of assembler format. Can someone 
take a look at it. It could read at most 3 bytes beyond the ending 0 in 
the string but i don't think it could be a problem since the page size is 
4 kb the other reason could be the ebx register I'm not saving. as opposed 
to the previous function.

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

*/



/* Synopsis:  returns length of passed string about 3x faster

 *  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



_tcslen:



#ifdef _UNICODE



 push   %edi

 mov    0x8(%esp), %edi

 xor    %eax, %eax

 mov    $0xffffffff, %ecx

 

 mov    %ecx, %edx



 cld



 repne _tscas



 not    %ecx



 pop    %edi



 dec    %ecx

 mov    %ecx, %eax

 

 ret



#else



 mov    0x8(%esp), %eax

 lea    0x3(%eax),%edx

 mov    (%eax),%ebx

 add    $0x4,%eax

 lea    0xfefefeff(%ebx),%ecx // -$0x01010101

 not    %ebx

 and    %ebx,%ecx

 and    $0x80808080,%ecx



 jnz    L2



 shr    $0x2,%eax

 shl    $0x2,%eax



L1:

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

 add    $0x4,%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

 je     L1



L2:

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

 jnz    L3



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

 add    $0x2,%eax



L3:     

 shl    %cl                   // use carry flag to avoid branch

 sbb    %edx,%eax             // compute length

 ret    



#endif



/* EOF */



More information about the Ros-kernel mailing list