153442Sbostic /*-
2*61160Sbostic * Copyright (c) 1992, 1993
3*61160Sbostic * The Regents of the University of California. All rights reserved.
453442Sbostic *
553794Sbostic * This software was developed by the Computer Systems Engineering group
653794Sbostic * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
753794Sbostic * contributed to Berkeley.
853794Sbostic *
953442Sbostic * %sccs.include.redist.c%
1053442Sbostic */
1153442Sbostic
1253442Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*61160Sbostic static char sccsid[] = "@(#)moddi3.c 8.1 (Berkeley) 06/04/93";
1453442Sbostic #endif /* LIBC_SCCS and not lint */
1553442Sbostic
1653794Sbostic #include "quad.h"
1753459Sbostic
1853794Sbostic /*
1953794Sbostic * Return remainder after dividing two signed quads.
2053794Sbostic *
2153794Sbostic * XXX
2253794Sbostic * If -1/2 should produce -1 on this machine, this code is wrong.
2353794Sbostic */
2454431Sbostic quad_t
__moddi3(a,b)2554431Sbostic __moddi3(a, b)
2654431Sbostic quad_t a, b;
2753794Sbostic {
2854431Sbostic u_quad_t ua, ub, ur;
2953794Sbostic int neg;
3053459Sbostic
3153794Sbostic if (a < 0)
3254431Sbostic ua = -(u_quad_t)a, neg = 1;
3353794Sbostic else
3453794Sbostic ua = a, neg = 0;
3553794Sbostic if (b < 0)
3654431Sbostic ub = -(u_quad_t)b, neg ^= 1;
3753794Sbostic else
3853794Sbostic ub = b;
3954083Sbostic (void)__qdivrem(ua, ub, &ur);
4053794Sbostic return (neg ? -ur : ur);
4153442Sbostic }
42