#ifndef _FFWRAPPER_INCLUDE_1#define _FFWRAPPER_INCLUDE_23#include "gmp.h"4#include "ff.h"56/*7Copyright 2007 Andrew V. Sutherland89This file is part of smalljac.1011smalljac is free software: you can redistribute it and/or modify12it under the terms of the GNU General Public License as published by13the Free Software Foundation, either version 2 of the License, or14(at your option) any later version.1516smalljac is distributed in the hope that it will be useful,17but WITHOUT ANY WARRANTY; without even the implied warranty of18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19GNU General Public License for more details.2021You should have received a copy of the GNU General Public License22along with smalljac. If not, see <http://www.gnu.org/licenses/>.23*/2425// This header file contains declarations and wrappers for code that was26// written for a more general multi-precision version of ff.c and needs27// to deal with multi-precision and initialization issues. It assume GMP is28// available2930#define _ff_t_declare ff_t31#define _ff_t_declare_static static ff_t32#define _ff_t_declare_dynamic ff_t33#if FF_WORDS == 134#define _ff_t_declare_reg register ff_t35#else36#define _ff_t_declare_reg ff_t37#endif3839#define _ff_init(x)40#define _ff_clear(x)4142#define _ff_set_mpz(x,Z) _ff_set_ui(x, mpz_fdiv_ui(Z,_ff_p))43#define _ff_get_mpz(Z,x) (mpz_set_ui(Z,_ff_get_ui(x)),(Z))4445#define FF_MPZ_WRAPS 164647// shared global temps - of course these are not thread safe and should probably have a home48int _ff_wrapper_initialized;49mpz_t __ff_mpz_p;50#define _ff_mpz_p (mpz_set_ui(__ff_mpz_p,_ff_p), __ff_mpz_p)5152mpz_t _ff_mpz_wraps[FF_MPZ_WRAPS]; // Wrappers used to convert to mpz for formatted output53#define _ff_wrap_mpz(x,i) _ff_get_mpz(_ff_mpz_wraps[i],x)5455#define _ff_random(x) ((x) = ui_randomm(_ff_p))56#define ff_random(x) _ff_random(*(x))5758// These macros are used for intermediate operations where reduction mod p may not necessary59// With single precision, its generally better to keep things reduced, so we don't attempt to optmize these60#define _ff_qneg(z,x) _ff_neg(z,x);61#define _ff_qnegsum(z,x,y) { _ff_neg(z,x); _ff_subfrom(z,y); }62#define _ff_qsub(z,x,y) _ff_sub(z,x,y);63#define _ff_qsubfrom(z,x) _ff_subfrom(z,x);64#define _ff_qadd(z,x,y) _ff_add(z,x,y);65#define _ff_qaddto(z,x) _ff_addto(z,x);666768// MUST BE CALLED AT LEAST ONCE69static inline void _ff_wrapper_init (void)70{71int i;72if ( _ff_wrapper_initialized ) return;73mpz_init2(__ff_mpz_p, ULONG_BITS);74for ( i = 0 ; i < FF_MPZ_WRAPS ; i++ ) mpz_init2 (_ff_mpz_wraps[i], ULONG_BITS);75_ff_wrapper_initialized = 1;76}7778static inline void ff_setup (mpz_t P)79{ _ff_wrapper_init(); ff_setup_ui (mpz_get_ui(P)); }8081#endif828384