32bit multiplication in a PowerPC405 of a VirtexIIPro

Hello,

I would like to do a 32bit multiplication. The result must be stored in a "64bitregister".

I did that :

Xuint32 test1=0xFFFFFFFF; Xuint32 test2=0xBBBBBBBB; Xuint64 *res64; res64 ->Upper = (test1 * test2) >> 32; res64 ->Lower = test1 * test2;

But it didn't work ! Do you have an idea how to do that ?

Regards, Laurent.

Reply to
LilacSkin
Loading thread data ...

What about

Xuint32 test1=0xFFFFFFFF; Xuint32 test2=0xBBBBBBBB; Xuint64 res64;

res64 = mul32by32(test1, test2);

Reply to
Sylvain Munaut

You need to type cast test1 and test2 to be 64 bits before you multiply them together.

Try:

*res64 = ((Xuint64)test1) * ((Xuint64)test2);

Regards,

John McCaskill

formatting link

Reply to
John McCaskill

Nope ... that would work if xilinx used the "unsigned long long" type for their

64 bits type ... But they didn't ... (don't ask me why they did that ...)

typedef struct { Xuint32 Upper; Xuint32 Lower; } Xuint64;

Sylvain

Reply to
Sylvain Munaut

their 64 bits type ...

My mistake then,

I boot into Linux and use the u_int64_t or the unsigned long long as you mention. A bit more type casting would get the OP there I think. Or just use the routine you mentioned.

Regards,

John McCaskill

formatting link

Reply to
John McCaskill

Xuint32 test1=0xFFFFFFFF; Xuint32 test2=0xBBBBBBBB; unsigned long long res64;

res64 = ((unsigned long long) test1) * ((unsigned long long) test2)

- Peter

LilacSk> Hello,

Reply to
Peter Ryser

The definitions in xbasic_types.h are compiler independent. In other words, unfortunately, not all compilers support "unsigned long long". We also found that some of them do but the result of the computation was incorrect.

GCC does support "unsigned long long" and produces the correct result.

- Peter

Sylva>> You need to type cast test1 and test2 to be 64 bits before you

their 64 bits type ...

Reply to
Peter Ryser

C does what's called "integral promotion" when doing a math operation. Basically, if you do some math with two types, the compiler chooses a type for the intermediate results. The simplified rule is: if the operand types fit in an int, use an int, otherwise use an unsigned int. Your multiply on the first line is going to have a 32 bit result on any

32-bit-int system. That means when you shift it down 32, you'll get 0.

The only way to get the compiler to do the math in a wider type is to explicitly force one of them to be wider. That's what all the casting is about in the other replies you've gotten. If it's not working, it's a flaw of your compiler. The PPC target of GCC could do what you want just fine.

--
Ben Jackson AD7GD

http://www.ben.com/
Reply to
Ben Jackson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.