Shop OBEX P1 Docs P2 Docs Learn Events
64 bit math with a 32 bit CPU — Parallax Forums

64 bit math with a 32 bit CPU

HumanoidoHumanoido Posts: 5,770
edited 2009-09-03 19:18 in Propeller 1
How to convert a Prop chip from 32 bit to 64 bit in a very simple way?
Think ultra very simple example here...

edit subject
from: 32 to 64BIT Prop
to: 64 bit math with a 32 bit CPU

Post Edited (humanoido) : 8/14/2009 8:27:39 AM GMT

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-08-13 09:20
    Perhaps you should have been told that the Propeller is a 32-bit CPU running at 5MHz. Then you could "challenge" us to run it 16 times faster and then further "challenge" us to "multiply" the CPU eight times in a very simple way. Having accomplished this would you be happy then? We are.

    *Peter*
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-08-13 09:50
    Thanks Peter, it's a good point. I'm already very happy with the Propeller chip and all of its magic - and have the clock design increased to 200MIPS running across eight cogs with 32-bit math. It's a simple 64-bit math example that I was thinking about to more readily compare apples and oranges.
  • Jay KickliterJay Kickliter Posts: 446
    edited 2009-08-13 12:31
    There's no magic, just 'trons. As far as 64 bit is concerned. You can do 64 bit math in software, but you can't change the chip from 32 to 64 bit architecture. It's hardwired in there. Check the Propeller Wiki for 64 bit math examples.
  • hinvhinv Posts: 1,255
    edited 2009-08-13 13:58
    To be more specific, there is a carry signal(and others) that flows through the 32 bits when adding and on to the carry flag. Since this signal is not externally wired(no pin), it is not a straight forward proposition to add on another 32 bits to the ALU. It is possible to do this in software by putting the carry bit(and others) out a pin and then picking it up with pins on a second prop, or another cog within the same prop, but the effect is that your calculations have just cost you a whole lot more(slower) than if you would just do the 64bit calculations in a sequential algorithm within the same 32bit processor.

    I hope that helps.

    Thanks,
    Doug
  • KyeKye Posts: 2,200
    edited 2009-08-13 14:13
    Use the addx, subx, cmpx, etc instuctions. The carry from the first instruction gets considered in the next.

    For example:

    add a, b wc
    addx c, d

    That would add a to be, then the overflow would appear in c plus d. Of course you need to figure out what to do when the value is split across two registers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-08-13 15:15
    hinv said...
    ...if you would just do the 64bit calculations in a sequential algorithm within the same 32bit processor.
    Kye said...
    Use the addx, subx, cmpx, etc instuctions. The carry from the first instruction gets considered in the next. For example: add a, b wc addx c, d That would add a to be, then the overflow would appear in c plus d. Of course you need to figure out what to do when the value is split across two registers.
    How about simply equating single to double precision math operations as a relationship from 32bit to 64bit?
  • hinvhinv Posts: 1,255
    edited 2009-08-13 15:20
    Please explain what you are trying to accomplish.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-08-13 23:35
    Add 56 and 78 via a "relationship" from single digit to multi digit do you mean? Ok, 6 + 8 = 4 plus a carry 1 to the next higher digit, 5 + 7 + carry 1 = 3 plus a carry 1 to the next higher digit. Alright, if you know your 2nd grade maths then you would know that is exactly how it was explained to you concerning 64-bit maths on a 32-bit machine (which btw was not your original question).

    You do know this, don't you?

    *Peter*
  • Agent420Agent420 Posts: 439
    edited 2009-08-13 23:40
    humanoido said...
    It's a simple 64-bit math example that I was thinking about to more readily compare apples and oranges.
    What's the orange in your comparison...· Prop vs ?

    ·
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-14 02:03
    humanoido said...
    How to convert a Prop chip from 32 bit to 64 bit in a very simple way? ... How about simply equating single to double precision math operations as a relationship from 32bit to 64bit?
    And just what kind of fairy dust do you think can be sprinkled on silicon to magically transform it like that? Humanoido, if your quixotic quests finally lead you to that enchanted rabbit hole, please don't hesitate to inform us. Until then, good luck!

    -Phil
  • KyeKye Posts: 2,200
    edited 2009-08-14 02:11
    Ah, he's just pushing the limits of the hardware, don't get mad at him.

    But, what he's trying to do is pretty much beyond the prop chip in a SIMPLE way. Anying with 64 bit math will require complex stuff all over the place.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-14 02:13
    Kye,

    'More like failing to acknowledge that there are limits. It's not anger, just heavy eye-rolling. eyes.gif

    -Phil
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-08-14 04:07
    The 32-bit to 64-bit Propeller study project is now complete. Results will appear with an upcoming project. Thanks to well designed extended math routines of the Propeller chip and mathematical algorithms, it's a relative breeze to calculate the results once you see the light. The propeller chip is very powerful - if you have a couple minutes of spare time, take a look at the math tables and functions. While most bit manipulation considerations move 32 into 64, there are relatively few considerations that move 64 into 32, hence, it's a rather unique project. While posts can include theoretical thinking, this is one that is entirely doable and does not involve any leaps of faith. Thanks to everyone who gave a vote of confidence.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    humanoido
    *Stamp SEED Supercomputer *Basic Stamp Supercomputer *TriCore Stamp Supercomputer
    *Minuscule Stamp Supercomputer *Three Dimensional Computer *Penguin with 12 Brains
    *Penguin Tech *StampOne News! *Penguin Robot Society
  • Nick MuellerNick Mueller Posts: 815
    edited 2009-08-14 07:13
    If you would have named the subject "64 bit math with a 32 bit CPU" you wouldn't have had to face so many raised eyebrowns. smile.gif
    A 32 bit CPU is a 32 bit CPU is a 32 bit CPU. There's no way to change that.

    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-08-14 08:21
    Thanks Nick! So that's what happened!!! Ok, it's not too late to amend and improve the subject which I will do now. Thank you for noting this. To all the guys who thought it was a project requiring Angel dust and a magic wand, don't be too disappointed...

    humanoido
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2009-08-14 09:29
    You said...
    a project requiring Angel dust and a magic wand

    Lol! I like that smile.gif

    You can do any task with a propeller that you can do with a supercomputer.
    It's just that the supercomputer can do something really intense, like say, simulate a complex weather system in perhaps
    .1 seconds and the propeller might take a century.

    It's all a cost/performance issue....picking the right hardware for the job at hand.

    It's amazing what can be done with an 8 dollar prop...it's also amazing what geeks did with old 1mhz 8 bit computers in the 70's.
    Those old coders must have been magicians!

    I have used something as cheap and simple as a 50 cent 8 bit ATtiny11 to do a job...and it did it very well!
    melody1.jpg

    I have used a 500mhz ARM9 board to do much more complex jobs...at a cost of around 250.00 ... the ATtiny11 could never
    have handled the job.
    Technologic_Systems_TS-7800.jpg


    For a few really intense projects we used a small motherboard with a quad core cpu at 2.6Ghz. We used a small flash drive
    to boot Linux and the mobo had built in ethernet, video, audio, usb..etc. The cost was about 350.00 but the power of the board was
    amazing...this is what you use if you get a project requiring Angel dust and a magic wand smile.gif
    mb_productimage_ga-ma785gm-us2h_big.jpg

    Now I am learning how to squeeze every last bit of power from the 8 dollar Propeller and it turns out to be able to stand
    in for an ARM in some projects, this saves $ and makes me look smarter than I really am wink.gif

    So, I say squeeze all you can out of the Prop...it's really fun to do that, but don't expect it to perform like a 500mhz ARM or a quad core 64bit AMD.
  • ericballericball Posts: 774
    edited 2009-09-03 16:19
    humanoido said...
    How to convert a Prop chip from 32 bit to 64 bit in a very simple way?
    Think ultra very simple example here...
    The Propeller ALU is 32 bits with 2 flags.· So all operations generate a 32 bit output + 2 flags from two 32 bit inputs + 2 flags.· Depending on the opcode, the 2 flags may or may not affect the outputs.· Plus, whether the flags and or the destination are updated is controlled by the programmer.

    In SPIN, variables may be signed 32 bit numbers (native) or unsigned 16 or 8 bit numbers.· The latter are done by zero extending the input values to 32 bits and truncating the result to 8 or 16 bits.· In PASM the 32 bit values mean what the programmer wants them to and do not have any specific format (i.e. signed versus unsigned, integer versus fraction) except for the context in which they are used.

    As Kye indicated, the Carry flag may be used to extend the ADD and SUBtract operations across multiple registers and thus to any number of bits.· This same feature has been used since the earliest microprocessors.· Unfortunately, in order to access the flags you will need to program in PASM.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-09-03 17:50
    ericball said...
    As Kye indicated, the Carry flag may be used to extend the ADD and SUBtract
    operations across multiple registers and thus to any number of bits. This same
    feature has been used since the earliest microprocessors. Unfortunately, in order
    to access the flags you will need to program in PASM.
    I only need one sample program, to add two numbers resulting in a 64-bit sum,
    using this technique in Propeller Assembly language so it can serve as a benchmark.

    humanoido
  • TimmooreTimmoore Posts: 1,031
    edited 2009-09-03 19:18
    Here should be an add 64 in spin, the only special case is when the 2 lower 32bits both have 1 in their most significant bit, when there will be an overflow
    so check for this and increment upper 32bit sum.

    long h1,l1, h2, l2, ho, lo ' h1, l1 is 1 input, h2,l2 is other input, ho,lo is output
    
    ho := h1 + h2
    lo := l1 + l2
    if l1 < 0 AND l2 < 0 OR (((l1 | l2) < 0) AND lo < 0) ' if both lower 32bits have MSB 1 then will overflow so carry to higher 32 bits
                                                                             ' or lo MSB is 1 and either l1 or l2 MSB is 1
      ho++
    
    



    sub is similar - 2 subs, a check for underflow and a fix

    Post Edited (Timmoore) : 9/3/2009 7:25:02 PM GMT
Sign In or Register to comment.