Skip to main content
jdmallett
Associate II
May 1, 2009
Question

How to get 64bit result from 32 x 32 multiply

  • May 1, 2009
  • 10 replies
  • 2552 views
Posted on May 02, 2009 at 00:36

How to get 64bit result from 32 x 32 multiply

    This topic has been closed for replies.

    10 replies

    jdmallett
    jdmallettAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    I am using the Raisonance compiler (Ride7). Does anyone know how to get a 64bit result from a 32 x 32 multiply using C or assembler?

    Many thanks if you can help!!

    [ This message was edited by: jdmallett on 30-04-2009 15:49 ]

    brunoalltest
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    I didn´t tested, but you need to work with long long casts.

    It is something like this.

    Code:

    typedef long long s64; // Just to follow the FWlib typedefs

    s64 a;

    s32 b;

    s32 c;

    a = (s64) b * (s64) c;

    ccowdery9
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    joseph239955
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    For signed multiply you should use SMULL rather than UMULL.

    picguy
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    UMULL r2,r3,r0,r1

    Unsigned multiply r0*r1. Low 32 bits of result to r2. High bits to r3.

    (FYI) Standard subroutine call puts parameters in r0 & r1. With r2 & r3 scratch – no need to save and restore r2 & r3. Copy result back to r0 & r1. Use an unsigned 64-but type as subroutine return type. Test to make sure you don’t have your two result words returned out of order.

    I assume MULL will do a signed multiply as above. I never use unsigned.

    picguy
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    Don’t know about Ride. But experiment to find a way to get a 64-bit return from your assembly language subroutine. Or you could return the product in a fixed location (not reentrant.) Or if all else fails you could pass the storage address for the product.

    jdmallett
    jdmallettAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    I have tried the typedef as in brunoalltest's post, however I get a 32 bit result with Ride7. Does the UMULL and SMULL work with inline assembler in Ride7? If so how do I do this?

    jaroslaw2
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    Small modification, it should work

    Code:

    typedef long long s64; // Just to follow the FWlib typedefs

    s64 a;

    s32 b;

    s32 c;

    s64 d;

    s64 e;

    d=(s64) b

    e=(s64) c

    a = d*e;

    jdmallett
    jdmallettAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    That's the problem I don't know the assembler mnemonics in Ride7...

    brunoalltest
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:10

    Quote:

    On 01-05-2009 at 14:54, Anonymous wrote:

    I have tried the typedef as in brunoalltest's post, however I get a 32 bit result with Ride7. Does the UMULL and SMULL work with inline assembler in Ride7? If so how do I do this?

    I´ve just tested the code with crossworks(it uses gcc, just like ride) and the arm7 simulator and it worked just like expected. My cortex-m3 board isn´t with me right now, but I´ve worked with long long casts and cortex-m3 before and it worked just fine.

    How are you checking the result? Hope you´re not using printf, it probably won´t support a long long variable. Use a breakpoint and check with the debuger interface instead.