Merge gpxe-for-syslinux
[syslinux.git] / dos / __udivmoddi4.c
blob8e7661f5f6d1fe73ba91694a1ad2b0ed9d04fb08
1 #include <stdint.h>
3 uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p)
5 uint64_t quot = 0, qbit = 1;
7 if ( den == 0 ) {
8 asm volatile("int $0");
9 return 0; /* If trap returns... */
12 /* Left-justify denominator and count shift */
13 while ( (int64_t)den >= 0 ) {
14 den <<= 1;
15 qbit <<= 1;
18 while ( qbit ) {
19 if ( den <= num ) {
20 num -= den;
21 quot += qbit;
23 den >>= 1;
24 qbit >>= 1;
27 if ( rem_p )
28 *rem_p = num;
30 return quot;