thread support

This commit is contained in:
Vítor Santos Costa 2013-01-10 23:22:11 +00:00
parent 1bb1138b3a
commit d078a2b2c4
3 changed files with 28 additions and 25 deletions

View File

@ -968,7 +968,7 @@ Yap_absmi(int inp)
{ {
yamop *pt; yamop *pt;
saveregs(); saveregs();
pt = Yap_ExoLookup(PredFromDefCode(PREG)); pt = Yap_ExoLookup(PredFromDefCode(PREG) PASS_REGS);
setregs(); setregs();
#ifdef SHADOW_S #ifdef SHADOW_S
SREG = S; SREG = S;
@ -1050,12 +1050,13 @@ Yap_absmi(int inp)
Op(retry_exo, lp); Op(retry_exo, lp);
BEGD(d0); BEGD(d0);
CACHE_Y(B); CACHE_Y(B);
saveregs(); {
d0 = Yap_NextExo(B_YREG, (struct index_t *)PREG->u.lp.l); struct index_t *it = (struct index_t *)(PREG->u.lp.l);
setregs(); CELL offset = EXO_ADDRESS_TO_OFFSET(it,(CELL *)((CELL *)(B+1))[it->arity]);
#ifdef SHADOW_S d0 = it->links[offset];
SREG = S; ((CELL *)(B+1))[it->arity] = (CELL)EXO_OFFSET_TO_ADDRESS(it, d0);
#endif SREG = it->cls+it->arity*offset;
}
if (d0) { if (d0) {
/* After retry, cut should be pointing at the parent /* After retry, cut should be pointing at the parent
* choicepoint for the current B */ * choicepoint for the current B */

36
C/exo.c
View File

@ -58,12 +58,12 @@ HASH(UInt hash0, UInt j, CELL *cl, struct index_t *it)
/* search for matching elements */ /* search for matching elements */
static int static int
MATCH(CELL *clp, CELL *kvp, UInt j, struct index_t *it) MATCH(CELL *clp, CELL *kvp, UInt j, struct index_t *it, UInt bnds[])
{ {
if ((kvp - it->cls)%it->arity != j) if ((kvp - it->cls)%it->arity != j)
return FALSE; return FALSE;
do { do {
if ( LOCAL_ibnds[j] && *clp != *kvp) if ( bnds[j] && *clp != *kvp)
return FALSE; return FALSE;
clp--; clp--;
kvp--; kvp--;
@ -112,14 +112,14 @@ ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
* else * else
*/ */
static void static void
INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0) INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0, UInt bnds[])
{ {
UInt j = base; UInt j = base;
CELL *kvp; CELL *kvp;
UInt hash; UInt hash;
/* skip over argument */ /* skip over argument */
while (!LOCAL_ibnds[j]) { while (!bnds[j]) {
j++; j++;
} }
/* j is the firs bound element */ /* j is the firs bound element */
@ -134,16 +134,16 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0)
it->nentries++; it->nentries++;
it->key[hash] = cl+j; it->key[hash] = cl+j;
return; return;
} else if (MATCH(cl+j, kvp, j, it)) { } else if (MATCH(cl+j, kvp, j, it, bnds)) {
/* collision */ /* collision */
UInt k; UInt k;
CELL *target; CELL *target;
for (k =j+1, target = kvp+1; k < arity; k++,target++ ) { for (k =j+1, target = kvp+1; k < arity; k++,target++ ) {
if (LOCAL_ibnds[k]) { if (bnds[k]) {
if (*target != cl[k]) { if (*target != cl[k]) {
/* found a new forking point */ /* found a new forking point */
INSERT(cl, it, arity, k, hash0); INSERT(cl, it, arity, k, hash0, bnds);
return; return;
} }
} }
@ -160,8 +160,9 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0)
} }
static yamop * static yamop *
LOOKUP(struct index_t *it, UInt arity, UInt j) LOOKUP(struct index_t *it, UInt arity, UInt j, UInt bnds[])
{ {
CACHE_REGS
CELL *kvp; CELL *kvp;
UInt hash, hash0 = 0; UInt hash, hash0 = 0;
@ -175,13 +176,13 @@ LOOKUP(struct index_t *it, UInt arity, UInt j)
if (kvp == NULL) { if (kvp == NULL) {
/* simple case, no element */ /* simple case, no element */
return FAILCODE; return FAILCODE;
} else if (MATCH(XREGS+(j+1), kvp, j, it)) { } else if (MATCH(XREGS+(j+1), kvp, j, it, bnds)) {
/* found element */ /* found element */
UInt k; UInt k;
CELL *target; CELL *target;
for (k =j+1, target = kvp+1; k < arity; k++ ) { for (k =j+1, target = kvp+1; k < arity; k++ ) {
if (LOCAL_ibnds[k]) { if (bnds[k]) {
if (*target != XREGS[k+1]) { if (*target != XREGS[k+1]) {
j = k; j = k;
goto hash; goto hash;
@ -202,14 +203,14 @@ LOOKUP(struct index_t *it, UInt arity, UInt j)
} }
static void static void
fill_hash(UInt bmap, struct index_t *it) fill_hash(UInt bmap, struct index_t *it, UInt bnds[])
{ {
UInt i; UInt i;
UInt arity = it->arity; UInt arity = it->arity;
CELL *cl = it->cls; CELL *cl = it->cls;
for (i=0; i < it->nels; i++) { for (i=0; i < it->nels; i++) {
INSERT(cl, it, arity, 0, 0); INSERT(cl, it, arity, 0, 0, bnds);
cl += arity; cl += arity;
} }
for (i=0; i < it->hsize; i++) { for (i=0; i < it->hsize; i++) {
@ -226,7 +227,7 @@ fill_hash(UInt bmap, struct index_t *it)
} }
static struct index_t * static struct index_t *
add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count) add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count, UInt bnds[])
{ {
UInt ncls = ap->cs.p_code.NOfClauses, j; UInt ncls = ap->cs.p_code.NOfClauses, j;
CELL *base = NULL; CELL *base = NULL;
@ -269,7 +270,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *)); i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *));
*ip = i; *ip = i;
if (count) { if (count) {
fill_hash(bmap, i); fill_hash(bmap, i, bnds);
printf("entries=%ld collisions=%ld trys=%ld\n", i->nentries, i->ncollisions, i->ntrys); printf("entries=%ld collisions=%ld trys=%ld\n", i->nentries, i->ncollisions, i->ntrys);
if (!i->ntrys) { if (!i->ntrys) {
i->is_key = TRUE; i->is_key = TRUE;
@ -311,7 +312,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
} }
yamop * yamop *
Yap_ExoLookup(PredEntry *ap) Yap_ExoLookup(PredEntry *ap USES_REGS)
{ {
UInt arity = ap->ArityOfPE; UInt arity = ap->ArityOfPE;
UInt bmap = 0L, bit = 1, count = 0, j, j0 = 0; UInt bmap = 0L, bit = 1, count = 0, j, j0 = 0;
@ -345,10 +346,10 @@ Yap_ExoLookup(PredEntry *ap)
i = i->next; i = i->next;
} }
if (!i) { if (!i) {
i = add_index(ip, bmap, ap, count); i = add_index(ip, bmap, ap, count, LOCAL_ibnds);
} }
if (count) if (count)
return LOOKUP(i, arity, j0); return LOOKUP(i, arity, j0, LOCAL_ibnds);
else else
return i->code; return i->code;
} }
@ -356,6 +357,7 @@ Yap_ExoLookup(PredEntry *ap)
CELL CELL
Yap_NextExo(choiceptr cptr, struct index_t *it) Yap_NextExo(choiceptr cptr, struct index_t *it)
{ {
CACHE_REGS
CELL offset = EXO_ADDRESS_TO_OFFSET(it,(CELL *)((CELL *)(B+1))[it->arity]); CELL offset = EXO_ADDRESS_TO_OFFSET(it,(CELL *)((CELL *)(B+1))[it->arity]);
CELL next = it->links[offset]; CELL next = it->links[offset];
((CELL *)(B+1))[it->arity] = (CELL)EXO_OFFSET_TO_ADDRESS(it, next); ((CELL *)(B+1))[it->arity] = (CELL)EXO_OFFSET_TO_ADDRESS(it, next);

View File

@ -263,7 +263,7 @@ LogUpdClause *STD_PROTO(Yap_NthClause,(PredEntry *,Int));
LogUpdClause *STD_PROTO(Yap_FollowIndexingCode,(PredEntry *,yamop *, Term *, yamop *,yamop *)); LogUpdClause *STD_PROTO(Yap_FollowIndexingCode,(PredEntry *,yamop *, Term *, yamop *,yamop *));
/* exo.c */ /* exo.c */
yamop *Yap_ExoLookup(PredEntry *ap); yamop *Yap_ExoLookup(PredEntry *ap USES_REGS);
CELL Yap_NextExo(choiceptr cpt, struct index_t *it); CELL Yap_NextExo(choiceptr cpt, struct index_t *it);
#if USE_THREADED_CODE #if USE_THREADED_CODE