2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Signed 64 bit multiplication function.
10 /*****************************************************************************
13 #include <proto/utility.h>
15 AROS_LH2(QUAD
, SMult64
,
18 AROS_LHA(LONG
, arg1
, D0
),
19 AROS_LHA(LONG
, arg2
, D1
),
22 struct UtilityBase
*, UtilityBase
, 33, Utility
)
25 Compute the signed 64-bit product of arg1 * arg2.
28 arg1, arg2 - 32 bit signed numbers.
34 For m68k assembly programmers, QUADs are returned in D0:D1 (with
35 the high 32 bits in D0).
37 The utility.library math functions are unlike all other utility
38 functions in that they don't require the library base to be
39 loaded in register A6, and they also save the values of the
40 address registers A0/A1.
42 This function is mainly to support assembly programers, and is
43 probably of limited use to higher-level language programmers.
50 SMult32(), UMult32(), UMult64()
53 Actually handled in config/$(KERNEL)/utility_math.s
55 This is essentially SMult32(), but with the code to calculate
56 the product of the high 32 bits of the multiplicands.
58 In fact all that is added is the 2^32 * ac term (see docs for
62 29-10-95 digulla automatically created from
63 utility_lib.fd and clib/utility_protos.h
64 18-08-96 iaint Modified SMult32().
66 *****************************************************************************/
70 /* If we have native support for 32 * 32 -> 64, use that.
71 The compiler will complain if it cannot support QUAD's
75 return (QUAD
)arg1
* arg2
;
78 /* This is partially the algoritm that is used, however for a
79 more complete version see config/m68k-native/smult64.s
81 This version has problems with:
82 - adding the partial products together
83 - setting the value of QUADs
91 /* Fix everything up so that -ve signs don't vanish */
94 neg
= 1; arg1
= -arg1
;
101 neg
^= 1; arg2
= -arg2
;
105 a1
= (arg1
>> 16) & 0xFFFF;
108 b1
= (arg2
>> 16) & 0xFFFF;
110 part_prod
= (a0
* b1
) + (a1
* b0
);
112 /* In case numbers are small - note, does NOT compile */
114 SET_HIGH32OF64(product
, a1
* b1
+ (part_prod
>> 16));
116 SET_HIGH32OF64(product
, (part_prod
>> 16));
118 SET_LOW32OF64(product
, (part_prod
& 0xFFFF) + (a0
* b0
));
120 return (neg
? NEG64(product
) : product
);