summaryrefslogtreecommitdiffstats
path: root/lib/libstand
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-05-13 13:31:20 +0000
committerphk <phk@FreeBSD.org>2002-05-13 13:31:20 +0000
commita38b002c0bef457e70afe124452fb78691d1dea0 (patch)
treee9298121dbb9a587719499fa7801999a3d183ad6 /lib/libstand
parentd529c32d2df41ece26d4d262804d66f1b34b9f39 (diff)
downloadFreeBSD-src-a38b002c0bef457e70afe124452fb78691d1dea0.zip
FreeBSD-src-a38b002c0bef457e70afe124452fb78691d1dea0.tar.gz
Add __divdi3() and __moddi3() to libstand. We will need them for UFS2.
Sponsored by: DARPA & NAI Labs.
Diffstat (limited to 'lib/libstand')
-rw-r--r--lib/libstand/qdivrem.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/libstand/qdivrem.c b/lib/libstand/qdivrem.c
index c6fd4eb..584a0b1 100644
--- a/lib/libstand/qdivrem.c
+++ b/lib/libstand/qdivrem.c
@@ -303,3 +303,51 @@ __umoddi3(a, b)
(void)__qdivrem(a, b, &r);
return (r);
}
+
+/*
+ * Divide two signed quads.
+ * ??? if -1/2 should produce -1 on this machine, this code is wrong
+ */
+quad_t
+__divdi3(a, b)
+ quad_t a, b;
+{
+ u_quad_t ua, ub, uq;
+ int neg;
+
+ if (a < 0)
+ ua = -(u_quad_t)a, neg = 1;
+ else
+ ua = a, neg = 0;
+ if (b < 0)
+ ub = -(u_quad_t)b, neg ^= 1;
+ else
+ ub = b;
+ uq = __qdivrem(ua, ub, (u_quad_t *)0);
+ return (neg ? -uq : uq);
+}
+
+/*
+ * Return remainder after dividing two signed quads.
+ *
+ * XXX
+ * If -1/2 should produce -1 on this machine, this code is wrong.
+ */
+quad_t
+__moddi3(a, b)
+ quad_t a, b;
+{
+ u_quad_t ua, ub, ur;
+ int neg;
+
+ if (a < 0)
+ ua = -(u_quad_t)a, neg = 1;
+ else
+ ua = a, neg = 0;
+ if (b < 0)
+ ub = -(u_quad_t)b;
+ else
+ ub = b;
+ (void)__qdivrem(ua, ub, &ur);
+ return (neg ? -ur : ur);
+}
OpenPOWER on IntegriCloud