2009-05-01 03:36 PM
How to get 64bit result from 32 x 32 multiply
2011-05-17 04:10 AM
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;2011-05-17 04:10 AM
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 ]2011-05-17 04:10 AM
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.2011-05-17 04:10 AM
For signed multiply you should use SMULL rather than UMULL.
2011-05-17 04:10 AM
2011-05-17 04:10 AM
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?
2011-05-17 04:10 AM
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.
2011-05-17 04:10 AM
That's the problem I don't know the assembler mnemonics in Ride7...
2011-05-17 04:10 AM
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;