Beispiel #1
0
/* Looks up an hash in the tree and maintains the replacement chain */
static inline int cacheset_lookup(struct cache_set *cs, unsigned char *md5, size_t size, uint32_t reclevel) {
    int64_t hash[2];

    memcpy(hash, md5, 16);
    if(splay(hash, size, cs)) {
	struct node *o = cs->root->prev, *p = cs->root, *q = cs->root->next;
#ifdef PRINT_CHAINS
	printf("promoting %02d\n", p - cs->data);
	printchain("before", cs);
#endif
    	if(q) {
	    if(o)
		o->next = q;
	    else
		cs->first = q;
	    q->prev = o;
	    cs->last->next = p;
	    p->prev = cs->last;
	    p->next = NULL;
	    cs->last = p;
	}
#ifdef PRINT_CHAINS
	printchain("after", cs);
#endif
	if(reclevel >= p->minrec)
	    return 1;
    }
    return 0;
}
Beispiel #2
0
u32int
icegetreg(JMedium *jmed, int regaddr)
{
	Chain ch;
	ShiftTDesc req;
	int res;
	EiceChain2 ec2;
	char debugstr[128];

	ec2.data = 0;
	ec2.addr = regaddr;
	ec2.rw = 0;
	memset(&ch, 0, sizeof ch);

	res = packech2(&ch, &ec2);
	if(res < 0)
		return -1;
	if(debug[Dchain] || debug[DAll]){
		printech2(&ec2, debugstr, sizeof debugstr);
		fprint(2, "%s", debugstr);
		printchain(&ch);
	}
	req.reg = TapDR;
	req.buf = ch.buf;
	req.nbits = EiceCh2Len;
	req.op = ShiftOut;
	res = tapshift(jmed, &req, nil, jmed->tapcpu);
	if(res < 0)
		return -1;
	req.reg = TapDR;
	req.buf = ch.buf;
	req.nbits = EiceCh2Len;
	req.op = ShiftOut|ShiftIn;
	res = tapshift(jmed, &req, nil, jmed->tapcpu);
	if(res < 0)
		return -1;
	ch.b = 0;
	ch.e = EiceCh2Len;
	res = unpackech2(&ec2, &ch);
	if(res < 0)
		return -1;
	if(debug[Dice] || debug[DAll]){
		printchain(&ch);
		printech2(&ec2, debugstr, sizeof debugstr);
		fprint(2, "Get eice 2 reg[%#2.2ux] to %#8.8ux\n", regaddr, ec2.data);
	}
	return ec2.data;
}
Beispiel #3
0
int
armgofetch(JMedium *jmed, u32int instr, int sysspeed)
{
	char debugstr[128];
	ShiftTDesc req;
	EiceChain1 ec1;
	Chain ch;
	int res;

	ec1.instr = instr;
	ec1.sysspeed = sysspeed;
	ec1.wptandbkpt = 0;
	ec1.rwdata = 0;
	memset(&ch, 0, sizeof (Chain));
	res = packech1(&ch, &ec1);
	if(res < 0)
		return -1;
	if(debug[Dchain] || debug[DAll]){
		printech1(&ec1, debugstr, sizeof debugstr);
		fprint(2, "%s", debugstr);
		printchain(&ch);
	}
	req.reg = TapDR;
	req.buf = ch.buf;
	req.nbits = ch.e-ch.b;
	req.op = ShiftOut|ShiftPauseOut|ShiftPauseIn;
	res = tapshift(jmed, &req, nil, jmed->tapcpu);
	if(res < 0)
		return -1;
	return 0;

}
Beispiel #4
0
int
icesetreg(JMedium *jmed, int regaddr, u32int val)
{
	Chain ch;
	ShiftTDesc req;
	EiceChain2 ec2;
	char debugstr[128];
	int res;

	dprint(Dice, "Set eice 2 reg[%#2.2ux] to %#8.8ux\n", regaddr, val);
	ec2.data = val;
	ec2.addr = regaddr;
	ec2.rw = 1;
	memset(&ch, 0, sizeof ch);


	res = packech2(&ch, &ec2);
	if(res < 0)
		return -1;
	if(debug[Dchain] || debug[DAll]){
		printech2(&ec2, debugstr, sizeof debugstr);
		fprint(2, "%s", debugstr);
		printchain(&ch);
	}
	req.reg = TapDR;
	req.buf = ch.buf;
	req.nbits = EiceCh2Len;
	req.op = ShiftOut;
	res = tapshift(jmed, &req, nil, jmed->tapcpu);
	if(res < 0)
		return -1;

	return 0;
}
Beispiel #5
0
static void
printchain(mmv_t *mmv, REP *p)
{
    if (p->r_thendo != NULL) {
        printchain(mmv, p->r_thendo);
    }
    printf("%s%s -> ", p->r_hfrom->h_name, p->r_ffrom->fi_name);
    ++mmv->badreps;
    --mmv->nreps;
    p->r_ffrom->fi_rep = &mmv->mistake;
}
Beispiel #6
0
static void
nochains(mmv_t *mmv)
{
    REP *p, *q;

    for (q = &mmv->hrep, p = q->r_next; p != NULL; q = p, p = p->r_next) {
        if (p->r_flags & R_ISCYCLE || p->r_thendo != NULL) {
            printchain(mmv, p);
            printf("%s%s : no chain copies allowed.\n",
                p->r_hto->h_name, p->r_nto);
            q->r_next = p->r_next;
            p = q;
        }
    }
}
Beispiel #7
0
Datei: table.c Projekt: 8l/FUZIX
void statistics(void)
{
#ifdef DEBUG_HASH
    int i;
    int weight;

    for (i = 0; i < SPTSIZ; ++i)
	printchain(i);
    printf("nhash = %d, nsym = %d, nlookup = %d nx =\n", nhash, nsym, nlookup);
    weight = 0;
    for (i = 0; i < 30; ++i) 
    {
	printf("%5d", nx[i]);
	weight += nx[i] * i;
    }
    printf("\n");
    printf("weight = %d%d\n", weight);
#endif
}
Beispiel #8
0
/* If the hash is not present nothing happens other than splaying the tree.
   Otherwise the identified node is removed from the tree and then placed back at 
   the front of the chain. */
static inline void cacheset_remove(struct cache_set *cs, unsigned char *md5, size_t size) {
    struct node *targetnode;
    struct node *reattachnode;
    int64_t hash[2];

    memcpy(hash, md5, 16);
    if(splay(hash, size, cs) != 1) {
	cli_dbgmsg("cacheset_remove: node not found in tree\n");
	return; /* No op */
    }

    ptree("cacheset_remove: node found and splayed to root\n");
    targetnode = cs->root;
    printnode("targetnode", cs, targetnode);

    /* First fix the tree */
    if(targetnode->left == NULL) {
        /* At left edge so prune */
        cs->root = targetnode->right;
        if(cs->root)
            cs->root->up = NULL;
    }
    else {
        /* new root will come from leftside tree */
        cs->root = targetnode->left;
        cs->root->up = NULL;
        /* splay tree, expecting not found, bringing rightmost member to root */
        splay(hash, size, cs);

        if (targetnode->right) {
            /* reattach right tree to clean right-side attach point */
            reattachnode = cs->root;
            while (reattachnode->right) 
                reattachnode = reattachnode->right; /* shouldn't happen, but safer in case of dupe */
            reattachnode->right = targetnode->right;
            targetnode->right->up = reattachnode;
        }
    }
    targetnode->size = (size_t)0;
    targetnode->digest[0] = 0;
    targetnode->digest[1] = 0;
    targetnode->up = NULL;
    targetnode->left = NULL;
    targetnode->right = NULL;

    /* Tree is fixed, so now fix chain around targetnode */
    if(targetnode->prev) 
        targetnode->prev->next = targetnode->next;
    if(targetnode->next) 
        targetnode->next->prev = targetnode->prev;
    if(cs->last == targetnode)
        cs->last = targetnode->prev;

    /* Put targetnode at front of chain, if not there already */
    if(cs->first != targetnode) {
        targetnode->next = cs->first;
        if(cs->first)
            cs->first->prev = targetnode;
        cs->first = targetnode;
    }
    targetnode->prev = NULL;

    printnode("root", cs, cs->root);
    printnode("first", cs, cs->first);
    printnode("last", cs, cs->last);

    printchain("remove (after)", cs);
}
Beispiel #9
0
Datei: table.c Projekt: 8l/FUZIX
struct sym_s *lookup(void)
{
    struct sym_s **hashptr;
    register char *nameptr;
    register struct sym_s *symptr;
    register unsigned hashval;
    register unsigned length;
#ifdef DEBUG_HASH
    int tries;

    ++nlookup;
    tries = 0;
#endif

    /* Hash function is a weighted xor of 1 to 4 chars in the string.
     * This works seems to work better than looking at all the chars.
     * It is important that the function be fast.
     * The string comparision function should also be fast and it helps
     * if it is optimized for mostly identical comparisions.
     * The multiplication by MULTIPLIER should compile as a shift.
     */

#define MULTIPLIER (SPTSIZ / (1 << USEFUL_BITS_IN_ASCII))
#define USEFUL_BITS_IN_ASCII 6

    nameptr = lineptr;
    length = nameptr - symname;
    if (length <= 3)
    {
	if (length <= 2)
	    hashval  = hconv(nameptr[-1]) * MULTIPLIER;
	else
	    hashval  = hconv(nameptr[-2]) * MULTIPLIER,
	    hashval ^= hconv(nameptr[-1]);
    }
    else
	hashval  = hconv(symname[length-(length / 2)]) * MULTIPLIER,
	hashval ^= hconv(nameptr[-2]) << 2,
	hashval ^= hconv(nameptr[-1]);
    nameptr = symname;
    if ((symptr = *(hashptr = spt +
			      (hashval ^ (hconv(nameptr[0]) << 1)) % SPTSIZ))
	!= NUL_PTR)
    {
	do
	{
#ifdef DEBUG_HASH
	    if (tries != 0)
		--nx[tries];
	    ++tries;
	    if (tries < sizeof nx / sizeof nx[0])
		++nx[tries];
	    if (tries >= 5)
		printchain(hashptr - spt);
#endif
	    if ((unsigned char) length != symptr->length)
		continue;
	    if (memcmp(symptr->name, nameptr, length) == 0)
		return symptr;
	}
	while ((symptr = symptr->next) != NUL_PTR);

	/* Calculate last non-NUL_PTR hash ptr.
	 * This is faster than keeping hashptr up to date in previous loop
	 * since most lookups are successful and hash ptr is not needed.
	 */
	do
	{
	    symptr = *hashptr;
	    hashptr = &symptr->next;
	}
	while (symptr->next != NUL_PTR);
    }
    if (!ifflag)
	return NUL_PTR;
#ifdef DEBUG_HASH
    ++nsym;
    if (hashptr >= spt && hashptr < spt + SPTSIZ)
	++nhash;
#endif
    *hashptr = symptr = asalloc(sizeof(struct sym_s) + length);
    symptr->type = 0;
    symptr->data = inidata;
    symptr->length = length;
    symptr->value_reg_or_op.value = (offset_t) (symptr->next = NUL_PTR);
    memcpy(symptr->name, nameptr, length);
    symptr->name[length] = 0;
    return symptr;
}