BASIC compiler
Chris Hall (132) 3554 posts |
Equivalent figures for RiscBASIC are: Using Virtual Risc PC: Integer BASIC interpreted : 5549cs Float BASIC interpreted : 7100cs |
Rick Murray (539) 13840 posts |
I tried to hack the C program to using VFP1, but I must have screwed something up. It never increments beyond the first 1/30 (or maybe LDF/STF vs VFP format issues?). However given the speed that it takes getting there, my mostly-pulled-out-of-my-backside guesstimate is something in the order of 8-10cs. You know, if it had worked. ;-) 1 Somewhat complicated by the fact that setting an FP register to zero, and adding one (or any constant?) to an FP register don’t appear to be valid operations…hmm… |
David Feugey (2125) 2709 posts |
I repeat: it’s ANSI Basic. The idea was to compare different Basic dialects.
That’s exactly what I did. |
Clive Semmens (2335) 3276 posts |
Indeed. What instructions would you want to issue to implement these? You’d have to load the zero (as an integer) into a (single-precision) VFP register (FLDS), then convert it to FP (FSITOS or FSITOD); load the 1 (or other constant) into another VFP register, then convert it to FP. Then add the two registers. There are indeed no “set to zero” or “add constant” (integer or otherwise) instructions in the VFP instruction set. (Or at least, there weren’t in the original VFP instruction set that I documented. What if anything has been added to the set since I’ve no idea.) |
David Pitt (102) 743 posts |
I have run David Feugey’s tests from above on a few conveniently to hand platforms. VRPC and RPCEmu are on a 3.4GHz iMac. VRPC RPCEmu RPCEmu RPCEmu PRi3 Titanimm 6.20 6.20 5.23 4.02 5.23 5.23 Integer BASIC 3445 7647 5400 7744 3132 2308 Float BASIC 3518 7964 5784 8143 3195 2337 Integer ABC 1675 2015 1963 2001 877 800 Float ABC 6324 7108 7168 7150 3317 3339 |
Rick Murray (539) 13840 posts |
Your documentation matches mine (as you co wrote it!), but debugger and Zap expect UAL. I did stack R0, MOV 1 into R0, VMOV S1, R0 then VADD.F32 S1,S0,S1 and finally unstack R0 and return. |
Clive Semmens (2335) 3276 posts |
Yes, you do have to convert the integer to FP format before you can do anything with it. You also have to convert the zero – which will become +0.0 (which is different from -0.0 – you’d have to FNEGS it if you wanted -0.0 – not that I can imagine why you would!) UAL? As in Unified Assembler Language? Doesn’t cover VFP at all, afaik – VFP was obsolete by the time UAL came out. But in principle it ought to be happy with VFP instructions anyway, why not? |
Clive Semmens (2335) 3276 posts |
I was fibbing (unintentionally…) – I didn’t write the VFP documentation at all. I know it fairly well, but it was written before my ARM days. Which bits I wrote and which I merely know well is sometimes hard to remember! But nothing before 1997 or after 2007 is me. |
David Feugey (2125) 2709 posts |
VRPC is fast. I’m curious to know if VRPC DL + ROS 4.02 is faster than RPCEmu + ROS 5.22 |
Steve Drain (222) 1620 posts |
@Rick I looked at your test program and decided it could be used to illustrate my point about gaining speed without using a compiler. I ran the original on my ARMX6 and it took 2541 cs. I then worked on it to produce the program below and it took 675 cs. As far as I can tell it does an identical job, and if I print the
Here are things I did, some having a much bigger effect than others:
|
David Pitt (102) 743 posts |
I have done a quick comparison on an elderly Windows 7 laptop. RPCEmu VRPC DL 5.23 4.02 Integer BASIC 11397 12595 Integer ABC 4448 3607 How’s that for a nice clear cut answer. |
Steve Pampling (1551) 8170 posts |
Um, 5.22 queried, 5.23 tested :) How about RPCEmu with RO4.02 vs RPCEmu with RO5.23 vs VRPC DL with RO4.02 |
David Feugey (2125) 2709 posts |
And what about the new BBC Basic module on an old OS? Is it easy to extract/copy? A modernisation pack for old OS would be great. I use a few ROS 5 components under ROS 3.11, and it’s very useful. |
Martin Avison (27) 1494 posts |
They are in the PlingSystem download (ie Distribution of !System for use with pre-RISC OS 5 machines). Take care not to softload a Basic module more than once, unless you are sure nothing is running that is still using it. |
David Pitt (102) 743 posts |
I have added results for RPCEmu 4.02. (I don’t have OS5.22 to hand here, OS5.23 is my best offer.) RPCEmu RPCEmu VRPC DL 5.23 4.02 4.02 Integer BASIC 11397 17463 12595 Integer ABC 4448 4356 3607 My take on this is the converse. That the compiled versions run at a similar speeds on RPCEmu seems reasonable as they are just machine code reflecting the speed of the emulator, which is the same in both cases. The difference in the BASIC results seems a bit large! HTH. |
Rick Murray (539) 13840 posts |
@ Steve: It isn’t my program, it is David’s. All I did was tart it up a little and add ‘%’s. I have no idea what it is supposed to be doing – it looks like a lot of screen position (?) calculations for something that never happens…? I just picked upon it because it did a bigger spread of calculations than my example.
Something so easily forgotten. It is not set on my system. Hmmm, I thought I did that in the boot stuff? Must go look…
Otherwise known as “know your language”.
Don’t they do the same thing?
That’ll be me. I believe that if there is any doubt as to how the calculation will be performed, add brackets. Operator precedence notwithstanding, just add brackets! ;-)
Good call.
Back to “know your language”. I think David has mentioned it was a program written in “standard ANSI BASIC”, though thankfully he spared me the awfulness of the keyword “WEND”, as did Sophie. ENDWHILE is much nicer.
Again, maybe ANSI BASIC can’t do implied casting?
It “looked complicated” so I ignored the logic. ;-) But, yes, something I believe in is that if I am writing a function with a complex algorithm in it, I will often write it, test it, make sure it works, and then I’ll delete it and start again. The first stages are helping to get the code flow set up in my head, and the rewritten algorithm is probably not great (as my mathematical ability sucks) but is usually better than the first go.
…and reduce them to single chracter values so there is less time spent looking up the variable. Your result of 1/4 of the speed just by rewriting it is really impressive. |
Rick Murray (539) 13840 posts |
I thought I’d have a crack at compiling Xeroid with ABC. Here are some of the issues uncovered during this experiment:
Somewhere along the way I messed something up and all I get on-screen is colour changes, no text or anything. I’m thinking I probably gave the wrong GCOL action as this looks like it is flood filling or something. Notwithstanding, it builds a program that is about 66K long that does not work – Okay, it’s an insane sized DIM, but still… ;-) |
David Feugey (2125) 2709 posts |
Oups, sorry. I did not remember :)
It’s not mine. It’s a generic ANSI Basic benchmark. That’s why I left it (almost) ‘as is’. To be fair with other offers.
It was a WEND. I just change it (but I don’t remember why). |
Chris Hall (132) 3554 posts |
ABC gives a list of unknown objects found (variables referred to that were not otherwise defined (actually – it was a debug routine marking reference to LOCAL variables outside of the function that they exist in)) ABC cannot handle LOCAL variables, it assumes PRIVATE variables such that (i) if there is no global equivalent the following will say variable not found:
If there is a global equivalent the following will use the wrong value:
|
Steve Drain (222) 1620 posts |
I knew that, but I was just using it for my example.
That is what I am on about, I suppose. ;-)
Save us from
My other beef: “It’s the algorithm, stupid!”. I was surprised that eventually all that logic was superfluous. I got there in stages, reducing a bit at a time. I do not think “well, it works” is a sufficient reason for sticking with what you already have. If I understand correctly, optimising compilers will sort out some of this excess, but that is not ABC.
That should really be left to a crunching program, of course. Using meaningful variable names is important.
That is a where I gave up on ABC so long ago. Writing loops to do the same did not compile to anything like the same speed.
But that is still excessive, and can be replaced by |
Jeffrey Lee (213) 6048 posts |
I’ve been having a bit of a play around with what the frontend for a BASIC compiler might look like – trying to see how much effort would be required to get to the point where you can get a syntax tree and start doing the interesting things like checking/resolving expression types or working out the possible program flows. I don’t expect it to go anywhere significant (I haven’t worked on it for the past few days, and I now have other things to do), but I figured it would be worth reporting my findings here.
I’ve also discovered some interesting things about BASIC, such as ‘.’ being a valid floating point number. |
Chris Evans (457) 1614 posts |
I’m sure there was mention of a BASIC to C converter a few months ago! Using Lau? I can’t now find the topic. |
Jeffrey Lee (213) 6048 posts |
There’s a BASIC to Lua converter (written in Lua), but no BASIC to C converters that I’m aware of. And really I was only planning on using C as a simple stepping stone to get a working compiler – if the project was to take off then I’d expect it would need to interface with either gcc or llvm in order to allow for constructs which C doesn’t really support (but I don’t yet fully understand BASIC’s flow control, so maybe C will be fine) |
GavinWraith (26) 1563 posts |
Unless I have overlooked it, I have not seen any mention on this thread of Martin Carradus’s BBC BASIC to Acornsoft C translator, nor of APDL’s BASIC to C translator. Has anyone any knowledge of these? |
Rick Murray (539) 13840 posts |
…uh, it was a thought exercise, not a serious proposition! ;-)
That’s worrisome, in several respects.
The “compiler” I didn’t write a decade and a half ago used tokenised code. I considered parsing text, but I decided it would just be a lot simpler if I left that to BASIC and worked with the result.
Mmm, BBC era vs RISC OS era; and everything Acorn vs BBfW.
That’s… strange. I guess Sophie has optimised out the need to specify superfluous zeros. I will point you also at some more legitimate BASIC just to highlight that, EVAL aside, there is a worrying amount of flexibility in the language (from the point of view of attempting to compile it). This thread has enough complaints about ABC (possibly justified, if the LOCAL behaviour is correct) to suggest that you’re going to fall foul of somebody’s pet “feature”…what do you mean {obscure behaviour that is likely a bug in BASIC} doesn’t work anymore! whinge! whinge! whinge!
The Google-fu is weak. Twenty seconds found this: http://www.martinkd.freeuk.com/ |