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;
saveregs();
pt = Yap_ExoLookup(PredFromDefCode(PREG));
pt = Yap_ExoLookup(PredFromDefCode(PREG) PASS_REGS);
setregs();
#ifdef SHADOW_S
SREG = S;
@ -1050,12 +1050,13 @@ Yap_absmi(int inp)
Op(retry_exo, lp);
BEGD(d0);
CACHE_Y(B);
saveregs();
d0 = Yap_NextExo(B_YREG, (struct index_t *)PREG->u.lp.l);
setregs();
#ifdef SHADOW_S
SREG = S;
#endif
{
struct index_t *it = (struct index_t *)(PREG->u.lp.l);
CELL offset = EXO_ADDRESS_TO_OFFSET(it,(CELL *)((CELL *)(B+1))[it->arity]);
d0 = it->links[offset];
((CELL *)(B+1))[it->arity] = (CELL)EXO_OFFSET_TO_ADDRESS(it, d0);
SREG = it->cls+it->arity*offset;
}
if (d0) {
/* After retry, cut should be pointing at the parent
* 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 */
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)
return FALSE;
do {
if ( LOCAL_ibnds[j] && *clp != *kvp)
if ( bnds[j] && *clp != *kvp)
return FALSE;
clp--;
kvp--;
@ -112,14 +112,14 @@ ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
* else
*/
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;
CELL *kvp;
UInt hash;
/* skip over argument */
while (!LOCAL_ibnds[j]) {
while (!bnds[j]) {
j++;
}
/* 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->key[hash] = cl+j;
return;
} else if (MATCH(cl+j, kvp, j, it)) {
} else if (MATCH(cl+j, kvp, j, it, bnds)) {
/* collision */
UInt k;
CELL *target;
for (k =j+1, target = kvp+1; k < arity; k++,target++ ) {
if (LOCAL_ibnds[k]) {
if (bnds[k]) {
if (*target != cl[k]) {
/* found a new forking point */
INSERT(cl, it, arity, k, hash0);
INSERT(cl, it, arity, k, hash0, bnds);
return;
}
}
@ -160,8 +160,9 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0)
}
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;
UInt hash, hash0 = 0;
@ -175,13 +176,13 @@ LOOKUP(struct index_t *it, UInt arity, UInt j)
if (kvp == NULL) {
/* simple case, no element */
return FAILCODE;
} else if (MATCH(XREGS+(j+1), kvp, j, it)) {
} else if (MATCH(XREGS+(j+1), kvp, j, it, bnds)) {
/* found element */
UInt k;
CELL *target;
for (k =j+1, target = kvp+1; k < arity; k++ ) {
if (LOCAL_ibnds[k]) {
if (bnds[k]) {
if (*target != XREGS[k+1]) {
j = k;
goto hash;
@ -202,14 +203,14 @@ LOOKUP(struct index_t *it, UInt arity, UInt j)
}
static void
fill_hash(UInt bmap, struct index_t *it)
fill_hash(UInt bmap, struct index_t *it, UInt bnds[])
{
UInt i;
UInt arity = it->arity;
CELL *cl = it->cls;
for (i=0; i < it->nels; i++) {
INSERT(cl, it, arity, 0, 0);
INSERT(cl, it, arity, 0, 0, bnds);
cl += arity;
}
for (i=0; i < it->hsize; i++) {
@ -226,7 +227,7 @@ fill_hash(UInt bmap, struct index_t *it)
}
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;
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 *));
*ip = i;
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);
if (!i->ntrys) {
i->is_key = TRUE;
@ -311,7 +312,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
}
yamop *
Yap_ExoLookup(PredEntry *ap)
Yap_ExoLookup(PredEntry *ap USES_REGS)
{
UInt arity = ap->ArityOfPE;
UInt bmap = 0L, bit = 1, count = 0, j, j0 = 0;
@ -345,10 +346,10 @@ Yap_ExoLookup(PredEntry *ap)
i = i->next;
}
if (!i) {
i = add_index(ip, bmap, ap, count);
i = add_index(ip, bmap, ap, count, LOCAL_ibnds);
}
if (count)
return LOOKUP(i, arity, j0);
return LOOKUP(i, arity, j0, LOCAL_ibnds);
else
return i->code;
}
@ -356,6 +357,7 @@ Yap_ExoLookup(PredEntry *ap)
CELL
Yap_NextExo(choiceptr cptr, struct index_t *it)
{
CACHE_REGS
CELL offset = EXO_ADDRESS_TO_OFFSET(it,(CELL *)((CELL *)(B+1))[it->arity]);
CELL next = it->links[offset];
((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 *));
/* exo.c */
yamop *Yap_ExoLookup(PredEntry *ap);
yamop *Yap_ExoLookup(PredEntry *ap USES_REGS);
CELL Yap_NextExo(choiceptr cpt, struct index_t *it);
#if USE_THREADED_CODE