00036 :
00037
00038 This routine divides an
unsigned 64-bit dividend by an
unsigned 64-bit
00039 divisor and returns a 64-bit quotient, and optionally a 64-bit remainder.
00040
00041 Arguments:
00042
00043 Dividend - Supplies
the 64-bit dividend
for the divide operation.
00044
00045 Divisor - Supplies
the 64-bit divisor
for the divide operation.
00046
00047 Remainder - Supplies an optional pointer to a variable which receives
00048
the remainder
00049
00050 Return Value:
00051
00052 The 64-bit quotient
is returned as
the function value.
00053
00054 --*/
00055
00056 {
00057
00058 ULONG
Index = 64;
00059 LARGE_INTEGER Partial = {0, 0};
00060 LARGE_INTEGER Quotient;
00061
00062
#ifndef BLDR_KERNEL_RUNTIME
00063
00064
00065
00066
00067
if (!(Divisor.LowPart | Divisor.HighPart)) {
00068
RtlRaiseStatus (STATUS_INTEGER_DIVIDE_BY_ZERO);
00069 }
00070
#endif
00071
00072
00073
00074
00075
00076 Quotient = Dividend;
00077
do {
00078
00079
00080
00081
00082
00083
00084 Partial.HighPart = (Partial.HighPart << 1) | (Partial.LowPart >> 31);
00085 Partial.LowPart = (Partial.LowPart << 1) | ((ULONG)Quotient.HighPart >> 31);
00086 Quotient.HighPart = (Quotient.HighPart << 1) | (Quotient.LowPart >> 31);
00087 Quotient.LowPart <<= 1;
00088
00089
00090
00091
00092
00093
00094
00095
if (((ULONG)Partial.HighPart > (ULONG)Divisor.HighPart) ||
00096 ((Partial.HighPart == Divisor.HighPart) &&
00097 (Partial.LowPart >= Divisor.LowPart))) {
00098
00099 Quotient.LowPart |= 1;
00100 Partial.HighPart -= Divisor.HighPart;
00101
if (Partial.LowPart < Divisor.LowPart) {
00102 Partial.HighPart -= 1;
00103 }
00104
00105 Partial.LowPart -= Divisor.LowPart;
00106 }
00107
00108
Index -= 1;
00109 }
while (
Index > 0);
00110
00111
00112
00113
00114
00115
if (ARGUMENT_PRESENT(Remainder)) {
00116 *Remainder = Partial;
00117 }
00118
00119
00120
00121
00122
00123
return Quotient;
00124 }
}