Annotation of OpenXM_contrib/gmp/mpz/tests/reuse.c, Revision 1.1
1.1 ! maekawa 1: /* Test that routines allow reusing a source variable as destination. */
! 2:
! 3: #include <stdio.h>
! 4: #include "gmp.h"
! 5: #include "gmp-impl.h"
! 6: #include "urandom.h"
! 7:
! 8: #ifndef SIZE
! 9: #define SIZE 16
! 10: #endif
! 11:
! 12: #if __STDC__
! 13: typedef void (*dss_func) (mpz_ptr, mpz_srcptr, mpz_srcptr);
! 14: #else
! 15: typedef void (*dss_func) ();
! 16: #endif
! 17:
! 18: dss_func dss_funcs[] =
! 19: {
! 20: mpz_add, mpz_and, mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r,
! 21: mpz_gcd, mpz_ior, mpz_mul, mpz_sub, mpz_tdiv_q, mpz_tdiv_r
! 22: };
! 23:
! 24: char *dss_func_names[] =
! 25: {
! 26: "mpz_add", "mpz_and", "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r",
! 27: "mpz_gcd", "mpz_ior", "mpz_mul", "mpz_sub", "mpz_tdiv_q", "mpz_tdiv_r"
! 28: };
! 29:
! 30: char dss_func_division[] = {0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1};
! 31:
! 32: #if 0
! 33: mpz_divexact /* requires special operands */
! 34: #endif
! 35:
! 36: main (argc, argv)
! 37: int argc;
! 38: char **argv;
! 39: {
! 40: int i;
! 41: int pass, reps = 10000;
! 42: mpz_t in1, in2, out1;
! 43: mpz_t res1, res2, res3;
! 44:
! 45: if (argc == 2)
! 46: reps = atoi (argv[1]);
! 47:
! 48: mpz_init (in1);
! 49: mpz_init (in2);
! 50: mpz_init (out1);
! 51: mpz_init (res1);
! 52: mpz_init (res2);
! 53: mpz_init (res3);
! 54:
! 55: for (pass = 1; pass <= reps; pass++)
! 56: {
! 57: mpz_random (in1, urandom () % SIZE - SIZE/2);
! 58: mpz_random (in2, urandom () % SIZE - SIZE/2);
! 59:
! 60: for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
! 61: {
! 62: if (dss_func_division[i] && mpz_cmp_ui (in2, 0) == 0)
! 63: continue;
! 64:
! 65: (dss_funcs[i]) (res1, in1, in2);
! 66:
! 67: mpz_set (out1, in1);
! 68: (dss_funcs[i]) (out1, out1, in2);
! 69: mpz_set (res2, out1);
! 70:
! 71: mpz_set (out1, in2);
! 72: (dss_funcs[i]) (out1, in1, out1);
! 73: mpz_set (res3, out1);
! 74:
! 75: if (mpz_cmp (res1, res2) != 0)
! 76: dump_abort (dss_func_names[i], in1, in2);
! 77: if (mpz_cmp (res1, res3) != 0)
! 78: dump_abort (dss_func_names[i], in1, in2);
! 79: }
! 80: }
! 81:
! 82: exit (0);
! 83: }
! 84:
! 85: dump_abort (name, in1, in2)
! 86: char *name;
! 87: mpz_t in1, in2;
! 88: {
! 89: printf ("failure in %s (", name);
! 90: mpz_out_str (stdout, -16, in1);
! 91: printf (" ");
! 92: mpz_out_str (stdout, -16, in2);
! 93: printf (")\n");
! 94: abort ();
! 95: }
! 96:
! 97: #if 0
! 98: void mpz_add_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 99: void mpz_div_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 100: void mpz_mod_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 101: void mpz_mul_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 102: void mpz_mul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 103: void mpz_pow_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 104: void mpz_sub_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 105: void mpz_tdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 106: void mpz_tdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 107:
! 108: void mpz_abs _PROTO ((mpz_ptr, mpz_srcptr));
! 109: void mpz_com _PROTO ((mpz_ptr, mpz_srcptr));
! 110: void mpz_sqrt _PROTO ((mpz_ptr, mpz_srcptr));
! 111: void mpz_neg _PROTO ((mpz_ptr, mpz_srcptr));
! 112:
! 113: void mpz_tdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
! 114:
! 115: void mpz_powm_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr));
! 116:
! 117: void mpz_gcdext _PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
! 118:
! 119: void mpz_cdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
! 120: void mpz_fdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
! 121: void mpz_tdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
! 122:
! 123: void mpz_powm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr));
! 124:
! 125: void mpz_sqrtrem _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr));
! 126:
! 127: unsigned long int mpz_cdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
! 128: unsigned long int mpz_fdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
! 129:
! 130: unsigned long int mpz_cdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 131: unsigned long int mpz_cdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 132: unsigned long int mpz_fdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 133: unsigned long int mpz_fdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 134: unsigned long int mpz_gcd_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
! 135: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>