X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/581c854ebf69254c5ae527a789994a0fc70368e7..cc3ca08f22460b15423bb88632f3a12741b19003:/pgen.h diff --git a/pgen.h b/pgen.h index 9ce4e86..a066e28 100644 --- a/pgen.h +++ b/pgen.h @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: pgen.h,v 1.4 1999/12/22 16:01:11 mdw Exp $ + * $Id$ * * Prime generation glue * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,27 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: pgen.h,v $ - * Revision 1.4 1999/12/22 16:01:11 mdw - * Same file, completely different code. Main interface for new prime- - * search system. - * - */ - #ifndef CATACOMB_PGEN_H #define CATACOMB_PGEN_H @@ -154,7 +145,7 @@ typedef struct pgen_filterctx { pfilt f; /* The rapid prime filter */ } pgen_filterctx; -extern int pgen_filter(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_filter; /* --- @pgen_jump@ --- * * @@ -167,7 +158,7 @@ typedef struct pgen_jumpctx { pfilt f; } pgen_jumpctx; -extern int pgen_jump(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_jump; /* --- @pgen_test@ --- * * @@ -175,33 +166,61 @@ extern int pgen_jump(int /*rq*/, pgen_event */*ev*/, void */*p*/); * @rabin@ context. */ -extern int pgen_test(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_test; + +/*----- Simultaneous primality checking -----------------------------------*/ + +typedef struct pgen_simulprime { + mp *mul, *add; /* Arguments from the client */ + unsigned f; /* Flags, set by client, changed */ +#define PGENF_KEEP 1u /* Keep this prime's value */ +#define PGENF_JUMP 8u /* Use jump table, not stepping */ + pfilt p; /* This prime's filter */ + rabin r; /* Rabin testing context */ + union { + mpw step; /* The simple step to use */ + pfilt *jump; /* The jump to move by */ + mp *x; /* The result, if wanted */ + } u; +} pgen_simulprime; + +typedef struct pgen_simulctx { + pgen_simulprime *v; /* Vector of related primes */ + unsigned n; /* Size of the vector */ + mp *step; /* Basic stepping value */ +} pgen_simulctx; + +/* --- @pgen_simulstep@ --- * + * + * Step a collection of numbers simultaneously. + */ -/*----- Safe prime functions ----------------------------------------------*/ +extern pgen_proc pgen_simulstep; -/* --- @pgen_safestep@ --- * +/* --- @pgen_simultest@ --- * * - * Steps two numbers, %$q$% and %$p = 2q + 1$%, such that neither has any - * small factors. %$p$% is put in the event block. + * Test a collection of numbers simultaneously. */ -typedef struct pgen_safestepctx { - pfilt q, p; -} pgen_safestepctx; +extern pgen_proc pgen_simultest; -extern int pgen_safestep(int /*rq*/, pgen_event */*ev*/, void */*p*/); +/*----- Miscellaneous steppers and testers --------------------------------*/ -/* --- @pgen_safetest@ --- * +typedef struct pgen_gcdstepctx { + pfilt p, jp; /* Prime filter and step filter */ + mp *q, *jq; /* %$p - 1$%, and a step value*/ + mp *r; /* Other argument for GCD */ + mp *g; /* GCD output (must be inited) */ + mp *max; /* Maximum permissible GCD */ +} pgen_gcdstepctx; + +/* --- @pgen_gcdstep@ --- * * - * Applies Rabin-Miller tests to %$p$% and %$(p - 1)/2$%. + * Steps @p@ and @q@, until @p@ has no small factors, and + * %$\gcd(p, r) \le max$%. */ -typedef struct pgen_safetestctx { - pgen_safestepctx c; - rabin q, p; -} pgen_safetestctx; - -extern int pgen_safetest(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_gcdstep; /*----- Standard event handlers -------------------------------------------*/ @@ -210,14 +229,21 @@ extern int pgen_safetest(int /*rq*/, pgen_event */*ev*/, void */*p*/); * Displays a spinning baton to show progress. */ -extern int pgen_evspin(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_evspin; /* --- @pgen_ev@ --- * * * Traditional event handler, shows dots for each test. */ -extern int pgen_ev(int /*rq*/, pgen_event */*ev*/, void */*p*/); +extern pgen_proc pgen_ev; + +/* --- @pgen_subev@ --- * + * + * Subsidiary event handler, mainly for Lim-Lee searches and so on. + */ + +extern pgen_proc pgen_subev; /*----- The main driver ---------------------------------------------------*/ @@ -235,7 +261,7 @@ extern int pgen_ev(int /*rq*/, pgen_event */*ev*/, void */*p*/); * @pgen_proc *test@ = tester function to use * @void *tctx@ = context argument for tester * - * Returns: If successful, @PGEN_DONE@; otherwise @PGEN_ABORT@. + * Returns: The resulting value, or null. * * Use: A generalized prime-number search skeleton. Yes, that's a * scary number of arguments. @@ -246,6 +272,16 @@ extern mp *pgen(const char */*name*/, mp */*d*/, mp */*m*/, unsigned /*steps*/, pgen_proc */*step*/, void */*sctx*/, unsigned /*tests*/, pgen_proc */*test*/, void */*tctx*/); +/* --- @pgen_primep@ --- * + * + * Arguments: @mp *p@ = a number to check + * @grand *gr@ = a random number source + * + * Returns: Nonzero if @p@ is really prime. + */ + +extern int pgen_primep(mp */*p*/, grand */*gr*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus