From: 101.165571@germanynet.de (Raymond Hellstern)
Newsgroups: comp.sys.hp48
Subject: ML version of apndvarlst !  Who can beat this ?
Date: Tue, 8 Dec 1998 21:02:02 GMT
Organization: germany.net Onlinesysteme
Lines: 210
Message-ID: <gh18023ms@germanynet.de>
References: <gh18023ms@germanynet.de> <366C4B3B.772EE1FB@gulf.net>
NNTP-Posting-Host: frankfurt.germany.net
Xref: republic.btigate.com comp.sys.hp48:19532

Hi,

below is the source for the ML version of apndvarlst.

The EqualPosComp routine which does the hard work was written by
Detlef Mueller in 1993 as part of the <-LIB-> package,and is much
faster than the built-in EQUALPOSCOMP.

Timings and conditions:

I used a list of ~20K (VARS, then DUP + 'til it got 2560 elements)

and a test string "LALA"

apndvarlst:
4259.386 ms when "LALA" was not in list
2308.825 ms when "LALA" was the last element of list

The program below:
2516.466 ms when "LALA" was not in list
569.689 ms when "LALA" was the last element of list !

Please note: Both apndvarlst and the program below, search from
the start of the list towards the end.

As you can see, the program below is much faster, especially in
the case where an item is already in the list. This is because
>TCOMP can be left out in that case.

But it seems that the speed gain is marginal, so I would suggest to
use apndvarlst if you don't need EqualPosComp for other tasks
already.

Hope this helps

Greetings

Raymond

BTW: Maybe one of you ML cracks can beat this ;-)
HP mnemonics preferred.


---begin_source---

**	( comp ob --> comp' )
**
** apndvarlst:
**:: OVER	( comp ob --> comp ob comp )
**   matchob?	( comp ob comp --> comp ob F )
**		( comp ob comp --> comp T )
**
**   ?SKIP
**
**   >TCOMP	( comp ob --> comp' )
**;
**

::
    CK2 2DUP		( *comp ob comp ob* )


** EqualPosComp *************************************************************
* Interface :	( comp ob --> #pos | #0 )
* Description : Replacement for slow RPL EQUALPOSCOMP. Returns the index of
*		the first object in comp matching (EQUAL) ob.
* Uses :
* Calls :	SavPtr SkipOb
* Defines :	Psh#Lp
* Ed. Hist. :
*	1.000	27.02.1993	DM	alpha
*	1.1	08.12.1998	RH	release
*****************************************************************************

*ASSEMBLE
*EqualPosComp


CODE
* CPU			A	B	C	D	D0	D1	xx
	A=DAT1	A	->ob
	R1=A								R1:->ob
	AD1EX
	C=DAT1	A			ob prologue
	R2=C								R2:ob prol
	D1=A
	D1=D1+	5
	D=D+1	A
	A=DAT1	A	->comp
	D1=D1+	5
	D=D+1	A
	GOSBVL	=SAVPTR

	B=A	A		->comp

	C=R1				->ob
	D=C	A				->ob
	D0=C						->ob
	GOSBVL	=SKIPOB					->past ob

	CD0EX				->past ob
	D=C-D	A				ob len

	A=B	A	->comp

	D0=A						->comp
	D0=D0+	5	** skip comp prol
	C=0	A	** init. cnt
	GONC	EqLpEn	** BET

NotFnd	A=0	A	** ob not in comp, push #0
	R0=A
	GOVLNG	=PUSH#LOOP

EqLp	GOSBVL	=SKIPOB					->nxt

	C=R0.F	A			cnt
EqLpEn	C=C+1	A			++cnt
	R0=C.F	A							R0:cnt'

	A=DAT0	A	->cob|prol
	LC(5)	=SEMI			SEMI
	?A=C	A	** list due ?
	GOYES	NotFnd	** yes, push #0

	D1=A							->cob|prlg
	A=DAT1	A	[->cob|prlg]
	LC(5)	=PRLG			PRLG
	?C#A	A	** [->cob|prlg] # PRLG ?
	GOYES	InDir	** yes, indirect

	AD0EX		->cob
	D0=A						->comp
	D1=A							->cob
	A=DAT1	A	cob prol

InDir	C=R2.F	A			ob prol
	?A#C	A	** prol not equal ?
	GOYES	EqLp	** yes, next ob

	CD1EX				->cob
	B=C	A		->cob
	D1=C							->cob
	CD0EX				->comp		->cob
	RSTK=C		** save ->comp

* CPU
*	D0: ->cob	R0: cnt
*	D1: ->cob	R1: ->ob
*	B:  ->cob	R2: ob
*	D:  ob len	RSTK: ->comp

	GOSBVL	=SKIPOB					->past cob

	CD0EX				->past cob
	C=C-B	A			cob len

	?C#D	A	** equal lengths ?
	GOYES	NotEq	** no, loop

	A=R1.F	A	->ob
	D0=A						->ob

	B=C	A		ob len
	BSR	A		reg count
	P=C	0	** P: nibble count

Comp16	B=B-1	A		--rcnt
	GOC	CompP	** check rest

	A=DAT0	W
	C=DAT1	W
	D0=D0+	16
	D1=D1+	16

	?A=C	W
	GOYES	Comp16

NotEq0	P=	0
NotEq	C=RSTK
	D0=C
	GOTO	EqLp

CompP	P=P-1
	GOC	FndEq

	A=DAT0	WP
	C=DAT1	WP

	?A#C	WP
	GOYES	NotEq0

FndEq	P=	0
	C=RSTK
Psh#Lp	GOVLNG	=PUSH#LOOP
ENDCODE

*Here:	( *comp ob #pos* )

    #0<> caseDROP

*Here:	( *comp ob* )

    >TCOMP		( *comp'* )
;

---end_source---


Raymond Hellstern -Magic48ges- Email: 101.165571@germany.net