Every time I read the propeller manual, I sort of stumble over add and addx, sub and subx and so on. Every time I think I should do something with the extended integer math.
Since I couldn't decide on how long my integers should be, I thought to just define that at variable level and do the math with any count of longs per variable. This lead to a pointer style of variable definition. A variable for the math routines is the address of a two long pointer, containing the length of a memory block (in longs) as first long and the address of the memory block (in longs) as the second long.
This sounds expensive, two longs overhead for a variable, and maybe it is, on a P1 I could press that into one long, but since the goal is to do math with long memory blocks, saving a long per variable seems not so important.
Using pointers makes a lot of things possible, the content of any variable can be at any address in HUB, including the ROM. So one can add the sine table to the cosine table and write the result to HUB, for example.
All variables are long aligned and 'longs' long, so we can do 32-bit, 64-bit, 96-bit, 128-bit..... math. All routines are fine with different sized variables, so adding a 64-bit variable and a 32-bit variable is supported. Same goes for 1024-bit (32 long) or 524,288-bit (4096 long) variables or any other size fitting into HUB.
So the math routines can add, subtract, multiply and divide signed and unsigned multi-long variables as long as they fit into memory. Since I needed CMP, CMPS, SHL, RCL and RCR for multiply and divide, they are also available.
As usual I did this in PASM, and build some simple SPIN test around it while debugging. All test cases seem to work fine.
BUT, what to do with it?
This is a solution, searching for a problem to solve.
Entering two 524,288-bit (4096 long) variables in the serial terminal and viewing the result seems boring. And confirming the result is not easy.
I even have no idea for a demo, besides a simple calculator in the serial terminal.
any input welcome,
I am just another Code Monkey
A determined coder can write COBOL programs in any language. -- Author unknown.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119