Exemplo n.º 1
0
static void spear_clocksource_init(void)
{
	u32 tick_rate;
	u16 val;

	
	writew(CTRL_PRESCALER256, gpt_base + CR(CLKSRC));

	
	tick_rate = clk_get_rate(gpt_clk);
	tick_rate >>= CTRL_PRESCALER256;

	writew(0xFFFF, gpt_base + LOAD(CLKSRC));

	val = readw(gpt_base + CR(CLKSRC));
	val &= ~CTRL_ONE_SHOT;	
	val |= CTRL_ENABLE ;
	writew(val, gpt_base + CR(CLKSRC));

	
	clocksource_mmio_init(gpt_base + COUNT(CLKSRC), "tmr1", tick_rate,
		200, 16, clocksource_mmio_readw_up);
}
Exemplo n.º 2
0
    virtual void startBlock(
        const Block *b
    )
    {
        const uint8_t *p = b->data;
        SKIP(uint32_t, version, p);
        SKIP(uint256_t, prevBlkHash, p);
        SKIP(uint256_t, blkMerkleRoot, p);
        LOAD(uint32_t, blkTime, p);
        bTime = blkTime;

        struct tm gmTime;
        time_t blockTime = bTime;
        gmtime_r(&blockTime, &gmTime);

        char timeBuf[256];
        asctime_r(&gmTime, timeBuf);

        size_t sz =strlen(timeBuf);
        if(0<sz) timeBuf[sz-1] = 0;

	info("Processing block at time: %s", timeBuf);
    }
Exemplo n.º 3
0
Arquivo: time.c Projeto: 4atty/linux
static void spear_clocksource_init(void)
{
	u32 tick_rate;
	u16 val;

	/* program the prescaler (/256)*/
	writew(CTRL_PRESCALER256, gpt_base + CR(CLKSRC));

	/* find out actual clock driving Timer */
	tick_rate = clk_get_rate(gpt_clk);
	tick_rate >>= CTRL_PRESCALER256;

	writew(0xFFFF, gpt_base + LOAD(CLKSRC));

	val = readw(gpt_base + CR(CLKSRC));
	val &= ~CTRL_ONE_SHOT;	/* autoreload mode */
	val |= CTRL_ENABLE ;
	writew(val, gpt_base + CR(CLKSRC));

	/* register the clocksource */
	clocksource_mmio_init(gpt_base + COUNT(CLKSRC), "tmr1", tick_rate,
		200, 16, clocksource_mmio_readw_up);
}
Exemplo n.º 4
0
  virtual void startBlock(
    const Block *b,
    uint64_t
    ) {
    if (lastBlock < b->height) {
      wrapup();
    }

    auto p = b->chunk->getData();
    uint8_t blockHash[kSHA256ByteSize];
    sha256Twice(blockHash, p, 80);

    SKIP(uint32_t,  version,       p);
    SKIP(uint256_t, prevBlkHash,   p);
    SKIP(uint256_t, blkMerkleRoot, p);
    LOAD(uint32_t, blkTime, p);

    blkID = b->height - 1;

    if (blkID >= firstBlock) {
      fprintf(blockFile, "%" PRIu64 "|", blkID);

      writeHexEscapedBinaryBuffer(blockFile, blockHash, kSHA256ByteSize);
      fputc('|', blockFile);
      fprintf(blockFile, "%" PRIu64 "\n", (uint64_t)blkTime);
    }

    if (0 == blkID % 5000) {
      fprintf(
        stderr,
        "block=%8" PRIu64 " "
        "nbOutputs=%9" PRIu64 "\n",
        blkID,
        outputMap.size()
        );
    }
  }
Exemplo n.º 5
0
static int load_flat_TagFlags(FILE *input, const char *name, TagFlags * flags)
{
    char prefix[80];
    char *next = get_line(input);
    char *data;
    int result = 0;

    *flags = 0;
    if (next != 0) {
	sprintf(prefix, "\t\t%s:", name);
	data = strtok(next, "\n ");

	if (data != 0 && !strcmp(data, prefix)) {
	    result = 1;

	    while ((data = strtok(NULL, "\n ")) != 0) {

		LOAD(endO);
		LOAD(startO);
		LOAD(mafse);
		LOAD(strict);
		LOAD(nreie);
		LOAD(frecyc);
		LOAD(nolyspcl);

		fprintf(stderr, "Unexpected TagFlag '%s'\n", data);
		result = 0;
		break;
	    }
	} else if (data) {
	    fprintf(stderr, "load_flat_TagFlags: '%s' vs '%s'\n", data, prefix);
	}
	free(next);
    }
    return result;
}
Exemplo n.º 6
0
void
paint3(Reg *r, int bn, int32 rb, int rn)
{
	Reg *r1;
	Prog *p;
	int z;
	uint32 bb;

	z = bn/32;
	bb = 1L << (bn%32);
	if(r->act.b[z] & bb)
		return;
	for(;;) {
		if(!(r->refbehind.b[z] & bb))
			break;
		r1 = (Reg*)r->f.p1;
		if(r1 == R)
			break;
		if(!(r1->refahead.b[z] & bb))
			break;
		if(r1->act.b[z] & bb)
			break;
		r = r1;
	}

	if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb)
		addmove(r, bn, rn, 0);
	for(;;) {
		r->act.b[z] |= bb;
		p = r->f.prog;

		if(r->use1.b[z] & bb) {
			if(debug['R'] && debug['v'])
				print("%P", p);
			addreg(&p->from, rn);
			if(debug['R'] && debug['v'])
				print(" ===change== %P\n", p);
		}
		if((r->use2.b[z]|r->set.b[z]) & bb) {
			if(debug['R'] && debug['v'])
				print("%P", p);
			addreg(&p->to, rn);
			if(debug['R'] && debug['v'])
				print(" ===change== %P\n", p);
		}

		if(STORE(r) & r->regdiff.b[z] & bb)
			addmove(r, bn, rn, 1);
		r->regu |= rb;

		if(r->refbehind.b[z] & bb)
			for(r1 = (Reg*)r->f.p2; r1 != R; r1 = (Reg*)r1->f.p2link)
				if(r1->refahead.b[z] & bb)
					paint3(r1, bn, rb, rn);

		if(!(r->refahead.b[z] & bb))
			break;
		r1 = (Reg*)r->f.s2;
		if(r1 != R)
			if(r1->refbehind.b[z] & bb)
				paint3(r1, bn, rb, rn);
		r = (Reg*)r->f.s1;
		if(r == R)
			break;
		if(r->act.b[z] & bb)
			break;
		if(!(r->refbehind.b[z] & bb))
			break;
	}
}
Exemplo n.º 7
0
void
regopt(Prog *firstp)
{
	Reg *r, *r1;
	Prog *p;
	Graph *g;
	ProgInfo info;
	int i, z;
	uint32 vreg;
	Bits bit;

	if(first) {
		fmtinstall('Q', Qconv);
		exregoffset = D_R15;
		first = 0;
	}

	mergetemp(firstp);

	/*
	 * control flow is more complicated in generated go code
	 * than in generated c code.  define pseudo-variables for
	 * registers, so we have complete register usage information.
	 */
	nvar = NREGVAR;
	memset(var, 0, NREGVAR*sizeof var[0]);
	for(i=0; i<NREGVAR; i++) {
		if(regnodes[i] == N)
			regnodes[i] = newname(lookup(regname[i]));
		var[i].node = regnodes[i];
	}

	regbits = RtoB(D_SP);
	for(z=0; z<BITS; z++) {
		externs.b[z] = 0;
		params.b[z] = 0;
		consts.b[z] = 0;
		addrs.b[z] = 0;
		ovar.b[z] = 0;
	}

	// build list of return variables
	setoutvar();

	/*
	 * pass 1
	 * build aux data structure
	 * allocate pcs
	 * find use and set of variables
	 */
	g = flowstart(firstp, sizeof(Reg));
	if(g == nil)
		return;
	firstr = (Reg*)g->start;

	for(r = firstr; r != R; r = (Reg*)r->f.link) {
		p = r->f.prog;
		if(p->as == AVARDEF)
			continue;
		proginfo(&info, p);

		// Avoid making variables for direct-called functions.
		if(p->as == ACALL && p->to.type == D_EXTERN)
			continue;

		r->use1.b[0] |= info.reguse | info.regindex;
		r->set.b[0] |= info.regset;

		bit = mkvar(r, &p->from);
		if(bany(&bit)) {
			if(info.flags & LeftAddr)
				setaddrs(bit);
			if(info.flags & LeftRead)
				for(z=0; z<BITS; z++)
					r->use1.b[z] |= bit.b[z];
			if(info.flags & LeftWrite)
				for(z=0; z<BITS; z++)
					r->set.b[z] |= bit.b[z];
		}

		bit = mkvar(r, &p->to);
		if(bany(&bit)) {	
			if(info.flags & RightAddr)
				setaddrs(bit);
			if(info.flags & RightRead)
				for(z=0; z<BITS; z++)
					r->use2.b[z] |= bit.b[z];
			if(info.flags & RightWrite)
				for(z=0; z<BITS; z++)
					r->set.b[z] |= bit.b[z];
		}
	}

	for(i=0; i<nvar; i++) {
		Var *v = var+i;
		if(v->addr) {
			bit = blsh(i);
			for(z=0; z<BITS; z++)
				addrs.b[z] |= bit.b[z];
		}

		if(debug['R'] && debug['v'])
			print("bit=%2d addr=%d et=%-6E w=%-2d s=%N + %lld\n",
				i, v->addr, v->etype, v->width, v->node, v->offset);
	}

	if(debug['R'] && debug['v'])
		dumpit("pass1", &firstr->f, 1);

	/*
	 * pass 2
	 * find looping structure
	 */
	flowrpo(g);

	if(debug['R'] && debug['v'])
		dumpit("pass2", &firstr->f, 1);

	/*
	 * pass 3
	 * iterate propagating usage
	 * 	back until flow graph is complete
	 */
loop1:
	change = 0;
	for(r = firstr; r != R; r = (Reg*)r->f.link)
		r->f.active = 0;
	for(r = firstr; r != R; r = (Reg*)r->f.link)
		if(r->f.prog->as == ARET)
			prop(r, zbits, zbits);
loop11:
	/* pick up unreachable code */
	i = 0;
	for(r = firstr; r != R; r = r1) {
		r1 = (Reg*)r->f.link;
		if(r1 && r1->f.active && !r->f.active) {
			prop(r, zbits, zbits);
			i = 1;
		}
	}
	if(i)
		goto loop11;
	if(change)
		goto loop1;

	if(debug['R'] && debug['v'])
		dumpit("pass3", &firstr->f, 1);

	/*
	 * pass 4
	 * iterate propagating register/variable synchrony
	 * 	forward until graph is complete
	 */
loop2:
	change = 0;
	for(r = firstr; r != R; r = (Reg*)r->f.link)
		r->f.active = 0;
	synch(firstr, zbits);
	if(change)
		goto loop2;

	if(debug['R'] && debug['v'])
		dumpit("pass4", &firstr->f, 1);

	/*
	 * pass 4.5
	 * move register pseudo-variables into regu.
	 */
	for(r = firstr; r != R; r = (Reg*)r->f.link) {
		r->regu = (r->refbehind.b[0] | r->set.b[0]) & REGBITS;

		r->set.b[0] &= ~REGBITS;
		r->use1.b[0] &= ~REGBITS;
		r->use2.b[0] &= ~REGBITS;
		r->refbehind.b[0] &= ~REGBITS;
		r->refahead.b[0] &= ~REGBITS;
		r->calbehind.b[0] &= ~REGBITS;
		r->calahead.b[0] &= ~REGBITS;
		r->regdiff.b[0] &= ~REGBITS;
		r->act.b[0] &= ~REGBITS;
	}

	/*
	 * pass 5
	 * isolate regions
	 * calculate costs (paint1)
	 */
	r = firstr;
	if(r) {
		for(z=0; z<BITS; z++)
			bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
			  ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
		if(bany(&bit) && !r->f.refset) {
			// should never happen - all variables are preset
			if(debug['w'])
				print("%L: used and not set: %Q\n", r->f.prog->lineno, bit);
			r->f.refset = 1;
		}
	}
	for(r = firstr; r != R; r = (Reg*)r->f.link)
		r->act = zbits;
	rgp = region;
	nregion = 0;
	for(r = firstr; r != R; r = (Reg*)r->f.link) {
		for(z=0; z<BITS; z++)
			bit.b[z] = r->set.b[z] &
			  ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
		if(bany(&bit) && !r->f.refset) {
			if(debug['w'])
				print("%L: set and not used: %Q\n", r->f.prog->lineno, bit);
			r->f.refset = 1;
			excise(&r->f);
		}
		for(z=0; z<BITS; z++)
			bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
		while(bany(&bit)) {
			i = bnum(bit);
			rgp->enter = r;
			rgp->varno = i;
			change = 0;
			paint1(r, i);
			bit.b[i/32] &= ~(1L<<(i%32));
			if(change <= 0)
				continue;
			rgp->cost = change;
			nregion++;
			if(nregion >= NRGN) {
				if(debug['R'] && debug['v'])
					print("too many regions\n");
				goto brk;
			}
			rgp++;
		}
	}
brk:
	qsort(region, nregion, sizeof(region[0]), rcmp);

	if(debug['R'] && debug['v'])
		dumpit("pass5", &firstr->f, 1);

	/*
	 * pass 6
	 * determine used registers (paint2)
	 * replace code (paint3)
	 */
	rgp = region;
	for(i=0; i<nregion; i++) {
		bit = blsh(rgp->varno);
		vreg = paint2(rgp->enter, rgp->varno);
		vreg = allreg(vreg, rgp);
		if(rgp->regno != 0) {
			if(debug['R'] && debug['v']) {
				Var *v;

				v = var + rgp->varno;
				print("registerize %N+%lld (bit=%2d et=%2E) in %R\n",
						v->node, v->offset, rgp->varno, v->etype, rgp->regno);
			}
			paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
		}
		rgp++;
	}

	if(debug['R'] && debug['v'])
		dumpit("pass6", &firstr->f, 1);
	
	/*
	 * free aux structures. peep allocates new ones.
	 */
	flowend(g);
	firstr = R;

	/*
	 * pass 7
	 * peep-hole on basic block
	 */
	if(!debug['R'] || debug['P'])
		peep(firstp);

	/*
	 * eliminate nops
	 */
	for(p=firstp; p!=P; p=p->link) {
		while(p->link != P && p->link->as == ANOP)
			p->link = p->link->link;
		if(p->to.type == D_BRANCH)
			while(p->to.u.branch != P && p->to.u.branch->as == ANOP)
				p->to.u.branch = p->to.u.branch->link;
	}

	if(debug['R']) {
		if(ostats.ncvtreg ||
		   ostats.nspill ||
		   ostats.nreload ||
		   ostats.ndelmov ||
		   ostats.nvar ||
		   ostats.naddr ||
		   0)
			print("\nstats\n");

		if(ostats.ncvtreg)
			print("	%4d cvtreg\n", ostats.ncvtreg);
		if(ostats.nspill)
			print("	%4d spill\n", ostats.nspill);
		if(ostats.nreload)
			print("	%4d reload\n", ostats.nreload);
		if(ostats.ndelmov)
			print("	%4d delmov\n", ostats.ndelmov);
		if(ostats.nvar)
			print("	%4d var\n", ostats.nvar);
		if(ostats.naddr)
			print("	%4d addr\n", ostats.naddr);

		memset(&ostats, 0, sizeof(ostats));
	}
}
Exemplo n.º 8
0
HRESULT OPEN(PCTSTR ptzDir, PCTSTR ptzFile, BOOL bSubDir = FALSE)
{
	HRESULT hResult = ERROR_FILE_NOT_FOUND;

	// Lookup
	WIN32_FIND_DATA fd;
	TCHAR tzPath[MAX_PATH];
	UStrPrint(tzPath, TEXT("%s\\%s"), ptzDir, ptzFile);
	HANDLE hFind = FindFirstFile(tzPath, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				UStrPrint(tzPath, TEXT("%s\\%s"), ptzDir, fd.cFileName);

				// Take action
				PTSTR ptzExt = UStrRChr(fd.cFileName, '.');
				if (ptzExt)
				{
					if ((UStrCmpI(ptzExt, TEXT(".csc")) == 0) || (UStrCmpI(ptzExt, TEXT(".reg")) == 0))
					{
						hResult = LOAD(tzPath);
					}
					else if ((UStrCmpI(ptzExt, TEXT(".dll")) == 0) || (UStrCmpI(ptzExt, TEXT(".ocx")) == 0) || (UStrCmpI(ptzExt, TEXT(".ax")) == 0))
					{
						hResult = CDLL(tzPath);
					}
					else if (UStrCmpI(ptzExt, TEXT(".inf")) == 0)
					{
						TCHAR tzCmd[MAX_PATH];
						UStrPrint(tzCmd, TEXT("DefaultInstall 132 %s"), tzPath);
						InstallHinfSection(NULL, NULL, tzCmd, 0);
						hResult = S_OK;
					}
					else
					{
						// Pass to shell to execute it
						hResult = !ShellOpen(tzPath, NULL, (fd.cFileName[0] == '!') ? SW_HIDE : SW_NORMAL);
					}
				}		
			}
		}
		while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}

	if (bSubDir)
	{
		UStrPrint(tzPath, TEXT("%s\\*"), ptzDir);
		hFind = FindFirstFile(tzPath, &fd);
		if (hFind != INVALID_HANDLE_VALUE)
		{
			do
			{
				if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (fd.cFileName[0] != '.'))
				{
					UStrPrint(tzPath, TEXT("%s\\%s"), ptzDir, fd.cFileName);
					if (hResult == ERROR_FILE_NOT_FOUND)
					{
						hResult = OPEN(tzPath, ptzFile, bSubDir);
					}
					else
					{
						OPEN(tzPath, ptzFile, bSubDir);
					}
				}
			}
			while (FindNextFile(hFind, &fd));
			FindClose(hFind);
		}
	}
	return hResult;
}
Exemplo n.º 9
0
void
paint1(Reg *r, int bn)
{
	Reg *r1;
	Prog *p;
	int z;
	uint32_t bb;

	z = bn/32;
	bb = 1L<<(bn%32);
	if(r->act.b[z] & bb)
		return;
	for(;;) {
		if(!(r->refbehind.b[z] & bb))
			break;
		r1 = r->p1;
		if(r1 == R)
			break;
		if(!(r1->refahead.b[z] & bb))
			break;
		if(r1->act.b[z] & bb)
			break;
		r = r1;
	}

	if(LOAD(r) & ~(r->set.b[z]&~(r->use1.b[z]|r->use2.b[z])) & bb) {
		change -= CLOAD * r->loop;
		if(debug['R'] && debug['v'])
			print("%ld%P\tld %B $%d\n", r->loop,
				r->prog, blsh(bn), change);
	}
	for(;;) {
		r->act.b[z] |= bb;
		p = r->prog;

		if(r->use1.b[z] & bb) {
			change += CREF * r->loop;
			if(p->as == AFMOVL || p->as == AFMOVW)
				if(BtoR(bb) != D_F0)
					change = -CINF;
			if(debug['R'] && debug['v'])
				print("%ld%P\tu1 %B $%d\n", r->loop,
					p, blsh(bn), change);
		}

		if((r->use2.b[z]|r->set.b[z]) & bb) {
			change += CREF * r->loop;
			if(p->as == AFMOVL || p->as == AFMOVW)
				if(BtoR(bb) != D_F0)
					change = -CINF;
			if(debug['R'] && debug['v'])
				print("%ld%P\tu2 %B $%d\n", r->loop,
					p, blsh(bn), change);
		}

		if(STORE(r) & r->regdiff.b[z] & bb) {
			change -= CLOAD * r->loop;
			if(p->as == AFMOVL || p->as == AFMOVW)
				if(BtoR(bb) != D_F0)
					change = -CINF;
			if(debug['R'] && debug['v'])
				print("%ld%P\tst %B $%d\n", r->loop,
					p, blsh(bn), change);
		}

		if(r->refbehind.b[z] & bb)
			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
				if(r1->refahead.b[z] & bb)
					paint1(r1, bn);

		if(!(r->refahead.b[z] & bb))
			break;
		r1 = r->s2;
		if(r1 != R)
			if(r1->refbehind.b[z] & bb)
				paint1(r1, bn);
		r = r->s1;
		if(r == R)
			break;
		if(r->act.b[z] & bb)
			break;
		if(!(r->refbehind.b[z] & bb))
			break;
	}
}
Exemplo n.º 10
0
/*static*/ int
pulse_init(cubeb ** context, char const * context_name)
{
  void * libpulse = NULL;
  cubeb * ctx;

  *context = NULL;

#ifndef DISABLE_LIBPULSE_DLOPEN
  libpulse = dlopen("libpulse.so.0", RTLD_LAZY);
  if (!libpulse) {
    return CUBEB_ERROR;
  }

#define LOAD(x) do { \
    cubeb_##x = dlsym(libpulse, #x); \
    if (!cubeb_##x) { \
      dlclose(libpulse); \
      return CUBEB_ERROR; \
    } \
  } while(0)
  LOAD(pa_channel_map_init_auto);
  LOAD(pa_context_connect);
  LOAD(pa_context_disconnect);
  LOAD(pa_context_drain);
  LOAD(pa_context_get_state);
  LOAD(pa_context_new);
  LOAD(pa_context_rttime_new);
  LOAD(pa_context_set_state_callback);
  LOAD(pa_context_get_sink_info_by_name);
  LOAD(pa_context_get_server_info);
  LOAD(pa_context_unref);
  LOAD(pa_frame_size);
  LOAD(pa_operation_get_state);
  LOAD(pa_operation_unref);
  LOAD(pa_rtclock_now);
  LOAD(pa_stream_begin_write);
  LOAD(pa_stream_cancel_write);
  LOAD(pa_stream_connect_playback);
  LOAD(pa_stream_cork);
  LOAD(pa_stream_disconnect);
  LOAD(pa_stream_get_latency);
  LOAD(pa_stream_get_state);
  LOAD(pa_stream_get_time);
  LOAD(pa_stream_new);
  LOAD(pa_stream_set_state_callback);
  LOAD(pa_stream_set_write_callback);
  LOAD(pa_stream_unref);
  LOAD(pa_stream_update_timing_info);
  LOAD(pa_stream_write);
  LOAD(pa_threaded_mainloop_free);
  LOAD(pa_threaded_mainloop_get_api);
  LOAD(pa_threaded_mainloop_lock);
  LOAD(pa_threaded_mainloop_in_thread);
  LOAD(pa_threaded_mainloop_new);
  LOAD(pa_threaded_mainloop_signal);
  LOAD(pa_threaded_mainloop_start);
  LOAD(pa_threaded_mainloop_stop);
  LOAD(pa_threaded_mainloop_unlock);
  LOAD(pa_threaded_mainloop_wait);
  LOAD(pa_usec_to_bytes);
#undef LOAD
#endif

  ctx = calloc(1, sizeof(*ctx));
  assert(ctx);

  ctx->ops = &pulse_ops;
  ctx->libpulse = libpulse;

  ctx->mainloop = WRAP(pa_threaded_mainloop_new)();
  ctx->context = WRAP(pa_context_new)(WRAP(pa_threaded_mainloop_get_api)(ctx->mainloop), context_name);

  WRAP(pa_context_set_state_callback)(ctx->context, context_state_callback, ctx);
  WRAP(pa_threaded_mainloop_start)(ctx->mainloop);

  WRAP(pa_threaded_mainloop_lock)(ctx->mainloop);
  WRAP(pa_context_connect)(ctx->context, NULL, 0, NULL);

  if (wait_until_context_ready(ctx) != 0) {
    WRAP(pa_threaded_mainloop_unlock)(ctx->mainloop);
    pulse_destroy(ctx);
    return CUBEB_ERROR;
  }
  WRAP(pa_context_get_server_info)(ctx->context, server_info_callback, ctx);
  WRAP(pa_threaded_mainloop_unlock)(ctx->mainloop);

  *context = ctx;

  return CUBEB_OK;
}
Exemplo n.º 11
0
int main(int argc, char** argv) {
    if (argc != 2) {
        fprintf(stderr, "ERROR: ENTER ONLY ONE ARGUMENT...\n");
        exit(1);
    }
    char v_char;
    signed char v_byte;
    unsigned char v_ubyte;
    short int v_short;
    int v_int;
    long int v_long;
    unsigned short int v_ushort;
    unsigned int v_uint;
    unsigned long int v_ulong;
    float v_float;
    double v_double;
    std::string v_str;
    
    Point point_obj;
    Line line_obj;
    std::vector<Point> array_obj;
    std::vector<double> tensor_obj;
    
    xc::STextInterface<xc::load_mode> text_obj(argv[1], strlen(argv[1]));
    #define LOAD(v) text_obj.load(v)
    LOAD(v_char);
    LOAD(v_byte);
    LOAD(v_ubyte);
    LOAD(v_short);
    LOAD(v_int);
    LOAD(v_long);
    LOAD(v_ushort);
    LOAD(v_uint);
    LOAD(v_ulong);
    LOAD(v_float);
    LOAD(v_double);
    LOAD(v_str);
    LOAD(point_obj);
    LOAD(line_obj);
    text_obj.load(array_obj, array_obj[0]);
    text_obj.load(tensor_obj, tensor_obj[0]);
    text_obj.close();
    
    #define PRINT(v) std::cout << #v << ": " << v << "\n";
    PRINT(v_char);
    PRINT((int)v_byte);
    PRINT((int)v_ubyte);
    PRINT(v_short);
    PRINT(v_int);
    PRINT(v_long);
    PRINT(v_ushort);
    PRINT(v_uint);
    PRINT(v_ulong);
    PRINT(v_float);
    PRINT(v_double);
    PRINT(v_str);
    printf("point_obj: Point(%f, %f)\n", point_obj.x, point_obj.y);
    printf("line_obj: [Point(%f, %f), Point(%f, %f)]\n", 
            line_obj.a.x, line_obj.a.y, line_obj.b.x, line_obj.b.y);
    printf("array_obj: \n");
    for (int i=0; i < array_obj.size(); ++i) {
        printf("  Point(%f, %f)\n", array_obj[i].x, array_obj[i].y);
    }
    printf("tensor_obj: \n");
    for (int i=0; i < tensor_obj.size(); ++i) {
        printf("  %f\n", tensor_obj[i]);
    }
}
Exemplo n.º 12
0
/*
 *  SHA: Compression function, unrolled.
 *
 * Some operations in shaCompress are done as 5 groups of 16 operations.
 * Others are done as 4 groups of 20 operations.
 * The code below shows that structure.
 *
 * The functions that compute the new values of the 5 state variables
 * A-E are done in 4 groups of 20 operations (or you may also think
 * of them as being done in 16 groups of 5 operations).  They are
 * done by the SHA_RNDx macros below, in the right column.
 *
 * The functions that set the 16 values of the W array are done in
 * 5 groups of 16 operations.  The first group is done by the
 * LOAD macros below, the latter 4 groups are done by SHA_MIX below,
 * in the left column.
 *
 * gcc's optimizer observes that each member of the W array is assigned
 * a value 5 times in this code.  It reduces the number of store
 * operations done to the W array in the context (that is, in the X array)
 * by creating a W array on the stack, and storing the W values there for
 * the first 4 groups of operations on W, and storing the values in the
 * context's W array only in the fifth group.  This is undesirable.
 * It is MUCH bigger code than simply using the context's W array, because
 * all the offsets to the W array in the stack are 32-bit signed offsets,
 * and it is no faster than storing the values in the context's W array.
 *
 * The original code for sha_fast.c prevented this creation of a separate
 * W array in the stack by creating a W array of 80 members, each of
 * whose elements is assigned only once. It also separated the computations
 * of the W array values and the computations of the values for the 5
 * state variables into two separate passes, W's, then A-E's so that the
 * second pass could be done all in registers (except for accessing the W
 * array) on machines with fewer registers.  The method is suboptimal
 * for machines with enough registers to do it all in one pass, and it
 * necessitates using many instructions with 32-bit offsets.
 *
 * This code eliminates the separate W array on the stack by a completely
 * different means: by declaring the X array volatile.  This prevents
 * the optimizer from trying to reduce the use of the X array by the
 * creation of a MORE expensive W array on the stack. The result is
 * that all instructions use signed 8-bit offsets and not 32-bit offsets.
 *
 * The combination of this code and the -O3 optimizer flag on GCC 3.4.3
 * results in code that is 3 times faster than the previous NSS sha_fast
 * code on AMD64.
 */
static void NO_SANITIZE_ALIGNMENT
shaCompress(volatile SHA_HW_t *X, const PRUint32 *inbuf)
{
    register SHA_HW_t A, B, C, D, E;

#if defined(SHA_NEED_TMP_VARIABLE)
    register PRUint32 tmp;
#endif

#if !defined(SHA_PUT_W_IN_STACK)
#define XH(n) X[n - H2X]
#define XW(n) X[n - W2X]
#else
    SHA_HW_t w_0, w_1, w_2, w_3, w_4, w_5, w_6, w_7,
        w_8, w_9, w_10, w_11, w_12, w_13, w_14, w_15;
#define XW(n) w_##n
#define XH(n) X[n]
#endif

#define K0 0x5a827999L
#define K1 0x6ed9eba1L
#define K2 0x8f1bbcdcL
#define K3 0xca62c1d6L

#define SHA_RND1(a, b, c, d, e, n)                         \
    a = SHA_ROTL(b, 5) + SHA_F1(c, d, e) + a + XW(n) + K0; \
    c = SHA_ROTL(c, 30)
#define SHA_RND2(a, b, c, d, e, n)                         \
    a = SHA_ROTL(b, 5) + SHA_F2(c, d, e) + a + XW(n) + K1; \
    c = SHA_ROTL(c, 30)
#define SHA_RND3(a, b, c, d, e, n)                         \
    a = SHA_ROTL(b, 5) + SHA_F3(c, d, e) + a + XW(n) + K2; \
    c = SHA_ROTL(c, 30)
#define SHA_RND4(a, b, c, d, e, n)                         \
    a = SHA_ROTL(b, 5) + SHA_F4(c, d, e) + a + XW(n) + K3; \
    c = SHA_ROTL(c, 30)

#define LOAD(n) XW(n) = SHA_HTONL(inbuf[n])

    A = XH(0);
    B = XH(1);
    C = XH(2);
    D = XH(3);
    E = XH(4);

    LOAD(0);
    SHA_RND1(E, A, B, C, D, 0);
    LOAD(1);
    SHA_RND1(D, E, A, B, C, 1);
    LOAD(2);
    SHA_RND1(C, D, E, A, B, 2);
    LOAD(3);
    SHA_RND1(B, C, D, E, A, 3);
    LOAD(4);
    SHA_RND1(A, B, C, D, E, 4);
    LOAD(5);
    SHA_RND1(E, A, B, C, D, 5);
    LOAD(6);
    SHA_RND1(D, E, A, B, C, 6);
    LOAD(7);
    SHA_RND1(C, D, E, A, B, 7);
    LOAD(8);
    SHA_RND1(B, C, D, E, A, 8);
    LOAD(9);
    SHA_RND1(A, B, C, D, E, 9);
    LOAD(10);
    SHA_RND1(E, A, B, C, D, 10);
    LOAD(11);
    SHA_RND1(D, E, A, B, C, 11);
    LOAD(12);
    SHA_RND1(C, D, E, A, B, 12);
    LOAD(13);
    SHA_RND1(B, C, D, E, A, 13);
    LOAD(14);
    SHA_RND1(A, B, C, D, E, 14);
    LOAD(15);
    SHA_RND1(E, A, B, C, D, 15);

    SHA_MIX(0, 13, 8, 2);
    SHA_RND1(D, E, A, B, C, 0);
    SHA_MIX(1, 14, 9, 3);
    SHA_RND1(C, D, E, A, B, 1);
    SHA_MIX(2, 15, 10, 4);
    SHA_RND1(B, C, D, E, A, 2);
    SHA_MIX(3, 0, 11, 5);
    SHA_RND1(A, B, C, D, E, 3);

    SHA_MIX(4, 1, 12, 6);
    SHA_RND2(E, A, B, C, D, 4);
    SHA_MIX(5, 2, 13, 7);
    SHA_RND2(D, E, A, B, C, 5);
    SHA_MIX(6, 3, 14, 8);
    SHA_RND2(C, D, E, A, B, 6);
    SHA_MIX(7, 4, 15, 9);
    SHA_RND2(B, C, D, E, A, 7);
    SHA_MIX(8, 5, 0, 10);
    SHA_RND2(A, B, C, D, E, 8);
    SHA_MIX(9, 6, 1, 11);
    SHA_RND2(E, A, B, C, D, 9);
    SHA_MIX(10, 7, 2, 12);
    SHA_RND2(D, E, A, B, C, 10);
    SHA_MIX(11, 8, 3, 13);
    SHA_RND2(C, D, E, A, B, 11);
    SHA_MIX(12, 9, 4, 14);
    SHA_RND2(B, C, D, E, A, 12);
    SHA_MIX(13, 10, 5, 15);
    SHA_RND2(A, B, C, D, E, 13);
    SHA_MIX(14, 11, 6, 0);
    SHA_RND2(E, A, B, C, D, 14);
    SHA_MIX(15, 12, 7, 1);
    SHA_RND2(D, E, A, B, C, 15);

    SHA_MIX(0, 13, 8, 2);
    SHA_RND2(C, D, E, A, B, 0);
    SHA_MIX(1, 14, 9, 3);
    SHA_RND2(B, C, D, E, A, 1);
    SHA_MIX(2, 15, 10, 4);
    SHA_RND2(A, B, C, D, E, 2);
    SHA_MIX(3, 0, 11, 5);
    SHA_RND2(E, A, B, C, D, 3);
    SHA_MIX(4, 1, 12, 6);
    SHA_RND2(D, E, A, B, C, 4);
    SHA_MIX(5, 2, 13, 7);
    SHA_RND2(C, D, E, A, B, 5);
    SHA_MIX(6, 3, 14, 8);
    SHA_RND2(B, C, D, E, A, 6);
    SHA_MIX(7, 4, 15, 9);
    SHA_RND2(A, B, C, D, E, 7);

    SHA_MIX(8, 5, 0, 10);
    SHA_RND3(E, A, B, C, D, 8);
    SHA_MIX(9, 6, 1, 11);
    SHA_RND3(D, E, A, B, C, 9);
    SHA_MIX(10, 7, 2, 12);
    SHA_RND3(C, D, E, A, B, 10);
    SHA_MIX(11, 8, 3, 13);
    SHA_RND3(B, C, D, E, A, 11);
    SHA_MIX(12, 9, 4, 14);
    SHA_RND3(A, B, C, D, E, 12);
    SHA_MIX(13, 10, 5, 15);
    SHA_RND3(E, A, B, C, D, 13);
    SHA_MIX(14, 11, 6, 0);
    SHA_RND3(D, E, A, B, C, 14);
    SHA_MIX(15, 12, 7, 1);
    SHA_RND3(C, D, E, A, B, 15);

    SHA_MIX(0, 13, 8, 2);
    SHA_RND3(B, C, D, E, A, 0);
    SHA_MIX(1, 14, 9, 3);
    SHA_RND3(A, B, C, D, E, 1);
    SHA_MIX(2, 15, 10, 4);
    SHA_RND3(E, A, B, C, D, 2);
    SHA_MIX(3, 0, 11, 5);
    SHA_RND3(D, E, A, B, C, 3);
    SHA_MIX(4, 1, 12, 6);
    SHA_RND3(C, D, E, A, B, 4);
    SHA_MIX(5, 2, 13, 7);
    SHA_RND3(B, C, D, E, A, 5);
    SHA_MIX(6, 3, 14, 8);
    SHA_RND3(A, B, C, D, E, 6);
    SHA_MIX(7, 4, 15, 9);
    SHA_RND3(E, A, B, C, D, 7);
    SHA_MIX(8, 5, 0, 10);
    SHA_RND3(D, E, A, B, C, 8);
    SHA_MIX(9, 6, 1, 11);
    SHA_RND3(C, D, E, A, B, 9);
    SHA_MIX(10, 7, 2, 12);
    SHA_RND3(B, C, D, E, A, 10);
    SHA_MIX(11, 8, 3, 13);
    SHA_RND3(A, B, C, D, E, 11);

    SHA_MIX(12, 9, 4, 14);
    SHA_RND4(E, A, B, C, D, 12);
    SHA_MIX(13, 10, 5, 15);
    SHA_RND4(D, E, A, B, C, 13);
    SHA_MIX(14, 11, 6, 0);
    SHA_RND4(C, D, E, A, B, 14);
    SHA_MIX(15, 12, 7, 1);
    SHA_RND4(B, C, D, E, A, 15);

    SHA_MIX(0, 13, 8, 2);
    SHA_RND4(A, B, C, D, E, 0);
    SHA_MIX(1, 14, 9, 3);
    SHA_RND4(E, A, B, C, D, 1);
    SHA_MIX(2, 15, 10, 4);
    SHA_RND4(D, E, A, B, C, 2);
    SHA_MIX(3, 0, 11, 5);
    SHA_RND4(C, D, E, A, B, 3);
    SHA_MIX(4, 1, 12, 6);
    SHA_RND4(B, C, D, E, A, 4);
    SHA_MIX(5, 2, 13, 7);
    SHA_RND4(A, B, C, D, E, 5);
    SHA_MIX(6, 3, 14, 8);
    SHA_RND4(E, A, B, C, D, 6);
    SHA_MIX(7, 4, 15, 9);
    SHA_RND4(D, E, A, B, C, 7);
    SHA_MIX(8, 5, 0, 10);
    SHA_RND4(C, D, E, A, B, 8);
    SHA_MIX(9, 6, 1, 11);
    SHA_RND4(B, C, D, E, A, 9);
    SHA_MIX(10, 7, 2, 12);
    SHA_RND4(A, B, C, D, E, 10);
    SHA_MIX(11, 8, 3, 13);
    SHA_RND4(E, A, B, C, D, 11);
    SHA_MIX(12, 9, 4, 14);
    SHA_RND4(D, E, A, B, C, 12);
    SHA_MIX(13, 10, 5, 15);
    SHA_RND4(C, D, E, A, B, 13);
    SHA_MIX(14, 11, 6, 0);
    SHA_RND4(B, C, D, E, A, 14);
    SHA_MIX(15, 12, 7, 1);
    SHA_RND4(A, B, C, D, E, 15);

    XH(0) += A;
    XH(1) += B;
    XH(2) += C;
    XH(3) += D;
    XH(4) += E;
}
Exemplo n.º 13
0
SECStatus   
RC2_InitContext(RC2Context *cx, const unsigned char *key, unsigned int len,
	        const unsigned char *input, int mode, unsigned int efLen8, 
		unsigned int unused)
{
    PRUint8    *L,*L2;
    int         i;
#if !defined(IS_LITTLE_ENDIAN)
    PRUint16    tmpS;
#endif
    PRUint8     tmpB;

    if (!key || !cx || !len || len > (sizeof cx->B) || 
	efLen8 > (sizeof cx->B)) {
	PORT_SetError(SEC_ERROR_INVALID_ARGS);
    	return SECFailure;
    }
    if (mode == NSS_RC2) {
    	/* groovy */
    } else if (mode == NSS_RC2_CBC) {
    	if (!input) {
	    PORT_SetError(SEC_ERROR_INVALID_ARGS);
	    return SECFailure;
	}
    } else {
	PORT_SetError(SEC_ERROR_INVALID_ARGS);
	return SECFailure;
    }

    if (mode == NSS_RC2_CBC) {
    	cx->enc = & rc2_EncryptCBC;
	cx->dec = & rc2_DecryptCBC;
	LOAD(cx->iv.s);
    } else {
    	cx->enc = & rc2_EncryptECB;
	cx->dec = & rc2_DecryptECB;
    }

    /* Step 0. Copy key into table. */
    memcpy(cx->B, key, len);

    /* Step 1. Compute all values to the right of the key. */
    L2 = cx->B;
    L = L2 + len;
    tmpB = L[-1];
    for (i = (sizeof cx->B) - len; i > 0; --i) {
	*L++ = tmpB = S[ (PRUint8)(tmpB + *L2++) ];
    }

    /* step 2. Adjust left most byte of effective key. */
    i = (sizeof cx->B) - efLen8;
    L = cx->B + i;
    *L = tmpB = S[*L];				/* mask is always 0xff */

    /* step 3. Recompute all values to the left of effective key. */
    L2 = --L + efLen8;
    while(L >= cx->B) {
	*L-- = tmpB = S[ tmpB ^ *L2-- ];
    }

#if !defined(IS_LITTLE_ENDIAN)
    for (i = 63; i >= 0; --i) {
        SWAPK(i);		/* candidate for unrolling */
    }
#endif
    return SECSuccess;
}
Exemplo n.º 14
0
void rust_gpr::load() {
    LOAD(rax); LOAD(rbx); LOAD(rcx); LOAD(rdx);
    LOAD(rsi); LOAD(rdi); LOAD(rbp); LOAD(rsi);
    LOAD(r8);  LOAD(r9);  LOAD(r10); LOAD(r11);
    LOAD(r12); LOAD(r13); LOAD(r14); LOAD(r15);
}
Exemplo n.º 15
0
enum {
	TITLE_SCRIPT_WAIT,
	TITLE_SCRIPT_LOAD,
	TITLE_SCRIPT_LOCATION,
	TITLE_SCRIPT_ROTATE,
	TITLE_SCRIPT_RESTART,
};

#define WAIT(t)				TITLE_SCRIPT_WAIT, t
#define LOAD()				TITLE_SCRIPT_LOAD
#define LOCATION(x, y)		TITLE_SCRIPT_LOCATION, x, y
#define ROTATE(n)			TITLE_SCRIPT_ROTATE, n
#define RESTART()			TITLE_SCRIPT_RESTART

static const uint8 _magicMountainScript[] = {
	LOAD(),
	LOCATION(210, 112), WAIT(13),
	ROTATE(1), LOCATION(210, 112), WAIT(14),
	ROTATE(3), LOCATION(167, 180), WAIT(12),
	ROTATE(1), LOCATION(155, 189), WAIT(12),
	LOCATION(106, 39), WAIT(12),
	LOCATION(182, 50), WAIT(12),
	ROTATE(3), LOCATION(209, 47), WAIT(12),
	ROTATE(1), LOCATION(159, 93), WAIT(12),
	RESTART(),
};

static const uint8* _currentScript;
static int _scriptWaitCounter;

static void title_init_showcase();
Exemplo n.º 16
0
Eina_Bool
ecore_audio_pulse_lib_load(void)
{
   if (ecore_audio_pulse_lib)
     {
        if (!ecore_audio_pulse_lib->mod)
          {
             ERR("Cannot find libpulse at runtime!");
             return EINA_FALSE;
          }
        return EINA_TRUE;
     }

   ecore_audio_pulse_lib = calloc(1, sizeof(Ecore_Audio_Lib_Pulse));
   if (!ecore_audio_pulse_lib) return EINA_FALSE;
# define LOAD(x)                                               \
   if (!ecore_audio_pulse_lib->mod) {                          \
      if ((ecore_audio_pulse_lib->mod = eina_module_new(x))) { \
         if (!eina_module_load(ecore_audio_pulse_lib->mod)) {  \
            eina_module_free(ecore_audio_pulse_lib->mod);      \
            ecore_audio_pulse_lib->mod = NULL;                 \
         }                                                     \
      }                                                        \
   }
# if defined(_WIN32) || defined(__CYGWIN__)
   LOAD("libpulse-0.dll");
   LOAD("libpulse.dll");
   LOAD("pulse.dll");
   if (!ecore_audio_pulse_lib->mod)
     ERR("Could not find libpulse-0.dll, libpulse.dll, pulse.dll");
# elif defined(__APPLE__) && defined(__MACH__)
   LOAD("libpulse.0.dylib");
   LOAD("libpulse.0.so");
   LOAD("libpulse.so.0");
   if (!ecore_audio_pulse_lib->mod)
     ERR("Could not find libpulse.0.dylib, libpulse.0.so, libpulse.so.0");
# else
   LOAD("libpulse.so.0");
   if (!ecore_audio_pulse_lib->mod)
     ERR("Could not find libpulse.so.0");
# endif
# undef LOAD
   if (!ecore_audio_pulse_lib->mod) return EINA_FALSE;

#define SYM(x) \
   if (!(ecore_audio_pulse_lib->x = eina_module_symbol_get(ecore_audio_pulse_lib->mod, #x))) { \
      ERR("Cannot find symbol '%s' in'%s", #x, eina_module_file_get(ecore_audio_pulse_lib->mod)); \
      goto err; \
   }
   SYM(pa_context_new);
   SYM(pa_context_connect);
   SYM(pa_context_set_sink_input_volume);
   SYM(pa_context_get_state);
   SYM(pa_context_set_state_callback);
   SYM(pa_operation_unref);
   SYM(pa_cvolume_set);
   SYM(pa_stream_new);
   SYM(pa_stream_unref);
   SYM(pa_stream_connect_playback);
   SYM(pa_stream_disconnect);
   SYM(pa_stream_drain);
   SYM(pa_stream_cork);
   SYM(pa_stream_write);
   SYM(pa_stream_begin_write);
   SYM(pa_stream_set_write_callback);
   SYM(pa_stream_trigger);
   SYM(pa_stream_update_sample_rate);
   SYM(pa_stream_get_index);
#undef SYM
   return EINA_TRUE;
err:
   if (ecore_audio_pulse_lib->mod)
     {
        eina_module_free(ecore_audio_pulse_lib->mod);
        ecore_audio_pulse_lib->mod = NULL;
     }
   return EINA_FALSE;
}
Exemplo n.º 17
0
/** Loads functions used by NT services. Returns on success, or prints a
 * complaint to stdout and exits on error. */
static void
nt_service_loadlibrary(void)
{
  HMODULE library = 0;
  void *fn;

  if (service_fns.loaded)
    return;

  /* XXXX Possibly, we should hardcode the location of this DLL. */
  if (!(library = LoadLibrary("advapi32.dll"))) {
    log_err(LD_GENERAL, "Couldn't open advapi32.dll.  Are you trying to use "
            "NT services on Windows 98? That doesn't work.");
    goto err;
  }

#define LOAD(f) STMT_BEGIN                                              \
    if (!(fn = GetProcAddress(library, #f))) {                          \
      log_err(LD_BUG,                                                   \
              "Couldn't find %s in advapi32.dll! We probably got the "  \
              "name wrong.", #f);                                       \
      goto err;                                                         \
    } else {                                                            \
      service_fns.f ## _fn = fn;                                        \
    }                                                                   \
  STMT_END

  LOAD(ChangeServiceConfig2A);
  LOAD(CloseServiceHandle);
  LOAD(ControlService);
  LOAD(CreateServiceA);
  LOAD(DeleteService);
  LOAD(OpenSCManagerA);
  LOAD(OpenServiceA);
  LOAD(QueryServiceStatus);
  LOAD(RegisterServiceCtrlHandlerA);
  LOAD(SetServiceStatus);
  LOAD(StartServiceCtrlDispatcherA);
  LOAD(StartServiceA);
  LOAD(LookupAccountNameA);

  service_fns.loaded = 1;

  return;
 err:
  printf("Unable to load library support for NT services: exiting.\n");
  exit(1);
}
Exemplo n.º 18
0
void
paint1(Reg *r, int bn)
{
	Reg *r1;
	Prog *p;
	int z;
	uint32 bb;

	z = bn/32;
	bb = 1L<<(bn%32);
	if(r->act.b[z] & bb)
		return;
	for(;;) {
		if(!(r->refbehind.b[z] & bb))
			break;
		r1 = r->p1;
		if(r1 == R)
			break;
		if(!(r1->refahead.b[z] & bb))
			break;
		if(r1->act.b[z] & bb)
			break;
		r = r1;
	}

	if(LOAD(r) & ~(r->set.b[z]&~(r->use1.b[z]|r->use2.b[z])) & bb) {
		change -= CLOAD * r->loop;
	}
	for(;;) {
		r->act.b[z] |= bb;
		p = r->prog;

		if(r->use1.b[z] & bb) {
			change += CREF * r->loop;
			if(p->as == AFMOVL || p->as == AFMOVW)
				if(BtoR(bb) != D_F0)
					change = -CINF;
		}

		if((r->use2.b[z]|r->set.b[z]) & bb) {
			change += CREF * r->loop;
			if(p->as == AFMOVL || p->as == AFMOVW)
				if(BtoR(bb) != D_F0)
					change = -CINF;
		}

		if(STORE(r) & r->regdiff.b[z] & bb) {
			change -= CLOAD * r->loop;
			if(p->as == AFMOVL || p->as == AFMOVW)
				if(BtoR(bb) != D_F0)
					change = -CINF;
		}

		if(r->refbehind.b[z] & bb)
			for(r1 = r->p2; r1 != R; r1 = r1->p2link)
				if(r1->refahead.b[z] & bb)
					paint1(r1, bn);

		if(!(r->refahead.b[z] & bb))
			break;
		r1 = r->s2;
		if(r1 != R)
			if(r1->refbehind.b[z] & bb)
				paint1(r1, bn);
		r = r->s1;
		if(r == R)
			break;
		if(r->act.b[z] & bb)
			break;
		if(!(r->refbehind.b[z] & bb))
			break;
	}
}
Exemplo n.º 19
0
static Eina_Bool
_c_init(void)
{
   long ms = 0;

   if (_c) return EINA_TRUE;
   if (_c_fail) return EINA_FALSE;
   _c = calloc(1, sizeof(Ecore_Con_Curl));
   if (!_c) goto error;

#define LOAD(x)                               \
  if (!_c->mod) {                             \
       if ((_c->mod = eina_module_new(x))) {  \
            if (!eina_module_load(_c->mod)) { \
                 eina_module_free(_c->mod);   \
                 _c->mod = NULL;              \
              }                               \
         }                                    \
    }
#if defined(_WIN32) || defined(__CYGWIN__)
   LOAD("libcurl-4.dll"); // try correct dll first
   LOAD("libcurl.dll"); // try 1
   LOAD("curllib.dll"); // if fail try 2
#elif defined(__APPLE__) && defined(__MACH__)
   LOAD("libcurl.4.dylib"); // try 1
   LOAD("libcurl.so.4"); // if fail try 2
#else
   LOAD("libcurl.so.4"); // try only
#endif
   if (!_c->mod) goto error;

#define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) \
    goto error
   SYM(curl_global_init);
   SYM(curl_global_cleanup);
   SYM(curl_multi_init);
   SYM(curl_multi_timeout);
   SYM(curl_multi_cleanup);
   SYM(curl_multi_remove_handle);
   SYM(curl_multi_strerror);
   SYM(curl_multi_info_read);
   SYM(curl_multi_fdset);
   SYM(curl_multi_perform);
   SYM(curl_multi_add_handle);
   SYM(curl_multi_setopt);
   SYM(curl_easy_init);
   SYM(curl_easy_setopt);
   SYM(curl_easy_strerror);
   SYM(curl_easy_cleanup);
   SYM(curl_easy_getinfo);
   SYM(curl_slist_free_all);
   SYM(curl_slist_append);
   SYM(curl_version_info);

   // curl_global_init() is not thread safe!
   if (_c->curl_global_init(CURL_GLOBAL_ALL)) goto error;
   _c->_curlm = _c->curl_multi_init();
   if (!_c->_curlm)
     {
        _c->curl_global_cleanup();
        goto error;
     }
   _c->curl_multi_timeout(_c->_curlm, &ms);
   if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
   _curl_timer = ecore_timer_add((double)ms / 1000.0,
                                 _ecore_con_url_timer, NULL);
   ecore_timer_freeze(_curl_timer);
   return EINA_TRUE;
error:
   if (_c)
     {
        if (_c->mod) eina_module_free(_c->mod);
        free(_c);
        _c = NULL;
     }
   _c_fail = EINA_TRUE;
   return EINA_FALSE;
}
Exemplo n.º 20
0
void
regopt(Prog *firstp)
{
	Reg *r, *r1;
	Prog *p;
	int i, z, nr;
	uint32 vreg;
	Bits bit;

	if(first) {
		fmtinstall('Q', Qconv);
		exregoffset = D_DI;	// no externals
		first = 0;
	}
	
	fixjmp(firstp);

	// count instructions
	nr = 0;
	for(p=firstp; p!=P; p=p->link)
		nr++;
	// if too big dont bother
	if(nr >= 10000) {
//		print("********** %S is too big (%d)\n", curfn->nname->sym, nr);
		return;
	}

	r1 = R;
	firstr = R;
	lastr = R;
	
	/*
	 * control flow is more complicated in generated go code
	 * than in generated c code.  define pseudo-variables for
	 * registers, so we have complete register usage information.
	 */
	nvar = NREGVAR;
	memset(var, 0, NREGVAR*sizeof var[0]);
	for(i=0; i<NREGVAR; i++)
		var[i].node = newname(lookup(regname[i]));

	regbits = RtoB(D_SP);
	for(z=0; z<BITS; z++) {
		externs.b[z] = 0;
		params.b[z] = 0;
		consts.b[z] = 0;
		addrs.b[z] = 0;
		ovar.b[z] = 0;
	}

	// build list of return variables
	setoutvar();

	/*
	 * pass 1
	 * build aux data structure
	 * allocate pcs
	 * find use and set of variables
	 */
	nr = 0;
	for(p=firstp; p!=P; p=p->link) {
		switch(p->as) {
		case ADATA:
		case AGLOBL:
		case ANAME:
		case ASIGNAME:
			continue;
		}
		r = rega();
		nr++;
		if(firstr == R) {
			firstr = r;
			lastr = r;
		} else {
			lastr->link = r;
			r->p1 = lastr;
			lastr->s1 = r;
			lastr = r;
		}
		r->prog = p;
		p->reg = r;

		r1 = r->p1;
		if(r1 != R) {
			switch(r1->prog->as) {
			case ARET:
			case AJMP:
			case AIRETL:
				r->p1 = R;
				r1->s1 = R;
			}
		}

		bit = mkvar(r, &p->from);
		if(bany(&bit))
		switch(p->as) {
		/*
		 * funny
		 */
		case ALEAL:
		case AFMOVL: 
		case AFMOVW:
		case AFMOVV:
			setaddrs(bit);
			break;

		/*
		 * left side read
		 */
		default:
			for(z=0; z<BITS; z++)
				r->use1.b[z] |= bit.b[z];
			break;

		/*
		 * left side read+write
		 */
		case AXCHGB:
		case AXCHGW:
		case AXCHGL:
			for(z=0; z<BITS; z++) {
				r->use1.b[z] |= bit.b[z];
				r->set.b[z] |= bit.b[z];
			}
			break;
		}

		bit = mkvar(r, &p->to);
		if(bany(&bit))
		switch(p->as) {
		default:
			yyerror("reg: unknown op: %A", p->as);
			break;

		/*
		 * right side read
		 */
		case ACMPB:
		case ACMPL:
		case ACMPW:
		case ATESTB:
		case ATESTL:
		case ATESTW:
			for(z=0; z<BITS; z++)
				r->use2.b[z] |= bit.b[z];
			break;

		/*
		 * right side write
		 */
		case AFSTSW:
		case ALEAL:
		case ANOP:
		case AMOVL:
		case AMOVB:
		case AMOVW:
		case AMOVBLSX:
		case AMOVBLZX:
		case AMOVBWSX:
		case AMOVBWZX:
		case AMOVWLSX:
		case AMOVWLZX:
		case APOPL:
			for(z=0; z<BITS; z++)
				r->set.b[z] |= bit.b[z];
			break;

		/*
		 * right side read+write
		 */
		case AINCB:
		case AINCL:
		case AINCW:
		case ADECB:
		case ADECL:
		case ADECW:

		case AADDB:
		case AADDL:
		case AADDW:
		case AANDB:
		case AANDL:
		case AANDW:
		case ASUBB:
		case ASUBL:
		case ASUBW:
		case AORB:
		case AORL:
		case AORW:
		case AXORB:
		case AXORL:
		case AXORW:
		case ASALB:
		case ASALL:
		case ASALW:
		case ASARB:
		case ASARL:
		case ASARW:
		case ARCLB:
		case ARCLL:
		case ARCLW:
		case ARCRB:
		case ARCRL:
		case ARCRW:
		case AROLB:
		case AROLL:
		case AROLW:
		case ARORB:
		case ARORL:
		case ARORW:
		case ASHLB:
		case ASHLL:
		case ASHLW:
		case ASHRB:
		case ASHRL:
		case ASHRW:
		case AIMULL:
		case AIMULW:
		case ANEGB:
		case ANEGL:
		case ANEGW:
		case ANOTB:
		case ANOTL:
		case ANOTW:
		case AADCL:
		case ASBBL:

		case ASETCC:
		case ASETCS:
		case ASETEQ:
		case ASETGE:
		case ASETGT:
		case ASETHI:
		case ASETLE:
		case ASETLS:
		case ASETLT:
		case ASETMI:
		case ASETNE:
		case ASETOC:
		case ASETOS:
		case ASETPC:
		case ASETPL:
		case ASETPS:

		case AXCHGB:
		case AXCHGW:
		case AXCHGL:
			for(z=0; z<BITS; z++) {
				r->set.b[z] |= bit.b[z];
				r->use2.b[z] |= bit.b[z];
			}
			break;

		/*
		 * funny
		 */
		case AFMOVDP:
		case AFMOVFP:
		case AFMOVLP:
		case AFMOVVP:
		case AFMOVWP:
		case ACALL:
			setaddrs(bit);
			break;
		}

		switch(p->as) {
		case AIMULL:
		case AIMULW:
			if(p->to.type != D_NONE)
				break;

		case AIDIVL:
		case AIDIVW:
		case ADIVL:
		case ADIVW:
		case AMULL:
		case AMULW:
			r->set.b[0] |= RtoB(D_AX) | RtoB(D_DX);
			r->use1.b[0] |= RtoB(D_AX) | RtoB(D_DX);
			break;

		case AIDIVB:
		case AIMULB:
		case ADIVB:
		case AMULB:
			r->set.b[0] |= RtoB(D_AX);
			r->use1.b[0] |= RtoB(D_AX);
			break;

		case ACWD:
			r->set.b[0] |= RtoB(D_AX) | RtoB(D_DX);
			r->use1.b[0] |= RtoB(D_AX);
			break;

		case ACDQ:
			r->set.b[0] |= RtoB(D_DX);
			r->use1.b[0] |= RtoB(D_AX);
			break;

		case AREP:
		case AREPN:
		case ALOOP:
		case ALOOPEQ:
		case ALOOPNE:
			r->set.b[0] |= RtoB(D_CX);
			r->use1.b[0] |= RtoB(D_CX);
			break;

		case AMOVSB:
		case AMOVSL:
		case AMOVSW:
		case ACMPSB:
		case ACMPSL:
		case ACMPSW:
			r->set.b[0] |= RtoB(D_SI) | RtoB(D_DI);
			r->use1.b[0] |= RtoB(D_SI) | RtoB(D_DI);
			break;

		case ASTOSB:
		case ASTOSL:
		case ASTOSW:
		case ASCASB:
		case ASCASL:
		case ASCASW:
			r->set.b[0] |= RtoB(D_DI);
			r->use1.b[0] |= RtoB(D_AX) | RtoB(D_DI);
			break;

		case AINSB:
		case AINSL:
		case AINSW:
			r->set.b[0] |= RtoB(D_DX) | RtoB(D_DI);
			r->use1.b[0] |= RtoB(D_DI);
			break;

		case AOUTSB:
		case AOUTSL:
		case AOUTSW:
			r->set.b[0] |= RtoB(D_DI);
			r->use1.b[0] |= RtoB(D_DX) | RtoB(D_DI);
			break;
		}
	}
	if(firstr == R)
		return;

	for(i=0; i<nvar; i++) {
		Var *v = var+i;
		if(v->addr) {
			bit = blsh(i);
			for(z=0; z<BITS; z++)
				addrs.b[z] |= bit.b[z];
		}

//		print("bit=%2d addr=%d et=%-6E w=%-2d s=%S + %lld\n",
//			i, v->addr, v->etype, v->width, v->sym, v->offset);
	}

	if(debug['R'] && debug['v'])
		dumpit("pass1", firstr);

	/*
	 * pass 2
	 * turn branch references to pointers
	 * build back pointers
	 */
	for(r=firstr; r!=R; r=r->link) {
		p = r->prog;
		if(p->to.type == D_BRANCH) {
			if(p->to.branch == P)
				fatal("pnil %P", p);
			r1 = p->to.branch->reg;
			if(r1 == R)
				fatal("rnil %P", p);
			if(r1 == r) {
				//fatal("ref to self %P", p);
				continue;
			}
			r->s2 = r1;
			r->p2link = r1->p2;
			r1->p2 = r;
		}
	}

	if(debug['R'] && debug['v'])
		dumpit("pass2", firstr);

	/*
	 * pass 2.5
	 * find looping structure
	 */
	for(r = firstr; r != R; r = r->link)
		r->active = 0;
	change = 0;
	loopit(firstr, nr);

	if(debug['R'] && debug['v'])
		dumpit("pass2.5", firstr);

	/*
	 * pass 3
	 * iterate propagating usage
	 * 	back until flow graph is complete
	 */
loop1:
	change = 0;
	for(r = firstr; r != R; r = r->link)
		r->active = 0;
	for(r = firstr; r != R; r = r->link)
		if(r->prog->as == ARET)
			prop(r, zbits, zbits);
loop11:
	/* pick up unreachable code */
	i = 0;
	for(r = firstr; r != R; r = r1) {
		r1 = r->link;
		if(r1 && r1->active && !r->active) {
			prop(r, zbits, zbits);
			i = 1;
		}
	}
	if(i)
		goto loop11;
	if(change)
		goto loop1;

	if(debug['R'] && debug['v'])
		dumpit("pass3", firstr);

	/*
	 * pass 4
	 * iterate propagating register/variable synchrony
	 * 	forward until graph is complete
	 */
loop2:
	change = 0;
	for(r = firstr; r != R; r = r->link)
		r->active = 0;
	synch(firstr, zbits);
	if(change)
		goto loop2;

	if(debug['R'] && debug['v'])
		dumpit("pass4", firstr);

	/*
	 * pass 4.5
	 * move register pseudo-variables into regu.
	 */
	for(r = firstr; r != R; r = r->link) {
		r->regu = (r->refbehind.b[0] | r->set.b[0]) & REGBITS;

		r->set.b[0] &= ~REGBITS;
		r->use1.b[0] &= ~REGBITS;
		r->use2.b[0] &= ~REGBITS;
		r->refbehind.b[0] &= ~REGBITS;
		r->refahead.b[0] &= ~REGBITS;
		r->calbehind.b[0] &= ~REGBITS;
		r->calahead.b[0] &= ~REGBITS;
		r->regdiff.b[0] &= ~REGBITS;
		r->act.b[0] &= ~REGBITS;
	}

	/*
	 * pass 5
	 * isolate regions
	 * calculate costs (paint1)
	 */
	r = firstr;
	if(r) {
		for(z=0; z<BITS; z++)
			bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
			  ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
		if(bany(&bit) && !r->refset) {
			// should never happen - all variables are preset
			if(debug['w'])
				print("%L: used and not set: %Q\n", r->prog->lineno, bit);
			r->refset = 1;
		}
	}
	for(r = firstr; r != R; r = r->link)
		r->act = zbits;
	rgp = region;
	nregion = 0;
	for(r = firstr; r != R; r = r->link) {
		for(z=0; z<BITS; z++)
			bit.b[z] = r->set.b[z] &
			  ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
		if(bany(&bit) && !r->refset) {
			if(debug['w'])
				print("%L: set and not used: %Q\n", r->prog->lineno, bit);
			r->refset = 1;
			excise(r);
		}
		for(z=0; z<BITS; z++)
			bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
		while(bany(&bit)) {
			i = bnum(bit);
			rgp->enter = r;
			rgp->varno = i;
			change = 0;
			paint1(r, i);
			bit.b[i/32] &= ~(1L<<(i%32));
			if(change <= 0)
				continue;
			rgp->cost = change;
			nregion++;
			if(nregion >= NRGN) {
				if(debug['R'] && debug['v'])
					print("too many regions\n");
				goto brk;
			}
			rgp++;
		}
	}
brk:
	qsort(region, nregion, sizeof(region[0]), rcmp);

	/*
	 * pass 6
	 * determine used registers (paint2)
	 * replace code (paint3)
	 */
	rgp = region;
	for(i=0; i<nregion; i++) {
		bit = blsh(rgp->varno);
		vreg = paint2(rgp->enter, rgp->varno);
		vreg = allreg(vreg, rgp);
		if(rgp->regno != 0)
			paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
		rgp++;
	}

	if(debug['R'] && debug['v'])
		dumpit("pass6", firstr);

	/*
	 * pass 7
	 * peep-hole on basic block
	 */
	if(!debug['R'] || debug['P']) {
		peep();
	}

	/*
	 * eliminate nops
	 * free aux structures
	 */
	for(p=firstp; p!=P; p=p->link) {
		while(p->link != P && p->link->as == ANOP)
			p->link = p->link->link;
		if(p->to.type == D_BRANCH)
			while(p->to.branch != P && p->to.branch->as == ANOP)
				p->to.branch = p->to.branch->link;
	}

	if(r1 != R) {
		r1->link = freer;
		freer = firstr;
	}

	if(debug['R']) {
		if(ostats.ncvtreg ||
		   ostats.nspill ||
		   ostats.nreload ||
		   ostats.ndelmov ||
		   ostats.nvar ||
		   ostats.naddr ||
		   0)
			print("\nstats\n");

		if(ostats.ncvtreg)
			print("	%4d cvtreg\n", ostats.ncvtreg);
		if(ostats.nspill)
			print("	%4d spill\n", ostats.nspill);
		if(ostats.nreload)
			print("	%4d reload\n", ostats.nreload);
		if(ostats.ndelmov)
			print("	%4d delmov\n", ostats.ndelmov);
		if(ostats.nvar)
			print("	%4d var\n", ostats.nvar);
		if(ostats.naddr)
			print("	%4d addr\n", ostats.naddr);

		memset(&ostats, 0, sizeof(ostats));
	}
}
Exemplo n.º 21
0
void
regopt(Prog *p)
{
	Reg *r, *r1, *r2;
	Prog *p1;
	int i, z;
	int32_t initpc, val, npc;
	uint32_t vreg;
	Bits bit;
	struct
	{
		int32_t	m;
		int32_t	c;
		Reg*	p;
	} log5[6], *lp;

	firstr = R;
	lastr = R;
	nvar = 0;
	regbits = RtoB(D_SP) | RtoB(D_AX);
	for(z=0; z<BITS; z++) {
		externs.b[z] = 0;
		params.b[z] = 0;
		consts.b[z] = 0;
		addrs.b[z] = 0;
	}

	/*
	 * pass 1
	 * build aux data structure
	 * allocate pcs
	 * find use and set of variables
	 */
	val = 5L * 5L * 5L * 5L * 5L;
	lp = log5;
	for(i=0; i<5; i++) {
		lp->m = val;
		lp->c = 0;
		lp->p = R;
		val /= 5L;
		lp++;
	}
	val = 0;
	for(; p != P; p = p->link) {
		switch(p->as) {
		case ADATA:
		case AGLOBL:
		case ANAME:
		case ASIGNAME:
			continue;
		}
		r = rega();
		if(firstr == R) {
			firstr = r;
			lastr = r;
		} else {
			lastr->link = r;
			r->p1 = lastr;
			lastr->s1 = r;
			lastr = r;
		}
		r->prog = p;
		r->pc = val;
		val++;

		lp = log5;
		for(i=0; i<5; i++) {
			lp->c--;
			if(lp->c <= 0) {
				lp->c = lp->m;
				if(lp->p != R)
					lp->p->log5 = r;
				lp->p = r;
				(lp+1)->c = 0;
				break;
			}
			lp++;
		}

		r1 = r->p1;
		if(r1 != R)
		switch(r1->prog->as) {
		case ARET:
		case AJMP:
		case AIRETL:
			r->p1 = R;
			r1->s1 = R;
		}

		bit = mkvar(r, &p->from, p->as==AMOVL);
		if(bany(&bit))
		switch(p->as) {
		/*
		 * funny
		 */
		case ALEAL:
			for(z=0; z<BITS; z++)
				addrs.b[z] |= bit.b[z];
			break;

		/*
		 * left side read
		 */
		default:
			for(z=0; z<BITS; z++)
				r->use1.b[z] |= bit.b[z];
			break;
		}

		bit = mkvar(r, &p->to, 0);
		if(bany(&bit))
		switch(p->as) {
		default:
			diag(Z, "reg: unknown op: %A", p->as);
			break;

		/*
		 * right side read
		 */
		case ACMPB:
		case ACMPL:
		case ACMPW:
			for(z=0; z<BITS; z++)
				r->use2.b[z] |= bit.b[z];
			break;

		/*
		 * right side write
		 */
		case ANOP:
		case AMOVL:
		case AMOVB:
		case AMOVW:
		case AMOVBLSX:
		case AMOVBLZX:
		case AMOVWLSX:
		case AMOVWLZX:
			for(z=0; z<BITS; z++)
				r->set.b[z] |= bit.b[z];
			break;

		/*
		 * right side read+write
		 */
		case AADDB:
		case AADDL:
		case AADDW:
		case AANDB:
		case AANDL:
		case AANDW:
		case ASUBB:
		case ASUBL:
		case ASUBW:
		case AORB:
		case AORL:
		case AORW:
		case AXORB:
		case AXORL:
		case AXORW:
		case ASALB:
		case ASALL:
		case ASALW:
		case ASARB:
		case ASARL:
		case ASARW:
		case AROLB:
		case AROLL:
		case AROLW:
		case ARORB:
		case ARORL:
		case ARORW:
		case ASHLB:
		case ASHLL:
		case ASHLW:
		case ASHRB:
		case ASHRL:
		case ASHRW:
		case AIMULL:
		case AIMULW:
		case ANEGL:
		case ANOTL:
		case AADCL:
		case ASBBL:
			for(z=0; z<BITS; z++) {
				r->set.b[z] |= bit.b[z];
				r->use2.b[z] |= bit.b[z];
			}
			break;

		/*
		 * funny
		 */
		case AFMOVDP:
		case AFMOVFP:
		case AFMOVLP:
		case AFMOVVP:
		case AFMOVWP:
		case ACALL:
			for(z=0; z<BITS; z++)
				addrs.b[z] |= bit.b[z];
			break;
		}

		switch(p->as) {
		case AIMULL:
		case AIMULW:
			if(p->to.type != D_NONE)
				break;

		case AIDIVB:
		case AIDIVL:
		case AIDIVW:
		case AIMULB:
		case ADIVB:
		case ADIVL:
		case ADIVW:
		case AMULB:
		case AMULL:
		case AMULW:

		case ACWD:
		case ACDQ:
			r->regu |= RtoB(D_AX) | RtoB(D_DX);
			break;

		case AREP:
		case AREPN:
		case ALOOP:
		case ALOOPEQ:
		case ALOOPNE:
			r->regu |= RtoB(D_CX);
			break;

		case AMOVSB:
		case AMOVSL:
		case AMOVSW:
		case ACMPSB:
		case ACMPSL:
		case ACMPSW:
			r->regu |= RtoB(D_SI) | RtoB(D_DI);
			break;

		case ASTOSB:
		case ASTOSL:
		case ASTOSW:
		case ASCASB:
		case ASCASL:
		case ASCASW:
			r->regu |= RtoB(D_AX) | RtoB(D_DI);
			break;

		case AINSB:
		case AINSL:
		case AINSW:
		case AOUTSB:
		case AOUTSL:
		case AOUTSW:
			r->regu |= RtoB(D_DI) | RtoB(D_DX);
			break;

		case AFSTSW:
		case ASAHF:
			r->regu |= RtoB(D_AX);
			break;
		}
	}
	if(firstr == R)
		return;
	initpc = pc - val;
	npc = val;

	/*
	 * pass 2
	 * turn branch references to pointers
	 * build back pointers
	 */
	for(r = firstr; r != R; r = r->link) {
		p = r->prog;
		if(p->to.type == D_BRANCH) {
			val = p->to.offset - initpc;
			r1 = firstr;
			while(r1 != R) {
				r2 = r1->log5;
				if(r2 != R && val >= r2->pc) {
					r1 = r2;
					continue;
				}
				if(r1->pc == val)
					break;
				r1 = r1->link;
			}
			if(r1 == R) {
				nearln = p->lineno;
				diag(Z, "ref not found\n%P", p);
				continue;
			}
			if(r1 == r) {
				nearln = p->lineno;
				diag(Z, "ref to self\n%P", p);
				continue;
			}
			r->s2 = r1;
			r->p2link = r1->p2;
			r1->p2 = r;
		}
	}
	if(debug['R']) {
		p = firstr->prog;
		print("\n%L %D\n", p->lineno, &p->from);
	}

	/*
	 * pass 2.5
	 * find looping structure
	 */
	for(r = firstr; r != R; r = r->link)
		r->active = 0;
	change = 0;
	loopit(firstr, npc);
	if(debug['R'] && debug['v']) {
		print("\nlooping structure:\n");
		for(r = firstr; r != R; r = r->link) {
			print("%ld:%P", r->loop, r->prog);
			for(z=0; z<BITS; z++)
				bit.b[z] = r->use1.b[z] |
					   r->use2.b[z] |
					   r->set.b[z];
			if(bany(&bit)) {
				print("\t");
				if(bany(&r->use1))
					print(" u1=%B", r->use1);
				if(bany(&r->use2))
					print(" u2=%B", r->use2);
				if(bany(&r->set))
					print(" st=%B", r->set);
			}
			print("\n");
		}
	}

	/*
	 * pass 3
	 * iterate propagating usage
	 * 	back until flow graph is complete
	 */
loop1:
	change = 0;
	for(r = firstr; r != R; r = r->link)
		r->active = 0;
	for(r = firstr; r != R; r = r->link)
		if(r->prog->as == ARET)
			prop(r, zbits, zbits);
loop11:
	/* pick up unreachable code */
	i = 0;
	for(r = firstr; r != R; r = r1) {
		r1 = r->link;
		if(r1 && r1->active && !r->active) {
			prop(r, zbits, zbits);
			i = 1;
		}
	}
	if(i)
		goto loop11;
	if(change)
		goto loop1;


	/*
	 * pass 4
	 * iterate propagating register/variable synchrony
	 * 	forward until graph is complete
	 */
loop2:
	change = 0;
	for(r = firstr; r != R; r = r->link)
		r->active = 0;
	synch(firstr, zbits);
	if(change)
		goto loop2;


	/*
	 * pass 5
	 * isolate regions
	 * calculate costs (paint1)
	 */
	r = firstr;
	if(r) {
		for(z=0; z<BITS; z++)
			bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
			  ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
		if(bany(&bit)) {
			nearln = r->prog->lineno;
			warn(Z, "used and not set: %B", bit);
			if(debug['R'] && !debug['w'])
				print("used and not set: %B\n", bit);
		}
	}
	if(debug['R'] && debug['v'])
		print("\nprop structure:\n");
	for(r = firstr; r != R; r = r->link)
		r->act = zbits;
	rgp = region;
	nregion = 0;
	for(r = firstr; r != R; r = r->link) {
		if(debug['R'] && debug['v']) {
			print("%P\t", r->prog);
			if(bany(&r->set))
				print("s:%B ", r->set);
			if(bany(&r->refahead))
				print("ra:%B ", r->refahead);
			if(bany(&r->calahead))
				print("ca:%B ", r->calahead);
			print("\n");
		}
		for(z=0; z<BITS; z++)
			bit.b[z] = r->set.b[z] &
			  ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
		if(bany(&bit)) {
			nearln = r->prog->lineno;
			warn(Z, "set and not used: %B", bit);
			if(debug['R'])
				print("set and not used: %B\n", bit);
			excise(r);
		}
		for(z=0; z<BITS; z++)
			bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
		while(bany(&bit)) {
			i = bnum(bit);
			rgp->enter = r;
			rgp->varno = i;
			change = 0;
			if(debug['R'] && debug['v'])
				print("\n");
			paint1(r, i);
			bit.b[i/32] &= ~(1L<<(i%32));
			if(change <= 0) {
				if(debug['R'])
					print("%L$%d: %B\n",
						r->prog->lineno, change, blsh(i));
				continue;
			}
			rgp->cost = change;
			nregion++;
			if(nregion >= NRGN) {
				warn(Z, "too many regions");
				goto brk;
			}
			rgp++;
		}
	}
brk:
	qsort(region, nregion, sizeof(region[0]), rcmp);

	/*
	 * pass 6
	 * determine used registers (paint2)
	 * replace code (paint3)
	 */
	rgp = region;
	for(i=0; i<nregion; i++) {
		bit = blsh(rgp->varno);
		vreg = paint2(rgp->enter, rgp->varno);
		vreg = allreg(vreg, rgp);
		if(debug['R']) {
			print("%L$%d %R: %B\n",
				rgp->enter->prog->lineno,
				rgp->cost,
				rgp->regno,
				bit);
		}
		if(rgp->regno != 0)
			paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
		rgp++;
	}
	/*
	 * pass 7
	 * peep-hole on basic block
	 */
	if(!debug['R'] || debug['P'])
		peep();

	/*
	 * pass 8
	 * recalculate pc
	 */
	val = initpc;
	for(r = firstr; r != R; r = r1) {
		r->pc = val;
		p = r->prog;
		p1 = P;
		r1 = r->link;
		if(r1 != R)
			p1 = r1->prog;
		for(; p != p1; p = p->link) {
			switch(p->as) {
			default:
				val++;
				break;

			case ANOP:
			case ADATA:
			case AGLOBL:
			case ANAME:
			case ASIGNAME:
				break;
			}
		}
	}
	pc = val;

	/*
	 * fix up branches
	 */
	if(debug['R'])
		if(bany(&addrs))
			print("addrs: %B\n", addrs);

	r1 = 0; /* set */
	for(r = firstr; r != R; r = r->link) {
		p = r->prog;
		if(p->to.type == D_BRANCH)
			p->to.offset = r->s2->pc;
		r1 = r;
	}

	/*
	 * last pass
	 * eliminate nops
	 * free aux structures
	 */
	for(p = firstr->prog; p != P; p = p->link){
		while(p->link && p->link->as == ANOP)
			p->link = p->link->link;
	}
	if(r1 != R) {
		r1->link = freer;
		freer = firstr;
	}
}
Exemplo n.º 22
0
int crypto_aead_decrypt(
                        unsigned char *m,unsigned long long *mlen,          // message
                        unsigned char *nsec,                                // not relavent to CLOC or SLIC
                        const unsigned char *c,unsigned long long clen,     // ciphertext
                        const unsigned char *ad,unsigned long long adlen,   // associated data
                        const unsigned char *npub,                          // nonce
                        const unsigned char *k                              // the master key
                        )
{
    block estate, tstate, tmp;  // encryption state, tag state, and temporary state
    estate = SETZERO();
    unsigned char ltag[16];     // local copy of temporary tag value
    unsigned long long i, lastblocklen,j;
    
    /* set ciphertext length */
    *mlen = clen - CRYPTO_ABYTES;
    
    /* generate round keys from master key */
    AES128_KeyExpansion(k);
    
    
    /* process the first (partial) block of ad */
    load_partial_block(&estate, ad, (adlen>STATE_LEN)?STATE_LEN:adlen, ONE_ZERO_PADDING);
    fix0(estate);
    AES128_encrypt(estate, estate);
    if((ad[0] & 0x80) || (adlen == 0)){
        // appy h
        h(estate);
    }
    else{
        // do nothing
    }
    
    if(adlen > STATE_LEN){ // ad is of moer than one block
        i = STATE_LEN;
        
        /* process the middle ad blocks, excluding the first and last (partial) block */
        while((i+STATE_LEN) < adlen)
        {
            tmp = LOAD(ad+i);
            estate = XOR(estate, tmp);
            AES128_encrypt(estate, estate);
            i += STATE_LEN;
        }
        
        /* process the last (partial) ad block */
        load_partial_block(&tmp, ad+i, adlen - i, ONE_ZERO_PADDING);
        estate = XOR(estate, tmp);
        AES128_encrypt(estate, estate);
    }
    
    
    /* process the nonce */
    load_partial_block(&tmp, npub, CRYPTO_NPUBBYTES, PARAM_OZP);
    estate = XOR(estate, tmp);
    
    if((adlen % STATE_LEN) || (adlen == 0)){
        /* apply f2 */
        f2(estate);
    }
    else{
        /* apply f1 */
        f1(estate);
    }
    
    /* process ciphertext */
    
    tstate = estate;
    AES128_encrypt(estate, estate);
    
    if(*mlen){
        /* apply g2 to tag state */
        g2(tstate);
    }
    else{
        /* apply g1 to tag state */
        g1(tstate);
    }
    AES128_encrypt(tstate, tstate);
    
    
    
    i = 0;
    /* process all the message except for the last message/ciphertext block */
    while((i + STATE_LEN) < (*mlen)){
        tmp = LOAD(c+i);
        estate = XOR(estate, tmp);
        STORE(m+i, estate);
        tstate = XOR(tmp, tstate);
        AES128_encrypt(tstate, tstate);
        fix1(tmp);
        print_state("after applying fix1\n", estate);
        AES128_encrypt(tmp, estate);
        i += STATE_LEN;
    }
    
    /* process the last block of the message/ciphetext */
    lastblocklen = (*mlen) - i;
    
    if(lastblocklen > 0){
        load_partial_block(&tmp, c+i, lastblocklen, ZERO_APPEND);
        estate = XOR(estate, tmp);
        print_state("after xoring last partial message block\n", estate);
        store_partial_block(m+i, estate, lastblocklen);
        unsigned char shift_bytes = (STATE_LEN - (unsigned char)lastblocklen);
        tmp = AND(SHR(_mm_set1_epi8(0xff), shift_bytes), tmp);
        tstate = XOR(tstate, tmp);
        /* add the one zero padding */
        tstate = XOR(tstate, SHL(_mm_set_epi8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80), lastblocklen));
        
        if((*mlen) % STATE_LEN){
            /* apply f2 */
            f2(tstate);
        }
        else{
            /* apply f1 */
            f1(tstate);
        }
        AES128_encrypt(tstate, tstate);
    }
    
    /* compare tag and output message */
    STORE(ltag, tstate);
    for(j = 0; j < CRYPTO_ABYTES; j++){
        if(ltag[j] != c[clen - CRYPTO_ABYTES + j])
            return RETURN_TAG_NO_MATCH;
    }
    return RETURN_SUCCESS;

}
Exemplo n.º 23
0
/** Loads functions used by NT services. Returns on success, or prints a
 * complaint to stdout and exits on error. */
static void
nt_service_loadlibrary(void)
{
  HMODULE library = 0;
  void *fn;

  if (service_fns.loaded)
    return;

  if (!(library = load_windows_system_library(TEXT("advapi32.dll")))) {
    log_err(LD_GENERAL, "Couldn't open advapi32.dll.  Are you trying to use "
            "NT services on Windows 98? That doesn't work.");
    goto err;
  }

/* Helper macro: try to load a function named <b>f</b> from "library" into
 * service_functions.<b>f</b>_fn.  On failure, log an error message, and goto
 * err.
 */
#define LOAD(f) STMT_BEGIN                                              \
    if (!(fn = GetProcAddress(library, #f))) {                          \
      log_err(LD_BUG,                                                   \
              "Couldn't find %s in advapi32.dll! We probably got the "  \
              "name wrong.", #f);                                       \
      goto err;                                                         \
    } else {                                                            \
      service_fns.f ## _fn = fn;                                        \
    }                                                                   \
  STMT_END

  LOAD(ChangeServiceConfig2A);
  LOAD(CloseServiceHandle);
  LOAD(ControlService);
  LOAD(CreateServiceA);
  LOAD(DeleteService);
  LOAD(OpenSCManagerA);
  LOAD(OpenServiceA);
  LOAD(QueryServiceStatus);
  LOAD(RegisterServiceCtrlHandlerA);
  LOAD(SetServiceStatus);
  LOAD(StartServiceCtrlDispatcherA);
  LOAD(StartServiceA);
  LOAD(LookupAccountNameA);

  service_fns.loaded = 1;

  return;
 err:
  printf("Unable to load library support for NT services: exiting.\n");
  exit(1);
}
Exemplo n.º 24
0
void remcmd()
{
 P_PARM valptr;
 int parm;
 int size;

 putx1('-');
 gethex1();			/* read parameter */
 parm = val;
 switch (parm)
 {
 case ZMOVE:
  zMoveCmd();
  break;

 case ZMOVEREL:
  zMoveRelCmd();
  break;

 case ZJMOV:
  zJogCmd();
  break;

 case ZSTOP:
  zStop();
  break;

 case ZHOME:
  zHomeCmd();
  break;

 case ZSETLOC:
  zLocCmd();
  break;

 case ZGOHOME:
  zGoHomeCmd();
  break;

 case XMOVE:
  xMoveCmd();
  break;

 case XMOVEREL:
  xMoveRelCmd();
  break;

 case XJMOV:
  xJogCmd();
  break;

 case XSTOP:
  xStop();
  break;

 case XHOME:
  xHomeCmd();
  break;
   
 case XSETLOC:
  xLocCmd();
  break;

 case XGOHOME:
  xGoHomeCmd();
  break;

 case SPINDLE_START:
  spindleStart();
  break;

 case SPINDLE_STOP:
  spindleStop();
  break;

 case CMD_PAUSE:
  pauseCmd();
  break;

 case CMD_RESUME:
  resumeCmd();
  break;

 case CMD_STOP:
  stopCmd();
  break;

 case CMD_CLEAR:
  clearCmd();
  break;

 case CMD_SETUP:
  setup();
  break;

 case CMD_SPSETUP:
  spindleSetup();
  break;

 case CMD_ZSETUP:
  zSetup();
  break;

 case CMD_ZSYNSETUP:
  zSynSetup();
  break;

 case CMD_ZTAPERSETUP:
  zTaperSetup();
  break;

 case CMD_XSETUP:
  xSetup();
  break;

 case CMD_XSYNSETUP:
  xSynSetup();
  break;

 case CMD_XTAPERSETUP:
  xTaperSetup();
  break;

 case READSTAT:
  break;

 case READISTATE:
 {
  char tmpval = zMoveCtl.state;
  tmpval |= xMoveCtl.state << 4;
  SNDHEX1(tmpval);
 }
 break;
  
 case LOADVAL:			/* load a local parameter */
  gethex1();			/* read the parameter number */
  parm = val;			/* save it */

  if (parm < MAX_PARM)		/* if in range */
  {
   valptr = &remparm[parm];	/* pointer to parameter info */
   p = valptr->p;		/* destination pointer */
   size = valptr->size;		/* value size */

   int type = getnum1();	/* get the value */
   if (type == 1)		/* if integer */
   {
    if (size == 4)		/* if a long word */
     *(int32_t *) p = val;	/* save as a long word */
    else if (size == 1)		/* if a character */
     *p = (char) val;		/* save the character */
    else if (size == 2)		/* if a short integer */
     *(int16_t *) p = val;	/* save the value */
   }
   else if (type == 2)		/* if floating value */
   {
    *(float *) p = fVal;	/* save as a long word */
   }
  }
  break;

 case READVAL:			/* read a local parameter */
  gethex1();			/* save the parameter number */
  parm = val;			/* save it */
  valptr = &remparm[parm];	/* pointer to parameters */
  sndhex1(valptr->p,valptr->size); /* send the response */
  break;

 case LOADXREG:			/* load a xilinx register */
  gethex1();			/* save the parameter number */
  parm = val;			/* save it */
  gethex1();			/* get the value */
  LOAD(parm,val);		/* load value to xilinx register */
  break;

 case READXREG:			/* read a xilinx register */
  gethex1();			/* save the parameter number */
  parm = val;			/* save it */
//   read(parm);			/* read the xilinx register */
  read1(parm);			/* read the xilinx register */
  SNDHEX1(readval);		/* return the parameter */
  break;

 case SENDMOVE:
  gethex1();			/* save op code and flag */
  parm = val;			/* save input value */
  char rtn = getnum1();		/* read parameter */
  if (rtn != NO_VAL)		/* if valid number */
  {
   if (rtn == FLOAT_VAL)	/* if floating */
    queMoveCmd(parm, fVal);	/* que command */
   else				/* if integer */
    queIntCmd(parm, val);	/* que command */
  }
  break;

 case MOVEQUESTATUS:
  parm = MAX_CMDS - moveQue.count; /* calculate amount empty */
  sndhex1((unsigned char *) &parm, sizeof(parm)); /* send it back */
  break;

 case READLOC:
 {
  char buf[10];
  if (zAxis.stepsInch != 0)
  {
   sprintf(buf, "%0.4f ", ((float) zLoc) / zAxis.stepsInch);
   putstr1(buf);
  }
  else
   putstr1("# ");
  if (xAxis.stepsInch != 0)
  {
   sprintf(buf, "%0.4f ", ((float) xLoc) / xAxis.stepsInch);
   putstr1(buf);
  }
  else
   putstr1("# ");
#if 0
  int clocksRev = indexPreScaler * indexPeriod;
  if (clocksRev != 0)
  {
   sprintf(buf, "%0.4f", ((float) FCY / clocksRev) * 60);
   putstr1(buf);
  }
  else
#endif
   putstr1("#");
 }
 break;

#if DBGMSG
 case READDBG:
  if (dbgcnt > 0)		/* if debug messages */
  {
   P_DBGMSG p;
   --dbgcnt;			/* count off a message */
   p = &dbgdata[dbgemp];	/* get pointer to data */
   dbgemp++;			/* update empty pointer */
   if (dbgemp >= MAXDBGMSG)	/* if past end */
    dbgemp = 0;			/* point back to beginning */

   int16_t count = sizeof(p->str); /* get maximum length */
   char *p1 = p->str;		/* get poninter to string */
   while (--count >= 0)		/* while not at end of buffer */
   {
    char ch = *p1++;		/* read a character */
    if (ch == 0)		/* if null */
     break;			/* exit loop */
    putx1(ch);			/* output character */
   }
   putx1(' ');			/* output a space */
   if (p->val < 0)
   {
    putx1('-');
    p->val = -p->val;
   }
   sndhex1((unsigned char *) &p->val,sizeof(p->val)); /* output data */
  }
  break;

 case CLRDBG:
  clrDbgBuf();
  break;
#endif

 case ENCSTART:
  encStart(true);
  break;

 case ENCSTOP:
  encStop();
  break;
 }
 putx1('*');
}
Exemplo n.º 25
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Dispatch command
//#pragma comment(lib, "ComCtl32.lib")
HRESULT Dispatch(PTSTR ptzCmd, CXT& XT)
{
	// Get command ID
	UINT uCmd;
	PTSTR p = ptzCmd;
	for (uCmd = 0; uCmd < _NumOf(c_tzCmd); uCmd++)
	{
		if (UStrMatchI(p, c_tzCmd[uCmd]) >= CC_LEN)
		{
			// skip white space
			for (p += CC_LEN; (*p == ' ') || (*p == '\t'); p++);
			break;
		}
	}

	switch (uCmd)
	{
	case CMD_LOAD:
		return LOAD(p);

	case CMD_BATC:
		return BATC(p, XT);

	case CMD_IFEX:
		if (*p)
		{
			if (PTSTR ptzArg = UStrChr(p, CC_SEP))
			{
				*ptzArg++ = 0;
				if (IFEX(p))
				{
					Dispatch(ptzArg, XT);
				}
				return XT.hXVar;
			}
			else if (!IFEX(p))
			{
				if (p = UStrStr(XT.ptzNext, TEXT("IFEX\r\n")))
				{
					XT.ptzNext = p + CC_LEN + 2;
					return S_OK;
				}
				else if (p = UStrStr(XT.ptzNext, TEXT("IFEX\n")))
				{
					XT.ptzNext = p + CC_LEN + 1;
					return S_OK;
				}
				else
				{
					XT.ptzNext = TEXT("");
					return S_FALSE;
				}
			}
		}
		return S_OK;

	case CMD_ELSE:
		if (!g_bResult) Dispatch(p, XT);
		return XT.hXVar;

	case CMD_EVAL:
		return EVAL(p);

	case CMD_LINK:
		return LINK(p);

	case CMD_FILE:
		return FILe(p);

	case CMD_REGX:
		return REGX(p);

	case CMD_ENVI:
		return (*p == '$') ? ENVI(p + 1, TRUE) : ENVI(p);

	case CMD_SEND:
		return SEND(p);

	case CMD_WAIT:
		Sleep(UStrToInt(p));
		return S_OK;

	case CMD_KILL:
		return KILL(p);

	case CMD_SHUT:
		return SHUT(p);

	case CMD_PLAY:
		return PLAY(p);

	case CMD_BEEP:
		return !MessageBeep(UStrToInt(p));

	case CMD_MSGX:
		return MSGX(p);

	case CMD_DLGX:
		return (HRESULT) DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_Dialog), NULL, DLGX, (LPARAM) p);

	case CMD_EXEC:
		return EXEC(p);

	case CMD_CDLL:
		return CDLL(p);

	case CMD_CCUI:
		return (HRESULT) DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_Main), NULL, MAIN, (LPARAM) XT.ptzFile);

	case CMD_CALL:
	case CMD_GOTO:
	case CMD_PROC:
		UMemCopy(ptzCmd, c_tzCmd[(uCmd == CMD_PROC) ? CMD_ENDP : CMD_PROC], CC_LEN * sizeof(TCHAR));
		if (p = UStrStr(XT.ptzNext, ptzCmd))
		{
			p += CC_LEN;
			while (*p && (*p++ != '\n'));
			if (uCmd == CMD_CALL)
			{
				return Process(p, XT.ptzFile);
			}
			else
			{
				XT.ptzNext = p;
			}
			return S_OK;
		}
		else if (uCmd == CMD_PROC)
		{
			XT.ptzNext = TEXT("");
		}
		return S_FALSE;

	case CMD_ENDP:
		XT.ptzNext = TEXT("");
		return S_OK;

	case CMD_ASOC:
		return ASOC(p);

	case CMD_DEVI:
		return SERV(p);
		
	case CMD_SERV:
		return SERV(p);

	case CMD_PAGE:
		return PAGE(p);

	case CMD_DISP:
		return DISP(p);

	default:
		PTSTR ptzFile;
		if (ptzFile = UStrRChr(p, '\\'))
		{
			*ptzFile++ = 0;
		}
		return (*p == '!') ? OPEN(p + 1, ptzFile, TRUE) : OPEN(p, ptzFile);
	}
}
Exemplo n.º 26
0
void updateH(N3 N, P3F3 E, P3F3 H, P3F3 CH) {
	int i,j,k;
	v4sf h, ch, e1, e2, e3, e4; 

	//omp_set_num_threads(8);
	for (i=1;i<N.x;i++){
		for (j=1;j<N.y;j++){
			for (k=0;k<N.z;k+=4){
				h = LOAD(&H.x[i][j][k]);
				ch = LOAD(&CH.x[i][j][k]);
				e1 = LOAD(&E.z[i][j][k]);
				e2 = LOAD(&E.z[i][j-1][k]);
				e3 = LOAD(&E.y[i][j][k]);
				e4 = LOAD(&E.y[i][j][k-1]);
				STORE(&H.x[i][j][k], SUB(h, MUL(ch, SUB( SUB(e1,e2), SUB(e3,e4))))); 
			}
		}
	}

	for (i=1;i<N.x;i++){
		for (j=1;j<N.y;j++){
			for (k=0;k<N.z;k+=4){

				h = LOAD(&H.y[i][j][k]);
				ch = LOAD(&CH.y[i][j][k]);
				e1 = LOAD(&E.x[i][j][k]);
				e2 = LOAD(&E.x[i][j][k-1]);
				e3 = LOAD(&E.z[i][j][k]);
				e4 = LOAD(&E.z[i-1][j][k]);
				STORE(&H.y[i][j][k], SUB(h, MUL(ch, SUB( SUB(e1,e2), SUB(e3,e4))))); 
			}
		}
	}
	for (i=1;i<N.x;i++){
		for (j=1;j<N.y;j++){
			for (k=0;k<N.z;k+=4){

				h = LOAD(&H.z[i][j][k]);
				ch = LOAD(&CH.z[i][j][k]);
				e1 = LOAD(&E.y[i][j][k]);
				e2 = LOAD(&E.y[i-1][j][k]);
				e3 = LOAD(&E.x[i][j][k]);
				e4 = LOAD(&E.x[i][j-1][k]);
				STORE(&H.z[i][j][k], SUB(h, MUL(ch, SUB( SUB(e1,e2), SUB(e3,e4))))); 
			}
		}
	}

	i=0;
	for (j=1;j<N.y;j++){
		for (k=0;k<N.z;k+=4){
			h = LOAD(&H.x[i][j][k]);
			ch = LOAD(&CH.x[i][j][k]);
			e1 = LOAD(&E.z[i][j][k]);
			e2 = LOAD(&E.z[i][j-1][k]);
			e3 = LOAD(&E.y[i][j][k]);
			e4 = LOAD(&E.y[i][j][k-1]);
			STORE(&H.x[i][j][k], SUB(h, MUL(ch, SUB( SUB(e1,e2), SUB(e3,e4))))); 
		}
	}

	j=0;
	for (i=1;i<N.x;i++){
		for (k=0;k<N.z;k+=4){
			h = LOAD(&H.y[i][j][k]);	
			ch = LOAD(&CH.y[i][j][k]);
			e1 = LOAD(&E.x[i][j][k]);
			e2 = LOAD(&E.x[i][j][k-1]);
			e3 = LOAD(&E.z[i][j][k]);
			e4 = LOAD(&E.z[i-1][j][k]);
			STORE(&H.y[i][j][k], SUB(h, MUL(ch, SUB( SUB(e1,e2), SUB(e3,e4))))); 
		}
	}
}
Exemplo n.º 27
0
void
paint1(Reg *r, int bn)
{
	Reg *r1;
	int z;
	uint32 bb;

	z = bn/32;
	bb = 1L<<(bn%32);
	if(r->act.b[z] & bb)
		return;
	for(;;) {
		if(!(r->refbehind.b[z] & bb))
			break;
		r1 = (Reg*)r->f.p1;
		if(r1 == R)
			break;
		if(!(r1->refahead.b[z] & bb))
			break;
		if(r1->act.b[z] & bb)
			break;
		r = r1;
	}

	if(LOAD(r) & ~(r->set.b[z]&~(r->use1.b[z]|r->use2.b[z])) & bb) {
		change -= CLOAD * r->f.loop;
	}
	for(;;) {
		r->act.b[z] |= bb;

		if(r->use1.b[z] & bb) {
			change += CREF * r->f.loop;
		}

		if((r->use2.b[z]|r->set.b[z]) & bb) {
			change += CREF * r->f.loop;
		}

		if(STORE(r) & r->regdiff.b[z] & bb) {
			change -= CLOAD * r->f.loop;
		}

		if(r->refbehind.b[z] & bb)
			for(r1 = (Reg*)r->f.p2; r1 != R; r1 = (Reg*)r1->f.p2link)
				if(r1->refahead.b[z] & bb)
					paint1(r1, bn);

		if(!(r->refahead.b[z] & bb))
			break;
		r1 = (Reg*)r->f.s2;
		if(r1 != R)
			if(r1->refbehind.b[z] & bb)
				paint1(r1, bn);
		r = (Reg*)r->f.s1;
		if(r == R)
			break;
		if(r->act.b[z] & bb)
			break;
		if(!(r->refbehind.b[z] & bb))
			break;
	}
}
Exemplo n.º 28
0
void updateE(N3 N, P3F3 E, P3F3 H, P3F3 CE) {
	int i,j,k;
	v4sf e, ce, h1, h2, h3, h4; 

	for (i=0;i<N.x-1;i++){
		for (j=0;j<N.y-1;j++){
			for (k=0;k<N.z;k+=4){
				e = LOAD(&E.x[i][j][k]);
				ce = LOAD(&CE.x[i][j][k]);
				h1 = LOAD(&H.z[i][j+1][k]);
				h2 = LOAD(&H.z[i][j][k]);
				h3 = LOAD(&H.y[i][j][k+1]);
				h4 = LOAD(&H.y[i][j][k]);
				STORE(&E.x[i][j][k], ADD(e, MUL(ce, SUB( SUB(h1,h2), SUB(h3,h4))))); 
			}
		}
	}

	for (i=0;i<N.x-1;i++){
		for (j=0;j<N.y-1;j++){
			for (k=0;k<N.z;k+=4){

				e = LOAD(&E.y[i][j][k]);
				ce = LOAD(&CE.y[i][j][k]);
				h1 = LOAD(&H.x[i][j][k+1]);
				h2 = LOAD(&H.x[i][j][k]);
				h3 = LOAD(&H.z[i+1][j][k]);
				h4 = LOAD(&H.z[i][j][k]);
				STORE(&E.y[i][j][k], ADD(e, MUL(ce, SUB( SUB(h1,h2), SUB(h3,h4))))); 
			}
		}
	}

	for (i=0;i<N.x-1;i++){
		for (j=0;j<N.y-1;j++){
			for (k=0;k<N.z;k+=4){

				e = LOAD(&E.z[i][j][k]);
				ce = LOAD(&CE.z[i][j][k]);
				h1 = LOAD(&H.y[i+1][j][k]);
				h2 = LOAD(&H.y[i][j][k]);
				h3 = LOAD(&H.x[i][j+1][k]);
				h4 = LOAD(&H.x[i][j][k]);
				STORE(&E.z[i][j][k], ADD(e, MUL(ce, SUB( SUB(h1,h2), SUB(h3,h4))))); 
			}
		}
	}

	i=N.x-1;
	for (j=0;j<N.y-1;j++){
		for (k=0;k<N.z;k+=4){
			e = LOAD(&E.x[i][j][k]);
			ce = LOAD(&CE.x[i][j][k]);
			h1 = LOAD(&H.z[i][j+1][k]);
			h2 = LOAD(&H.z[i][j][k]);
			h3 = LOAD(&H.y[i][j][k+1]);
			h4 = LOAD(&H.y[i][j][k]);
			STORE(&E.x[i][j][k], ADD(e, MUL(ce, SUB( SUB(h1,h2), SUB(h3,h4))))); 
		}
	}

	j=N.y-1;
	for (i=0;i<N.x-1;i++){
		for (k=0;k<N.z;k+=4){
			e = LOAD(&E.y[i][j][k]);
			ce = LOAD(&CE.y[i][j][k]);
			h1 = LOAD(&H.x[i][j][k+1]);
			h2 = LOAD(&H.x[i][j][k]);
			h3 = LOAD(&H.z[i+1][j][k]);
			h4 = LOAD(&H.z[i][j][k]);
			STORE(&E.y[i][j][k], ADD(e, MUL(ce, SUB( SUB(h1,h2), SUB(h3,h4))))); 
		}
	}
}
Exemplo n.º 29
0
/* Process 2OPI Integer instructions */
bool eval_2OPI_Int(struct lilith* vm, struct Instruction* c)
{
	#ifdef DEBUG
	char Name[20] = "ILLEGAL_2OPI";
	#endif

	/* 0x0E ... 0x2B */
	/* 0xB0 ... 0xDF */
	switch(c->raw2)
	{
		case 0x0E: /* ADDI */
		{
			#ifdef DEBUG
			strncpy(Name, "ADDI", 19);
			#elif TRACE
			record_trace("ADDI");
			#endif

			ADDI(vm, c);
			break;
		}
		case 0x0F: /* ADDUI */
		{
			#ifdef DEBUG
			strncpy(Name, "ADDUI", 19);
			#elif TRACE
			record_trace("ADDUI");
			#endif

			ADDUI(vm, c);
			break;
		}
		case 0x10: /* SUBI */
		{
			#ifdef DEBUG
			strncpy(Name, "SUBI", 19);
			#elif TRACE
			record_trace("SUBI");
			#endif

			SUBI(vm, c);
			break;
		}
		case 0x11: /* SUBUI */
		{
			#ifdef DEBUG
			strncpy(Name, "SUBUI", 19);
			#elif TRACE
			record_trace("SUBUI");
			#endif

			SUBUI(vm, c);
			break;
		}
		case 0x12: /* CMPI */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPI", 19);
			#elif TRACE
			record_trace("CMPI");
			#endif

			CMPI(vm, c);
			break;
		}
		case 0x13: /* LOAD */
		{
			#ifdef DEBUG
			strncpy(Name, "LOAD", 19);
			#elif TRACE
			record_trace("LOAD");
			#endif

			LOAD(vm, c);
			break;
		}
		case 0x14: /* LOAD8 */
		{
			#ifdef DEBUG
			strncpy(Name, "LOAD8", 19);
			#elif TRACE
			record_trace("LOAD8");
			#endif

			LOAD8(vm, c);
			break;
		}
		case 0x15: /* LOADU8 */
		{
			#ifdef DEBUG
			strncpy(Name, "LOADU8", 19);
			#elif TRACE
			record_trace("LOADU8");
			#endif

			LOADU8(vm, c);
			break;
		}
		case 0x16: /* LOAD16 */
		{
			#ifdef DEBUG
			strncpy(Name, "LOAD16", 19);
			#elif TRACE
			record_trace("LOAD16");
			#endif

			LOAD16(vm, c);
			break;
		}
		case 0x17: /* LOADU16 */
		{
			#ifdef DEBUG
			strncpy(Name, "LOADU16", 19);
			#elif TRACE
			record_trace("LOADU16");
			#endif

			LOADU16(vm, c);
			break;
		}
		case 0x18: /* LOAD32 */
		{
			#ifdef DEBUG
			strncpy(Name, "LOAD32", 19);
			#elif TRACE
			record_trace("LOAD32");
			#endif

			LOAD32(vm, c);
			break;
		}
		case 0x19: /* LOADU32 */
		{
			#ifdef DEBUG
			strncpy(Name, "LOADU32", 19);
			#elif TRACE
			record_trace("LOADU32");
			#endif

			LOADU32(vm, c);
			break;
		}
		case 0x1F: /* CMPUI */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPUI", 19);
			#elif TRACE
			record_trace("CMPUI");
			#endif

			CMPUI(vm, c);
			break;
		}
		case 0x20: /* STORE */
		{
			#ifdef DEBUG
			strncpy(Name, "STORE", 19);
			#elif TRACE
			record_trace("STORE");
			#endif

			STORE(vm, c);
			break;
		}
		case 0x21: /* STORE8 */
		{
			#ifdef DEBUG
			strncpy(Name, "STORE8", 19);
			#elif TRACE
			record_trace("STORE8");
			#endif

			STORE8(vm, c);
			break;
		}
		case 0x22: /* STORE16 */
		{
			#ifdef DEBUG
			strncpy(Name, "STORE16", 19);
			#elif TRACE
			record_trace("STORE16");
			#endif

			STORE16(vm, c);
			break;
		}
		case 0x23: /* STORE32 */
		{
			#ifdef DEBUG
			strncpy(Name, "STORE32", 19);
			#elif TRACE
			record_trace("STORE32");
			#endif

			STORE32(vm, c);
			break;
		}
		case 0xB0: /* ANDI */
		{
			#ifdef DEBUG
			strncpy(Name, "ANDI", 19);
			#elif TRACE
			record_trace("ANDI");
			#endif

			ANDI(vm, c);
			break;
		}
		case 0xB1: /* ORI */
		{
			#ifdef DEBUG
			strncpy(Name, "ORI", 19);
			#elif TRACE
			record_trace("ORI");
			#endif

			ORI(vm, c);
			break;
		}
		case 0xB2: /* XORI */
		{
			#ifdef DEBUG
			strncpy(Name, "XORI", 19);
			#elif TRACE
			record_trace("XORI");
			#endif

			XORI(vm, c);
			break;
		}
		case 0xB3: /* NANDI */
		{
			#ifdef DEBUG
			strncpy(Name, "NANDI", 19);
			#elif TRACE
			record_trace("NANDI");
			#endif

			NANDI(vm, c);
			break;
		}
		case 0xB4: /* NORI */
		{
			#ifdef DEBUG
			strncpy(Name, "NORI", 19);
			#elif TRACE
			record_trace("NORI");
			#endif

			NORI(vm, c);
			break;
		}
		case 0xB5: /* XNORI */
		{
			#ifdef DEBUG
			strncpy(Name, "XNORI", 19);
			#elif TRACE
			record_trace("XNORI");
			#endif

			XNORI(vm, c);
			break;
		}
		case 0xC0: /* CMPJUMPI.G */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPI.G", 19);
			#elif TRACE
			record_trace("CMPJUMPI.G");
			#endif

			CMPJUMPI_G(vm, c);
			break;
		}
		case 0xC1: /* CMPJUMPI.GE */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPI.GE", 19);
			#elif TRACE
			record_trace("CMPJUMPI.GE");
			#endif

			CMPJUMPI_GE(vm, c);
			break;
		}
		case 0xC2: /* CMPJUMPI.E */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPI.E", 19);
			#elif TRACE
			record_trace("CMPJUMPI.E");
			#endif

			CMPJUMPI_E(vm, c);
			break;
		}
		case 0xC3: /* CMPJUMPI.NE */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPI.NE", 19);
			#elif TRACE
			record_trace("CMPJUMPI.NE");
			#endif

			CMPJUMPI_NE(vm, c);
			break;
		}
		case 0xC4: /* CMPJUMPI.LE */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPI.LE", 19);
			#elif TRACE
			record_trace("CMPJUMPI.LE");
			#endif

			CMPJUMPI_LE(vm, c);
			break;
		}
		case 0xC5: /* CMPJUMPI.L */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPI.L", 19);
			#elif TRACE
			record_trace("CMPJUMPI.L");
			#endif

			CMPJUMPI_L(vm, c);
			break;
		}
		case 0xD0: /* CMPJUMPUI.G */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPUI.G", 19);
			#elif TRACE
			record_trace("CMPJUMPUI.G");
			#endif

			CMPJUMPUI_G(vm, c);
			break;
		}
		case 0xD1: /* CMPJUMPUI.GE */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPUI.GE", 19);
			#elif TRACE
			record_trace("CMPJUMPUI.GE");
			#endif

			CMPJUMPUI_GE(vm, c);
			break;
		}
		case 0xD4: /* CMPJUMPUI.LE */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPUI.LE", 19);
			#elif TRACE
			record_trace("CMPJUMPUI.LE");
			#endif

			CMPJUMPUI_LE(vm, c);
			break;
		}
		case 0xD5: /* CMPJUMPUI.L */
		{
			#ifdef DEBUG
			strncpy(Name, "CMPJUMPUI.L", 19);
			#elif TRACE
			record_trace("CMPJUMPUI.L");
			#endif

			CMPJUMPUI_L(vm, c);
			break;
		}
		default:
		{
			illegal_instruction(vm, c);
			break;
		}
	}
	#ifdef DEBUG
	fprintf(stdout, "# %s reg%u reg%u %i\n", Name, c->reg0, c->reg1, c->raw_Immediate);
	#endif
	return false;
}
Exemplo n.º 30
0
Eina_Bool
ecore_audio_sndfile_lib_load(void)
{
   if (ecore_audio_sndfile_lib)
     {
        if (!ecore_audio_sndfile_lib->mod)
          {
             ERR("Cannot find libsndfile at runtime!");
             return EINA_FALSE;
          }
        return EINA_TRUE;
     }

   ecore_audio_sndfile_lib = calloc(1, sizeof(Ecore_Audio_Lib_Sndfile));
   if (!ecore_audio_sndfile_lib) return EINA_FALSE;
# define LOAD(x)                                                 \
   if (!ecore_audio_sndfile_lib->mod) {                          \
      if ((ecore_audio_sndfile_lib->mod = eina_module_new(x))) { \
         if (!eina_module_load(ecore_audio_sndfile_lib->mod)) {  \
            eina_module_free(ecore_audio_sndfile_lib->mod);      \
            ecore_audio_sndfile_lib->mod = NULL;                 \
         }                                                       \
      }                                                          \
   }
# if defined(_WIN32) || defined(__CYGWIN__)
   LOAD("libsndfile-1.dll");
   LOAD("libsndfile.dll");
   LOAD("sndfile.dll");
# elif defined(__APPLE__) && defined(__MACH__)
   LOAD("libsndfile.1.dylib");
   LOAD("libsndfile.1.so");
   LOAD("libsndfile.so.1");
# else
   LOAD("libsndfile.so.1");
# endif
# undef LOAD
   if (!ecore_audio_sndfile_lib->mod) return EINA_FALSE;

#define SYM(x) \
   if (!(ecore_audio_sndfile_lib->x = eina_module_symbol_get(ecore_audio_sndfile_lib->mod, #x))) { \
      ERR("Cannot find symbol '%s' in'%s", #x, eina_module_file_get(ecore_audio_sndfile_lib->mod)); \
      goto err; \
   }
   SYM(sf_open);
   SYM(sf_open_virtual);
   SYM(sf_close);
   SYM(sf_read_float);
   SYM(sf_write_float);
   SYM(sf_write_sync);
   SYM(sf_seek);
   SYM(sf_strerror);
#undef SYM
   return EINA_TRUE;
err:
   if (ecore_audio_sndfile_lib->mod)
     {
        eina_module_free(ecore_audio_sndfile_lib->mod);
        ecore_audio_sndfile_lib->mod = NULL;
     }
   return EINA_FALSE;
}