128bit math[started but more is needed.]
mctrivia
Posts: 3,772
ok so I am trying to do 128bit math on a 32bit processor. i remember multiply:
i do not remember how to get the carrys so that part of the code is wrong at present.
but how do i do a modulus?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $21.99 has backlight driver and touch sensitive decoder.
Post Edited (mctrivia) : 1/4/2010 3:03:25 AM GMT
VAR long x 'holds 128 bit value of x long M 'holds 128 bit value of M long t[noparse][[/noparse]9] '8+1 to handle overflow cause by simplified square function. PUB computebit| i 'Clear t for i:=0 to 7 t[i]:=0 't=x*x for i:=0 to 3 for j:=0 to 3 t[noparse][[/noparse]i+j]+=x[i]*x[noparse][[/noparse]j] t[noparse][[/noparse]i+j+1]+=(x[i]**x[noparse][[/noparse]j])+carry t[noparse][[/noparse]i+j+2]+=carry 'x=t//M [/i][/i][/i]
i do not remember how to get the carrys so that part of the code is wrong at present.
but how do i do a modulus?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $21.99 has backlight driver and touch sensitive decoder.
Post Edited (mctrivia) : 1/4/2010 3:03:25 AM GMT
Comments
-Phil
64/32 is easy to do. 128/32 is also easy. the problem is when you want to do 256/128 and return only the remainder that it gets hard. Successive approximation would take forever. Anyone know a cool trick?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $21.99 has backlight driver and touch sensitive decoder.
propeller.wikispaces.com/MATH
I wish someone would put the code on this page into a wrapper so it is easy to use. I'm not up to it.
Rgds, David
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $21.99 has backlight driver and touch sensitive decoder.
need to multiply to 64bit prime numbers together.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $21.99 has backlight driver and touch sensitive decoder.
The code doesn't work as it is. I assume the result is kept in the txxx registers.... call instructions are lacking a '#' but that is not the biggest problem.... I'll see if I can fix it.
Edit: this code works
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
Post Edited (Ale) : 1/7/2010 1:56:41 PM GMT
Why multiply more than once? The Propeller doesn't have a multiply instruction.
Use the shift and conditional add method for multiplying any number of bits.
Instead of 32 loops for a LONG you have 128 or 256 loops for that many bits and that does the whole multiplication.
For only 256 bits you could even do a long division (like in elementary school) to get the remainder.
You might not need any more than 1024 bits of chalkboard space since you don't need to remember
math that has already finished and has given answers, you know, all the numbers that go down the chalkboard
every time you get another digit of the answer, you can erase and forget, because you don't need to use them again.
I don't think there is anything good or evil for prime numbers here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $24.99 has backlight driver and touch sensitive decoder.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU