🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #260

Re: help sought, possible asm/cpu/other problem???

#260
From: Bob Gonder
Date: Fri, 18 Jul 2008 03:02
84 lines
2360 bytes
Larry Griffiths wrote:

>Look at this and see if it is close to what you want.

Three to four times faster (tested):

#pragma	argsused
__declspec(naked)
BOOL __fastcall BytesOKBob( unsigned char *pAddr, unsigned char bval, unsigned nbytes )
{	// eax = pAddr	edx = bval	ecx = nbytes
asm{
	mov	dh,dl
	sub	ecx,4
	jc short loop2
	push	edx	// mul edx, 0x00010001
	mov	word ptr [esp+2],dx
	pop	edx
	}
loop4:
asm{
	cmp	[eax],edx
	jne short fail
	add	eax,4
	sub	ecx,4
	jnc	loop4
	}
loop2:
asm{
	add	ecx,2
	js short loop1
	cmp	[eax],dx
	jne short fail
	add	eax,2
	sub	ecx,2
	}
loop1:
asm{
	add	ecx,1
	js short pass
	cmp	[eax],dl
	jne short fail
	}
pass:
asm{
	xor	eax,eax	;// return 0
	ret
	}	
fail:
asm{
	cmp	[survivalmode],0
	jne short noint
	cmp	[callint3onerror],0
	je short noint
	int	3
	}
noint:
asm{
	mov	eax,1	;// return 1
	ret
	}	
	return 1;	// compiler prefers to see a C return.
			// but there is a no-stack bug that doesn't generate the ret.
}

>bool BytesOK( unsigned char *pAddr, unsigned char bval, unsigned nbytes )
>{
> if( nbytes )
> {
>  _asm
>  {
>    cld
>    mov   al, bval  // Value to compare
>    mov   ecx, nbytes  // Number of bytes to compare
>    mov   edi, pAddr // Address of buffer
>    repe  scasb
>    jz  ItsOK:
>  }
>  //if(!MM3AdminData.survivalmode)
>  // if(MM3AdminData.callint3onerror) __asm int 3 ;
>  return 0 ;
> }
> ItsOK:
> return 1 ;
>}
Technical Details
Message-ID: <8bqv74t64fcgrl6largtp9p68n3d0m0rkh@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <487e5d3c$1@newsgroups.borland.com> <487fe05e$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ced19374283c232f
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <none@nowhere.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: help sought, possible asm/cpu/other problem???
Date: Thu, 17 Jul 2008 20:02:31 -0700
Message-ID: <8bqv74t64fcgrl6largtp9p68n3d0m0rkh@4ax.com>
References: <487e5d3c$1@newsgroups.borland.com> <487fe05e$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.147.31
X-Trace: newsgroups.borland.com 1216350149 67.77.147.31 (17 Jul 2008 20:02:29 -0700)
Lines: 86
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail