153435Sbostic /*-
2*61158Sbostic * Copyright (c) 1992, 1993
3*61158Sbostic * The Regents of the University of California. All rights reserved.
453435Sbostic *
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 *
953435Sbostic * %sccs.include.redist.c%
1053435Sbostic */
1153435Sbostic
1253435Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*61158Sbostic static char sccsid[] = "@(#)divdi3.c 8.1 (Berkeley) 06/04/93";
1453435Sbostic #endif /* LIBC_SCCS and not lint */
1553435Sbostic
1653794Sbostic #include "quad.h"
1753459Sbostic
1853794Sbostic /*
1953794Sbostic * Divide two signed quads.
2053794Sbostic * ??? if -1/2 should produce -1 on this machine, this code is wrong
2153794Sbostic */
2254431Sbostic quad_t
__divdi3(a,b)2354431Sbostic __divdi3(a, b)
2454431Sbostic quad_t a, b;
2553794Sbostic {
2654431Sbostic u_quad_t ua, ub, uq;
2753794Sbostic int neg;
2853459Sbostic
2953794Sbostic if (a < 0)
3054431Sbostic ua = -(u_quad_t)a, neg = 1;
3153794Sbostic else
3253794Sbostic ua = a, neg = 0;
3353794Sbostic if (b < 0)
3454431Sbostic ub = -(u_quad_t)b, neg ^= 1;
3553794Sbostic else
3653794Sbostic ub = b;
3754431Sbostic uq = __qdivrem(ua, ub, (u_quad_t *)0);
3853794Sbostic return (neg ? -uq : uq);
3953435Sbostic }
40