EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
86 stars 15 forks source link

no speed increase with this program? #27

Closed nippur72 closed 5 years ago

nippur72 commented 5 years ago

I have a strange case where a BASIC program results in almost no speed improvement when compiled with Mospeed. I'm trying to figure out the reason... my suspect it's the floating point ops being the bottleneck, but I am not sure.

It's a 3d-plot of a circular sine function. It's a mixture of BASIC and ML (for plotting on the screen). I wrote it with asmproc, a language tool of my own.

You can run the two side by side in VICE and see no gain:

Also:

Do you have any clue?

Edit: this is what is given to mospeed:

100 poke 53272,peek(53272) or 8
105 poke 53265,peek(53265) or 32
106 sys 6660
110 dim m(192)
120 fort=0to192:m(t)=184:next
130 fory=35to-35step-1
140 foro=0to191
150 x=(o+y*4-96)/7
160 h=sqr(x*x+y*y)
170 ifh<>0thenz=-sin(h)/h
180 v=84+y*2+z*70
190 ifv>m(o)thenv=m(o):goto 200
191 m(o)=v
200 poke 6656,o and 255:poke 6656+1,int(o/256)
210 poke 6658,v
220 sys 6723
230 next
240 next
250 goto 250
EgonOlsen71 commented 5 years ago

I'm not sure, why you don't see a speed improvement here!? When I run both programs side by side, the compiled version is almost 3 times faster than the interpreted one. It's not more mainly because of the SIN call, which is very expensive (and the rest is quit a lot of fp math as well) and the compiler doesn't do anything to speed it up, because it uses the ROM routines for floating point math...except for your SQR call. It will accelerate that one slightly.

nippur72 commented 5 years ago

Doh!

For some very odd reason, the following shell command runs two instances of VICE but loads the SAME .prg

x64 3dfun_c64.prg & x64 3dfun_c64_mospeed.prg

(it's a Windows 10 x64 system).

Run them separately and the world is ok again! Thanks!

And yes, the speed gain is about 3x. Very nice, love this compiler.