P
persenaama
Here's a brute-force peasant algorithm implementation:
uint32 mul(uint32 a, uint32 b)
{
uint32 v = 0;
for ( ; b; )
{
v += a & (0 - (b & 1));
a <<= 1;
b >>= 1;
}
return v;
}
It multiplies two 32 bit values, if you want 64 bit result you need to
write 64 bit addition and use "uint64" for v. Easiest way to do that is
something like this, since you don't have 64 bit integers:
struct uint64
{
uint32 v[2];
// .. operators you need here..
};
How you going to use the 64 bit result is up to you.. if you want
signed, too, it is fairly trivial.
This is not really answering your question, which is a bit mystry what
the problem is. Choosing the right types for compiler/language built-in
* operator? Or how to store and broadcast the user supplied
non-statically typed values to the built-in * operator?
By now, you should already have the code. I'm 99% sure that you do, so
the thread is closed? ;-o
uint32 mul(uint32 a, uint32 b)
{
uint32 v = 0;
for ( ; b; )
{
v += a & (0 - (b & 1));
a <<= 1;
b >>= 1;
}
return v;
}
It multiplies two 32 bit values, if you want 64 bit result you need to
write 64 bit addition and use "uint64" for v. Easiest way to do that is
something like this, since you don't have 64 bit integers:
struct uint64
{
uint32 v[2];
// .. operators you need here..
};
How you going to use the 64 bit result is up to you.. if you want
signed, too, it is fairly trivial.
This is not really answering your question, which is a bit mystry what
the problem is. Choosing the right types for compiler/language built-in
* operator? Or how to store and broadcast the user supplied
non-statically typed values to the built-in * operator?
By now, you should already have the code. I'm 99% sure that you do, so
the thread is closed? ;-o