annotate src/fftw-3.3.8/kernel/planner.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents bd3cc4d1df30
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2000 Matteo Frigo
cannam@167 3 * Copyright (c) 2000 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21 #include "kernel/ifftw.h"
cannam@167 22 #include <string.h>
cannam@167 23
cannam@167 24 /* GNU Coding Standards, Sec. 5.2: "Please write the comments in a GNU
cannam@167 25 program in English, because English is the one language that nearly
cannam@167 26 all programmers in all countries can read."
cannam@167 27
cannam@167 28 ingemisco tanquam reus
cannam@167 29 culpa rubet vultus meus
cannam@167 30 supplicanti parce [rms]
cannam@167 31 */
cannam@167 32
cannam@167 33 #define VALIDP(solution) ((solution)->flags.hash_info & H_VALID)
cannam@167 34 #define LIVEP(solution) ((solution)->flags.hash_info & H_LIVE)
cannam@167 35 #define SLVNDX(solution) ((solution)->flags.slvndx)
cannam@167 36 #define BLISS(flags) (((flags).hash_info) & BLESSING)
cannam@167 37 #define INFEASIBLE_SLVNDX ((1U<<BITS_FOR_SLVNDX)-1)
cannam@167 38
cannam@167 39
cannam@167 40 #define MAXNAM 64 /* maximum length of registrar's name.
cannam@167 41 Used for reading wisdom. There is no point
cannam@167 42 in doing this right */
cannam@167 43
cannam@167 44
cannam@167 45 #ifdef FFTW_DEBUG
cannam@167 46 static void check(hashtab *ht);
cannam@167 47 #endif
cannam@167 48
cannam@167 49 /* x <= y */
cannam@167 50 #define LEQ(x, y) (((x) & (y)) == (x))
cannam@167 51
cannam@167 52 /* A subsumes B */
cannam@167 53 static int subsumes(const flags_t *a, unsigned slvndx_a, const flags_t *b)
cannam@167 54 {
cannam@167 55 if (slvndx_a != INFEASIBLE_SLVNDX) {
cannam@167 56 A(a->timelimit_impatience == 0);
cannam@167 57 return (LEQ(a->u, b->u) && LEQ(b->l, a->l));
cannam@167 58 } else {
cannam@167 59 return (LEQ(a->l, b->l)
cannam@167 60 && a->timelimit_impatience <= b->timelimit_impatience);
cannam@167 61 }
cannam@167 62 }
cannam@167 63
cannam@167 64 static unsigned addmod(unsigned a, unsigned b, unsigned p)
cannam@167 65 {
cannam@167 66 /* gcc-2.95/sparc produces incorrect code for the fast version below. */
cannam@167 67 #if defined(__sparc__) && defined(__GNUC__)
cannam@167 68 /* slow version */
cannam@167 69 return (a + b) % p;
cannam@167 70 #else
cannam@167 71 /* faster version */
cannam@167 72 unsigned c = a + b;
cannam@167 73 return c >= p ? c - p : c;
cannam@167 74 #endif
cannam@167 75 }
cannam@167 76
cannam@167 77 /*
cannam@167 78 slvdesc management:
cannam@167 79 */
cannam@167 80 static void sgrow(planner *ego)
cannam@167 81 {
cannam@167 82 unsigned osiz = ego->slvdescsiz, nsiz = 1 + osiz + osiz / 4;
cannam@167 83 slvdesc *ntab = (slvdesc *)MALLOC(nsiz * sizeof(slvdesc), SLVDESCS);
cannam@167 84 slvdesc *otab = ego->slvdescs;
cannam@167 85 unsigned i;
cannam@167 86
cannam@167 87 ego->slvdescs = ntab;
cannam@167 88 ego->slvdescsiz = nsiz;
cannam@167 89 for (i = 0; i < osiz; ++i)
cannam@167 90 ntab[i] = otab[i];
cannam@167 91 X(ifree0)(otab);
cannam@167 92 }
cannam@167 93
cannam@167 94 static void register_solver(planner *ego, solver *s)
cannam@167 95 {
cannam@167 96 slvdesc *n;
cannam@167 97 int kind;
cannam@167 98
cannam@167 99 if (s) { /* add s to solver list */
cannam@167 100 X(solver_use)(s);
cannam@167 101
cannam@167 102 A(ego->nslvdesc < INFEASIBLE_SLVNDX);
cannam@167 103 if (ego->nslvdesc >= ego->slvdescsiz)
cannam@167 104 sgrow(ego);
cannam@167 105
cannam@167 106 n = ego->slvdescs + ego->nslvdesc;
cannam@167 107
cannam@167 108 n->slv = s;
cannam@167 109 n->reg_nam = ego->cur_reg_nam;
cannam@167 110 n->reg_id = ego->cur_reg_id++;
cannam@167 111
cannam@167 112 A(strlen(n->reg_nam) < MAXNAM);
cannam@167 113 n->nam_hash = X(hash)(n->reg_nam);
cannam@167 114
cannam@167 115 kind = s->adt->problem_kind;
cannam@167 116 n->next_for_same_problem_kind = ego->slvdescs_for_problem_kind[kind];
cannam@167 117 ego->slvdescs_for_problem_kind[kind] = (int)/*from unsigned*/ego->nslvdesc;
cannam@167 118
cannam@167 119 ego->nslvdesc++;
cannam@167 120 }
cannam@167 121 }
cannam@167 122
cannam@167 123 static unsigned slookup(planner *ego, char *nam, int id)
cannam@167 124 {
cannam@167 125 unsigned h = X(hash)(nam); /* used to avoid strcmp in the common case */
cannam@167 126 FORALL_SOLVERS(ego, s, sp, {
cannam@167 127 UNUSED(s);
cannam@167 128 if (sp->reg_id == id && sp->nam_hash == h
cannam@167 129 && !strcmp(sp->reg_nam, nam))
cannam@167 130 return (unsigned)/*from ptrdiff_t*/(sp - ego->slvdescs);
cannam@167 131 });
cannam@167 132 return INFEASIBLE_SLVNDX;
cannam@167 133 }
cannam@167 134
cannam@167 135 /* Compute a MD5 hash of the configuration of the planner.
cannam@167 136 We store it into the wisdom file to make absolutely sure that
cannam@167 137 we are reading wisdom that is applicable */
cannam@167 138 static void signature_of_configuration(md5 *m, planner *ego)
cannam@167 139 {
cannam@167 140 X(md5begin)(m);
cannam@167 141 X(md5unsigned)(m, sizeof(R)); /* so we don't mix different precisions */
cannam@167 142 FORALL_SOLVERS(ego, s, sp, {
cannam@167 143 UNUSED(s);
cannam@167 144 X(md5int)(m, sp->reg_id);
cannam@167 145 X(md5puts)(m, sp->reg_nam);
cannam@167 146 });
cannam@167 147 X(md5end)(m);
cannam@167 148 }
cannam@167 149
cannam@167 150 /*
cannam@167 151 md5-related stuff:
cannam@167 152 */
cannam@167 153
cannam@167 154 /* first hash function */
cannam@167 155 static unsigned h1(const hashtab *ht, const md5sig s)
cannam@167 156 {
cannam@167 157 unsigned h = s[0] % ht->hashsiz;
cannam@167 158 A(h == (s[0] % ht->hashsiz));
cannam@167 159 return h;
cannam@167 160 }
cannam@167 161
cannam@167 162 /* second hash function (for double hashing) */
cannam@167 163 static unsigned h2(const hashtab *ht, const md5sig s)
cannam@167 164 {
cannam@167 165 unsigned h = 1U + s[1] % (ht->hashsiz - 1);
cannam@167 166 A(h == (1U + s[1] % (ht->hashsiz - 1)));
cannam@167 167 return h;
cannam@167 168 }
cannam@167 169
cannam@167 170 static void md5hash(md5 *m, const problem *p, const planner *plnr)
cannam@167 171 {
cannam@167 172 X(md5begin)(m);
cannam@167 173 X(md5unsigned)(m, sizeof(R)); /* so we don't mix different precisions */
cannam@167 174 X(md5int)(m, plnr->nthr);
cannam@167 175 p->adt->hash(p, m);
cannam@167 176 X(md5end)(m);
cannam@167 177 }
cannam@167 178
cannam@167 179 static int md5eq(const md5sig a, const md5sig b)
cannam@167 180 {
cannam@167 181 return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3];
cannam@167 182 }
cannam@167 183
cannam@167 184 static void sigcpy(const md5sig a, md5sig b)
cannam@167 185 {
cannam@167 186 b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; b[3] = a[3];
cannam@167 187 }
cannam@167 188
cannam@167 189 /*
cannam@167 190 memoization routines :
cannam@167 191 */
cannam@167 192
cannam@167 193 /*
cannam@167 194 liber scriptus proferetur
cannam@167 195 in quo totum continetur
cannam@167 196 unde mundus iudicetur
cannam@167 197 */
cannam@167 198 struct solution_s {
cannam@167 199 md5sig s;
cannam@167 200 flags_t flags;
cannam@167 201 };
cannam@167 202
cannam@167 203 static solution *htab_lookup(hashtab *ht, const md5sig s,
cannam@167 204 const flags_t *flagsp)
cannam@167 205 {
cannam@167 206 unsigned g, h = h1(ht, s), d = h2(ht, s);
cannam@167 207 solution *best = 0;
cannam@167 208
cannam@167 209 ++ht->lookup;
cannam@167 210
cannam@167 211 /* search all entries that match; select the one with
cannam@167 212 the lowest flags.u */
cannam@167 213 /* This loop may potentially traverse the whole table, since at
cannam@167 214 least one element is guaranteed to be !LIVEP, but all elements
cannam@167 215 may be VALIDP. Hence, we stop after at the first invalid
cannam@167 216 element or after traversing the whole table. */
cannam@167 217 g = h;
cannam@167 218 do {
cannam@167 219 solution *l = ht->solutions + g;
cannam@167 220 ++ht->lookup_iter;
cannam@167 221 if (VALIDP(l)) {
cannam@167 222 if (LIVEP(l)
cannam@167 223 && md5eq(s, l->s)
cannam@167 224 && subsumes(&l->flags, SLVNDX(l), flagsp) ) {
cannam@167 225 if (!best || LEQ(l->flags.u, best->flags.u))
cannam@167 226 best = l;
cannam@167 227 }
cannam@167 228 } else
cannam@167 229 break;
cannam@167 230
cannam@167 231 g = addmod(g, d, ht->hashsiz);
cannam@167 232 } while (g != h);
cannam@167 233
cannam@167 234 if (best)
cannam@167 235 ++ht->succ_lookup;
cannam@167 236 return best;
cannam@167 237 }
cannam@167 238
cannam@167 239 static solution *hlookup(planner *ego, const md5sig s,
cannam@167 240 const flags_t *flagsp)
cannam@167 241 {
cannam@167 242 solution *sol = htab_lookup(&ego->htab_blessed, s, flagsp);
cannam@167 243 if (!sol) sol = htab_lookup(&ego->htab_unblessed, s, flagsp);
cannam@167 244 return sol;
cannam@167 245 }
cannam@167 246
cannam@167 247 static void fill_slot(hashtab *ht, const md5sig s, const flags_t *flagsp,
cannam@167 248 unsigned slvndx, solution *slot)
cannam@167 249 {
cannam@167 250 ++ht->insert;
cannam@167 251 ++ht->nelem;
cannam@167 252 A(!LIVEP(slot));
cannam@167 253 slot->flags.u = flagsp->u;
cannam@167 254 slot->flags.l = flagsp->l;
cannam@167 255 slot->flags.timelimit_impatience = flagsp->timelimit_impatience;
cannam@167 256 slot->flags.hash_info |= H_VALID | H_LIVE;
cannam@167 257 SLVNDX(slot) = slvndx;
cannam@167 258
cannam@167 259 /* keep this check enabled in case we add so many solvers
cannam@167 260 that the bitfield overflows */
cannam@167 261 CK(SLVNDX(slot) == slvndx);
cannam@167 262 sigcpy(s, slot->s);
cannam@167 263 }
cannam@167 264
cannam@167 265 static void kill_slot(hashtab *ht, solution *slot)
cannam@167 266 {
cannam@167 267 A(LIVEP(slot)); /* ==> */ A(VALIDP(slot));
cannam@167 268
cannam@167 269 --ht->nelem;
cannam@167 270 slot->flags.hash_info = H_VALID;
cannam@167 271 }
cannam@167 272
cannam@167 273 static void hinsert0(hashtab *ht, const md5sig s, const flags_t *flagsp,
cannam@167 274 unsigned slvndx)
cannam@167 275 {
cannam@167 276 solution *l;
cannam@167 277 unsigned g, h = h1(ht, s), d = h2(ht, s);
cannam@167 278
cannam@167 279 ++ht->insert_unknown;
cannam@167 280
cannam@167 281 /* search for nonfull slot */
cannam@167 282 for (g = h; ; g = addmod(g, d, ht->hashsiz)) {
cannam@167 283 ++ht->insert_iter;
cannam@167 284 l = ht->solutions + g;
cannam@167 285 if (!LIVEP(l)) break;
cannam@167 286 A((g + d) % ht->hashsiz != h);
cannam@167 287 }
cannam@167 288
cannam@167 289 fill_slot(ht, s, flagsp, slvndx, l);
cannam@167 290 }
cannam@167 291
cannam@167 292 static void rehash(hashtab *ht, unsigned nsiz)
cannam@167 293 {
cannam@167 294 unsigned osiz = ht->hashsiz, h;
cannam@167 295 solution *osol = ht->solutions, *nsol;
cannam@167 296
cannam@167 297 nsiz = (unsigned)X(next_prime)((INT)nsiz);
cannam@167 298 nsol = (solution *)MALLOC(nsiz * sizeof(solution), HASHT);
cannam@167 299 ++ht->nrehash;
cannam@167 300
cannam@167 301 /* init new table */
cannam@167 302 for (h = 0; h < nsiz; ++h)
cannam@167 303 nsol[h].flags.hash_info = 0;
cannam@167 304
cannam@167 305 /* install new table */
cannam@167 306 ht->hashsiz = nsiz;
cannam@167 307 ht->solutions = nsol;
cannam@167 308 ht->nelem = 0;
cannam@167 309
cannam@167 310 /* copy table */
cannam@167 311 for (h = 0; h < osiz; ++h) {
cannam@167 312 solution *l = osol + h;
cannam@167 313 if (LIVEP(l))
cannam@167 314 hinsert0(ht, l->s, &l->flags, SLVNDX(l));
cannam@167 315 }
cannam@167 316
cannam@167 317 X(ifree0)(osol);
cannam@167 318 }
cannam@167 319
cannam@167 320 static unsigned minsz(unsigned nelem)
cannam@167 321 {
cannam@167 322 return 1U + nelem + nelem / 8U;
cannam@167 323 }
cannam@167 324
cannam@167 325 static unsigned nextsz(unsigned nelem)
cannam@167 326 {
cannam@167 327 return minsz(minsz(nelem));
cannam@167 328 }
cannam@167 329
cannam@167 330 static void hgrow(hashtab *ht)
cannam@167 331 {
cannam@167 332 unsigned nelem = ht->nelem;
cannam@167 333 if (minsz(nelem) >= ht->hashsiz)
cannam@167 334 rehash(ht, nextsz(nelem));
cannam@167 335 }
cannam@167 336
cannam@167 337 #if 0
cannam@167 338 /* shrink the hash table, never used */
cannam@167 339 static void hshrink(hashtab *ht)
cannam@167 340 {
cannam@167 341 unsigned nelem = ht->nelem;
cannam@167 342 /* always rehash after deletions */
cannam@167 343 rehash(ht, nextsz(nelem));
cannam@167 344 }
cannam@167 345 #endif
cannam@167 346
cannam@167 347 static void htab_insert(hashtab *ht, const md5sig s, const flags_t *flagsp,
cannam@167 348 unsigned slvndx)
cannam@167 349 {
cannam@167 350 unsigned g, h = h1(ht, s), d = h2(ht, s);
cannam@167 351 solution *first = 0;
cannam@167 352
cannam@167 353 /* Remove all entries that are subsumed by the new one. */
cannam@167 354 /* This loop may potentially traverse the whole table, since at
cannam@167 355 least one element is guaranteed to be !LIVEP, but all elements
cannam@167 356 may be VALIDP. Hence, we stop after at the first invalid
cannam@167 357 element or after traversing the whole table. */
cannam@167 358 g = h;
cannam@167 359 do {
cannam@167 360 solution *l = ht->solutions + g;
cannam@167 361 ++ht->insert_iter;
cannam@167 362 if (VALIDP(l)) {
cannam@167 363 if (LIVEP(l) && md5eq(s, l->s)) {
cannam@167 364 if (subsumes(flagsp, slvndx, &l->flags)) {
cannam@167 365 if (!first) first = l;
cannam@167 366 kill_slot(ht, l);
cannam@167 367 } else {
cannam@167 368 /* It is an error to insert an element that
cannam@167 369 is subsumed by an existing entry. */
cannam@167 370 A(!subsumes(&l->flags, SLVNDX(l), flagsp));
cannam@167 371 }
cannam@167 372 }
cannam@167 373 } else
cannam@167 374 break;
cannam@167 375
cannam@167 376 g = addmod(g, d, ht->hashsiz);
cannam@167 377 } while (g != h);
cannam@167 378
cannam@167 379 if (first) {
cannam@167 380 /* overwrite FIRST */
cannam@167 381 fill_slot(ht, s, flagsp, slvndx, first);
cannam@167 382 } else {
cannam@167 383 /* create a new entry */
cannam@167 384 hgrow(ht);
cannam@167 385 hinsert0(ht, s, flagsp, slvndx);
cannam@167 386 }
cannam@167 387 }
cannam@167 388
cannam@167 389 static void hinsert(planner *ego, const md5sig s, const flags_t *flagsp,
cannam@167 390 unsigned slvndx)
cannam@167 391 {
cannam@167 392 htab_insert(BLISS(*flagsp) ? &ego->htab_blessed : &ego->htab_unblessed,
cannam@167 393 s, flagsp, slvndx );
cannam@167 394 }
cannam@167 395
cannam@167 396
cannam@167 397 static void invoke_hook(planner *ego, plan *pln, const problem *p,
cannam@167 398 int optimalp)
cannam@167 399 {
cannam@167 400 if (ego->hook)
cannam@167 401 ego->hook(ego, pln, p, optimalp);
cannam@167 402 }
cannam@167 403
cannam@167 404 #ifdef FFTW_RANDOM_ESTIMATOR
cannam@167 405 /* a "random" estimate, used for debugging to generate "random"
cannam@167 406 plans, albeit from a deterministic seed. */
cannam@167 407
cannam@167 408 unsigned X(random_estimate_seed) = 0;
cannam@167 409
cannam@167 410 static double random_estimate(const planner *ego, const plan *pln,
cannam@167 411 const problem *p)
cannam@167 412 {
cannam@167 413 md5 m;
cannam@167 414 X(md5begin)(&m);
cannam@167 415 X(md5unsigned)(&m, X(random_estimate_seed));
cannam@167 416 X(md5int)(&m, ego->nthr);
cannam@167 417 p->adt->hash(p, &m);
cannam@167 418 X(md5putb)(&m, &pln->ops, sizeof(pln->ops));
cannam@167 419 X(md5putb)(&m, &pln->adt, sizeof(pln->adt));
cannam@167 420 X(md5end)(&m);
cannam@167 421 return ego->cost_hook ? ego->cost_hook(p, m.s[0], COST_MAX) : m.s[0];
cannam@167 422 }
cannam@167 423
cannam@167 424 #endif
cannam@167 425
cannam@167 426 double X(iestimate_cost)(const planner *ego, const plan *pln, const problem *p)
cannam@167 427 {
cannam@167 428 double cost =
cannam@167 429 + pln->ops.add
cannam@167 430 + pln->ops.mul
cannam@167 431
cannam@167 432 #if HAVE_FMA
cannam@167 433 + pln->ops.fma
cannam@167 434 #else
cannam@167 435 + 2 * pln->ops.fma
cannam@167 436 #endif
cannam@167 437
cannam@167 438 + pln->ops.other;
cannam@167 439 if (ego->cost_hook)
cannam@167 440 cost = ego->cost_hook(p, cost, COST_MAX);
cannam@167 441 return cost;
cannam@167 442 }
cannam@167 443
cannam@167 444 static void evaluate_plan(planner *ego, plan *pln, const problem *p)
cannam@167 445 {
cannam@167 446 if (ESTIMATEP(ego) || !BELIEVE_PCOSTP(ego) || pln->pcost == 0.0) {
cannam@167 447 ego->nplan++;
cannam@167 448
cannam@167 449 if (ESTIMATEP(ego)) {
cannam@167 450 estimate:
cannam@167 451 /* heuristic */
cannam@167 452 #ifdef FFTW_RANDOM_ESTIMATOR
cannam@167 453 pln->pcost = random_estimate(ego, pln, p);
cannam@167 454 ego->epcost += X(iestimate_cost)(ego, pln, p);
cannam@167 455 #else
cannam@167 456 pln->pcost = X(iestimate_cost)(ego, pln, p);
cannam@167 457 ego->epcost += pln->pcost;
cannam@167 458 #endif
cannam@167 459 } else {
cannam@167 460 double t = X(measure_execution_time)(ego, pln, p);
cannam@167 461
cannam@167 462 if (t < 0) { /* unavailable cycle counter */
cannam@167 463 /* Real programmers can write FORTRAN in any language */
cannam@167 464 goto estimate;
cannam@167 465 }
cannam@167 466
cannam@167 467 pln->pcost = t;
cannam@167 468 ego->pcost += t;
cannam@167 469 ego->need_timeout_check = 1;
cannam@167 470 }
cannam@167 471 }
cannam@167 472
cannam@167 473 invoke_hook(ego, pln, p, 0);
cannam@167 474 }
cannam@167 475
cannam@167 476 /* maintain dynamic scoping of flags, nthr: */
cannam@167 477 static plan *invoke_solver(planner *ego, const problem *p, solver *s,
cannam@167 478 const flags_t *nflags)
cannam@167 479 {
cannam@167 480 flags_t flags = ego->flags;
cannam@167 481 int nthr = ego->nthr;
cannam@167 482 plan *pln;
cannam@167 483 ego->flags = *nflags;
cannam@167 484 PLNR_TIMELIMIT_IMPATIENCE(ego) = 0;
cannam@167 485 A(p->adt->problem_kind == s->adt->problem_kind);
cannam@167 486 pln = s->adt->mkplan(s, p, ego);
cannam@167 487 ego->nthr = nthr;
cannam@167 488 ego->flags = flags;
cannam@167 489 return pln;
cannam@167 490 }
cannam@167 491
cannam@167 492 /* maintain the invariant TIMED_OUT ==> NEED_TIMEOUT_CHECK */
cannam@167 493 static int timeout_p(planner *ego, const problem *p)
cannam@167 494 {
cannam@167 495 /* do not timeout when estimating. First, the estimator is the
cannam@167 496 planner of last resort. Second, calling X(elapsed_since)() is
cannam@167 497 slower than estimating */
cannam@167 498 if (!ESTIMATEP(ego)) {
cannam@167 499 /* do not assume that X(elapsed_since)() is monotonic */
cannam@167 500 if (ego->timed_out) {
cannam@167 501 A(ego->need_timeout_check);
cannam@167 502 return 1;
cannam@167 503 }
cannam@167 504
cannam@167 505 if (ego->timelimit >= 0 &&
cannam@167 506 X(elapsed_since)(ego, p, ego->start_time) >= ego->timelimit) {
cannam@167 507 ego->timed_out = 1;
cannam@167 508 ego->need_timeout_check = 1;
cannam@167 509 return 1;
cannam@167 510 }
cannam@167 511 }
cannam@167 512
cannam@167 513 A(!ego->timed_out);
cannam@167 514 ego->need_timeout_check = 0;
cannam@167 515 return 0;
cannam@167 516 }
cannam@167 517
cannam@167 518 static plan *search0(planner *ego, const problem *p, unsigned *slvndx,
cannam@167 519 const flags_t *flagsp)
cannam@167 520 {
cannam@167 521 plan *best = 0;
cannam@167 522 int best_not_yet_timed = 1;
cannam@167 523
cannam@167 524 /* Do not start a search if the planner timed out. This check is
cannam@167 525 necessary, lest the relaxation mechanism kick in */
cannam@167 526 if (timeout_p(ego, p))
cannam@167 527 return 0;
cannam@167 528
cannam@167 529 FORALL_SOLVERS_OF_KIND(p->adt->problem_kind, ego, s, sp, {
cannam@167 530 plan *pln;
cannam@167 531
cannam@167 532 pln = invoke_solver(ego, p, s, flagsp);
cannam@167 533
cannam@167 534 if (ego->need_timeout_check)
cannam@167 535 if (timeout_p(ego, p)) {
cannam@167 536 X(plan_destroy_internal)(pln);
cannam@167 537 X(plan_destroy_internal)(best);
cannam@167 538 return 0;
cannam@167 539 }
cannam@167 540
cannam@167 541 if (pln) {
cannam@167 542 /* read COULD_PRUNE_NOW_P because PLN may be destroyed
cannam@167 543 before we use COULD_PRUNE_NOW_P */
cannam@167 544 int could_prune_now_p = pln->could_prune_now_p;
cannam@167 545
cannam@167 546 if (best) {
cannam@167 547 if (best_not_yet_timed) {
cannam@167 548 evaluate_plan(ego, best, p);
cannam@167 549 best_not_yet_timed = 0;
cannam@167 550 }
cannam@167 551 evaluate_plan(ego, pln, p);
cannam@167 552 if (pln->pcost < best->pcost) {
cannam@167 553 X(plan_destroy_internal)(best);
cannam@167 554 best = pln;
cannam@167 555 *slvndx = (unsigned)/*from ptrdiff_t*/(sp - ego->slvdescs);
cannam@167 556 } else {
cannam@167 557 X(plan_destroy_internal)(pln);
cannam@167 558 }
cannam@167 559 } else {
cannam@167 560 best = pln;
cannam@167 561 *slvndx = (unsigned)/*from ptrdiff_t*/(sp - ego->slvdescs);
cannam@167 562 }
cannam@167 563
cannam@167 564 if (ALLOW_PRUNINGP(ego) && could_prune_now_p)
cannam@167 565 break;
cannam@167 566 }
cannam@167 567 });
cannam@167 568
cannam@167 569 return best;
cannam@167 570 }
cannam@167 571
cannam@167 572 static plan *search(planner *ego, const problem *p, unsigned *slvndx,
cannam@167 573 flags_t *flagsp)
cannam@167 574 {
cannam@167 575 plan *pln = 0;
cannam@167 576 unsigned i;
cannam@167 577
cannam@167 578 /* relax impatience in this order: */
cannam@167 579 static const unsigned relax_tab[] = {
cannam@167 580 0, /* relax nothing */
cannam@167 581 NO_VRECURSE,
cannam@167 582 NO_FIXED_RADIX_LARGE_N,
cannam@167 583 NO_SLOW,
cannam@167 584 NO_UGLY
cannam@167 585 };
cannam@167 586
cannam@167 587 unsigned l_orig = flagsp->l;
cannam@167 588 unsigned x = flagsp->u;
cannam@167 589
cannam@167 590 /* guaranteed to be different from X */
cannam@167 591 unsigned last_x = ~x;
cannam@167 592
cannam@167 593 for (i = 0; i < sizeof(relax_tab) / sizeof(relax_tab[0]); ++i) {
cannam@167 594 if (LEQ(l_orig, x & ~relax_tab[i]))
cannam@167 595 x = x & ~relax_tab[i];
cannam@167 596
cannam@167 597 if (x != last_x) {
cannam@167 598 last_x = x;
cannam@167 599 flagsp->l = x;
cannam@167 600 pln = search0(ego, p, slvndx, flagsp);
cannam@167 601 if (pln) break;
cannam@167 602 }
cannam@167 603 }
cannam@167 604
cannam@167 605 if (!pln) {
cannam@167 606 /* search [L_ORIG, U] */
cannam@167 607 if (l_orig != last_x) {
cannam@167 608 last_x = l_orig;
cannam@167 609 flagsp->l = l_orig;
cannam@167 610 pln = search0(ego, p, slvndx, flagsp);
cannam@167 611 }
cannam@167 612 }
cannam@167 613
cannam@167 614 return pln;
cannam@167 615 }
cannam@167 616
cannam@167 617 #define CHECK_FOR_BOGOSITY \
cannam@167 618 if ((ego->bogosity_hook ? \
cannam@167 619 (ego->wisdom_state = ego->bogosity_hook(ego->wisdom_state, p)) \
cannam@167 620 : ego->wisdom_state) == WISDOM_IS_BOGUS) \
cannam@167 621 goto wisdom_is_bogus;
cannam@167 622
cannam@167 623 static plan *mkplan(planner *ego, const problem *p)
cannam@167 624 {
cannam@167 625 plan *pln;
cannam@167 626 md5 m;
cannam@167 627 unsigned slvndx;
cannam@167 628 flags_t flags_of_solution;
cannam@167 629 solution *sol;
cannam@167 630 solver *s;
cannam@167 631
cannam@167 632 ASSERT_ALIGNED_DOUBLE;
cannam@167 633 A(LEQ(PLNR_L(ego), PLNR_U(ego)));
cannam@167 634
cannam@167 635 if (ESTIMATEP(ego))
cannam@167 636 PLNR_TIMELIMIT_IMPATIENCE(ego) = 0; /* canonical form */
cannam@167 637
cannam@167 638
cannam@167 639 #ifdef FFTW_DEBUG
cannam@167 640 check(&ego->htab_blessed);
cannam@167 641 check(&ego->htab_unblessed);
cannam@167 642 #endif
cannam@167 643
cannam@167 644 pln = 0;
cannam@167 645
cannam@167 646 CHECK_FOR_BOGOSITY;
cannam@167 647
cannam@167 648 ego->timed_out = 0;
cannam@167 649
cannam@167 650 ++ego->nprob;
cannam@167 651 md5hash(&m, p, ego);
cannam@167 652
cannam@167 653 flags_of_solution = ego->flags;
cannam@167 654
cannam@167 655 if (ego->wisdom_state != WISDOM_IGNORE_ALL) {
cannam@167 656 if ((sol = hlookup(ego, m.s, &flags_of_solution))) {
cannam@167 657 /* wisdom is acceptable */
cannam@167 658 wisdom_state_t owisdom_state = ego->wisdom_state;
cannam@167 659
cannam@167 660 /* this hook is mainly for MPI, to make sure that
cannam@167 661 wisdom is in sync across all processes for MPI problems */
cannam@167 662 if (ego->wisdom_ok_hook && !ego->wisdom_ok_hook(p, sol->flags))
cannam@167 663 goto do_search; /* ignore not-ok wisdom */
cannam@167 664
cannam@167 665 slvndx = SLVNDX(sol);
cannam@167 666
cannam@167 667 if (slvndx == INFEASIBLE_SLVNDX) {
cannam@167 668 if (ego->wisdom_state == WISDOM_IGNORE_INFEASIBLE)
cannam@167 669 goto do_search;
cannam@167 670 else
cannam@167 671 return 0; /* known to be infeasible */
cannam@167 672 }
cannam@167 673
cannam@167 674 flags_of_solution = sol->flags;
cannam@167 675
cannam@167 676 /* inherit blessing either from wisdom
cannam@167 677 or from the planner */
cannam@167 678 flags_of_solution.hash_info |= BLISS(ego->flags);
cannam@167 679
cannam@167 680 ego->wisdom_state = WISDOM_ONLY;
cannam@167 681
cannam@167 682 s = ego->slvdescs[slvndx].slv;
cannam@167 683 if (p->adt->problem_kind != s->adt->problem_kind)
cannam@167 684 goto wisdom_is_bogus;
cannam@167 685
cannam@167 686 pln = invoke_solver(ego, p, s, &flags_of_solution);
cannam@167 687
cannam@167 688 CHECK_FOR_BOGOSITY; /* catch error in child solvers */
cannam@167 689
cannam@167 690 sol = 0; /* Paranoia: SOL may be dangling after
cannam@167 691 invoke_solver(); make sure we don't accidentally
cannam@167 692 reuse it. */
cannam@167 693
cannam@167 694 if (!pln)
cannam@167 695 goto wisdom_is_bogus;
cannam@167 696
cannam@167 697 ego->wisdom_state = owisdom_state;
cannam@167 698
cannam@167 699 goto skip_search;
cannam@167 700 }
cannam@167 701 else if (ego->nowisdom_hook) /* for MPI, make sure lack of wisdom */
cannam@167 702 ego->nowisdom_hook(p); /* is in sync across all processes */
cannam@167 703 }
cannam@167 704
cannam@167 705 do_search:
cannam@167 706 /* cannot search in WISDOM_ONLY mode */
cannam@167 707 if (ego->wisdom_state == WISDOM_ONLY)
cannam@167 708 goto wisdom_is_bogus;
cannam@167 709
cannam@167 710 flags_of_solution = ego->flags;
cannam@167 711 pln = search(ego, p, &slvndx, &flags_of_solution);
cannam@167 712 CHECK_FOR_BOGOSITY; /* catch error in child solvers */
cannam@167 713
cannam@167 714 if (ego->timed_out) {
cannam@167 715 A(!pln);
cannam@167 716 if (PLNR_TIMELIMIT_IMPATIENCE(ego) != 0) {
cannam@167 717 /* record (below) that this plan has failed because of
cannam@167 718 timeout */
cannam@167 719 flags_of_solution.hash_info |= BLESSING;
cannam@167 720 } else {
cannam@167 721 /* this is not the top-level problem or timeout is not
cannam@167 722 active: record no wisdom. */
cannam@167 723 return 0;
cannam@167 724 }
cannam@167 725 } else {
cannam@167 726 /* canonicalize to infinite timeout */
cannam@167 727 flags_of_solution.timelimit_impatience = 0;
cannam@167 728 }
cannam@167 729
cannam@167 730 skip_search:
cannam@167 731 if (ego->wisdom_state == WISDOM_NORMAL ||
cannam@167 732 ego->wisdom_state == WISDOM_ONLY) {
cannam@167 733 if (pln) {
cannam@167 734 hinsert(ego, m.s, &flags_of_solution, slvndx);
cannam@167 735 invoke_hook(ego, pln, p, 1);
cannam@167 736 } else {
cannam@167 737 hinsert(ego, m.s, &flags_of_solution, INFEASIBLE_SLVNDX);
cannam@167 738 }
cannam@167 739 }
cannam@167 740
cannam@167 741 return pln;
cannam@167 742
cannam@167 743 wisdom_is_bogus:
cannam@167 744 X(plan_destroy_internal)(pln);
cannam@167 745 ego->wisdom_state = WISDOM_IS_BOGUS;
cannam@167 746 return 0;
cannam@167 747 }
cannam@167 748
cannam@167 749 static void htab_destroy(hashtab *ht)
cannam@167 750 {
cannam@167 751 X(ifree)(ht->solutions);
cannam@167 752 ht->solutions = 0;
cannam@167 753 ht->nelem = 0U;
cannam@167 754 }
cannam@167 755
cannam@167 756 static void mkhashtab(hashtab *ht)
cannam@167 757 {
cannam@167 758 ht->nrehash = 0;
cannam@167 759 ht->succ_lookup = ht->lookup = ht->lookup_iter = 0;
cannam@167 760 ht->insert = ht->insert_iter = ht->insert_unknown = 0;
cannam@167 761
cannam@167 762 ht->solutions = 0;
cannam@167 763 ht->hashsiz = ht->nelem = 0U;
cannam@167 764 hgrow(ht); /* so that hashsiz > 0 */
cannam@167 765 }
cannam@167 766
cannam@167 767 /* destroy hash table entries. If FORGET_EVERYTHING, destroy the whole
cannam@167 768 table. If FORGET_ACCURSED, then destroy entries that are not blessed. */
cannam@167 769 static void forget(planner *ego, amnesia a)
cannam@167 770 {
cannam@167 771 switch (a) {
cannam@167 772 case FORGET_EVERYTHING:
cannam@167 773 htab_destroy(&ego->htab_blessed);
cannam@167 774 mkhashtab(&ego->htab_blessed);
cannam@167 775 /* fall through */
cannam@167 776 case FORGET_ACCURSED:
cannam@167 777 htab_destroy(&ego->htab_unblessed);
cannam@167 778 mkhashtab(&ego->htab_unblessed);
cannam@167 779 break;
cannam@167 780 default:
cannam@167 781 break;
cannam@167 782 }
cannam@167 783 }
cannam@167 784
cannam@167 785 /* FIXME: what sort of version information should we write? */
cannam@167 786 #define WISDOM_PREAMBLE PACKAGE "-" VERSION " " STRINGIZE(X(wisdom))
cannam@167 787 static const char stimeout[] = "TIMEOUT";
cannam@167 788
cannam@167 789 /* tantus labor non sit cassus */
cannam@167 790 static void exprt(planner *ego, printer *p)
cannam@167 791 {
cannam@167 792 unsigned h;
cannam@167 793 hashtab *ht = &ego->htab_blessed;
cannam@167 794 md5 m;
cannam@167 795
cannam@167 796 signature_of_configuration(&m, ego);
cannam@167 797
cannam@167 798 p->print(p,
cannam@167 799 "(" WISDOM_PREAMBLE " #x%M #x%M #x%M #x%M\n",
cannam@167 800 m.s[0], m.s[1], m.s[2], m.s[3]);
cannam@167 801
cannam@167 802 for (h = 0; h < ht->hashsiz; ++h) {
cannam@167 803 solution *l = ht->solutions + h;
cannam@167 804 if (LIVEP(l)) {
cannam@167 805 const char *reg_nam;
cannam@167 806 int reg_id;
cannam@167 807
cannam@167 808 if (SLVNDX(l) == INFEASIBLE_SLVNDX) {
cannam@167 809 reg_nam = stimeout;
cannam@167 810 reg_id = 0;
cannam@167 811 } else {
cannam@167 812 slvdesc *sp = ego->slvdescs + SLVNDX(l);
cannam@167 813 reg_nam = sp->reg_nam;
cannam@167 814 reg_id = sp->reg_id;
cannam@167 815 }
cannam@167 816
cannam@167 817 /* qui salvandos salvas gratis
cannam@167 818 salva me fons pietatis */
cannam@167 819 p->print(p, " (%s %d #x%x #x%x #x%x #x%M #x%M #x%M #x%M)\n",
cannam@167 820 reg_nam, reg_id,
cannam@167 821 l->flags.l, l->flags.u, l->flags.timelimit_impatience,
cannam@167 822 l->s[0], l->s[1], l->s[2], l->s[3]);
cannam@167 823 }
cannam@167 824 }
cannam@167 825 p->print(p, ")\n");
cannam@167 826 }
cannam@167 827
cannam@167 828 /* mors stupebit et natura
cannam@167 829 cum resurget creatura */
cannam@167 830 static int imprt(planner *ego, scanner *sc)
cannam@167 831 {
cannam@167 832 char buf[MAXNAM + 1];
cannam@167 833 md5uint sig[4];
cannam@167 834 unsigned l, u, timelimit_impatience;
cannam@167 835 flags_t flags;
cannam@167 836 int reg_id;
cannam@167 837 unsigned slvndx;
cannam@167 838 hashtab *ht = &ego->htab_blessed;
cannam@167 839 hashtab old;
cannam@167 840 md5 m;
cannam@167 841
cannam@167 842 if (!sc->scan(sc,
cannam@167 843 "(" WISDOM_PREAMBLE " #x%M #x%M #x%M #x%M\n",
cannam@167 844 sig + 0, sig + 1, sig + 2, sig + 3))
cannam@167 845 return 0; /* don't need to restore hashtable */
cannam@167 846
cannam@167 847 signature_of_configuration(&m, ego);
cannam@167 848 if (m.s[0] != sig[0] || m.s[1] != sig[1] ||
cannam@167 849 m.s[2] != sig[2] || m.s[3] != sig[3]) {
cannam@167 850 /* invalid configuration */
cannam@167 851 return 0;
cannam@167 852 }
cannam@167 853
cannam@167 854 /* make a backup copy of the hash table (cache the hash) */
cannam@167 855 {
cannam@167 856 unsigned h, hsiz = ht->hashsiz;
cannam@167 857 old = *ht;
cannam@167 858 old.solutions = (solution *)MALLOC(hsiz * sizeof(solution), HASHT);
cannam@167 859 for (h = 0; h < hsiz; ++h)
cannam@167 860 old.solutions[h] = ht->solutions[h];
cannam@167 861 }
cannam@167 862
cannam@167 863 while (1) {
cannam@167 864 if (sc->scan(sc, ")"))
cannam@167 865 break;
cannam@167 866
cannam@167 867 /* qua resurget ex favilla */
cannam@167 868 if (!sc->scan(sc, "(%*s %d #x%x #x%x #x%x #x%M #x%M #x%M #x%M)",
cannam@167 869 MAXNAM, buf, &reg_id, &l, &u, &timelimit_impatience,
cannam@167 870 sig + 0, sig + 1, sig + 2, sig + 3))
cannam@167 871 goto bad;
cannam@167 872
cannam@167 873 if (!strcmp(buf, stimeout) && reg_id == 0) {
cannam@167 874 slvndx = INFEASIBLE_SLVNDX;
cannam@167 875 } else {
cannam@167 876 if (timelimit_impatience != 0)
cannam@167 877 goto bad;
cannam@167 878
cannam@167 879 slvndx = slookup(ego, buf, reg_id);
cannam@167 880 if (slvndx == INFEASIBLE_SLVNDX)
cannam@167 881 goto bad;
cannam@167 882 }
cannam@167 883
cannam@167 884 /* inter oves locum praesta */
cannam@167 885 flags.l = l;
cannam@167 886 flags.u = u;
cannam@167 887 flags.timelimit_impatience = timelimit_impatience;
cannam@167 888 flags.hash_info = BLESSING;
cannam@167 889
cannam@167 890 CK(flags.l == l);
cannam@167 891 CK(flags.u == u);
cannam@167 892 CK(flags.timelimit_impatience == timelimit_impatience);
cannam@167 893
cannam@167 894 if (!hlookup(ego, sig, &flags))
cannam@167 895 hinsert(ego, sig, &flags, slvndx);
cannam@167 896 }
cannam@167 897
cannam@167 898 X(ifree0)(old.solutions);
cannam@167 899 return 1;
cannam@167 900
cannam@167 901 bad:
cannam@167 902 /* ``The wisdom of FFTW must be above suspicion.'' */
cannam@167 903 X(ifree0)(ht->solutions);
cannam@167 904 *ht = old;
cannam@167 905 return 0;
cannam@167 906 }
cannam@167 907
cannam@167 908 /*
cannam@167 909 * create a planner
cannam@167 910 */
cannam@167 911 planner *X(mkplanner)(void)
cannam@167 912 {
cannam@167 913 int i;
cannam@167 914
cannam@167 915 static const planner_adt padt = {
cannam@167 916 register_solver, mkplan, forget, exprt, imprt
cannam@167 917 };
cannam@167 918
cannam@167 919 planner *p = (planner *) MALLOC(sizeof(planner), PLANNERS);
cannam@167 920
cannam@167 921 p->adt = &padt;
cannam@167 922 p->nplan = p->nprob = 0;
cannam@167 923 p->pcost = p->epcost = 0.0;
cannam@167 924 p->hook = 0;
cannam@167 925 p->cost_hook = 0;
cannam@167 926 p->wisdom_ok_hook = 0;
cannam@167 927 p->nowisdom_hook = 0;
cannam@167 928 p->bogosity_hook = 0;
cannam@167 929 p->cur_reg_nam = 0;
cannam@167 930 p->wisdom_state = WISDOM_NORMAL;
cannam@167 931
cannam@167 932 p->slvdescs = 0;
cannam@167 933 p->nslvdesc = p->slvdescsiz = 0;
cannam@167 934
cannam@167 935 p->flags.l = 0;
cannam@167 936 p->flags.u = 0;
cannam@167 937 p->flags.timelimit_impatience = 0;
cannam@167 938 p->flags.hash_info = 0;
cannam@167 939 p->nthr = 1;
cannam@167 940 p->need_timeout_check = 1;
cannam@167 941 p->timelimit = -1;
cannam@167 942
cannam@167 943 mkhashtab(&p->htab_blessed);
cannam@167 944 mkhashtab(&p->htab_unblessed);
cannam@167 945
cannam@167 946 for (i = 0; i < PROBLEM_LAST; ++i)
cannam@167 947 p->slvdescs_for_problem_kind[i] = -1;
cannam@167 948
cannam@167 949 return p;
cannam@167 950 }
cannam@167 951
cannam@167 952 void X(planner_destroy)(planner *ego)
cannam@167 953 {
cannam@167 954 /* destroy hash table */
cannam@167 955 htab_destroy(&ego->htab_blessed);
cannam@167 956 htab_destroy(&ego->htab_unblessed);
cannam@167 957
cannam@167 958 /* destroy solvdesc table */
cannam@167 959 FORALL_SOLVERS(ego, s, sp, {
cannam@167 960 UNUSED(sp);
cannam@167 961 X(solver_destroy)(s);
cannam@167 962 });
cannam@167 963
cannam@167 964 X(ifree0)(ego->slvdescs);
cannam@167 965 X(ifree)(ego); /* dona eis requiem */
cannam@167 966 }
cannam@167 967
cannam@167 968 plan *X(mkplan_d)(planner *ego, problem *p)
cannam@167 969 {
cannam@167 970 plan *pln = ego->adt->mkplan(ego, p);
cannam@167 971 X(problem_destroy)(p);
cannam@167 972 return pln;
cannam@167 973 }
cannam@167 974
cannam@167 975 /* like X(mkplan_d), but sets/resets flags as well */
cannam@167 976 plan *X(mkplan_f_d)(planner *ego, problem *p,
cannam@167 977 unsigned l_set, unsigned u_set, unsigned u_reset)
cannam@167 978 {
cannam@167 979 flags_t oflags = ego->flags;
cannam@167 980 plan *pln;
cannam@167 981
cannam@167 982 PLNR_U(ego) &= ~u_reset;
cannam@167 983 PLNR_L(ego) &= ~u_reset;
cannam@167 984 PLNR_L(ego) |= l_set;
cannam@167 985 PLNR_U(ego) |= u_set | l_set;
cannam@167 986 pln = X(mkplan_d)(ego, p);
cannam@167 987 ego->flags = oflags;
cannam@167 988 return pln;
cannam@167 989 }
cannam@167 990
cannam@167 991 /*
cannam@167 992 * Debugging code:
cannam@167 993 */
cannam@167 994 #ifdef FFTW_DEBUG
cannam@167 995 static void check(hashtab *ht)
cannam@167 996 {
cannam@167 997 unsigned live = 0;
cannam@167 998 unsigned i;
cannam@167 999
cannam@167 1000 A(ht->nelem < ht->hashsiz);
cannam@167 1001
cannam@167 1002 for (i = 0; i < ht->hashsiz; ++i) {
cannam@167 1003 solution *l = ht->solutions + i;
cannam@167 1004 if (LIVEP(l))
cannam@167 1005 ++live;
cannam@167 1006 }
cannam@167 1007
cannam@167 1008 A(ht->nelem == live);
cannam@167 1009
cannam@167 1010 for (i = 0; i < ht->hashsiz; ++i) {
cannam@167 1011 solution *l1 = ht->solutions + i;
cannam@167 1012 int foundit = 0;
cannam@167 1013 if (LIVEP(l1)) {
cannam@167 1014 unsigned g, h = h1(ht, l1->s), d = h2(ht, l1->s);
cannam@167 1015
cannam@167 1016 g = h;
cannam@167 1017 do {
cannam@167 1018 solution *l = ht->solutions + g;
cannam@167 1019 if (VALIDP(l)) {
cannam@167 1020 if (l1 == l)
cannam@167 1021 foundit = 1;
cannam@167 1022 else if (LIVEP(l) && md5eq(l1->s, l->s)) {
cannam@167 1023 A(!subsumes(&l->flags, SLVNDX(l), &l1->flags));
cannam@167 1024 A(!subsumes(&l1->flags, SLVNDX(l1), &l->flags));
cannam@167 1025 }
cannam@167 1026 } else
cannam@167 1027 break;
cannam@167 1028 g = addmod(g, d, ht->hashsiz);
cannam@167 1029 } while (g != h);
cannam@167 1030
cannam@167 1031 A(foundit);
cannam@167 1032 }
cannam@167 1033 }
cannam@167 1034 }
cannam@167 1035 #endif