- DeviceNodes shouldn't be added to mountlist if DOS is already up.
[AROS.git] / rom / utility / smult64.c
blob41ddfd08fd8304f0bf34d1afc12238481d6cedba
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Signed 64 bit multiplication function.
6 Lang: english
7 */
8 #include "intern.h"
10 /*****************************************************************************
12 NAME */
13 #include <proto/utility.h>
15 AROS_LH2(QUAD, SMult64,
17 /* SYNOPSIS */
18 AROS_LHA(LONG, arg1, D0),
19 AROS_LHA(LONG, arg2, D1),
21 /* LOCATION */
22 struct UtilityBase *, UtilityBase, 33, Utility)
24 /* FUNCTION
25 Compute the signed 64-bit product of arg1 * arg2.
27 INPUTS
28 arg1, arg2 - 32 bit signed numbers.
30 RESULT
31 arg1 * arg2
33 NOTES
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.
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 SMult32(), UMult32(), UMult64()
52 INTERNALS
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
59 SMult32().)
61 HISTORY
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 *****************************************************************************/
68 AROS_LIBFUNC_INIT
70 /* If we have native support for 32 * 32 -> 64, use that.
71 The compiler will complain if it cannot support QUAD's
72 natively (GNU C can)
75 return (QUAD)arg1 * arg2;
77 #if 0
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
86 QUAD product;
87 WORD a0, a1, b0, b1;
88 LONG part_prod;
89 BOOL neg;
91 /* Fix everything up so that -ve signs don't vanish */
92 if(arg1 < 0)
94 neg = 1; arg1 = -arg1;
96 else
97 neg = 0;
99 if(arg2 <= 0)
101 neg ^= 1; arg2 = -arg2;
104 a0 = arg1 & 0xFFFF;
105 a1 = (arg1 >> 16) & 0xFFFF;
107 b0 = arg2 & 0xFFFF;
108 b1 = (arg2 >> 16) & 0xFFFF;
110 part_prod = (a0 * b1) + (a1 * b0);
112 /* In case numbers are small - note, does NOT compile */
113 if(a1 && b1)
114 SET_HIGH32OF64(product, a1 * b1 + (part_prod >> 16));
115 else
116 SET_HIGH32OF64(product, (part_prod >> 16));
118 SET_LOW32OF64(product, (part_prod & 0xFFFF) + (a0 * b0));
120 return (neg ? NEG64(product) : product);
121 #endif
123 AROS_LIBFUNC_EXIT
124 } /* SMult64 */