2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Large integer support for DJGPP */
13 #include "largeint95.h"
15 LARGE_INTEGER LargeIntegerAdd(LARGE_INTEGER a, LARGE_INTEGER b)
18 long long *c1 = (long long *) &c;
19 long long *a1 = (long long *) &a;
20 long long *b1 = (long long *) &b;
25 LARGE_INTEGER LargeIntegerSubtract(LARGE_INTEGER a, LARGE_INTEGER b)
28 long long *c1 = (long long *) &c;
29 long long *a1 = (long long *) &a;
30 long long *b1 = (long long *) &b;
35 LARGE_INTEGER ConvertLongToLargeInteger(unsigned long a)
44 LARGE_INTEGER LargeIntegerMultiplyLongByLong(unsigned long a, unsigned long b)
47 long long *c1 = (long long *) &c;
49 *c1 = (long long) a * (long long) b;
53 LARGE_INTEGER LargeIntegerMultiplyByLong(LARGE_INTEGER a, unsigned long b)
56 long long *c1 = (long long *) &c;
57 long long *a1 = (long long *) &a;
59 *c1 = *a1 * (long long) b;
63 unsigned long LargeIntegerDivideByLong(LARGE_INTEGER a, unsigned long b)
66 long long *a1 = (long long *) &a;
68 q = lldiv(*a1, (long long) b);
69 return (unsigned long) q.quot;
73 LARGE_INTEGER LargeIntegerAdd(LARGE_INTEGER a, LARGE_INTEGER b)
77 c.LowPart = a.LowPart + b.LowPart;
78 c.HighPart = a.HighPart + b.HighPart;
80 /* not sure how to do a real carry */
81 if (c.LowPart < a.LowPart)
87 LARGE_INTEGER LargeIntegerSubtract(LARGE_INTEGER a, LARGE_INTEGER b)
91 c.LowPart = a.LowPart - b.LowPart;
92 c.HighPart = a.HighPart - b.HighPart;
95 if (c.LowPart > a.LowPart)
101 __inline__ unsigned long mult32(unsigned long a, unsigned long b,
106 /* multiply low part and save the overflow bits */
107 __asm__ __volatile__ ("movl %2, %%eax\n
113 : "ax", "dx", "memory"
119 __inline__ unsigned long div32(unsigned long a, unsigned long b,
124 /* multiply low part and save the overflow bits */
125 __asm__ __volatile__ ("movl %2, %%eax\n
131 : "ax", "dx", "memory"
137 LARGE_INTEGER LargeIntegerMultiplyLongByLong(unsigned long a, unsigned long b)
141 prod.LowPart = mult32(a, b, &prod.HighPart);
145 LARGE_INTEGER LargeIntegerMultiplyByLong(LARGE_INTEGER a, unsigned long b)
148 unsigned long x, prodl, prodh, ovl, ovh;
150 /* multiply low part and save the overflow bits */
151 prod.LowPart = mult32(a.LowPart, b, &ovl);
153 /* multiply high part */
154 prod.HighPart = mult32(a.HighPart, b, &ovh);
156 /* add overflow from low part */
157 prod.HighPart += ovl;
162 unsigned long LargeIntegerDivideByLong(LARGE_INTEGER a, unsigned long b, unsigned long *rem)
164 unsigned long n, r, q;
167 if (b == 0) { return 0; }
168 if (b == 1) { *rem = 0; return a.LowPart; }
170 n = div32(a.LowPart, b, &r);
178 q = div32(0xffffffff-b+1, b, &r);
181 n += LargeIntegerDivideByLong(LargeIntegerMultiplyLongByLong(r, a.HighPart), b, rem);
188 int LargeIntegerGreaterThan(LARGE_INTEGER a, LARGE_INTEGER b)
190 if (a.HighPart > b.HighPart) return 1;
191 else if (a.HighPart == b.HighPart && a.LowPart > b.LowPart) return 1;
195 int LargeIntegerGreaterThanOrEqualTo(LARGE_INTEGER a, LARGE_INTEGER b)
197 if (a.HighPart > b.HighPart) return 1;
198 else if (a.HighPart == b.HighPart && a.LowPart >= b.LowPart) return 1;
202 int LargeIntegerEqualTo(LARGE_INTEGER a, LARGE_INTEGER b)
204 if (a.HighPart == b.HighPart && a.LowPart == b.LowPart) return 1;
208 int LargeIntegerGreaterOrEqualToZero(LARGE_INTEGER a)
210 return ((a.HighPart & 0x8fffffff) ? 0 : 1);
213 int LargeIntegerLessThanZero(LARGE_INTEGER a)
215 return ((a.HighPart & 0x8fffffff) ? 1 : 0);