blob: c556a5003aa989a1452c629273ff954281dbe58c [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001
2unsigned long udivmodsi4(unsigned long num, unsigned long den, int modwanted)
3{
4 unsigned long bits = 1;
5 unsigned long ret = 0;
6 unsigned long tmpnum = num;
7 unsigned long tmpden = den;
8
9 while (tmpden < tmpnum && bits && !(tmpden & (1L<<31)))
10 {
11 tmpden <<=1;
12 bits <<=1;
13 }
14 while (bits)
15 {
16 if (tmpnum >= tmpden)
17 {
18 tmpnum -= tmpden;
19 ret |= bits;
20 }
21 bits >>=1;
22 tmpden >>=1;
23 }
24 if (modwanted) return tmpnum;
25
26 return ret;
27}