3 * $Id: mpx.h,v 1.16 2003/05/16 09:09:24 mdw Exp $
5 * Low level multiprecision arithmetic
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.16 2003/05/16 09:09:24 mdw
34 * Fix @mp_lsl2c@. Turns out to be surprisingly tricky.
36 * Revision 1.15 2002/10/19 17:56:50 mdw
37 * Fix bit operations. Test them (a bit) better.
39 * Revision 1.14 2002/10/09 00:36:03 mdw
40 * Fix bounds on workspace for Karatsuba operations.
42 * Revision 1.13 2002/10/06 22:52:50 mdw
43 * Pile of changes for supporting two's complement properly.
45 * Revision 1.12 2001/04/03 19:36:05 mdw
46 * Add some simple bitwise operations so that Perl can use them.
48 * Revision 1.11 2000/10/08 15:48:35 mdw
49 * Rename Karatsuba constants now that we have @gfx_kmul@ too.
51 * Revision 1.10 2000/10/08 12:06:12 mdw
52 * Provide @mpx_ueq@ for rapidly testing equality of two integers.
54 * Revision 1.9 1999/12/22 15:49:07 mdw
55 * New function for division by a small integer.
57 * Revision 1.8 1999/12/11 10:57:43 mdw
58 * Karatsuba squaring algorithm.
60 * Revision 1.7 1999/12/11 01:51:28 mdw
61 * Change Karatsuba parameters slightly.
63 * Revision 1.6 1999/12/10 23:23:51 mdw
64 * Karatsuba-Ofman multiplication algorithm.
66 * Revision 1.5 1999/11/20 22:23:27 mdw
67 * Add function versions of some low-level macros with wider use.
69 * Revision 1.4 1999/11/17 18:04:43 mdw
70 * Add two's complement support. Fix a bug in MPX_UMLAN.
72 * Revision 1.3 1999/11/13 01:51:29 mdw
73 * Minor interface changes. Should be stable now.
75 * Revision 1.2 1999/11/11 17:47:55 mdw
76 * Minor changes for different `mptypes.h' format.
78 * Revision 1.1 1999/09/03 08:41:12 mdw
83 #ifndef CATACOMB_MPX_H
84 #define CATACOMB_MPX_H
90 /*----- The idea ----------------------------------------------------------*
92 * This file provides functions and macros which work on vectors of words as
93 * unsigned multiprecision integers. The interface works in terms of base
94 * and limit pointers (i.e., a pointer to the start of a vector, and a
95 * pointer just past its end) rather than base pointer and length, because
96 * that requires more arithmetic and state to work on.
98 * The interfaces are slightly bizarre in other ways. Try to use the
99 * higher-level functions where you can: they're rather better designed to
100 * actually be friendly and useful.
103 /*----- Header files ------------------------------------------------------*/
107 #ifndef CATACOMB_MPW_H
111 /*----- General manipulation ----------------------------------------------*/
113 /* --- @MPX_SHRINK@ --- *
115 * Arguments: @const mpw *v@ = pointer to vector of words
116 * @const mpw *vl@ = (updated) current limit of vector
118 * Use: Shrinks down the limit of a multiprecision integer vector.
121 #define MPX_SHRINK(v, vl) do { \
122 const mpw *_vv = (v), *_vvl = (vl); \
123 while (_vvl > _vv && !_vvl[-1]) \
125 (vl) = (mpw *)_vvl; \
128 /* --- @MPX_BITS@ --- *
130 * Arguments: @unsigned long b@ = result variable
131 * @const mpw *v@ = pointer to array of words
132 * @const mpw *vl@ = limit of vector (from @MPX_SHRINK@)
134 * Use: Calculates the number of bits in a multiprecision value.
137 #define MPX_BITS(b, v, vl) do { \
138 const mpw *_v = (v), *_vl = (vl); \
139 MPX_SHRINK(_v, _vl); \
143 unsigned long _b = MPW_BITS * (_vl - _v - 1) + 1; \
145 unsigned _k = MPW_BITS / 2; \
157 /* --- @MPX_OCTETS@ --- *
159 * Arguments: @size_t o@ = result variable
160 * @const mpw *v, *vl@ = pointer to array of words
162 * Use: Calculates the number of octets in a multiprecision value.
165 #define MPX_OCTETS(o, v, vl) do { \
167 MPX_BITS(_bb, (v), (vl)); \
168 (o) = (_bb + 7) >> 3; \
171 /* --- @MPX_OCTETS2C@ --- *
173 * Arguments: @size_t o@ = result variable
174 * @const mpw *v, *vl@ = pointer to array of words
176 * Use: Calculates the number of octets in a multiprecision value, if
177 * you represent it as two's complement.
180 #define MPX_OCTETS2C(o, v, vl) do { \
182 MPX_BITS(_bb, (v), (vl)); \
183 (o) = (_bb >> 3) + 1; \
186 /* --- @MPX_COPY@ --- *
188 * Arguments: @dv, dvl@ = destination vector base and limit
189 * @av, avl@ = source vector base and limit
191 * Use: Copies a multiprecision integer.
194 #define MPX_COPY(dv, dvl, av, avl) do { \
195 mpw *_dv = (dv), *_dvl = (dvl); \
196 size_t _dn = _dvl - _dv; \
197 const mpw *_av = (av), *_avl = (avl); \
198 size_t _an = _avl - _av; \
201 memset(_dv, 0, MPWS(_dn - _an)); \
202 } else if (_an >= _dn) \
203 memmove(_dv, _av, MPWS(_dn)); \
205 memmove(_dv, _av, MPWS(_an)); \
206 memset(_dv + _an, 0, MPWS(_dn - _an)); \
210 /* --- @MPX_ZERO@ --- *
212 * Arguments: @v, vl@ = base and limit of vector to clear
214 * Use: Zeroes the area between the two vector pointers.
217 #define MPX_ZERO(v, vl) do { \
218 mpw *_v = (v), *_vl = (vl); \
220 memset(_v, 0, MPWS(_vl - _v)); \
223 /* --- @MPX_ONE@ --- *
225 * Arguments: @v, vl@ = base and limit of vector to clear
227 * Use: Fills the area between the two vector pointers with ones.
230 #define MPX_ONE(v, vl) do { \
232 const mpw *_vl = (vl); \
237 /*----- Loading and storing -----------------------------------------------*/
239 /* --- @mpx_storel@ --- *
241 * Arguments: @const mpw *v, *vl@ = base and limit of source vector
242 * @void *p@ = pointer to octet array
243 * @size_t sz@ = size of octet array
247 * Use: Stores an MP in an octet array, least significant octet
248 * first. High-end octets are silently discarded if there
249 * isn't enough space for them.
252 extern void mpx_storel(const mpw */
*v*/
, const mpw */
*vl*/
,
253 void */
*p*/
, size_t /*sz*/);
255 /* --- @mpx_loadl@ --- *
257 * Arguments: @mpw *v, *vl@ = base and limit of destination vector
258 * @const void *p@ = pointer to octet array
259 * @size_t sz@ = size of octet array
263 * Use: Loads an MP in an octet array, least significant octet
264 * first. High-end octets are ignored if there isn't enough
268 extern void mpx_loadl(mpw */
*v*/
, mpw */
*vl*/
,
269 const void */
*p*/
, size_t /*sz*/);
271 /* --- @mpx_storeb@ --- *
273 * Arguments: @const mpw *v, *vl@ = base and limit of source vector
274 * @void *p@ = pointer to octet array
275 * @size_t sz@ = size of octet array
279 * Use: Stores an MP in an octet array, most significant octet
280 * first. High-end octets are silently discarded if there
281 * isn't enough space for them.
284 extern void mpx_storeb(const mpw */
*v*/
, const mpw */
*vl*/
,
285 void */
*p*/
, size_t /*sz*/);
287 /* --- @mpx_loadb@ --- *
289 * Arguments: @mpw *v, *vl@ = base and limit of destination vector
290 * @const void *p@ = pointer to octet array
291 * @size_t sz@ = size of octet array
295 * Use: Loads an MP in an octet array, most significant octet
296 * first. High-end octets are ignored if there isn't enough
300 extern void mpx_loadb(mpw */
*v*/
, mpw */
*vl*/
,
301 const void */
*p*/
, size_t /*sz*/);
303 /* --- @mpx_storel2cn@ --- *
305 * Arguments: @const mpw *v, *vl@ = base and limit of source vector
306 * @void *pp@ = pointer to octet array
307 * @size_t sz@ = size of octet array
311 * Use: Stores a negative MP in an octet array, least significant
312 * octet first, as two's complement. High-end octets are
313 * silently discarded if there isn't enough space for them.
314 * This obviously makes the output bad.
317 extern void mpx_storel2cn(const mpw */
*v*/
, const mpw */
*vl*/
,
318 void */
*p*/
, size_t /*sz*/);
320 /* --- @mpx_loadl2cn@ --- *
322 * Arguments: @mpw *v, *vl@ = base and limit of destination vector
323 * @const void *pp@ = pointer to octet array
324 * @size_t sz@ = size of octet array
328 * Use: Loads a negative MP in an octet array, least significant
329 * octet first, as two's complement. High-end octets are
330 * ignored if there isn't enough space for them. This probably
331 * means you made the wrong choice coming here.
334 extern void mpx_loadl2cn(mpw */
*v*/
, mpw */
*vl*/
,
335 const void */
*p*/
, size_t /*sz*/);
337 /* --- @mpx_storeb2cn@ --- *
339 * Arguments: @const mpw *v, *vl@ = base and limit of source vector
340 * @void *pp@ = pointer to octet array
341 * @size_t sz@ = size of octet array
345 * Use: Stores a negative MP in an octet array, most significant
346 * octet first, as two's complement. High-end octets are
347 * silently discarded if there isn't enough space for them,
348 * which probably isn't what you meant.
351 extern void mpx_storeb2cn(const mpw */
*v*/
, const mpw */
*vl*/
,
352 void */
*p*/
, size_t /*sz*/);
354 /* --- @mpx_loadb2cn@ --- *
356 * Arguments: @mpw *v, *vl@ = base and limit of destination vector
357 * @const void *pp@ = pointer to octet array
358 * @size_t sz@ = size of octet array
362 * Use: Loads a negative MP in an octet array, most significant octet
363 * first as two's complement. High-end octets are ignored if
364 * there isn't enough space for them. This probably means you
365 * chose this function wrongly.
368 extern void mpx_loadb2cn(mpw */
*v*/
, mpw */
*vl*/
,
369 const void */
*p*/
, size_t /*sz*/);
372 /*----- Logical shifting --------------------------------------------------*/
374 /* --- @mpx_lsl@ --- *
376 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
377 * @const mpw *av, *avl@ = source vector base and limit
378 * @size_t n@ = number of bit positions to shift by
382 * Use: Performs a logical shift left operation on an integer.
385 extern void mpx_lsl(mpw */
*dv*/
, mpw */
*dvl*/
,
386 const mpw */
*av*/
, const mpw */
*avl*/
,
389 /* --- @mpx_lslc@ --- *
391 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
392 * @const mpw *av, *avl@ = source vector base and limit
393 * @size_t n@ = number of bit positions to shift by
397 * Use: Performs a logical shift left operation on an integer, only
398 * it fills in the bits with ones instead of zeroes.
401 extern void mpx_lslc(mpw */
*dv*/
, mpw */
*dvl*/
,
402 const mpw */
*av*/
, const mpw */
*avl*/
,
405 /* --- @mpx_lsr@ --- *
407 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
408 * @const mpw *av, *avl@ = source vector base and limit
409 * @size_t n@ = number of bit positions to shift by
413 * Use: Performs a logical shift right operation on an integer.
416 extern void mpx_lsr(mpw */
*dv*/
, mpw */
*dvl*/
,
417 const mpw */
*av*/
, const mpw */
*avl*/
,
420 /*----- Bitwise operations ------------------------------------------------*/
422 /* --- @mpx_bitop@ --- *
424 * Arguments: @mpw *dv, *dvl@ = destination vector
425 * @const mpw *av, *avl@ = first source vector
426 * @const mpw *bv, *bvl@ = second source vector
430 * Use: Provide the dyadic boolean functions. The functions are
431 * named after the truth table they generate:
438 #define MPX_DOBIN(what) \
439 what(0000) what(0001) what(0010) what(0011) \
440 what(0100) what(0101) what(0110) what(0111) \
441 what(1000) what(1001) what(1010) what(1011) \
442 what(1100) what(1101) what(1110) what(1111)
444 #define MPX_BITDECL(string) \
445 extern void mpx_bit##string(mpw */*dv*/, mpw */*dvl*/, \
446 const mpw */*av*/, const mpw */*avl*/, \
447 const mpw */*bv*/, const mpw */*bvl*/);
448 MPX_DOBIN(MPX_BITDECL
)
450 /* --- @mpx_[n]and@, @mpx_[n]or@, @mpx_xor@ --- *
452 * Synonyms for the commonly-used functions above.
455 #define mpx_and mpx_bit0001
456 #define mpx_or mpx_bit0111
457 #define mpx_nand mpx_bit1110
458 #define mpx_nor mpx_bit1000
459 #define mpx_xor mpx_bit0110
461 /* --- @mpx_not@ --- *
463 * Arguments: @mpw *dv, *dvl@ = destination vector
464 * @const mpw *av, *avl@ = first source vector
471 extern void mpx_not(mpw */
*dv*/
, mpw */
*dvl*/
,
472 const mpw */
*av*/
, const mpw */
*avl*/
);
474 /*----- Unsigned arithmetic -----------------------------------------------*/
476 /* --- @mpx_2c@ --- *
478 * Arguments: @mpw *dv, *dvl@ = destination vector
479 * @const mpw *v, *vl@ = source vector
483 * Use: Calculates the two's complement of @v@.
486 extern void mpx_2c(mpw */
*dv*/
, mpw */
*dvl*/
,
487 const mpw */
*v*/
, const mpw */
*vl*/
);
489 /* --- @mpx_ueq@ --- *
491 * Arguments: @const mpw *av, *avl@ = first argument vector base and limit
492 * @const mpw *bv, *bvl@ = second argument vector base and limit
494 * Returns: Nonzero if the two vectors are equal.
496 * Use: Performs an unsigned integer test for equality.
499 extern int mpx_ueq(const mpw */
*av*/
, const mpw */
*avl*/
,
500 const mpw */
*bv*/
, const mpw */
*bvl*/
);
502 /* --- @mpx_ucmp@ --- *
504 * Arguments: @const mpw *av, *avl@ = first argument vector base and limit
505 * @const mpw *bv, *bvl@ = second argument vector base and limit
507 * Returns: Less than, equal to, or greater than zero depending on
508 * whether @a@ is less than, equal to or greater than @b@,
511 * Use: Performs an unsigned integer comparison.
514 #define MPX_UCMP(av, avl, op, dv, dvl) \
515 (mpx_ucmp((av), (avl), (dv), (dvl)) op 0)
517 extern int mpx_ucmp(const mpw */
*av*/
, const mpw */
*avl*/
,
518 const mpw */
*bv*/
, const mpw */
*bvl*/
);
520 /* --- @mpx_uadd@ --- *
522 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
523 * @const mpw *av, *avl@ = first addend vector base and limit
524 * @const mpw *bv, *bvl@ = second addend vector base and limit
528 * Use: Performs unsigned integer addition. If the result overflows
529 * the destination vector, high-order bits are discarded. This
530 * means that two's complement addition happens more or less for
531 * free, although that's more a side-effect than anything else.
532 * The result vector may be equal to either or both source
533 * vectors, but may not otherwise overlap them.
536 extern void mpx_uadd(mpw */
*dv*/
, mpw */
*dvl*/
,
537 const mpw */
*av*/
, const mpw */
*avl*/
,
538 const mpw */
*bv*/
, const mpw */
*bvl*/
);
540 /* --- @mpx_uaddn@ --- *
542 * Arguments: @mpw *dv, *dvl@ = source and destination base and limit
543 * @mpw n@ = other addend
547 * Use: Adds a small integer to a multiprecision number.
550 #define MPX_UADDN(dv, dvl, n) do { \
551 mpw *_ddv = (dv), *_ddvl = (dvl); \
554 while (_c && _ddv < _ddvl) { \
555 mpd _x = (mpd)*_ddv + (mpd)_c; \
557 _c = _x >> MPW_BITS; \
561 extern void mpx_uaddn(mpw */
*dv*/
, mpw */
*dvl*/
, mpw
/*n*/);
563 /* --- @mpx_usub@ --- *
565 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
566 * @const mpw *av, *avl@ = first argument vector base and limit
567 * @const mpw *bv, *bvl@ = second argument vector base and limit
571 * Use: Performs unsigned integer subtraction. If the result
572 * overflows the destination vector, high-order bits are
573 * discarded. This means that two's complement subtraction
574 * happens more or less for free, although that's more a side-
575 * effect than anything else. The result vector may be equal to
576 * either or both source vectors, but may not otherwise overlap
580 extern void mpx_usub(mpw */
*dv*/
, mpw */
*dvl*/
,
581 const mpw */
*av*/
, const mpw */
*avl*/
,
582 const mpw */
*bv*/
, const mpw */
*bvl*/
);
584 /* --- @mpx_usubn@ --- *
586 * Arguments: @mpw *dv, *dvl@ = source and destination base and limit
591 * Use: Subtracts a small integer from a multiprecision number.
594 #define MPX_USUBN(dv, dvl, n) do { \
595 mpw *_ddv = (dv), *_ddvl = (dvl); \
598 while (_ddv < _ddvl) { \
599 mpd _x = (mpd)*_ddv - (mpd)_c; \
601 if (_x >> MPW_BITS) \
608 extern void mpx_usubn(mpw */
*dv*/
, mpw */
*dvl*/
, mpw
/*n*/);
610 /* --- @mpx_umul@ --- *
612 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
613 * @const mpw *av, *avl@ = multiplicand vector base and limit
614 * @const mpw *bv, *bvl@ = multiplier vector base and limit
618 * Use: Performs unsigned integer multiplication. If the result
619 * overflows the desination vector, high-order bits are
620 * discarded. The result vector may not overlap the argument
621 * vectors in any way.
624 extern void mpx_umul(mpw */
*dv*/
, mpw */
*dvl*/
,
625 const mpw */
*av*/
, const mpw */
*avl*/
,
626 const mpw */
*bv*/
, const mpw */
*bvl*/
);
628 /* --- @mpx_umuln@ --- *
630 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
631 * @const mpw *av, *avl@ = multiplicand vector base and limit
632 * @mpw m@ = multiplier
636 * Use: Multiplies a multiprecision integer by a single-word value.
637 * The destination and source may be equal. The destination
638 * is completely cleared after use.
641 #define MPX_UMULN(dv, dvl, av, avl, m) do { \
642 mpw *_dv = (dv), *_dvl = (dvl); \
643 const mpw *_av = (av), *_avl = (avl); \
647 while (_av < _avl) { \
651 _x = (mpd)_m * (mpd)*_av++ + _c; \
653 _c = _x >> MPW_BITS; \
657 MPX_ZERO(_dv, _dvl); \
661 extern void mpx_umuln(mpw */
*dv*/
, mpw */
*dvl*/
,
662 const mpw */
*av*/
, const mpw */
*avl*/
, mpw m
);
664 /* --- @mpx_umlan@ --- *
666 * Arguments: @mpw *dv, *dvl@ = destination/accumulator base and limit
667 * @const mpw *av, *avl@ = multiplicand vector base and limit
668 * @mpw m@ = multiplier
672 * Use: Multiplies a multiprecision integer by a single-word value
673 * and adds the result to an accumulator.
676 #define MPX_UMLAN(dv, dvl, av, avl, m) do { \
677 mpw *_dv = (dv), *_dvl = (dvl); \
678 const mpw *_av = (av), *_avl = (avl); \
682 while (_dv < _dvl && _av < _avl) { \
684 _x = (mpd)*_dv + (mpd)_m * (mpd)*_av++ + _cc; \
686 _cc = _x >> MPW_BITS; \
688 MPX_UADDN(_dv, _dvl, _cc); \
691 extern void mpx_umlan(mpw */
*dv*/
, mpw */
*dvl*/
,
692 const mpw */
*av*/
, const mpw */
*avl*/
, mpw m
);
694 /* --- @mpx_usqr@ --- *
696 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
697 * @const mpw *av, *av@ = source vector base and limit
701 * Use: Performs unsigned integer squaring. The result vector must
702 * not overlap the source vector in any way.
705 extern void mpx_usqr(mpw */
*dv*/
, mpw */
*dvl*/
,
706 const mpw */
*av*/
, const mpw */
*avl*/
);
708 /* --- @mpx_udiv@ --- *
710 * Arguments: @mpw *qv, *qvl@ = quotient vector base and limit
711 * @mpw *rv, *rvl@ = dividend/remainder vector base and limit
712 * @const mpw *dv, *dvl@ = divisor vector base and limit
713 * @mpw *sv, *svl@ = scratch workspace
717 * Use: Performs unsigned integer division. If the result overflows
718 * the quotient vector, high-order bits are discarded. (Clearly
719 * the remainder vector can't overflow.) The various vectors
720 * may not overlap in any way. Yes, I know it's a bit odd
721 * requiring the dividend to be in the result position but it
722 * does make some sense really. The remainder must have
723 * headroom for at least two extra words. The scratch space
724 * must be at least one word larger than the divisor.
727 extern void mpx_udiv(mpw */
*qv*/
, mpw */
*qvl*/
, mpw */
*rv*/
, mpw */
*rvl*/
,
728 const mpw */
*dv*/
, const mpw */
*dvl*/
,
729 mpw */
*sv*/
, mpw */
*svl*/
);
731 /* --- @mpx_udivn@ --- *
733 * Arguments: @mpw *qv, *qvl@ = storage for the quotient (may overlap
735 * @const mpw *rv, *rvl@ = dividend
736 * @mpw d@ = single-precision divisor
738 * Returns: Remainder after divison.
740 * Use: Performs a single-precision division operation.
743 extern mpw
mpx_udivn(mpw */
*qv*/
, mpw */
*qvl*/
,
744 const mpw */
*rv*/
, const mpw */
*rvl*/
, mpw
/*d*/);
746 /*----- Karatsuba multiplication algorithms -------------------------------*/
748 /* --- @MPK_THRESH@ --- *
750 * This is the limiting length for using Karatsuba algorithms. It's best to
751 * use the simpler classical multiplication method on numbers smaller than
752 * this. It is unsafe to make this constant less than four (i.e., the
753 * algorithms will fail).
756 #define MPK_THRESH 16
758 /* --- @mpx_kmul@ --- *
760 * Arguments: @mpw *dv, *dvl@ = pointer to destination buffer
761 * @const mpw *av, *avl@ = pointer to first argument
762 * @const mpw *bv, *bvl@ = pointer to second argument
763 * @mpw *sv, *svl@ = pointer to scratch workspace
767 * Use: Multiplies two multiprecision integers using Karatsuba's
768 * algorithm. This is rather faster than traditional long
769 * multiplication (e.g., @mpx_umul@) on large numbers, although
770 * more expensive on small ones.
772 * The destination must be three times as large as the larger
773 * argument. The scratch space must be five times as large as
774 * the larger argument.
777 extern void mpx_kmul(mpw */
*dv*/
, mpw */
*dvl*/
,
778 const mpw */
*av*/
, const mpw */
*avl*/
,
779 const mpw */
*bv*/
, const mpw */
*bvl*/
,
780 mpw */
*sv*/
, mpw */
*svl*/
);
782 /* --- @mpx_ksqr@ --- *
784 * Arguments: @mpw *dv, *dvl@ = pointer to destination buffer
785 * @const mpw *av, *avl@ = pointer to first argument
786 * @mpw *sv, *svl@ = pointer to scratch workspace
790 * Use: Squares a multiprecision integers using something similar to
791 * Karatsuba's multiplication algorithm. This is rather faster
792 * than traditional long multiplication (e.g., @mpx_umul@) on
793 * large numbers, although more expensive on small ones, and
794 * rather simpler than full-blown Karatsuba multiplication.
796 * The destination must be three times as large as the larger
797 * argument. The scratch space must be five times as large as
798 * the larger argument.
801 extern void mpx_ksqr(mpw */
*dv*/
, mpw */
*dvl*/
,
802 const mpw */
*av*/
, const mpw */
*avl*/
,
803 mpw */
*sv*/
, mpw */
*svl*/
);
805 /*----- That's all, folks -------------------------------------------------*/