2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: SDivMod32 - Divide two 32 bit numbers.
10 /*****************************************************************************
13 #include <proto/utility.h>
15 AROS_LH2(QUAD
, SDivMod32
,
18 AROS_LHA(LONG
, dividend
, D0
),
19 AROS_LHA(LONG
, divisor
, D1
),
22 struct UtilityBase
*, UtilityBase
, 25, Utility
)
25 Calculates the 32-bit signed division of dividend by divisor. That
26 is dividend / divisor. Will return both the quotient and the
30 dividend - The number to divide.
31 divisor - The to divide by.
34 For m68k assembly programmers:
38 The quotient is returned in the high 32 bits of the result.
39 The remainder in the low 32 bits.
42 The utility.library math functions are unlike all other utility
43 functions in that they don't require the library base to be
44 loaded in register A6, and they also save the values of the
45 address registers A0/A1.
47 This function is mainly to support assembly programers, and is
48 probably of limited use to higher-level language programmers.
53 It is very hard for a C programmer to obtain the value of the
54 remainder. In fact, its pretty near impossible.
57 SMult32(), SMult64(), UDivMod32(), UMult32(), UMult64()
60 This may be handled by code in config/$(KERNEL).
63 29-10-95 digulla automatically created from
64 utility_lib.fd and clib/utility_protos.h
66 *****************************************************************************/
70 return dividend
/ divisor
;
73 #error Sorry, but the SDivMod32() emulation code does NOT work...
75 This does NOT work. Do not even try and use this code...
83 /* Fix everything up so that -ve signs don't vanish */
86 neg
= 1; dividend
= -dividend
;
93 neg
^= 1; divisor
= -divisor
;
97 b
= dividend
& 0xFFFF;
101 /* See if the numerator is 32 bits or 16... */
107 /* 16/32 -> quo = 0; rem = dividend */
113 /* 16/16 -> can be done in native div */
120 /* 32 bit numerator */
123 /* 32 bit denominator, quo ~= a/c */
128 /* 16 bit denominator, quo ~= (a/d) * 65536 */
132 rem
= dividend
- UMult32(quo
,divisor
);
134 /* Take the remainder down to zero */
141 /* However a -ve remainder is silly,
142 this also catches the case when the remainder is < 0 from the