summaryrefslogtreecommitdiffstats
path: root/arch/parisc/lib/libgcc/__udivmoddi4.c
blob: 2df0caa5a7d80582daf5fd95f857a30b84dbb1bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "libgcc.h"

u64 __udivmoddi4(u64 num, u64 den, u64 * rem_p)
{
	u64 quot = 0, qbit = 1;

	if (den == 0) {
		BUG();
	}

	/* Left-justify denominator and count shift */
	while ((s64) den >= 0) {
		den <<= 1;
		qbit <<= 1;
	}

	while (qbit) {
		if (den <= num) {
			num -= den;
			quot += qbit;
		}
		den >>= 1;
		qbit >>= 1;
	}

	if (rem_p)
		*rem_p = num;

	return quot;
}
EXPORT_SYMBOL(__udivmoddi4);
OpenPOWER on IntegriCloud