xref: /csrg-svn/lib/libc/quad/negdi2.c (revision 53443)
1*53443Sbostic /*-
2*53443Sbostic  * Copyright (c) 1992 The Regents of the University of California.
3*53443Sbostic  * All rights reserved.
4*53443Sbostic  *
5*53443Sbostic  * %sccs.include.redist.c%
6*53443Sbostic  */
7*53443Sbostic 
8*53443Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*53443Sbostic static char sccsid[] = "@(#)negdi2.c	5.1 (Berkeley) 05/12/92";
10*53443Sbostic #endif /* LIBC_SCCS and not lint */
11*53443Sbostic 
12*53443Sbostic #include "longlong.h"
13*53443Sbostic 
14*53443Sbostic static int bneg ();
15*53443Sbostic 
16*53443Sbostic long long
17*53443Sbostic __negdi2 (u)
18*53443Sbostic      long long u;
19*53443Sbostic {
20*53443Sbostic   unsigned long a[2], b[2];
21*53443Sbostic   long_long w;
22*53443Sbostic   long_long uu;
23*53443Sbostic 
24*53443Sbostic   uu.ll = u;
25*53443Sbostic 
26*53443Sbostic   a[HIGH] = uu.s.high;
27*53443Sbostic   a[LOW] = uu.s.low;
28*53443Sbostic 
29*53443Sbostic   bneg (a, b, sizeof b);
30*53443Sbostic 
31*53443Sbostic   w.s.high = b[HIGH];
32*53443Sbostic   w.s.low = b[LOW];
33*53443Sbostic   return w.ll;
34*53443Sbostic }
35*53443Sbostic 
36*53443Sbostic static int
37*53443Sbostic bneg (a, b, n)
38*53443Sbostic      unsigned short *a, *b;
39*53443Sbostic      size_t n;
40*53443Sbostic {
41*53443Sbostic   signed long acc;
42*53443Sbostic   int i;
43*53443Sbostic 
44*53443Sbostic   n /= sizeof (short);
45*53443Sbostic 
46*53443Sbostic   acc = 0;
47*53443Sbostic   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
48*53443Sbostic     {
49*53443Sbostic       acc -= a[i];
50*53443Sbostic       b[i] = acc & low16;
51*53443Sbostic       acc = acc >> 16;
52*53443Sbostic     }
53*53443Sbostic   return acc;
54*53443Sbostic }
55