PowerBASIC Forums
  Third-Party Addons
  A Very Small Fast Parser ( Assembly code) (Page 2)

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone!
This topic is 4 pages long:   1  2  3  4 
next newest topic | next oldest topic
Author Topic:   A Very Small Fast Parser ( Assembly code)
Charles Pegge
Member
posted August 05, 2006 05:29 AM     Click Here to See the Profile for Charles Pegge     Edit/Delete Message   Reply w/Quote
Okay.

Here is the tabular version. It runs about 10% faster, and is more
configurable. Not too bulky either.

I have appended it to the previous forum topic as
ParseTableDemo.zip
http://www.forum.it-berater.org/index.php?topic=158.0

The source for the short-jump version is also included in the zip
for posterity.

Thanks for all your comments and CPU performance data.
Further ideas very welcome.

------------------
Charles

IP: Logged

Paul Dixon
Member
posted August 05, 2006 05:40 AM     Click Here to See the Profile for Paul Dixon     Edit/Delete Message   Reply w/Quote
Charles,
that's not quite what I had in mind.
If you use tables the right way you can do away with almost all of the jumps and most of the logic and probably double the speed of the code. Almost the entire logic of your code can be converted into 1 or 2 table lookups.
If I get time later today I'll see what I come up with.

Paul.

------------------

IP: Logged

Eros Olmi
Member
posted August 05, 2006 05:50 AM     Click Here to See the Profile for Eros Olmi     Edit/Delete Message   Reply w/Quote
Remembering old discussion on DWORD/LONG speed I changed

DIM bwi AS DWORD ' character position of word in the string
DIM lbi AS DWORD ' length of string
DIM ii AS DWORD ' next position after the end of the word
DIM testloops AS DWORD

to

DIM bwi AS LONG ' character position of word in the string
DIM lbi AS LONG ' length of string
DIM ii AS LONG ' next position after the end of the word
DIM testloops AS LONG

and jump from 24450 to 37790

For this reason I use DWORD only when interfacing with API functions.
In all other cases I always use LONG and only for this I've got a lot of speed
when inside big loops or many value assignments.

Regards


------------------
Eros Olmi
eros.olmi@thinbasic.com

[This message has been edited by Eros Olmi (edited August 05, 2006).]

IP: Logged

Charles Pegge
Member
posted August 05, 2006 06:28 AM     Click Here to See the Profile for Charles Pegge     Edit/Delete Message   Reply w/Quote
That is astonishing!

The speed has jumped from 21000 to about 32000.
I am just trying to pinpoint the cause.
It might be something to do with the inner loop:

WHILE ii<=lbi
GOSUB zbword
WEND

because bwi does not make a difference whether LONG or DWORD

------------------
Charles

IP: Logged

Eros Olmi
Member
posted August 05, 2006 06:33 AM     Click Here to See the Profile for Eros Olmi     Edit/Delete Message   Reply w/Quote
I've no time now to search but there was a discussion on this here somewhere.

I remember Marco Pontello and others did an assembly comparison
between DWORD and LONG and found the reason why this was appening.

I'm not an ASM guy so I've no clue why.

Ciao

------------------
Eros Olmi
eros.olmi@thinbasic.com

[This message has been edited by Eros Olmi (edited August 05, 2006).]

IP: Logged

Paul Dixon
Member
posted August 05, 2006 06:42 AM     Click Here to See the Profile for Paul Dixon     Edit/Delete Message   Reply w/Quote
DWORD vs LONG is nothing to do with ASM.
When variables are used in PB LONGs are quicker so you should always use them unless there is a very good reason to use DWORDs instead.
For bwi it makes no difference because, while in your timing loop, bwi is never accessed by BASIC commands, only by ASM.

Paul.

------------------

IP: Logged

Charles Pegge
Member
posted August 05, 2006 07:14 AM     Click Here to See the Profile for Charles Pegge     Edit/Delete Message   Reply w/Quote
Eros

The speed has just gone up even further from 32000 to 36000 by
replacing the inner loop with assembler

ii=1
' WHILE ii<=lbi
' GOSUB zbword
' WEND

! push eax
loopz:
GOSUB zbword
! mov eax,ii
! cmp eax,lbi
! jle short loopz
! pop eax

You could try this with some of your code.

------------------
Charles

IP: Logged

Eros Olmi
Member
posted August 05, 2006 07:39 AM     Click Here to See the Profile for Eros Olmi     Edit/Delete Message   Reply w/Quote
Paul,

I know asm as nothing to do with it but instead how PB compiler handle it.
But to understand what's behind the curtains asm is needed in order
to see what code is added or is different to manage LONG vs DWORD.
And at this point ... I'm lost


Found something but not what I was remembering: http://www.powerbasic.com/support/forums/Forum4/HTML/009037.html

------------------
Eros Olmi
eros.olmi@thinbasic.com

IP: Logged

Eros Olmi
Member
posted August 05, 2006 07:42 AM     Click Here to See the Profile for Eros Olmi     Edit/Delete Message   Reply w/Quote
Charles,
I'm very interested in your code.
I need some time to study it due to my lack in asm.

Thanks

------------------
Eros Olmi
eros.olmi@thinbasic.com

IP: Logged

Charles Pegge
Member
posted August 05, 2006 07:57 AM     Click Here to See the Profile for Charles Pegge     Edit/Delete Message   Reply w/Quote
Paul,

I confirm what you say.

Just ii=1 seems to make a speed difference, when ii is a
DWORD instead of a LONG.

The speed penalty here is 34666 vs 36211 words/msec.

I have been puzzling how to further reduce the logic in the
parser. I am using 9 conditionals. 12 have been eliminated.

The lowest theoretical limit must be:
1 for string length checking
1 for quote markers
1 for leading space checking
1 for delimits.

2 tables required:
1 for self delimit
1 for non-self delimit

just thinking aloud...

------------------
Charles

IP: Logged

Paul Dixon
Member
posted August 05, 2006 09:32 AM     Click Here to See the Profile for Paul Dixon     Edit/Delete Message   Reply w/Quote
Charles,
the way to reduce the number of compares/jumps is to use a jump table, I'll sort some example out later today.
If you can make your data string a zero terminated string then using jump tables should reduce your code size a lot and remove all of the compares.


Paul.

------------------

IP: Logged

Michael Mattias
Member
posted August 05, 2006 10:44 AM     Click Here to See the Profile for Michael Mattias     Edit/Delete Message   Reply w/Quote
Extract ParseTableDemo.Exe
Run
MSGBOX ==>>
Words/millisec 3288
Length of code 124

Dell PII/400 Mhz, Windows/98. Normal program mix, but did nothing whilst demo was running.

MCM

IP: Logged

Nick Luick
Member
posted August 05, 2006 11:25 AM     Click Here to See the Profile for Nick Luick     Edit/Delete Message   Reply w/Quote
P3 500MHz 256k Win98
ParseTableDemo.exe

4490
124

------------------

IP: Logged

Charles Pegge
Member
posted August 05, 2006 02:34 PM     Click Here to See the Profile for Charles Pegge     Edit/Delete Message   Reply w/Quote
Paul,

Yes I can see how a set of jump tables would work. I think
four would be needed to provide equivalent functionality, which
considerably bulks out the code. (4k)

To make efficient use of pipelining I presume the jump tables
have to be adjacent to the rest of the code. To ensure this happens,
the assembled binary could be fed into an array with the jump tables.
and then called by DWORD.

------------------
Charles

IP: Logged

Eros Olmi
Member
posted August 05, 2006 04:28 PM     Click Here to See the Profile for Eros Olmi     Edit/Delete Message   Reply w/Quote
Charles,

for those like me not expert in ASM, what about to create it in a form of function?
Something like GetNextToken(byval StringPtr, byval StartPos, byref TokenStart, byref TokenLen)
This would be very useful for many I think.

Thanks a lot

------------------
Eros Olmi
eros.olmi@thinbasic.com

IP: Logged


This topic is 4 pages long:   1  2  3  4 

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2006 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c