6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 14, 2024 6:41 am

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Mandelbrot Benchmarking
PostPosted: Thu Oct 05, 2023 4:02 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
I decided to update my old Mandelbrot benchmark to the one I used recently (originally in VTL) to check my TinyBasic, then on a whim, I decided to make it work on the other BASICs I had to-hand.

It should work on most retro/8-bit BASIC systems with minimal changes and work over 16-bit signed integer BASICs to 4 or 5 byte floating point ones.

I put it all here:

https://projects.drogon.net/retro-basic ... andelbrot/

Cheers,

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 5:45 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
Nice thanks for sharing it - I'm thinking of following your lead and porting BBC BASIC to my system, then maybe I can give it a go!


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 8:59 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Nice - thanks for writing up and sharing!

I wonder if there's something funny going on - I'm not 100% happy about the integer-mode output. Of course the problem might be my expectations!

Here's an owlet link for the Beeb running Basic 2
And here's the same thing but using integer arithmetic.
(In both cases, press the rocket button for a quick run.)

I'm suspicious of the shapes of the contours - posting this with a vague idea I might look into it tomorrow.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 9:44 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
BigEd wrote:
I'm suspicious of the shapes of the contours - posting this with a vague idea I might look into it tomorrow.


Me too... I'll translate it to another integer only system tomorrow when I get some time and compare.

Thanks,

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 05, 2023 10:35 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
BigEd wrote:
Nice - thanks for writing up and sharing!

I wonder if there's something funny going on - I'm not 100% happy about the integer-mode output. Of course the problem might be my expectations!
...
I'm suspicious of the shapes of the contours - posting this with a vague idea I might look into it tomorrow.

I had a play with this. Firstly I tried using "DIV" instead of "/" in the floating point version, and the output was not the same. Debugging this revealed that on line 220 the fraction from dividing by F% was affecting the result - i.e. in the integer version, this bit at least was benefiting from "/" being floating point division. So to get a truly integer execution in BBC BASIC, I think you do need to carefully change all the "/" to "DIV", or at least this one!

The real problem however is with the bounds check on lines 230-240:

Code:
230A%=T%: P%=A%/F%:Q%=B%/F%
240IF ((P%*P%)+(Q%*Q%))>=5 GOTO 280

P% and Q% suffer badly from rounding here, as you're dividing by the fixed point factor. You can use floating point for P and Q, or better, do the comparison in the fixed point space:

Code:
230A%=T%
240IF ((A%*A% DIV F%)+(B%*B% DIV F%))>=5*F% GOTO 280

This may suffer different problems if it ends up overflowing the maximum integer width - 16 bits is pretty narrow - I haven't thought much about what the worst-case inputs would be though!

It seems to work pretty well:
https://bbcmic.ro/#%7B%22v%22%3A1%2C%22 ... %5Cn%22%7D


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 7:07 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Oh, well done, that does look a lot better!


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 7:36 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
BigEd wrote:
Oh, well done, that does look a lot better!


Also, as an aside, interesting to note than even when presented with all integer variables, BBC Basic still does floating point operations if you're not careful...

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 7:53 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Yes... it does seem to make it a bit more difficult to experiment with the implications of different word sizes.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 06, 2023 9:43 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
gfoot wrote:
The real problem however is with the bounds check on lines 230-240:

Code:
230A%=T%: P%=A%/F%:Q%=B%/F%
240IF ((P%*P%)+(Q%*Q%))>=5 GOTO 280

P% and Q% suffer badly from rounding here, as you're dividing by the fixed point factor. You can use floating point for P and Q, or better, do the comparison in the fixed point space:

Code:
230A%=T%
240IF ((A%*A% DIV F%)+(B%*B% DIV F%))>=5*F% GOTO 280

This may suffer different problems if it ends up overflowing the maximum integer width - 16 bits is pretty narrow - I haven't thought much about what the worst-case inputs would be though!

WOZ BASIC errored out almost immediately with your modification, but was able to render a less accurate version of Gordon's original in about 696 seconds @ 1 MHz:
Code:
  100 REM PR#3 FROM > PROMPT FIRST!
  105 PRINT "MANDELBROT - WOZ BASIC"
  110 PRINT "START"
  130 DIM Z$(17):Z$=".:,;-=+^/%&S$X#@ "
  140 F=50
  150 FOR Y=-12 TO 12
  160 FOR X=-49 TO 29
  170 C=X*229/100
  180 D=Y*416/100
  190 A=C:B=D:I=1
  200 Q=B/F:S=B-Q*F
  210 T=(A*A-B*B)/F+C
  220 B=2*(A*Q+A*S/F)+D
  230 A=T:P=A/F:Q=B/F
  240 IF P*P+Q*Q>4 THEN 280
  250 I=I+1: IF I<17 THEN 200
  280 PRINT Z$(I,I);: NEXT X
  300 PRINT : NEXT Y
  330 PRINT "FINISHED";
  350 END

Attachment:
MAND_WOZ.PNG
MAND_WOZ.PNG [ 6.59 KiB | Viewed 5115 times ]

Applesoft renders a much better image, but takes about 860 seconds @ 1 MHz:
Code:
100  REM PR#3 FROM ] PROMPT FIRST!
105  PRINT "MANDELBROT - APPLESOFT"
110  PRINT "START"
130 Z$ = ".:,;-=+^/%&S$X#@ "
140 F = 50
150  FOR Y =  - 12 TO 12
160  FOR X =  - 49 TO 29
170 C = X * 229 / 100
180 D = Y * 416 / 100
190 A = C:B = D:I = 1
200 Q = B / F:S = B - Q * F
210 T = (A * A - B * B) / F + C
220 B = 2 * (A * Q + A * S / F) + D
230 A = T:P = A / F:Q = B / F
240  IF P * P + Q * Q > 4 THEN 280
250 I = I + 1: IF I < 17 THEN 200
280  PRINT  MID$ (Z$,I,1);: NEXT X
300  PRINT : NEXT Y
330  PRINT "FINISHED";
350  END


Attachment:
MAND_A2+.PNG
MAND_A2+.PNG [ 6.6 KiB | Viewed 5112 times ]

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 19, 2024 12:48 pm 
Offline

Joined: Thu Dec 26, 2002 12:29 pm
Posts: 81
Location: Occitanie, France
Hi,
I was looking for something simple to try out with my rather cumbersome (*) but all the same operational PLASMA Virtual Machine running on the Pico6502. I chose to adapt the Apple][ version that appears above. So the code becomes
[edit] BTW "word" in PLASMA means a 16-bit object.
Code:
byte[] Z = ".:,;-=+^/%&S$X#@ "
word A, B, C, D, E, F, I, P, Q, S, T, X, Y
    F = 50
    for Y = -12 to 12
        for X = -49 to 29
            C = X * 229 / 100
            D = Y * 416 / 100
            A = C; B = D; I = 1
            repeat
                Q = B / F; S = B - Q * F
                T = (A * A - B * B) / F + C
                B = 2 * (A * Q + A * S / F) + D
                A = T; P = A / F; Q = B / F
                if (P * P + Q * Q) > 4 break
                fin
                I++
            until I >= 17
            putc(Z[I])
            next
        putln
    next
    puts("FINISHED\n")
done

... which shows a part of the PLASMA vocabulary. If I run the code through the linux VM, it gives this picture
Code:
......::::::::::::::::::::::,,,,,,,,,;;;;;-=+/S$+^--;;,,,,,,:::::::::::........
.......:::::::::::::::::::::,,,,,,,,,;;;--=%/$  ^^%-;;;;,,,,,:::::::::.........
........::::::::::::::::,,,,,,,,;;;,----==+       %==-;;;;,,:::::::::..........
........:::::::::::,::::,,,,,,,;;;-==++=^^/       %^+==----,,,,::::::..........
.....::::::::::::,,,,,,,,;;;;;;;--=^ &S%              ^/^S=-;,::::::::::.......
...:::::::::::,,,,,,,,,,;;;;;;---++^                       =;,,,,:::::::::.....
....:::::::::::,,,;;;---------===&                       %+--;;,,,:::::::......
.....::::::,,,,,,;;-=X++=^ +===+^%                        &&-;;,,,:::::::......
....::,,,,,,,,;;;;-=+%  /$  #/^/%                          S-;;,,::::::::......
::::::,,,,,,;;;;;-==^/X        #                            -;;,,,::::::::::::.
:::::,,,;;;;-----^/%&                                      =-;;,,:::::::::::::.
::::,,;;--====+=/&                                       $+-;;,,,,,,::::::::::.
::::,                                                   %^=--;;,,,,:::::::::::.
::::,,;;--====+=/&                                       $+-;;,,,,,,::::::::::.
:::::,,,;;;;-----^/%&                                      =-;;,,:::::::::::::.
::::::,,,,,,;;;;;-==^/X        #                            -;;,,,::::::::::::.
....::,,,,,,,,;;;;-=+%  /$  #/^/%                          S-;;,,::::::::......
.....::::::,,,,,,;;-=X++=^ +===+^%                        &&-;;,,,:::::::......
....:::::::::::,,,;;;---------===&                       %+--;;,,,:::::::......
...:::::::::::,,,,,,,,,,;;;;;;---++^                       =;,,,,:::::::::.....
.....::::::::::::,,,,,,,,;;;;;;;--=^ &S%              ^/^S=-;,::::::::::.......
........:::::::::::,::::,,,,,,,;;;-==++=^^/       %^+==----,,,,::::::..........
........::::::::::::::::,,,,,,,,;;;,----==+       %==-;;;;,,:::::::::..........
.......:::::::::::::::::::::,,,,,,,,,;;;--=%/$  ^^%-;;;;,,,,,:::::::::.........
......::::::::::::::::::::::,,,,,,,,,;;;;;-=+/S$+^--;;,,,,,,:::::::::::........
FINISHED

If I run it through the 6502 VM, I get this picture
Attachment:
File comment: Picot_6502 Mandelbrot
PLASMA_Mandelbrot.jpg
PLASMA_Mandelbrot.jpg [ 2.71 MiB | Viewed 712 times ]

(*) I can't give any timing for the moment, because the "Pico6502" VM is, in fact, the linux version pushed through cc65 - with stdio and all the rest of it - and it spends 80% of it's time messing around with the C stack and only 20% doing any real work. More news soon on a more "native" 6502 version.

_________________
Glenn-in-France


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 29, 2024 8:16 am 
Offline

Joined: Thu Dec 26, 2002 12:29 pm
Posts: 81
Location: Occitanie, France
Hi all,
I have now successfully ported the PLASMA VM to the RP6502 "Picocomputer" in native ASM + Plasma.
It's probably because you're all so far away that I couldn't hear all of the "HOURRAA"s

Anyway, the above code completes in the native VM (bytecode interpreter) in 21.73 seconds. The 65C02 is being clocked at 7.5MHz, 'cos I'm getting fileIO errors at 8MHz. *AND* I had to cheat with the timing, the API entry for reading clock ticks doesn't work currently...

Have a great Sunday y'all.

_________________
Glenn-in-France


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 29, 2024 8:55 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Hurrah!


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 30, 2024 6:24 am 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 145
Location: Lake Tahoe
Hurrah! Can't wait to see what the hybrid VM will do


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 01, 2024 7:01 pm 
Offline

Joined: Thu Dec 26, 2002 12:29 pm
Posts: 81
Location: Occitanie, France
resman wrote:
Hurrah! Can't wait to see what the hybrid VM will do

Not sure what you mean... The last result is the "Native" (6502 assembler + Plasma code) VM. No C code at all.

_________________
Glenn-in-France


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 01, 2024 8:44 pm 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 145
Location: Lake Tahoe
GlennSmith wrote:
resman wrote:
Hurrah! Can't wait to see what the hybrid VM will do

Not sure what you mean... The last result is the "Native" (6502 assembler + Plasma code) VM. No C code at all.

When the C coded VM gets compiled for ARM and the byte codes get interpreted from the ARM core as an accelerator. Now you're cooking with gas.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 29 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: