3 * $Id: mpx.c,v 1.6 1999/11/20 22:43:44 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.6 1999/11/20 22:43:44 mdw
34 * Integrate testing for MPX routines.
36 * Revision 1.5 1999/11/20 22:23:27 mdw
37 * Add function versions of some low-level macros with wider use.
39 * Revision 1.4 1999/11/17 18:04:09 mdw
40 * Add two's-complement functionality. Improve mpx_udiv a little by
41 * performing the multiplication of the divisor by q with the subtraction
44 * Revision 1.3 1999/11/13 01:57:31 mdw
45 * Remove stray debugging code.
47 * Revision 1.2 1999/11/13 01:50:59 mdw
48 * Multiprecision routines finished and tested.
50 * Revision 1.1 1999/09/03 08:41:12 mdw
55 /*----- Header files ------------------------------------------------------*/
62 #include <mLib/bits.h>
67 /*----- Loading and storing -----------------------------------------------*/
69 /* --- @mpx_storel@ --- *
71 * Arguments: @const mpw *v, *vl@ = base and limit of source vector
72 * @void *pp@ = pointer to octet array
73 * @size_t sz@ = size of octet array
77 * Use: Stores an MP in an octet array, least significant octet
78 * first. High-end octets are silently discarded if there
79 * isn't enough space for them.
82 void mpx_storel(const mpw
*v
, const mpw
*vl
, void *pp
, size_t sz
)
85 octet
*p
= pp
, *q
= p
+ sz
;
95 *p
++ = U8(w
| n
<< bits
);
107 /* --- @mpx_loadl@ --- *
109 * Arguments: @mpw *v, *vl@ = base and limit of destination vector
110 * @const void *pp@ = pointer to octet array
111 * @size_t sz@ = size of octet array
115 * Use: Loads an MP in an octet array, least significant octet
116 * first. High-end octets are ignored if there isn't enough
120 void mpx_loadl(mpw
*v
, mpw
*vl
, const void *pp
, size_t sz
)
124 const octet
*p
= pp
, *q
= p
+ sz
;
133 if (bits
>= MPW_BITS
) {
135 w
= n
>> (MPW_BITS
- bits
+ 8);
145 /* --- @mpx_storeb@ --- *
147 * Arguments: @const mpw *v, *vl@ = base and limit of source vector
148 * @void *pp@ = pointer to octet array
149 * @size_t sz@ = size of octet array
153 * Use: Stores an MP in an octet array, most significant octet
154 * first. High-end octets are silently discarded if there
155 * isn't enough space for them.
158 void mpx_storeb(const mpw
*v
, const mpw
*vl
, void *pp
, size_t sz
)
161 octet
*p
= pp
, *q
= p
+ sz
;
171 *--q
= U8(w
| n
<< bits
);
173 bits
+= MPW_BITS
- 8;
183 /* --- @mpx_loadb@ --- *
185 * Arguments: @mpw *v, *vl@ = base and limit of destination vector
186 * @const void *pp@ = pointer to octet array
187 * @size_t sz@ = size of octet array
191 * Use: Loads an MP in an octet array, most significant octet
192 * first. High-end octets are ignored if there isn't enough
196 void mpx_loadb(mpw
*v
, mpw
*vl
, const void *pp
, size_t sz
)
200 const octet
*p
= pp
, *q
= p
+ sz
;
209 if (bits
>= MPW_BITS
) {
211 w
= n
>> (MPW_BITS
- bits
+ 8);
221 /*----- Logical shifting --------------------------------------------------*/
223 /* --- @mpx_lsl@ --- *
225 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
226 * @const mpw *av, *avl@ = source vector base and limit
227 * @size_t n@ = number of bit positions to shift by
231 * Use: Performs a logical shift left operation on an integer.
234 void mpx_lsl(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
, size_t n
)
239 /* --- Trivial special case --- */
242 MPX_COPY(dv
, dvl
, av
, avl
);
244 /* --- Single bit shifting --- */
253 *dv
++ = MPW((t
<< 1) | w
);
254 w
= t
>> (MPW_BITS
- 1);
263 /* --- Break out word and bit shifts for more sophisticated work --- */
268 /* --- Handle a shift by a multiple of the word size --- */
271 MPX_COPY(dv
+ nw
, dvl
, av
, avl
);
272 memset(dv
, 0, MPWS(nw
));
275 /* --- And finally the difficult case --- *
277 * This is a little convoluted, because I have to start from the end and
278 * work backwards to avoid overwriting the source, if they're both the same
284 size_t nr
= MPW_BITS
- nb
;
285 size_t dvn
= dvl
- dv
;
286 size_t avn
= avl
- av
;
293 if (dvn
> avn
+ nw
) {
294 size_t off
= avn
+ nw
+ 1;
295 MPX_ZERO(dv
+ off
, dvl
);
305 *--dvl
= (t
>> nr
) | w
;
316 /* --- @mpx_lsr@ --- *
318 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
319 * @const mpw *av, *avl@ = source vector base and limit
320 * @size_t n@ = number of bit positions to shift by
324 * Use: Performs a logical shift right operation on an integer.
327 void mpx_lsr(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
, size_t n
)
332 /* --- Trivial special case --- */
335 MPX_COPY(dv
, dvl
, av
, avl
);
337 /* --- Single bit shifting --- */
346 *dv
++ = MPW((t
<< (MPW_BITS
- 1)) | w
);
356 /* --- Break out word and bit shifts for more sophisticated work --- */
361 /* --- Handle a shift by a multiple of the word size --- */
364 MPX_COPY(dv
, dvl
, av
+ nw
, avl
);
366 /* --- And finally the difficult case --- */
370 size_t nr
= MPW_BITS
- nb
;
379 *dv
++ = MPW((w
>> nb
) | (t
<< nr
));
383 *dv
++ = MPW(w
>> nb
);
391 /*----- Unsigned arithmetic -----------------------------------------------*/
393 /* --- @mpx_2c@ --- *
395 * Arguments: @mpw *dv, *dvl@ = destination vector
396 * @const mpw *v, *vl@ = source vector
400 * Use: Calculates the two's complement of @v@.
403 void mpx_2c(mpw
*dv
, mpw
*dvl
, const mpw
*v
, const mpw
*vl
)
406 while (dv
< dvl
&& v
< vl
)
407 *dv
++ = c
= MPW(~*v
++);
414 MPX_UADDN(dv
, dvl
, 1);
417 /* --- @mpx_ucmp@ --- *
419 * Arguments: @const mpw *av, *avl@ = first argument vector base and limit
420 * @const mpw *bv, *bvl@ = second argument vector base and limit
422 * Returns: Less than, equal to, or greater than zero depending on
423 * whether @a@ is less than, equal to or greater than @b@,
426 * Use: Performs an unsigned integer comparison.
429 int mpx_ucmp(const mpw
*av
, const mpw
*avl
, const mpw
*bv
, const mpw
*bvl
)
434 if (avl
- av
> bvl
- bv
)
436 else if (avl
- av
< bvl
- bv
)
438 else while (avl
> av
) {
439 mpw a
= *--avl
, b
= *--bvl
;
448 /* --- @mpx_uadd@ --- *
450 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
451 * @const mpw *av, *avl@ = first addend vector base and limit
452 * @const mpw *bv, *bvl@ = second addend vector base and limit
456 * Use: Performs unsigned integer addition. If the result overflows
457 * the destination vector, high-order bits are discarded. This
458 * means that two's complement addition happens more or less for
459 * free, although that's more a side-effect than anything else.
460 * The result vector may be equal to either or both source
461 * vectors, but may not otherwise overlap them.
464 void mpx_uadd(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
,
465 const mpw
*bv
, const mpw
*bvl
)
469 while (av
< avl
|| bv
< bvl
) {
474 a
= (av
< avl
) ?
*av
++ : 0;
475 b
= (bv
< bvl
) ?
*bv
++ : 0;
476 x
= (mpd
)a
+ (mpd
)b
+ c
;
486 /* --- @mpx_uaddn@ --- *
488 * Arguments: @mpw *dv, *dvl@ = source and destination base and limit
489 * @mpw n@ = other addend
493 * Use: Adds a small integer to a multiprecision number.
496 void mpx_uaddn(mpw
*dv
, mpw
*dvl
, mpw n
) { MPX_UADDN(dv
, dvl
, n
); }
498 /* --- @mpx_usub@ --- *
500 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
501 * @const mpw *av, *avl@ = first argument vector base and limit
502 * @const mpw *bv, *bvl@ = second argument vector base and limit
506 * Use: Performs unsigned integer subtraction. If the result
507 * overflows the destination vector, high-order bits are
508 * discarded. This means that two's complement subtraction
509 * happens more or less for free, althuogh that's more a side-
510 * effect than anything else. The result vector may be equal to
511 * either or both source vectors, but may not otherwise overlap
515 void mpx_usub(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
,
516 const mpw
*bv
, const mpw
*bvl
)
520 while (av
< avl
|| bv
< bvl
) {
525 a
= (av
< avl
) ?
*av
++ : 0;
526 b
= (bv
< bvl
) ?
*bv
++ : 0;
527 x
= (mpd
)a
- (mpd
)b
- c
;
540 /* --- @mpx_usubn@ --- *
542 * Arguments: @mpw *dv, *dvl@ = source and destination base and limit
547 * Use: Subtracts a small integer from a multiprecision number.
550 void mpx_usubn(mpw
*dv
, mpw
*dvl
, mpw n
) { MPX_USUBN(dv
, dvl
, n
); }
552 /* --- @mpx_umul@ --- *
554 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
555 * @const mpw *av, *avl@ = multiplicand vector base and limit
556 * @const mpw *bv, *bvl@ = multiplier vector base and limit
560 * Use: Performs unsigned integer multiplication. If the result
561 * overflows the desination vector, high-order bits are
562 * discarded. The result vector may not overlap the argument
563 * vectors in any way.
566 void mpx_umul(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
,
567 const mpw
*bv
, const mpw
*bvl
)
569 /* --- This is probably worthwhile on a multiply --- */
574 /* --- Deal with a multiply by zero --- */
581 /* --- Do the initial multiply and initialize the accumulator --- */
583 MPX_UMULN(dv
, dvl
, av
, avl
, *bv
++);
585 /* --- Do the remaining multiply/accumulates --- */
587 while (dv
< dvl
&& bv
< bvl
) {
597 x
= (mpd
)*dvv
+ (mpd
)m
* (mpd
)*avv
++ + c
;
601 MPX_UADDN(dvv
, dvl
, c
);
606 /* --- @mpx_umuln@ --- *
608 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
609 * @const mpw *av, *avl@ = multiplicand vector base and limit
610 * @mpw m@ = multiplier
614 * Use: Multiplies a multiprecision integer by a single-word value.
615 * The destination and source may be equal. The destination
616 * is completely cleared after use.
619 void mpx_umuln(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
, mpw m
)
621 MPX_UMULN(dv
, dvl
, av
, avl
, m
);
624 /* --- @mpx_umlan@ --- *
626 * Arguments: @mpw *dv, *dvl@ = destination/accumulator base and limit
627 * @const mpw *av, *avl@ = multiplicand vector base and limit
628 * @mpw m@ = multiplier
632 * Use: Multiplies a multiprecision integer by a single-word value
633 * and adds the result to an accumulator.
636 void mpx_umlan(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
, mpw m
)
638 MPX_UMLAN(dv
, dvl
, av
, avl
, m
);
641 /* --- @mpx_usqr@ --- *
643 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
644 * @const mpw *av, *av@ = source vector base and limit
648 * Use: Performs unsigned integer squaring. The result vector must
649 * not overlap the source vector in any way.
652 void mpx_usqr(mpw
*dv
, mpw
*dvl
, const mpw
*av
, const mpw
*avl
)
656 /* --- Main loop --- */
664 /* --- Stop if I've run out of destination --- */
669 /* --- Work out the square at this point in the proceedings --- */
672 mpd x
= (mpd
)a
* (mpd
)a
+ *dvv
;
674 c
= MPW(x
>> MPW_BITS
);
677 /* --- Now fix up the rest of the vector upwards --- */
680 while (dvv
< dvl
&& avv
< avl
) {
681 mpd x
= (mpd
)a
* (mpd
)*avv
++;
682 mpd y
= ((x
<< 1) & MPW_MAX
) + c
+ *dvv
;
683 c
= (x
>> (MPW_BITS
- 1)) + (y
>> MPW_BITS
);
686 while (dvv
< dvl
&& c
) {
692 /* --- Get ready for the next round --- */
699 /* --- @mpx_udiv@ --- *
701 * Arguments: @mpw *qv, *qvl@ = quotient vector base and limit
702 * @mpw *rv, *rvl@ = dividend/remainder vector base and limit
703 * @const mpw *dv, *dvl@ = divisor vector base and limit
704 * @mpw *sv, *svl@ = scratch workspace
708 * Use: Performs unsigned integer division. If the result overflows
709 * the quotient vector, high-order bits are discarded. (Clearly
710 * the remainder vector can't overflow.) The various vectors
711 * may not overlap in any way. Yes, I know it's a bit odd
712 * requiring the dividend to be in the result position but it
713 * does make some sense really. The remainder must have
714 * headroom for at least two extra words. The scratch space
715 * must be at least one word larger than the divisor.
718 void mpx_udiv(mpw
*qv
, mpw
*qvl
, mpw
*rv
, mpw
*rvl
,
719 const mpw
*dv
, const mpw
*dvl
,
726 /* --- Initialize the quotient --- */
730 /* --- Perform some sanity checks --- */
733 assert(((void)"division by zero in mpx_udiv", dv
< dvl
));
735 /* --- Normalize the divisor --- *
737 * The algorithm requires that the divisor be at least two digits long.
738 * This is easy to fix.
745 for (b
= MPW_BITS
/ 2; b
; b
>>= 1) {
746 if (d
< (MPW_MAX
>> b
)) {
755 /* --- Normalize the dividend/remainder to match --- */
758 mpx_lsl(rv
, rvl
, rv
, rvl
, norm
);
759 mpx_lsl(sv
, svl
, dv
, dvl
, norm
);
769 /* --- Work out the relative scales --- */
772 size_t rvn
= rvl
- rv
;
773 size_t dvn
= dvl
- dv
;
775 /* --- If the divisor is clearly larger, notice this --- */
778 mpx_lsr(rv
, rvl
, rv
, rvl
, norm
);
785 /* --- Calculate the most significant quotient digit --- *
787 * Because the divisor has its top bit set, this can only happen once. The
788 * pointer arithmetic is a little contorted, to make sure that the
789 * behaviour is defined.
792 if (MPX_UCMP(rv
+ scale
, rvl
, >=, dv
, dvl
)) {
793 mpx_usub(rv
+ scale
, rvl
, rv
+ scale
, rvl
, dv
, dvl
);
794 if (qvl
- qv
> scale
)
798 /* --- Now for the main loop --- */
807 /* --- Get an estimate for the next quotient digit --- */
814 rh
= ((mpd
)r
<< MPW_BITS
) | rr
;
820 /* --- Refine the estimate --- */
824 mpd yl
= (mpd
)dd
* q
;
827 yh
+= yl
>> MPW_BITS
;
831 while (yh
> rh
|| (yh
== rh
&& yl
> rrr
)) {
842 /* --- Remove a chunk from the dividend --- */
849 /* --- Calculate the size of the chunk --- *
851 * This does the whole job of calculating @r >> scale - qd@.
854 for (svv
= rv
+ scale
, dvv
= dv
;
855 dvv
< dvl
&& svv
< rvl
;
857 mpd x
= (mpd
)*dvv
* (mpd
)q
+ mc
;
859 x
= (mpd
)*svv
- MPW(x
) - sc
;
868 mpd x
= (mpd
)*svv
- mc
- sc
;
878 /* --- Fix if the quotient was too large --- *
880 * This doesn't seem to happen very often.
883 if (rvl
[-1] > MPW_MAX
/ 2) {
884 mpx_uadd(rv
+ scale
, rvl
, rv
+ scale
, rvl
, dv
, dvl
);
889 /* --- Done for another iteration --- */
891 if (qvl
- qv
> scale
)
898 /* --- Now fiddle with unnormalizing and things --- */
900 mpx_lsr(rv
, rvl
, rv
, rvl
, norm
);
903 /*----- Test rig ----------------------------------------------------------*/
907 #include <mLib/alloc.h>
908 #include <mLib/dstr.h>
909 #include <mLib/quis.h>
910 #include <mLib/testrig.h>
914 #define ALLOC(v, vl, sz) do { \
916 mpw *_vv = xmalloc(MPWS(_sz)); \
917 mpw *_vvl = _vv + _sz; \
922 #define LOAD(v, vl, d) do { \
923 const dstr *_d = (d); \
925 ALLOC(_v, _vl, MPW_RQ(_d->len)); \
926 mpx_loadb(_v, _vl, _d->buf, _d->len); \
931 #define MAX(x, y) ((x) > (y) ? (x) : (y))
933 static void dumpbits(const char *msg
, const void *pp
, size_t sz
)
938 fprintf(stderr
, " %02x", *p
++);
942 static void dumpmp(const char *msg
, const mpw
*v
, const mpw
*vl
)
947 fprintf(stderr
, " %08lx", (unsigned long)*--vl
);
951 static int chkscan(const mpw
*v
, const mpw
*vl
,
952 const void *pp
, size_t sz
, int step
)
959 mpscan_initx(&mps
, v
, vl
);
964 for (i
= 0; i
< 8 && MPSCAN_STEP(&mps
); i
++) {
965 if (MPSCAN_BIT(&mps
) != (x
& 1)) {
967 "\n*** error, step %i, bit %u, expected %u, found %u\n",
968 step
, bit
, x
& 1, MPSCAN_BIT(&mps
));
980 static int loadstore(dstr
*v
)
983 size_t sz
= MPW_RQ(v
->len
) * 2, diff
;
987 dstr_ensure(&d
, v
->len
);
988 m
= xmalloc(MPWS(sz
));
990 for (diff
= 0; diff
< sz
; diff
+= 5) {
995 mpx_loadl(m
, ml
, v
->buf
, v
->len
);
996 if (!chkscan(m
, ml
, v
->buf
, v
->len
, +1))
998 MPX_OCTETS(oct
, m
, ml
);
999 mpx_storel(m
, ml
, d
.buf
, d
.sz
);
1000 if (memcmp(d
.buf
, v
->buf
, oct
) != 0) {
1001 dumpbits("\n*** storel failed", d
.buf
, d
.sz
);
1005 mpx_loadb(m
, ml
, v
->buf
, v
->len
);
1006 if (!chkscan(m
, ml
, v
->buf
+ v
->len
- 1, v
->len
, -1))
1008 MPX_OCTETS(oct
, m
, ml
);
1009 mpx_storeb(m
, ml
, d
.buf
, d
.sz
);
1010 if (memcmp(d
.buf
+ d
.sz
- oct
, v
->buf
+ v
->len
- oct
, oct
) != 0) {
1011 dumpbits("\n*** storeb failed", d
.buf
, d
.sz
);
1017 dumpbits("input data", v
->buf
, v
->len
);
1024 static int lsl(dstr
*v
)
1027 int n
= *(int *)v
[1].buf
;
1034 ALLOC(d
, dl
, al
- a
+ (n
+ MPW_BITS
- 1) / MPW_BITS
);
1036 mpx_lsl(d
, dl
, a
, al
, n
);
1037 if (MPX_UCMP(d
, dl
, !=, c
, cl
)) {
1038 fprintf(stderr
, "\n*** lsl(%i) failed\n", n
);
1039 dumpmp(" a", a
, al
);
1040 dumpmp("expected", c
, cl
);
1041 dumpmp(" result", d
, dl
);
1045 free(a
); free(c
); free(d
);
1049 static int lsr(dstr
*v
)
1052 int n
= *(int *)v
[1].buf
;
1059 ALLOC(d
, dl
, al
- a
+ (n
+ MPW_BITS
- 1) / MPW_BITS
+ 1);
1061 mpx_lsr(d
, dl
, a
, al
, n
);
1062 if (MPX_UCMP(d
, dl
, !=, c
, cl
)) {
1063 fprintf(stderr
, "\n*** lsr(%i) failed\n", n
);
1064 dumpmp(" a", a
, al
);
1065 dumpmp("expected", c
, cl
);
1066 dumpmp(" result", d
, dl
);
1070 free(a
); free(c
); free(d
);
1074 static int uadd(dstr
*v
)
1085 ALLOC(d
, dl
, MAX(al
- a
, bl
- b
) + 1);
1087 mpx_uadd(d
, dl
, a
, al
, b
, bl
);
1088 if (MPX_UCMP(d
, dl
, !=, c
, cl
)) {
1089 fprintf(stderr
, "\n*** uadd failed\n");
1090 dumpmp(" a", a
, al
);
1091 dumpmp(" b", b
, bl
);
1092 dumpmp("expected", c
, cl
);
1093 dumpmp(" result", d
, dl
);
1097 free(a
); free(b
); free(c
); free(d
);
1101 static int usub(dstr
*v
)
1112 ALLOC(d
, dl
, al
- a
);
1114 mpx_usub(d
, dl
, a
, al
, b
, bl
);
1115 if (MPX_UCMP(d
, dl
, !=, c
, cl
)) {
1116 fprintf(stderr
, "\n*** usub failed\n");
1117 dumpmp(" a", a
, al
);
1118 dumpmp(" b", b
, bl
);
1119 dumpmp("expected", c
, cl
);
1120 dumpmp(" result", d
, dl
);
1124 free(a
); free(b
); free(c
); free(d
);
1128 static int umul(dstr
*v
)
1139 ALLOC(d
, dl
, (al
- a
) + (bl
- b
));
1141 mpx_umul(d
, dl
, a
, al
, b
, bl
);
1142 if (MPX_UCMP(d
, dl
, !=, c
, cl
)) {
1143 fprintf(stderr
, "\n*** umul failed\n");
1144 dumpmp(" a", a
, al
);
1145 dumpmp(" b", b
, bl
);
1146 dumpmp("expected", c
, cl
);
1147 dumpmp(" result", d
, dl
);
1151 free(a
); free(b
); free(c
); free(d
);
1155 static int usqr(dstr
*v
)
1164 ALLOC(d
, dl
, 2 * (al
- a
));
1166 mpx_usqr(d
, dl
, a
, al
);
1167 if (MPX_UCMP(d
, dl
, !=, c
, cl
)) {
1168 fprintf(stderr
, "\n*** usqr failed\n");
1169 dumpmp(" a", a
, al
);
1170 dumpmp("expected", c
, cl
);
1171 dumpmp(" result", d
, dl
);
1175 free(a
); free(c
); free(d
);
1179 static int udiv(dstr
*v
)
1189 ALLOC(a
, al
, MPW_RQ(v
[0].len
) + 2); mpx_loadb(a
, al
, v
[0].buf
, v
[0].len
);
1193 ALLOC(qq
, qql
, al
- a
);
1194 ALLOC(s
, sl
, (bl
- b
) + 1);
1196 mpx_udiv(qq
, qql
, a
, al
, b
, bl
, s
, sl
);
1197 if (MPX_UCMP(qq
, qql
, !=, q
, ql
) ||
1198 MPX_UCMP(a
, al
, !=, r
, rl
)) {
1199 fprintf(stderr
, "\n*** udiv failed\n");
1200 dumpmp(" divisor", b
, bl
);
1201 dumpmp("expect r", r
, rl
);
1202 dumpmp("result r", a
, al
);
1203 dumpmp("expect q", q
, ql
);
1204 dumpmp("result q", qq
, qql
);
1208 free(a
); free(b
); free(r
); free(q
); free(s
); free(qq
);
1212 static test_chunk defs
[] = {
1213 { "load-store", loadstore
, { &type_hex
, 0 } },
1214 { "lsl", lsl
, { &type_hex
, &type_int
, &type_hex
, 0 } },
1215 { "lsr", lsr
, { &type_hex
, &type_int
, &type_hex
, 0 } },
1216 { "uadd", uadd
, { &type_hex
, &type_hex
, &type_hex
, 0 } },
1217 { "usub", usub
, { &type_hex
, &type_hex
, &type_hex
, 0 } },
1218 { "umul", umul
, { &type_hex
, &type_hex
, &type_hex
, 0 } },
1219 { "usqr", usqr
, { &type_hex
, &type_hex
, 0 } },
1220 { "udiv", udiv
, { &type_hex
, &type_hex
, &type_hex
, &type_hex
, 0 } },
1224 int main(int argc
, char *argv
[])
1226 test_run(argc
, argv
, defs
, SRCDIR
"/tests/mpx");
1233 /*----- That's all, folks -------------------------------------------------*/