/****************************************************************** * Utility routines to handle GMP headers *****************************************************************/ /* CVS info */ /* $Date: 2005/09/19 18:45:08 $ */ /* $Revision: 1.3 $ */ /* $RCSfile: wrap.c,v $ */ /* $Name: rel_5 $ */ #include "bench11.h" #include static char cvs_info[] = "BMARKGRP $Date: 2005/09/19 18:45:08 $ $Revision: 1.3 $ $RCSfile: wrap.c,v $ $Name: rel_5 $"; // alpha has size | alloc // X1 has alloc | size void MPINIT ( mplong * X, int alloc, int size ) { #ifdef _MPUTIL X[MPALLOC] = alloc; X[MPSIZE] = size; #else // GMP # if (GMP32 == 0) X[MPALLOC] = alloc; X[MPSIZE] = size; X[MPPTR] = (mplong) (& X[MPDATA]); # else # ifndef _CRAYX1 X[MPALLOC] = (mplong)alloc + (((mplong)(size))<<32); # else X[MPALLOC] = (mplong)size + (((mplong)(alloc))<<32); # endif X[MPPTR] = (mplong) (& X[MPDATA]); # endif #endif } void MPSETSIZE ( mplong * X, int size ) { #if (GMP32 == 0) // includes MPUTIL X[MPSIZE] = size; #else # ifndef _CRAYX1 int alloc = X[MPALLOC] & BitMask32; X[MPALLOC] = (mplong)alloc + (((mplong)(size))<<32); # else int alloc = (X[MPALLOC] >> 32) & BitMask32; X[MPALLOC] = (mplong)size + (((mplong)(alloc))<<32); # endif #endif } int MPGETSIZE ( mplong * X ) { #if (GMP32 == 0) // includes MPUTIL return (int) X[MPSIZE]; #else # ifdef _CRAYX1 return (int) (X[MPALLOC] & BitMask32); # else return (int) (X[MPALLOC] >> 32); # endif #endif } #ifdef GMP /****************************************************************** * Interface to translate MPUTIL calls into calls to GMP *****************************************************************/ # include "gmp.h" #include mpadd ( MP_INT *sum, MP_INT *u, MP_INT *v ) { mpz_add ( sum, u, v ); } mpmult ( MP_INT *prod, MP_INT *u, MP_INT *v ) { mpz_mul ( prod, u, v ); } mpmod ( MP_INT *rem, MP_INT *dividend, MP_INT *modulus ) { mpz_mod ( rem, dividend, modulus ); } mpclear ( MP_INT *num ) { mpz_clear ( num); } mpset ( MP_INT *dest, MP_INT *source ) { mpz_set ( dest, source ); } mpfromstring ( MP_INT *X, char * string ) { mpz_set_str ( X, string, 10 ); } mpread ( MP_INT *X ) { mpz_inp_str ( X, stdin, 10 ); return; } mpwrite ( MP_INT *X ) { mpz_out_str ( stdout, 10, X ); /* on some systems we need this newline */ printf("\n"); } // end GMP #else void dummy() { return; } #endif