Commit | Line | Data |
---|---|---|
35510e87 KB |
1 | /*- |
2 | * Copyright (c) 1992 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
80316a78 KB |
5 | * This software was developed by the Computer Systems Engineering group |
6 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | |
7 | * contributed to Berkeley. | |
8 | * | |
35510e87 KB |
9 | * %sccs.include.redist.c% |
10 | */ | |
11 | ||
12 | #if defined(LIBC_SCCS) && !defined(lint) | |
0f92e33b | 13 | static char sccsid[] = "@(#)divdi3.c 5.4 (Berkeley) %G%"; |
35510e87 KB |
14 | #endif /* LIBC_SCCS and not lint */ |
15 | ||
80316a78 | 16 | #include "quad.h" |
1d7b9c94 | 17 | |
80316a78 KB |
18 | /* |
19 | * Divide two signed quads. | |
20 | * ??? if -1/2 should produce -1 on this machine, this code is wrong | |
21 | */ | |
0f92e33b KB |
22 | quad_t |
23 | __divdi3(a, b) | |
24 | quad_t a, b; | |
35510e87 | 25 | { |
0f92e33b | 26 | u_quad_t ua, ub, uq; |
80316a78 KB |
27 | int neg; |
28 | ||
29 | if (a < 0) | |
0f92e33b | 30 | ua = -(u_quad_t)a, neg = 1; |
80316a78 KB |
31 | else |
32 | ua = a, neg = 0; | |
33 | if (b < 0) | |
0f92e33b | 34 | ub = -(u_quad_t)b, neg ^= 1; |
80316a78 KB |
35 | else |
36 | ub = b; | |
0f92e33b | 37 | uq = __qdivrem(ua, ub, (u_quad_t *)0); |
80316a78 | 38 | return (neg ? -uq : uq); |
35510e87 | 39 | } |