summaryrefslogtreecommitdiffstats
path: root/mig_test/software/lib/udivmodsi4.c
diff options
context:
space:
mode:
Diffstat (limited to 'mig_test/software/lib/udivmodsi4.c')
-rw-r--r--mig_test/software/lib/udivmodsi4.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/mig_test/software/lib/udivmodsi4.c b/mig_test/software/lib/udivmodsi4.c
new file mode 100644
index 0000000..7d1cb67
--- /dev/null
+++ b/mig_test/software/lib/udivmodsi4.c
@@ -0,0 +1,24 @@
+unsigned long
+udivmodsi4(unsigned long num, unsigned long den, int modwanted)
+{
+ unsigned long bit = 1;
+ unsigned long res = 0;
+
+ while (den < num && bit && !(den & (1L<<31)))
+ {
+ den <<=1;
+ bit <<=1;
+ }
+ while (bit)
+ {
+ if (num >= den)
+ {
+ num -= den;
+ res |= bit;
+ }
+ bit >>=1;
+ den >>=1;
+ }
+ if (modwanted) return num;
+ return res;
+}
OpenPOWER on IntegriCloud