annotate src/fftw-3.3.8/kernel/planner.c @ 82:d0c2a83c1364

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