|
|
Up |
|
|
  |
Author: perry.yuanperry.yuan Date: May 14, 2008 10:48
Hi Gurus,
I am looking for C code for multiplying 32bit by 32bit operands and
getting a 64bit product. i.e.
U32 m1, m2;
U64 p = m1 * m2;
Of course I can use
U64 p = (U64) m1 * m2;
But, disassembly listing shows that generated code calls a 64bit x
64bit multiplication routine.
The target I am working on has a 32bit x 32 bit => 64bit machine
instruction but doesn't have any 64bit x 64 bit instruction. Before I
wet my hand on assembly programming, I love to see any C code solution
to it.
TIA.
Perry Yuan
|
| |
|
| | 8 Comments |
|
  |
Author: BartBart Date: May 14, 2008 11:36
On May 14, 6:48 pm, "perry.yuan" gmail.com> wrote:
> Hi Gurus,
>
> I am looking for C code for multiplying 32bit by 32bit operands and
> getting a 64bit product. i.e.
>
> U32 m1, m2;
> U64 p = m1 * m2;
>
> Of course I can use
>
> U64 p = (U64) m1 * m2;
>
> But, disassembly listing shows that generated code calls a 64bit x
> 64bit multiplication routine.
>
> The target I am working on has a 32bit x 32 bit => 64bit machine
> instruction but doesn't have any 64bit x 64 bit instruction. Before I
> wet my hand on assembly programming, I love to see any C code solution
> to it. ...
|
| Show full article (1.01Kb) |
|
| | no comments |
|
  |
Author: Eric SosmanEric Sosman Date: May 14, 2008 11:46
perry.yuan wrote:
> Hi Gurus,
>
> I am looking for C code for multiplying 32bit by 32bit operands and
> getting a 64bit product. i.e.
>
> U32 m1, m2;
> U64 p = m1 * m2;
>
> Of course I can use
>
> U64 p = (U64) m1 * m2;
>
> But, disassembly listing shows that generated code calls a 64bit x
> 64bit multiplication routine.
>
> The target I am working on has a 32bit x 32 bit => 64bit machine
> instruction but doesn't have any 64bit x 64 bit instruction. Before I
> wet my hand on assembly programming, I love to see any C code solution
> to it. ...
|
| Show full article (1.78Kb) |
| no comments |
|
  |
Author: Keith ThompsonKeith Thompson Date: May 14, 2008 11:48
"perry.yuan" gmail.com> writes:
> I am looking for C code for multiplying 32bit by 32bit operands and
> getting a 64bit product. i.e.
>
> U32 m1, m2;
> U64 p = m1 * m2;
>
> Of course I can use
>
> U64 p = (U64) m1 * m2;
>
> But, disassembly listing shows that generated code calls a 64bit x
> 64bit multiplication routine.
>
> The target I am working on has a 32bit x 32 bit => 64bit machine
> instruction but doesn't have any 64bit x 64 bit instruction. Before I
> wet my hand on assembly programming, I love to see any C code solution
> to it.
|
| Show full article (2.38Kb) |
| no comments |
|
  |
Author: user923005user923005 Date: May 14, 2008 15:40
On May 14, 10:48 am, "perry.yuan" gmail.com> wrote:
> Hi Gurus,
>
> I am looking for C code for multiplying 32bit by 32bit operands and
> getting a 64bit product. i.e.
>
> U32 m1, m2;
> U64 p = m1 * m2;
>
> Of course I can use
>
> U64 p = (U64) m1 * m2;
>
> But, disassembly listing shows that generated code calls a 64bit x
> 64bit multiplication routine.
>
> The target I am working on has a 32bit x 32 bit => 64bit machine
> instruction but doesn't have any 64bit x 64 bit instruction. Before I
> wet my hand on assembly programming, I love to see any C code solution
> to it. ...
|
| Show full article (0.65Kb) |
| no comments |
|
  |
Author: rong889rong889 Date: May 15, 2008 22:01
On 5月15日, 上午6时40分, user923005 connx.com> wrote:
> On May 14, 10:48 am, "perry.yuan" gmail.com> wrote:
>
>
>
>> Hi Gurus,
>
>> I am looking for C code for multiplying 32bit by 32bit operands and
>> getting a 64bit product. i.e.
>
>> U32 m1, m2;
>> U64 p = m1 * m2;
>
>> Of course I can use
>
>> U64 p = (U64) m1 * m2;
>
>> But, disassembly listing shows that generated code calls a 64bit x
>> 64bit multiplication routine.
> ...
|
| Show full article (0.80Kb) |
| no comments |
|
  |
Author: thomas.mertesthomas.mertes Date: May 16, 2008 04:46
On 14 Mai, 19:48, "perry.yuan" gmail.com> wrote:
> Hi Gurus,
>
> I am looking for C code for multiplying 32bit by 32bit operands and
> getting a 64bit product. i.e.
It might not be exactly what you were looking for, but
years ago I wrote a function to multiply two 64 bit
unsigned numbers based on 32 bit unsigned logic (the
type uinttype in the example below is 32 bit).
This function makes sense when absolutely no 64 bit
arithmetic is available:
#define LOWER_16(A) ((A) & 0177777L)
#define UPPER_16(A) (((A) >> 16) & 0177777L)
#define LOWER_32(A) ((A) & (uinttype) 037777777777L)
static void mult_64 (uinttype a_high, uinttype a_low,
uinttype b_high, uinttype b_low,
uinttype *c_high, uinttype *c_low)
|
| Show full article (1.84Kb) |
| no comments |
|
  |
Author: perry.yuanperry.yuan Date: May 20, 2008 08:20
Thanks for all replies and comments. My thinking is: in C language,
operator * for integral types is type-closed (i.e. int32 * int32 =>
int32) but not value-closed (i.e. int32 * int32 => int63). So that
there is no way to do any value-closed integral * operation at C
language level.
|
| |
| no comments |
|
  |
|
|
  |
Author: Walter RobersonWalter Roberson Date: May 20, 2008 09:40
>Thanks for all replies and comments. My thinking is: in C language,
>operator * for integral types is type-closed (i.e. int32 * int32 =>
>int32) but not value-closed (i.e. int32 * int32 => int63).
It is value-closed for the unsigned integral types.
>So that
>there is no way to do any value-closed integral * operation at C
>language level.
unsigned int R = (unsigned int) A * (unsigned int) B;
You may wish to interpret the result in terms of the original signs
of A and B. R would be interpreted as negative if ((A < 0) ^ (B < 0))
(That's exclusive OR that I used.) If R > INT_MAX and should be
negative, or if R <= INT_MAX and should be positive, you have
quite straight-forward re-interpretations available, but if
R <= INT_MAX and should be negative or R > INT_MAX and should be positive,
it is less clear what the signed equivilent of R should be.
--
'Roberson' is my family name; my given name is 'Walter'.
|
| |
| no comments |
|
|
|
|