2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: UDivMod32 - divide two 32 bit numbers.
10 /*****************************************************************************
13 #include <proto/utility.h>
15 AROS_LH2(ULONG
, UDivMod32
,
18 AROS_LHA(ULONG
, dividend
, D0
),
19 AROS_LHA(ULONG
, divisor
, D1
),
22 struct Library
*, UtilityBase
, 26, Utility
)
25 Perform the 32 bit unsigned division and modulus of dividend by
26 divisor, that is dividend / divisor. Will return both the
27 quotient and the remainder.
30 dividend - The number to divide into (numerator).
31 divisor - The number to divide by (denominator).
34 For m68k assembly programmers,
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 impossible for C programmers to obtain the value of
57 SDivMod32(), SMult32(), SMult64(), UMult32(), UMult64()
60 May actually be handled by code that is in config/$(KERNEL)
61 This is the case for m68k-native.
64 29-10-95 digulla automatically created from
65 utility_lib.fd and clib/utility_protos.h
67 *****************************************************************************/
71 return dividend
/ divisor
;
74 #error The UDivMod32() emulation code does NOT work!
76 /* This does _NOT_ work, so do not use it */
83 b
= dividend
& 0xFFFF;
87 /* See if the numerator is 32 bits or 16... */
93 /* 16/32 -> quo = 0; rem = dividend */
99 /* 16/16 -> can be done in native div */
106 /* 32 bit numerator */
109 /* 32 bit denominator, quo ~= a/c */
114 /* 16 bit denominator, quo ~= (a/d) * 65536 */
118 rem
= dividend
- UMult32(quo
,divisor
);
120 /* Take the remainder down to zero */
127 /* However a -ve remainder is silly,
128 this also catches the case when the remainder is < 0 from the
137 SET_HIGH32OF64(result
, quo
);
138 SET_LOW32OF64(result
, rem
);