// Code for  :  x->x() {x->cond()} x->y() ? x->tval() : x->fval()
void LIRGenerator::do_IfOp(IfOp* x) {
#ifdef ASSERT
  {
    ValueTag xtag = x->x()->type()->tag();
    ValueTag ttag = x->tval()->type()->tag();
    assert(xtag == intTag || xtag == objectTag, "cannot handle others");
    assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others");
    assert(ttag == x->fval()->type()->tag(), "cannot handle others");
  }
#endif

  LIRItem left(x->x(), this);
  LIRItem right(x->y(), this);
  left.load_item();
  right.load_item();

  emit()->ifop_phase1(x->cond(), left.result(), right.result());

  LIRItem t_val(x->tval(), this);
  LIRItem f_val(x->fval(), this);
  t_val.dont_load_item();
  f_val.dont_load_item();
  RInfo reg;
  if (x->fval()->type()->tag() == longTag) {
    // must lock before releasing
    reg = rlock_result(x)->rinfo();
  }
  if (x->fval()->type()->tag() != longTag) {
    reg = rlock_result(x)->rinfo();
  }

  emit()->ifop_phase2(reg, t_val.result(), f_val.result(), x->cond());
}
示例#2
0
文件: bench.c 项目: maciej-czekaj/mem
static bool bench_try(struct thrarg *thrarg, unsigned iters)
{
	const unsigned min_samples = 10;
	double sum, avg, std_dev = 1.0, u = 1.0, e = 1.0;
	size_t n, i;
	bool print_samples = thrarg->params.print_samples;
	bool success = false;
	const unsigned max_samples = thrarg->params.max_samples ?
					thrarg->params.max_samples : 400;
	const double error = thrarg->params.max_error ?
			thrarg->params.max_error / 100.0 : 0.05;
	double *samples = (double *)calloc(max_samples, sizeof(double));

	if (max_samples < min_samples)
		return false;

	sum = 0.0;
	avg = 0.0;
	n = 0;
	for (i = 0; i < max_samples; i++) {
		bench_once(thrarg, iters);
		samples[i] = thrarg->result.avg;
		sum += samples[i];
		n = i + 1;
		if (n < min_samples)
			continue;
		avg = sum/n;
		std_dev = stdev(n, samples, avg);
		double t = t_val(n);
		u = std_dev * t;
		e = u/avg;
		//fprintf(stderr, "a=%f e=%f u=%f t=%f sd=%f\n", avg,  e, u, t, std_dev);
		if (e < error) {
			success = true;
			break;
		}
	}

	thrarg->result.avg = avg;
	thrarg->result.samples = n;
	thrarg->result.iters = iters;
	thrarg->result.sum = sum;
	thrarg->result.sdev = std_dev;
	thrarg->result.u = u;
	thrarg->result.err = e;

	if (print_samples) {
		for (i = 0; i < n; i++)
			fprintf(stderr, "%f\n", samples[i]);
	}

	fprintf(stderr, "i = %d n = %zd sdev = %f u = %f e = %f a = %f\n",
		iters, n, std_dev, u, e, avg);
	//fprintf(stderr, "i = %d n = %zd sdev = %f u = %f e = %f a = %f me = %f s = %hhd\n",
		//iters, n, std_dev, u, e, avg, error, (char)success);
	return success;
}