1186 lines · 37.5 KB · C
RawDownload
#include "platform.h"#include "mp.h"#include "dat.h"#include "fns.h" static voidtestcmp(void){	int fail=0;	int a, b;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			a=ldcmp(l2, l3);			ldtomp(l2, m2);			ldtomp(l3, m3);			b=mpcmp(m2, m3);			if(b<0) b=-1;			if(b>0) b=1;			if(a != b){				fprintf(stderr, "FAIL: mpcmp(%s, %s): return value: got %d, expected %d\n", LFMT(l2), LFMT(l3), b, a);				fail=1;			}			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpcmp(%s, %s): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpcmp(%s, %s): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}		}	}	ldfree(l2);	mpfree(m2);	ldfree(l3);	mpfree(m3);	if(!fail) fprintf(stderr, "mpcmp: passed\n");	anyfail |= fail;}static voidtestmagcmp(void){	int fail=0;	int a, b;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			a=ldmagcmp(l2, l3);			ldtomp(l2, m2);			ldtomp(l3, m3);			b=mpmagcmp(m2, m3);			if(b<0) b=-1;			if(b>0) b=1;			if(a != b){				fprintf(stderr, "FAIL: mpmagcmp(%s, %s): return value: got %d, expected %d\n", LFMT(l2), LFMT(l3), b, a);				fail=1;			}			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpmagcmp(%s, %s): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpmagcmp(%s, %s): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}		}	}	ldfree(l2);	mpfree(m2);	ldfree(l3);	mpfree(m3);	if(!fail) fprintf(stderr, "mpmagcmp: passed\n");	anyfail |= fail;}static voidtestadd(void){	int fail=0;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	ldint *l4 = ldnew(0);	mpint *m4 = mpnew(0);	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			ldadd(l2, l3, l4);			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpadd(m2, m3, m4);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m4->top == 0 && m4->sign < 0){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m4)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpadd(m2, m3, m2);			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m2->top == 0 && m2->sign < 0){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m2)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpadd(m2, m3, m3);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m3->top == 0 && m3->sign < 0){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m3)){				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));				fail=1;			}		}	}	ldfree(l2);	mpfree(m2);	ldfree(l3);	mpfree(m3);	ldfree(l4);	mpfree(m4);	if(!fail) fprintf(stderr, "mpadd: passed\n");	anyfail |= fail;}static voidtestsub(void){	int fail=0;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	ldint *l4 = ldnew(0);	mpint *m4 = mpnew(0);	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			ldsub(l2, l3, l4);			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpsub(m2, m3, m4);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m4->top == 0 && m4->sign < 0){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m4)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpsub(m2, m3, m2);			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m2->top == 0 && m2->sign < 0){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m2)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpsub(m2, m3, m3);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m3->top == 0 && m3->sign < 0){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m3)){				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));				fail=1;			}		}	}	ldfree(l2);	mpfree(m2);	ldfree(l3);	mpfree(m3);	ldfree(l4);	mpfree(m4);	if(!fail) fprintf(stderr, "mpsub: passed\n");	anyfail |= fail;}static voidtestmagadd(void){	int fail=0;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	ldint *l4 = ldnew(0);	mpint *m4 = mpnew(0);	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			ldmagadd(l2, l3, l4);			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpmagadd(m2, m3, m4);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m4->top == 0 && m4->sign < 0){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m4)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpmagadd(m2, m3, m2);			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m2->top == 0 && m2->sign < 0){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m2)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpmagadd(m2, m3, m3);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m3->top == 0 && m3->sign < 0){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m3)){				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));				fail=1;			}		}	}	ldfree(l2);	mpfree(m2);	ldfree(l3);	mpfree(m3);	ldfree(l4);	mpfree(m4);	if(!fail) fprintf(stderr, "mpmagadd: passed\n");	anyfail |= fail;}static voidtestmagsub(void){	int fail=0;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	ldint *l4 = ldnew(0);	mpint *m4 = mpnew(0);	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			ldmagsub(l2, l3, l4);			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpmagsub(m2, m3, m4);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m4->top == 0 && m4->sign < 0){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m4)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpmagsub(m2, m3, m2);			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m2->top == 0 && m2->sign < 0){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m2)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpmagsub(m2, m3, m3);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m3->top == 0 && m3->sign < 0){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m3)){				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));				fail=1;			}		}	}	ldfree(l2);	mpfree(m2);	ldfree(l3);	mpfree(m3);	ldfree(l4);	mpfree(m4);	if(!fail) fprintf(stderr, "mpmagsub: passed\n");	anyfail |= fail;}static voidtestand(void){	int fail=0;	ldint *l2 = ldnew(0);	mpint *m2 = mpnew(0);	int i2;	ldint *l3 = ldnew(0);	mpint *m3 = mpnew(0);	int i3;	ldint *l4 = ldnew(0);	mpint *m4 = mpnew(0);	for(i2=0;i2<NTEST;i2++){		testgen(i2, l2);		for(i3=0;i3<NTEST;i3++){			testgen(i3, l3);			ldand(l2, l3, l4);			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpand(m2, m3, m4);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m4->top == 0 && m4->sign < 0){				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m4)){				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpand(m2, m3, m2);			if(!ldmpeq(l3, m3)){				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m2->top == 0 && m2->sign < 0){				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));				fail=1;			}else if(!ldmpeq(l4, m2)){				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));				fail=1;			}			ldtomp(l2, m2);			ldtomp(l3, m3);			mptarget(m4);			mpand(m2, m3, m3);			if(!ldmpeq(l2, m2)){				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));				fail=1;			}			if(m3->top == 0 && m3->sign < 0){				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));

Lines 1–500 of 1186.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t