main() { int i; double temp1, temp2, rn; double temp_mult = TIMING_TRIAL_SIZE/1.0e6; temp1 = cputime(); for(i=0; i<TIMING_TRIAL_SIZE; i++) rn = drand48(); temp2 = cputime(); if(temp2-temp1 < 1.0e-15 ) { printf("Timing Information not available/not accurate enough.\n\t...Exiting\n"); exit(1); } /* The next line is just used to ensure that the optimization does not remove the call to the RNG. Nothing is really printed. */ fprintf(stderr,"Last random number generated\n", rn); printf("\nUser + System time Information (Note: MRS = Million Random Numbers Per Second)\n"); printf("\tDRAND48:\t Time = %7.3f seconds => %8.4f MRS\n", temp2-temp1, temp_mult/(temp2-temp1)); putchar('\n'); }

int main (int argc, char *argv[]) { gmp_randstate_t rs; mpz_t x, y, z; unsigned long int m, n, i, niter, t0, ti; double t, f, ops_per_sec; int decimals; if (argc != 3) { fprintf (stderr, "usage: %s m n\n", argv[0]); fprintf (stderr, " where m is number of dividend bits\n"); fprintf (stderr, " and n is number of divisor bits\n"); return -1; } m = atoi (argv[1]); n = atoi (argv[2]); gmp_randinit_default (rs); mpz_init (x); mpz_init (y); mpz_init (z); mpz_urandomb (x, rs, m); mpz_urandomb (y, rs, n); printf ("Calibrating CPU speed..."); fflush (stdout); TIME (t, mpz_tdiv_q (z, x, y)); printf ("done\n"); niter = 1 + (unsigned long) (1e4 / t); printf ("Dividing an %lu-bit number by an %lu-bit number %lu times...", m, n, niter); fflush (stdout); t0 = cputime (); for (i = niter; i > 0; i--) { mpz_tdiv_q (z, x, y); } ti = cputime () - t0; printf ("done!\n"); ops_per_sec = 1000.0 * niter / ti; f = 100.0; for (decimals = 0;; decimals++) { if (ops_per_sec > f) break; f = f * 0.1; } printf ("RESULT: %.*f operations per second\n", decimals, ops_per_sec); return 0; }

main() { int i, n = 1000000; float cpu_used, a = 0.0, b = 1.0; cpu_used = cputime(); for (i = 0; i < n; ++i) a += b; cpu_used = cputime() - cpu_used; printf("a = %f cpu time = %f\n", a, cpu_used); }

nemo_main() { int n=getiparam("n"); int iter=getiparam("iter"); int m=getiparam("m"); int seed = init_xrandom(getparam("seed")); int i,j,k,l; real *x, sum; real t0,t1,t2; init_timers(100); stamp_timers(0); x = (real *) allocate(n*sizeof(real)); for (i=0; i<n; i++) /* init the whole array */ x[i] = xrandom(0.0,1.0); for (i=0; i<m; i++) /* cache it in again ? */ x[i] = xrandom(0.0,1.0); sum = 0.0; t0 = cputime(); stamp_timers(1); if (m==0) { /* do it in one sweep, the N^2 algorithm */ stamp_timers(2); for (l=0; l<iter; l++) for (j=0; j<n; j++) for (i=0; i<n; i++) sum += FUN(x[i],x[j]); stamp_timers(3); } else { /* N/M times a small M*M patch that may be in cache */ stamp_timers(2); for (l=0; l<iter; l++) for (k=0; k<n-m; k++) for (j=k; j<k+m; j++) for (i=k; i<k+m; i++) sum += FUN(x[i],x[j]); stamp_timers(3); } stamp_timers(4); t1 = cputime(); if (m) printf("%d %d %d sum=%lg Mops=%lg\n", n,iter,m,sum,iter*m*m*n/(t1-t0)/60.0/1e6); else printf("%d %d %d sum=%lg Mops=%lg\n", n,iter,m,sum,iter*n*n/(t1-t0)/60.0/1e6); stamp_timers(5); printf("%Ld %Ld %Ld %Ld %Ld\n", diff_timers(0,1), diff_timers(1,2), diff_timers(2,3), diff_timers(3,4), diff_timers(4,5)); }

int main (int argc, char *argv[]) { unsigned long N = atoi (argv[1]), M; mp_prec_t p; mpfr_t i, j; char *lo; mp_exp_t exp_lo; int st, st0; fprintf (stderr, "Using GMP %s and MPFR %s\n", gmp_version, mpfr_version); st = cputime (); mpfr_init (i); mpfr_init (j); M = N; do { M += 10; mpfr_set_prec (i, 32); mpfr_set_d (i, LOG2_10, GMP_RNDU); mpfr_mul_ui (i, i, M, GMP_RNDU); mpfr_add_ui (i, i, 3, GMP_RNDU); p = mpfr_get_ui (i, GMP_RNDU); fprintf (stderr, "Setting precision to %lu\n", p); mpfr_set_prec (j, 2); mpfr_set_prec (i, p); mpfr_set_ui (j, 1, GMP_RNDN); mpfr_exp (i, j, GMP_RNDN); /* i = exp(1) */ mpfr_set_prec (j, p); mpfr_const_pi (j, GMP_RNDN); mpfr_div (i, i, j, GMP_RNDN); mpfr_sqrt (i, i, GMP_RNDN); st0 = cputime (); lo = mpfr_get_str (NULL, &exp_lo, 10, M, i, GMP_RNDN); st0 = cputime () - st0; } while (can_round (lo, N, M) == 0); lo[N] = '\0'; printf ("%s\n", lo); mpfr_clear (i); mpfr_clear (j); fprintf (stderr, "Cputime: %dms (output %dms)\n", cputime () - st, st0); return 0; }

int main() { cputime("started up"); int i; for (i = 0; i < NELEM; ++i) data[i] = rand(); cputime("filled with %d random values", NELEM); sleep(SLEEP); cputime("did nothing for %d seconds", SLEEP); memcpy(data2, data, sizeof data); cputime("copied %lu bytes with memcpy", (unsigned long) sizeof data); memcpy(data2, data, sizeof data); cputime("copied %lu bytes with memmove", (unsigned long) sizeof data); }

void patch(void) { vlong c, vexit; Prog *p, *q; Sym *s; int a; if(debug['v']) Bprint(&bso, "%5.2f patch\n", cputime()); Bflush(&bso); mkfwd(); s = lookup("exit", 0); vexit = s->value; for(p = firstp; p != P; p = p->link) { a = p->as; if(a == ATEXT) curtext = p; if((a == AJAL || a == AJMP || a == ARET) && p->to.type != D_BRANCH && p->to.sym != S) { s = p->to.sym; if(s->type != STEXT) { diag("undefined: %s\n%P", s->name, p); s->type = STEXT; s->value = vexit; } p->to.offset = s->value; p->to.type = D_BRANCH; } if(p->to.type != D_BRANCH) continue; c = p->to.offset; for(q = firstp; q != P;) { if(q->forwd != P) if(c >= q->forwd->pc) { q = q->forwd; continue; } if(c == q->pc) break; q = q->link; } if(q == P) { diag("branch out of range %lld\n%P", c, p); p->to.type = D_NONE; } p->cond = q; } for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) curtext = p; if(p->cond != P) { p->cond = brloop(p->cond); if(p->cond != P) if(p->to.type == D_BRANCH) p->to.offset = p->cond->pc; } } }

/* * Actual definition of mcount function. Defined in <machine/profile.h>, * which is included by <sys/gmon.h>. */ MCOUNT #ifdef GUPROF void mexitcount(uintfptr_t selfpc) { struct gmonparam *p; uintfptr_t selfpcdiff; p = &_gmonparam; selfpcdiff = selfpc - (uintfptr_t)p->lowpc; if (selfpcdiff < p->textsize) { int delta; /* * Count the time since cputime() was previously called * against `selfpc'. Compensate for overheads. */ delta = cputime() - cputime_bias - p->mexitcount_pre_overhead; cputime_bias = p->mexitcount_post_overhead; KCOUNT(p, selfpcdiff) += delta; *p->cputime_count += p->cputime_overhead; *p->mexitcount_count += p->mexitcount_overhead; } }

void TimeMeter::Start() { if (!stoped_) return; stoped_ = false; begin_ = cputime(); }

static void search_fopen(char *db, char **s) { FILE *fp; #ifdef DEBUG long t0; #endif /* can only read stdin once */ if (f_stdin) { fp = stdin; if (*(s+1) != NULL) { warnx("read database from stdin, use only `%s' as pattern", *s); *(s+1) = NULL; } } else if ((fp = fopen(path_fcodes, "r")) == NULL) err(1, "`%s'", path_fcodes); /* count only chars or lines */ if (f_statistic) { statistic(fp, path_fcodes); (void)fclose(fp); return; } /* foreach search string ... */ while(*s != NULL) { #ifdef DEBUG t0 = cputime(); #endif if (!f_stdin && fseek(fp, (long)0, SEEK_SET) == -1) err(1, "fseek to begin of ``%s''\n", path_fcodes); if (f_icase) fastfind_icase(fp, *s, path_fcodes); else fastfind(fp, *s, path_fcodes); #ifdef DEBUG warnx("fastfind %ld ms", cputime () - t0); #endif s++; } (void)fclose(fp); }

static int loop_for(int id, double exec_time) { double last_loop = 0, loop_start; int tmp = 0; double start = cputime(); double now = cputime(); while (now + last_loop < start + exec_time) { loop_start = now; tmp += loop_once(); now = cputime(); last_loop = now - loop_start; } return tmp; }

/* * The start and stop routines need not be here since we turn off profiling * before calling them. They are here for convenience. */ void startguprof(struct gmonparam *gp) { gp->profrate = tick_freq; cputime_bias = 0; cputime(); }

void sphreport(stream ostr, smxptr sm, string options) { bodyptr *bptr = sm->kd->bptr; int i, nupd, nlev[MAXLEV+1], *rprof = sm->rprof; real rbsum, rbmin, rbmax, flev[MAXLEV+1], flev4, xi[NRPROF-1]; nupd = 0; for (i = 0; i <= MAXLEV; i++) nlev[i] = 0; rbsum = 0.0; for (i = 0; i < sm->kd->ngas; i++) { if (Update(bptr[i])) { nupd++; nlev[NewLevel(bptr[i])]++; rbsum += Smooth(bptr[i]); rbmin = (nupd == 1 ? Smooth(bptr[i]) : MIN(rbmin, Smooth(bptr[i]))); rbmax = (nupd == 1 ? Smooth(bptr[i]) : MAX(rbmin, Smooth(bptr[i]))); } } flev4 = 0.0; for (i = 0; i <= MAXLEV; i++) { flev[i] = 100.0 * ((real) nlev[i]) / ((real) nupd); if (i >= 4) flev4 += flev[i]; } fprintf(ostr, "\n%9s %9s %9s %9s %29s %9s\n", "log hmin", "log havg", "log hmax", "freqavg", "timestep level distribution", "CPUsph"); fprintf(ostr, "%9.4f %9.4f %9.4f %9.2f %5.1f %5.1f %5.1f %5.1f %5.1f %9.3f\n", rlog10(rbmin), rlog10(rbsum / nupd), rlog10(rbmax), sm->freqsum / nupd, flev[0], flev[1], flev[2], flev[3], flev4, cputime() - sm->cpustart); if (scanopt(options, "corrfunc")) { for (i = 0; i <= NRPROF - 2; i++) xi[i] = -1 + rpow(8.0, i/2.0) * (rprof[i] - rprof[i+1]) / ((1 - rsqrt(0.125)) * rprof[0]); fprintf(ostr, "\n "); for (i = NRPROF - 2; i >= 0; i--) fprintf(ostr, " xi%d", i); fprintf(ostr, "\n "); for (i = NRPROF - 2; i >= 0; i--) fprintf(ostr, "%6.2f", xi[i]); fprintf(ostr, "\n"); } if (scanopt(options, "levelhist")) { fprintf(ostr, "\n "); for (i = 0; i <= MAXLEV; i++) if (nlev[i] != 0) fprintf(ostr, i<10 ? " lev%d" : " lev%d", i); fprintf(ostr, "\n "); for (i = 0; i <= MAXLEV; i++) if (nlev[i] != 0) fprintf(ostr, "%6d", nlev[i]); fprintf(ostr, "\n"); } fflush(ostr); }

void doprof1(void) { #if 0 Sym *s; int32 n; Prog *p, *q; if(debug['v']) Bprint(&bso, "%5.2f profile 1\n", cputime()); Bflush(&bso); s = lookup("__mcount", 0); n = 1; for(cursym = textp; cursym != nil; cursym = cursym->next) { p = cursym->text; q = prg(); q->line = p->line; q->link = datap; datap = q; q->as = ADATA; q->from.type = D_EXTERN; q->from.offset = n*4; q->from.sym = s; q->from.scale = 4; q->to = p->from; q->to.type = D_CONST; q = prg(); q->line = p->line; q->pc = p->pc; q->link = p->link; p->link = q; p = q; p->as = AADDL; p->from.type = D_CONST; p->from.offset = 1; p->to.type = D_EXTERN; p->to.sym = s; p->to.offset = n*4 + 4; n += 2; } q = prg(); q->line = 0; q->link = datap; datap = q; q->as = ADATA; q->from.type = D_EXTERN; q->from.sym = s; q->from.scale = 4; q->to.type = D_CONST; q->to.offset = n; s->type = SBSS; s->size = n*4; #endif }

int do_busywork(int wss, double budget) { double last_loop = 0; double loop_start; int tmp = 0; double start = cputime(); double now = cputime(); while (now + last_loop < start + (budget / 1000)) { loop_start = now; tmp += dirty_kb(wss); now = cputime(); last_loop = now - loop_start; } return tmp; }

void startguprof(struct gmonparam *gp) { if (cputime_clock == CPUTIME_CLOCK_UNINITIALIZED) cputime_clock = CPUTIME_CLOCK_I8254; gp->profrate = timer_freq << CPUTIME_CLOCK_I8254_SHIFT; cputime_bias = 0; cputime(); }

void TimeMeter::Stop() { if (stoped_) return; stoped_ = true; uint64_t stop_point = cputime(); total_ += stop_point - begin_; }

main_prompt() { ITEM c; char mess[MAXMESS],mess1[MAXMESS]; double start; for (;;) { printf("|- "); if((c=ccl_ttyread())==(ITEM)I_TERM) break; else if(c==(ITEM)I_ERROR) continue; ccl_swrite(mess,c); start=cputime(); c_interp(c); sprintf(mess1,"%s - Time taken %.2lfs",mess, fabs(cputime()-start)); g_message(1l,mess1); i_delete(c); } }

/* check adding n random numbers, iterated k times */ static void check_random (int n, int k, mpfr_prec_t prec, mpfr_rnd_t rnd) { mpfr_t *x, s, ref_s; mpfr_ptr *y; int i, st, ret = 0, ref_ret = 0; gmp_randstate_t state; gmp_randinit_default (state); mpfr_init2 (s, prec); mpfr_init2 (ref_s, prec); x = (mpfr_t *) tests_allocate (n * sizeof (mpfr_t)); y = (mpfr_ptr *) tests_allocate (n * sizeof (mpfr_ptr)); for (i = 0; i < n; i++) { y[i] = x[i]; mpfr_init2 (x[i], prec); mpfr_urandom (x[i], state, rnd); } st = cputime (); for (i = 0; i < k; i++) ref_ret = mpfr_sum_naive (ref_s, x, n, rnd); printf ("mpfr_sum_naive took %dms\n", cputime () - st); st = cputime (); for (i = 0; i < k; i++) ret = mpfr_sum (s, y, n, rnd); printf ("mpfr_sum took %dms\n", cputime () - st); if (n <= 2) { MPFR_ASSERTN (mpfr_cmp (ref_s, s) == 0); MPFR_ASSERTN (ref_ret == ret); } for (i = 0; i < n; i++) mpfr_clear (x[i]); tests_free (x, n * sizeof (mpfr_t)); tests_free (y, n * sizeof (mpfr_ptr)); mpfr_clear (s); mpfr_clear (ref_s); gmp_randclear (state); }

static int loop_for(double exec_time) { double t = 0; int tmp = 0; /* while (t + loop_length < exec_time) { tmp += loop_once(); t += loop_length; } */ double start = cputime(); double now = cputime(); while (now + loop_length < start + exec_time) { tmp += loop_once(); t += loop_length; now = cputime(); } return tmp; }

void gravforce(void) { double cpustart; vector rmid; actlen = FACTIVE * 216 * tdepth; /* estimate list length */ actlen = actlen * rpow(theta, -2.5); /* allow for opening angle */ active = (nodeptr *) allocate(actlen * sizeof(nodeptr)); interact = (cellptr) allocate(actlen * sizeof(cell)); cpustart = cputime(); /* record time, less alloc */ actmax = nfcalc = nbbcalc = nbccalc = 0; /* zero cumulative counters */ active[0] = (nodeptr) root; /* initialize active list */ CLRV(rmid); /* set center of root cell */ walkgrav(active, active + 1, interact, interact + actlen, (nodeptr) root, rsize, rmid); /* scan tree, update forces */ cpuforce = cputime() - cpustart; /* store CPU time w/o alloc */ free(active); /* free up temp storage */ free(interact); }

VALUE r_gmpmod_time (VALUE self) { long int __t0, __times, __t, __tmp; (void)self; __times = 1; rb_need_block(); rb_yield (Qnil); do { __times <<= 1; __t0 = cputime (); for (__t = 0; __t < __times; __t++) {rb_yield (Qnil);} __tmp = cputime () - __t0; } while (__tmp < 250); return rb_float_new ((double) __tmp / __times); }

// Gets the CPU count of all threads in process aproc //and returns the hour minute second in the references passed //If CPU count cant be obtained returns -1 int getCpuCount(TFileName& apname,TDes& aResult) { TInt64 proctime=0; int res; RThread thrd; TTimeIntervalMicroSeconds cputime(0); TBool notime; TFileName aprocname(apname); aprocname.Append('*'); TFindThread tfinder(aprocname); notime=false; while(1) { res = tfinder.Next(aprocname); if(res!=KErrNone) { break; } res=thrd.Open(tfinder); if(res!=KErrNone) { notime=true; continue; } res=thrd.GetCpuTime(cputime); if(res!=KErrNone) { // GetCpuTime() not supported. //kernel doesn't support this } proctime+=cputime.Int64(); thrd.Close(); } TTime time(proctime); TDateTime date=time.DateTime(); if(date.Day()==0) { aResult.AppendFormat(_L(" %02d:%02d:%02d "),date.Hour(),date.Minute(),date.Second()); } else { aResult.AppendFormat(_L(" %d-%02d:%02d:%02d "),date.Day(),date.Hour(),date.Minute(),date.Second()); } if(notime) { aResult.Append(_L("?")); } if(!notime) return 0; else return -1; }

static void search_mmap(char *db, char **s) { struct stat sb; int fd; caddr_t p; off_t len; #ifdef DEBUG long t0; #endif if ((fd = open(path_fcodes, O_RDONLY)) == -1 || fstat(fd, &sb) == -1) err(1, "`%s'", path_fcodes); len = sb.st_size; if ((p = mmap((caddr_t)0, (size_t)len, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) err(1, "mmap ``%s''", path_fcodes); /* foreach search string ... */ while (*s != NULL) { #ifdef DEBUG t0 = cputime(); #endif if (f_icase) fastfind_mmap_icase(*s, p, (int)len, path_fcodes); else fastfind_mmap(*s, p, (int)len, path_fcodes); #ifdef DEBUG warnx("fastfind %ld ms", cputime () - t0); #endif s++; } if (munmap(p, (size_t)len) == -1) warn("munmap %s\n", path_fcodes); (void)close(fd); }

void force_calc(void) { real *pp, *ap; double cpubase; string *rminxstr; int i; bodyptr bp; tol = getdparam("tol"); eps = getdparam("eps"); rsize = getdparam("rsize"); rminxstr = burststring(getparam("rmin"), ", "); if (xstrlen(rminxstr, sizeof(string)) < NDIM) { SETVS(rmin, - rsize / 2.0); } else for (i = 0; i < NDIM; i++) rmin[i] = atof(rminxstr[i]); dprintf(0,"initial rsize: %8f rmin: %8f %8f %8f\n", rsize, rmin[0], rmin[1], rmin[2]); fcells = getdparam("fcells"); phidata = pp = (real *) allocate(ntest * sizeof(real)); accdata = ap = (real *) allocate(ntest * NDIM * sizeof(real)); cpubase = cputime(); maketree(massdata, nmass); cputree = cputime() - cpubase; dprintf(0," final rsize: %8f rmin: %8f %8f %8f\n", rsize, rmin[0], rmin[1], rmin[2]); cpubase = cputime(); n2btot = nbctot = 0; for (bp = testdata; bp < testdata+ntest; bp++) { hackgrav(bp); *pp++ = Phi(bp); SETV(ap, Acc(bp)); ap += NDIM; n2btot += n2bterm; nbctot += nbcterm; } cpufcal = cputime() - cpubase; }

void follow(void) { if(debug['v']) Bprint(&bso, "%5.2f follow\n", cputime()); Bflush(&bso); firstp = prg(); lastp = firstp; xfol(textp); lastp->link = P; firstp = firstp->link; }

void reloc(void) { Sym *s; if(debug['v']) Bprint(&bso, "%5.2f reloc\n", cputime()); Bflush(&bso); for(s=textp; s!=S; s=s->next) relocsym(s); for(s=datap; s!=S; s=s->next) relocsym(s); }

local void my_put_snap_diagnostics(stream outstr, int *ofptr) { real cput; cput = cputime(); put_set(outstr, DiagnosticsTag); put_data(outstr, EnergyTag, RealType, etot, 3, 0); put_data(outstr, KETensorTag, RealType, keten, NDIM, NDIM, 0); put_data(outstr, PETensorTag, RealType, peten, NDIM, NDIM, 0); put_data(outstr, AMTensorTag, RealType, amten, NDIM, NDIM, 0); put_data(outstr, CMPhaseSpaceTag, RealType, cmphase, 2, NDIM, 0); put_data(outstr, "cputime", RealType, &cput, 0); put_tes(outstr, DiagnosticsTag); }

void show_vmstat_top(vmtotal_t *Total, uvmexp_sysctl_t *uvm, uvmexp_sysctl_t *uvm1) { float f1, f2; int psiz; int i, l, c; struct { struct uvmexp_sysctl *uvmexp; } us, us1; us.uvmexp = uvm; us1.uvmexp = uvm1; putint(ucount(), STATROW, STATCOL, 3); putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0); putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); mvaddstr(STATROW, STATCOL + 53, buf); putint(Total->t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3); putint(Total->t_dw, PROCSROW + 1, PROCSCOL + 6, 3); putint(Total->t_sl, PROCSROW + 1, PROCSCOL + 9, 3); PUTRATE(us, us1, uvmexp->swtch, GENSTATROW + 1, GENSTATCOL - 1, 7); PUTRATE(us, us1, uvmexp->traps, GENSTATROW + 1, GENSTATCOL + 7, 6); PUTRATE(us, us1, uvmexp->syscalls, GENSTATROW + 1, GENSTATCOL + 14, 6); PUTRATE(us, us1, uvmexp->intrs, GENSTATROW + 1, GENSTATCOL + 21, 5); PUTRATE(us, us1, uvmexp->softs, GENSTATROW + 1, GENSTATCOL + 27, 6); PUTRATE(us, us1, uvmexp->faults, GENSTATROW + 1, GENSTATCOL + 34, 6); /* Last CPU state not calculated yet. */ for (f2 = 0.0, psiz = 0, c = 0; c < CPUSTATES; c++) { i = cpuorder[c]; f1 = cputime(i); f2 += f1; l = (int) ((f2 + 1.0) / 2.0) - psiz; if (c == 0) putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0); else putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c + 1, 5, 1, 0); mvhline(GRAPHROW + 2, psiz, cpuchar[c], l); psiz += l; } PUTRATE(us, us1, uvmexp->pageins, PAGEROW + 2, PAGECOL + 5, 5); PUTRATE(us, us1, uvmexp->pdpageouts, PAGEROW + 2, PAGECOL + 10, 5); PUTRATE(us, us1, uvmexp->pgswapin, PAGEROW + 3, PAGECOL + 5, 5); PUTRATE(us, us1, uvmexp->pgswapout, PAGEROW + 3, PAGECOL + 10, 5); }

void deadcode(void) { int i; Sym *s, *last; Auto *z; if(debug['v']) Bprint(&bso, "%5.2f deadcode\n", cputime()); mark(lookup(INITENTRY, 0)); for(i=0; i<nelem(morename); i++) mark(lookup(morename[i], 0)); for(i=0; i<ndynexp; i++) mark(dynexp[i]); // remove dead text but keep file information (z symbols). last = nil; z = nil; for(s = textp; s != nil; s = s->next) { if(!s->reachable) { if(isz(s->autom)) z = s->autom; continue; } if(last == nil) textp = s; else last->next = s; last = s; if(z != nil) { if(!isz(s->autom)) addz(s, z); z = nil; } } if(last == nil) textp = nil; else last->next = nil; for(s = allsym; s != S; s = s->allsym) if(strncmp(s->name, "weak.", 5) == 0) { s->special = 1; // do not lay out in data segment s->reachable = 1; s->hide = 1; } }