cancel
Showing results for 
Search instead for 
Did you mean: 

How to get 64bit result from 32 x 32 multiply

jdmallett
Associate II
Posted on May 02, 2009 at 00:36

How to get 64bit result from 32 x 32 multiply

10 REPLIES 10
brunoalltest
Associate II
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;

jdmallett
Associate II
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 ]

picguy
Associate II
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.

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

For signed multiply you should use SMULL rather than UMULL.

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

jdmallett
Associate II
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?

picguy
Associate II
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
Associate II
Posted on May 17, 2011 at 13:10

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

jaroslaw2
Associate II
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;