+++ /dev/null
-/* $NetBSD: sum.c,v 1.1.1.1.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
-\r
-/****************************************************************\r
-\r
-The author of this software is David M. Gay.\r
-\r
-Copyright (C) 1998 by Lucent Technologies\r
-All Rights Reserved\r
-\r
-Permission to use, copy, modify, and distribute this software and\r
-its documentation for any purpose and without fee is hereby\r
-granted, provided that the above copyright notice appear in all\r
-copies and that both that the copyright notice and this\r
-permission notice and warranty disclaimer appear in supporting\r
-documentation, and that the name of Lucent or any of its entities\r
-not be used in advertising or publicity pertaining to\r
-distribution of the software without specific, written prior\r
-permission.\r
-\r
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
-THIS SOFTWARE.\r
-\r
-****************************************************************/\r
-\r
-/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
- * with " at " changed at "@" and " dot " changed to "."). */\r
-#include <LibConfig.h>\r
-\r
-#include "gdtoaimp.h"\r
-\r
- Bigint *\r
-#ifdef KR_headers\r
-sum(a, b) Bigint *a; Bigint *b;\r
-#else\r
-sum(Bigint *a, Bigint *b)\r
-#endif\r
-{\r
- Bigint *c;\r
- ULong carry, *xc, *xa, *xb, *xe, y;\r
-#ifdef Pack_32\r
- ULong z;\r
-#endif\r
-\r
- if (a->wds < b->wds) {\r
- c = b; b = a; a = c;\r
- }\r
- c = Balloc(a->k);\r
- if (c == NULL)\r
- return NULL;\r
- c->wds = a->wds;\r
- carry = 0;\r
- xa = a->x;\r
- xb = b->x;\r
- xc = c->x;\r
- xe = xc + b->wds;\r
-#ifdef Pack_32\r
- do {\r
- y = (*xa & 0xffff) + (*xb & 0xffff) + carry;\r
- carry = (y & 0x10000) >> 16;\r
- z = (*xa++ >> 16) + (*xb++ >> 16) + carry;\r
- carry = (z & 0x10000) >> 16;\r
- Storeinc(xc, z, y);\r
- }\r
- while(xc < xe);\r
- xe += a->wds - b->wds;\r
- while(xc < xe) {\r
- y = (*xa & 0xffff) + carry;\r
- carry = (y & 0x10000) >> 16;\r
- z = (*xa++ >> 16) + carry;\r
- carry = (z & 0x10000) >> 16;\r
- Storeinc(xc, z, y);\r
- }\r
-#else\r
- do {\r
- y = *xa++ + *xb++ + carry;\r
- carry = (y & 0x10000) >> 16;\r
- *xc++ = y & 0xffff;\r
- }\r
- while(xc < xe);\r
- xe += a->wds - b->wds;\r
- while(xc < xe) {\r
- y = *xa++ + carry;\r
- carry = (y & 0x10000) >> 16;\r
- *xc++ = y & 0xffff;\r
- }\r
-#endif\r
- if (carry) {\r
- if (c->wds == c->maxwds) {\r
- b = Balloc(c->k + 1);\r
- if (b == NULL)\r
- return NULL;\r
- Bcopy(b, c);\r
- Bfree(c);\r
- c = b;\r
- }\r
- c->x[c->wds++] = 1;\r
- }\r
- return c;\r
- }\r