IDEAL
P586
MODEL FLAT
CODESEG
ALIGN 4
include "macros.inc"
public _length_0
;
============================================================================
; NOTES:
; 1)
; This version of length_0
consists of public domain code which is the
; intellectual property of "Xbios2", a writer in the
; A S S E M B L Y P R O G R A M M I N G
J O U R N A L, Issue 4, March 1998,
; web-site:
http://madchat.org/vxdevl/vxmags/apj_3/APJ_3.TXT
; The code below is probably the fastest in the world, and it is the
copyright
; of "Xbios2".
; 2)
; This code is
the fastest, but after extensive testing, it was discovered that
; it is only 1 - 5 % faster than the "strlen" function, in Borland's
"Command
; Line Tools compiler" (which is public domain, despite its
high efficiency),
;
============================================================================
PROC _length_0
NEAR
mov eax, [esp+4]
xor ecx, ecx
loop2: test
al, 3
jz loop1
cmp [byte ptr eax], cl
jz short
ret0
cmp [byte ptr eax+1],
cl
jz short
ret1
cmp [byte ptr eax+2],
cl
jnz short
adjust
inc eax
ret1: inc eax
ret0: sub eax, [esp+4]
ret
adjust: add eax, 3
and eax, 0FFFFFFFCh
loop1: mov edx, [eax]
mov ecx, 81010100h
sub ecx, edx
add eax, 4
xor ecx, edx
and ecx, 81010100h
jz loop1
sub eax, [esp+4]
shr ecx, 9
jc minus4
shr ecx, 8
jc minus3
shr ecx, 8
jc minus2
minus1: dec eax
ret
minus4: sub eax, 4
ret
minus3: sub eax, 3
ret
minus2: sub eax, 2
ret
ENDP _length_0
END