1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
10 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
11 /* All Rights Reserved */
14 * Copyright (c) 1997, by Sun Microsystems, Inc.
15 * All rights reserved.
18 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
23 #include <sys/types.h>
26 static void m_mult(MINT
*, MINT
*, MINT
*);
29 mp_mult(MINT
*a
, MINT
*b
, MINT
*c
)
36 if (a
->len
== 0 || b
->len
== 0) {
67 * Knuth 4.3.1, Algorithm M
70 m_mult(MINT
*a
, MINT
*b
, MINT
*c
)
82 #define BASEBITS (8 * (unsigned int)sizeof (short) - 1)
83 #define BASE (1 << BASEBITS)
84 #define LOWBITS (BASE - 1)
90 c
->val
= _mp_xalloc(c
->len
, "m_mult");
98 for (i
= alen
; i
> 0; i
--) {
99 sum
+= *aptr
++ * bcache
;
100 *cptr
++ = (short)(sum
& LOWBITS
);
104 sum
= 0xfffe0000 | (sum
>> fifteen
);
111 for (j
= blen
- 1; j
> 0; j
--) {
114 for (i
= alen
; i
> 0; i
--) {
115 sum
+= *aptr
++ * bcache
+ *cptr
;
116 *cptr
++ = (short)(sum
& LOWBITS
);
120 sum
= 0xfffe0000 | (sum
>> fifteen
);
127 if (c
->val
[c
->len
-1] == 0) {