Possible SPIN float or bigint support?
avsa242
Posts: 452
in Propeller 1
Hi @cgracey, @ersmith, @"Roy Eltham"
Would any of you (or anyone, really) be amenable to getting one or both of some kind of fixed-point (runtime) decimal/not-necessarily-whole-number support and/or a 64bit int (longlong, dlong, qword, int64?) in openspin or fastspin sometime in the future (preferably in openspin, since it produces compact bytecode output)? I know this may raise some people's hackles, and may be totally out of the question for technical reasons, but I'm running into more and more devices for which writing a driver is painstaking when e.g., sensor values need to be calculated to some absolute scale (Bosch, Melexis, TI devices I find, especially) that either yields small fractional numbers or those far in excess of the Prop's signed 32-bit long. I've used objects like F32 or UMath64 for some things before, but I'm also not talking about a simple var = 0.123 * 2 or var = 2^48 type operation here. Rather, formulas that are already a paragraph or half a page long or more in native form; it becomes too difficult to follow, either for me or for someone trying to read my code, when implemented with one of the former. I absolutely adore SPIN, but this is one thing that makes writing some software so difficult, I find myself shelving it, at least for an extended period of time, to come back to it later and try to "chisel away a little bit more."
Thanks for your consideration even if the answer is no!
Cheers,
Jesse
Would any of you (or anyone, really) be amenable to getting one or both of some kind of fixed-point (runtime) decimal/not-necessarily-whole-number support and/or a 64bit int (longlong, dlong, qword, int64?) in openspin or fastspin sometime in the future (preferably in openspin, since it produces compact bytecode output)? I know this may raise some people's hackles, and may be totally out of the question for technical reasons, but I'm running into more and more devices for which writing a driver is painstaking when e.g., sensor values need to be calculated to some absolute scale (Bosch, Melexis, TI devices I find, especially) that either yields small fractional numbers or those far in excess of the Prop's signed 32-bit long. I've used objects like F32 or UMath64 for some things before, but I'm also not talking about a simple var = 0.123 * 2 or var = 2^48 type operation here. Rather, formulas that are already a paragraph or half a page long or more in native form; it becomes too difficult to follow, either for me or for someone trying to read my code, when implemented with one of the former. I absolutely adore SPIN, but this is one thing that makes writing some software so difficult, I find myself shelving it, at least for an extended period of time, to come back to it later and try to "chisel away a little bit more."
Thanks for your consideration even if the answer is no!
Cheers,
Jesse
Comments
fastspin does support floating point arithmetic in C and BASIC, and allows you to call functions written in those languages from Spin, so you can do something like:
What about 64-bit integers? I was thinking that since Spin has an operator that returns the upper 32 bits of a result (**) that it might possibly be only a few steps away? But then I'm not a compiler or interpreter writer
Yeah, I thought about the interoperability of C and SPIN in fastspin - and this would probably be the easiest way in the short term. Could probably use that route for 64-bit ints, also? I just wanted to know if there was a path down the bytecode way also, for when programs get bigger...
In my (not so humble) opinion that would be the best way to go because the ability to mix BASIC, C, SPIN and PASM in one Program is one of the major features of FastSpin. As of now he targets P1 and P2 in LMM or PASM.
Like @avsa242 said programs get bigger. Being able to use bytecode for not time critical stuff is something proven to work with the P1 memory restrictions, same will work for the P2.
Since I never wrote a compiler I have no clue how much work this would be. But looking at his results so far it seems to me that he is a hell of astonishing programmer, lets support him a bit.
Like I did with the P2-Eval I will make sure he gets a P2-Production as soon as Parallax sells them, same goes for the P2D2.
I am not a C guy at all but it seems to me that he is now adding some standard library code what might lead to running Blockly generated C code to run thru FastSpin (@"Ken Gracey" are you following this?), that would be a major step to get the P2 into Parallaxes Education System.
I never had a P2 FPGA (sometimes I am frugal) so I did not use Pnut a lot, as soon as FastSpin (and Spin2gui) was there I was happy.
Enjoy!
Mike
What features do you guys consider the highest priority?
(1) long (64 bit) integers
(2) long (64 bit) floating point
(3) bytecode output
(4) file I/O libraries
(5) automatic updates to spin2gui
There are also some cases where an interim 64 but result is enough, which may give some low hanging fruit ?
Things like scaling, where you might do A*B/C, where the (A*B) needs to be 64b, but the final answer can be 32b.
-Phil
1 and 2 are basically (pun intended) solved by the example you gave.
3 would be fantastic - but Chips Interpreter is not ready yet and the new TAQOZ in rom is in the next P2.
That leaves 4.
I had not thought about that one. Nice! Having file i/o consistent over all languages would be a perfect addition. And you are thinking about adding file support to micro python anyways, it might be a good idea to do that together.
Enjoy!
Mike
How important is it that the bytecode be the same as Chip's?
It seems like there are 4 choices for fastspin bytecode output:
(a) Spin1 bytecode (runs natively on P1, uses Cluso's or some similar interpreter on P2)
(b) Spin2 bytecode (we would need to wait for Chip's P2 interpreter, and then would need a port to P1)
(c) Tachyon/TAQOZ wordcode: I'm not even sure this is possible, I haven't looked at it
(d) A custom bytecode designed for fastspin
Option (a) is tempting, but it has some big disadvantages too: some fastspin features (like inline assembly) could not be supported by the P1 bytecode, and others (unsigned arithmetic) would be difficult.
Option (d) is the one that would allow for the best support. But I worry that no matter how good it is, if it isn't the "official" Spin bytecode people would not use it.
Since the bytecode Interpreter has to be loaded together with the bytecode [except (a) on P1] I think it does not matter.
My simple thinking was that it might be more easy to use a existing interpreter. As often I seem to be wrong.
If (d) would give best support - go for it. PropGcc for P1 and its CMM interpreter is also not compatible with Spin1 byte codes but is used pretty often. And I never heard anybody complaining that TAQOZ does not create Spin1 byte code.
Someone here on the forum mentioned the idea that since the interpreter needs to get soft loaded anyways a smart compiler could just include 'used' byte codes to optimize it down in size.
And I am quite sure that you do not need to worry about people not using FastSpin.
Enjoy!
Mike