Remove building with NOCRYPTO option
[minix3.git] / lib / libc / gdtoa / sum.c
blob6a987a1a4caa5b63b66dc19a31770e7a277b297c
1 /* $NetBSD: sum.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */
3 /****************************************************************
5 The author of this software is David M. Gay.
7 Copyright (C) 1998 by Lucent Technologies
8 All Rights Reserved
10 Permission to use, copy, modify, and distribute this software and
11 its documentation for any purpose and without fee is hereby
12 granted, provided that the above copyright notice appear in all
13 copies and that both that the copyright notice and this
14 permission notice and warranty disclaimer appear in supporting
15 documentation, and that the name of Lucent or any of its entities
16 not be used in advertising or publicity pertaining to
17 distribution of the software without specific, written prior
18 permission.
20 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
22 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
23 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
25 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27 THIS SOFTWARE.
29 ****************************************************************/
31 /* Please send bug reports to David M. Gay (dmg at acm dot org,
32 * with " at " changed at "@" and " dot " changed to "."). */
34 #include "gdtoaimp.h"
36 Bigint *
37 #ifdef KR_headers
38 sum(a, b) Bigint *a; Bigint *b;
39 #else
40 sum(Bigint *a, Bigint *b)
41 #endif
43 Bigint *c;
44 ULong carry, *xc, *xa, *xb, *xe, y;
45 #ifdef Pack_32
46 ULong z;
47 #endif
49 if (a->wds < b->wds) {
50 c = b; b = a; a = c;
52 c = Balloc(a->k);
53 if (c == NULL)
54 return NULL;
55 c->wds = a->wds;
56 carry = 0;
57 xa = a->x;
58 xb = b->x;
59 xc = c->x;
60 xe = xc + b->wds;
61 #ifdef Pack_32
62 do {
63 y = (*xa & 0xffff) + (*xb & 0xffff) + carry;
64 carry = (y & 0x10000) >> 16;
65 z = (*xa++ >> 16) + (*xb++ >> 16) + carry;
66 carry = (z & 0x10000) >> 16;
67 Storeinc(xc, z, y);
69 while(xc < xe);
70 xe += a->wds - b->wds;
71 while(xc < xe) {
72 y = (*xa & 0xffff) + carry;
73 carry = (y & 0x10000) >> 16;
74 z = (*xa++ >> 16) + carry;
75 carry = (z & 0x10000) >> 16;
76 Storeinc(xc, z, y);
78 #else
79 do {
80 y = *xa++ + *xb++ + carry;
81 carry = (y & 0x10000) >> 16;
82 *xc++ = y & 0xffff;
84 while(xc < xe);
85 xe += a->wds - b->wds;
86 while(xc < xe) {
87 y = *xa++ + carry;
88 carry = (y & 0x10000) >> 16;
89 *xc++ = y & 0xffff;
91 #endif
92 if (carry) {
93 if (c->wds == c->maxwds) {
94 b = Balloc(c->k + 1);
95 if (b == NULL)
96 return NULL;
97 Bcopy(b, c);
98 Bfree(c);
99 c = b;
101 c->x[c->wds++] = 1;
103 return c;