fix 32 bit offsets
This commit is contained in:
parent
b257218ece
commit
a1632ff3e7
@ -968,7 +968,7 @@ Yap_absmi(int inp)
|
|||||||
CACHE_Y(YREG);
|
CACHE_Y(YREG);
|
||||||
{
|
{
|
||||||
struct index_t *i = (struct index_t *)(PREG->u.lp.l);
|
struct index_t *i = (struct index_t *)(PREG->u.lp.l);
|
||||||
S_YREG[-1] = (CELL)EXO_OFFSET_TO_ADDRESS(i,i->links[(CELL)(SREG-i->cls)/i->arity]);
|
S_YREG[-1] = (CELL)LINK_TO_ADDRESS(i,i->links[EXO_ADDRESS_TO_OFFSET(i, SREG)]);
|
||||||
}
|
}
|
||||||
S_YREG--;
|
S_YREG--;
|
||||||
/* store arguments for procedure */
|
/* store arguments for procedure */
|
||||||
@ -1091,10 +1091,10 @@ Yap_absmi(int inp)
|
|||||||
CACHE_Y(B);
|
CACHE_Y(B);
|
||||||
{
|
{
|
||||||
struct index_t *it = (struct index_t *)(PREG->u.lp.l);
|
struct index_t *it = (struct index_t *)(PREG->u.lp.l);
|
||||||
CELL offset = EXO_ADDRESS_TO_OFFSET(it,(CELL *)((CELL *)(B+1))[it->arity]);
|
BITS32 offset = ADDRESS_TO_LINK(it,(BITS32 *)((CELL *)(B+1))[it->arity]);
|
||||||
d0 = it->links[offset];
|
d0 = it->links[offset];
|
||||||
((CELL *)(B+1))[it->arity] = (CELL)EXO_OFFSET_TO_ADDRESS(it, d0);
|
((CELL *)(B+1))[it->arity] = (CELL)LINK_TO_ADDRESS(it, d0);
|
||||||
SREG = it->cls+it->arity*offset;
|
SREG = EXO_OFFSET_TO_ADDRESS(it, offset);
|
||||||
}
|
}
|
||||||
if (d0) {
|
if (d0) {
|
||||||
/* After retry, cut should be pointing at the parent
|
/* After retry, cut should be pointing at the parent
|
||||||
|
17
C/exo.c
17
C/exo.c
@ -243,8 +243,8 @@ MATCH(CELL *clp, CELL *kvp, UInt arity, UInt bnds[])
|
|||||||
static void
|
static void
|
||||||
ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
|
ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
|
||||||
{
|
{
|
||||||
BITS32 old = (kvp-it->cls)/it->arity;
|
BITS32 old = EXO_ADDRESS_TO_OFFSET(it, kvp);
|
||||||
BITS32 new = (cl-it->cls)/it->arity;
|
BITS32 new = EXO_ADDRESS_TO_OFFSET(it, cl);
|
||||||
BITS32 *links = it->links;
|
BITS32 *links = it->links;
|
||||||
BITS32 tmp = links[old]; /* points to the end of the chain */
|
BITS32 tmp = links[old]; /* points to the end of the chain */
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ LOOKUP(struct index_t *it, UInt arity, UInt j, UInt bnds[])
|
|||||||
return FAILCODE;
|
return FAILCODE;
|
||||||
} else if (MATCH(kvp, XREGS+1, arity, bnds)) {
|
} else if (MATCH(kvp, XREGS+1, arity, bnds)) {
|
||||||
S = kvp;
|
S = kvp;
|
||||||
if (!it->is_key && it->links[(S-it->cls)/arity])
|
if (!it->is_key && it->links[EXO_ADDRESS_TO_OFFSET(it, S)])
|
||||||
return it->code;
|
return it->code;
|
||||||
else
|
else
|
||||||
return NEXTOP(NEXTOP(it->code,lp),lp);
|
return NEXTOP(NEXTOP(it->code,lp),lp);
|
||||||
@ -349,10 +349,10 @@ fill_hash(UInt bmap, struct index_t *it, UInt bnds[])
|
|||||||
}
|
}
|
||||||
for (i=0; i < it->hsize; i++) {
|
for (i=0; i < it->hsize; i++) {
|
||||||
if (it->key[i]) {
|
if (it->key[i]) {
|
||||||
BITS32 offset = it->key[i]/arity;
|
BITS32 offset = it->key[i];
|
||||||
BITS32 last = it->links[offset];
|
BITS32 last = it->links[offset];
|
||||||
if (last) {
|
if (last) {
|
||||||
/* the chain used to point straight to the last, and the last back to the origibal first */
|
/* the chain used to point straight to the last, and the last back to the original first */
|
||||||
it->links[offset] = it->links[last];
|
it->links[offset] = it->links[last];
|
||||||
it->links[last] = 0;
|
it->links[last] = 0;
|
||||||
}
|
}
|
||||||
@ -390,7 +390,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
|
|||||||
i->bmap = bmap;
|
i->bmap = bmap;
|
||||||
i->is_key = FALSE;
|
i->is_key = FALSE;
|
||||||
i->hsize = 2*ncls;
|
i->hsize = 2*ncls;
|
||||||
dsz = sizeof(BITS32)*(ncls+i->hsize);
|
dsz = sizeof(BITS32)*(ncls+1+i->hsize);
|
||||||
if (count) {
|
if (count) {
|
||||||
if (!(base = (CELL *)Yap_AllocCodeSpace(dsz))) {
|
if (!(base = (CELL *)Yap_AllocCodeSpace(dsz))) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -408,6 +408,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
|
|||||||
i->links = (BITS32 *)base+i->hsize;
|
i->links = (BITS32 *)base+i->hsize;
|
||||||
i->ncollisions = i->nentries = i->ntrys = 0;
|
i->ncollisions = i->nentries = i->ntrys = 0;
|
||||||
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 *));
|
||||||
|
i->bcls= i->cls-i->arity;
|
||||||
*ip = i;
|
*ip = i;
|
||||||
while (count) {
|
while (count) {
|
||||||
if (!fill_hash(bmap, i, bnds)) {
|
if (!fill_hash(bmap, i, bnds)) {
|
||||||
@ -416,7 +417,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
|
|||||||
if (i->is_key) {
|
if (i->is_key) {
|
||||||
sz = i->hsize*sizeof(BITS32);
|
sz = i->hsize*sizeof(BITS32);
|
||||||
} else {
|
} else {
|
||||||
sz = (ncls+i->hsize)*sizeof(BITS32);
|
sz = (ncls+1+i->hsize)*sizeof(BITS32);
|
||||||
}
|
}
|
||||||
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
|
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -441,7 +442,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
|
|||||||
if (i->is_key) {
|
if (i->is_key) {
|
||||||
sz = i->hsize*sizeof(BITS32);
|
sz = i->hsize*sizeof(BITS32);
|
||||||
} else {
|
} else {
|
||||||
sz = (ncls+i->hsize)*sizeof(BITS32);
|
sz = (ncls+1+i->hsize)*sizeof(BITS32);
|
||||||
}
|
}
|
||||||
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
|
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
34
C/exo_udi.c
34
C/exo_udi.c
@ -41,16 +41,15 @@ static int
|
|||||||
compar(const void *ip0, const void *jp0) {
|
compar(const void *ip0, const void *jp0) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
BITS32 *ip = (BITS32 *)ip0, *jp = (BITS32 *)jp0;
|
BITS32 *ip = (BITS32 *)ip0, *jp = (BITS32 *)jp0;
|
||||||
BITS32 *bs = LOCAL_exo_base;
|
Term i = EXO_OFFSET_TO_ADDRESS(LOCAL_exo_it, *ip)[LOCAL_exo_arg];
|
||||||
Int i = bs[LOCAL_exo_arity*(*ip)+LOCAL_exo_arg];
|
Term j = EXO_OFFSET_TO_ADDRESS(LOCAL_exo_it, *jp)[LOCAL_exo_arg];
|
||||||
Int j = bs[LOCAL_exo_arity*(*jp)+LOCAL_exo_arg];
|
//fprintf(stderr, "%ld-%ld\n", IntOfTerm(i), IntOfTerm(j));
|
||||||
return IntOfTerm(i)-IntOfTerm(j);
|
return IntOfTerm(i)-IntOfTerm(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
compare(const BITS32 *ip, Int j USES_REGS) {
|
compare(const BITS32 *ip, Int j USES_REGS) {
|
||||||
BITS32 *bs = LOCAL_exo_base;
|
Term i = EXO_OFFSET_TO_ADDRESS(LOCAL_exo_it, *ip)[LOCAL_exo_arg];
|
||||||
Int i = bs[LOCAL_exo_arity*(*ip)+LOCAL_exo_arg];
|
|
||||||
//fprintf(stderr, "%ld-%ld\n", IntOfTerm(i), j);
|
//fprintf(stderr, "%ld-%ld\n", IntOfTerm(i), j);
|
||||||
return IntOfTerm(i)-j;
|
return IntOfTerm(i)-j;
|
||||||
}
|
}
|
||||||
@ -61,7 +60,6 @@ compare(const BITS32 *ip, Int j USES_REGS) {
|
|||||||
{
|
{
|
||||||
size_t sz;
|
size_t sz;
|
||||||
struct index_t *it = *ip;
|
struct index_t *it = *ip;
|
||||||
UInt arity = it->arity;
|
|
||||||
yamop *code;
|
yamop *code;
|
||||||
|
|
||||||
/* hard-wired implementation for the Interval case */
|
/* hard-wired implementation for the Interval case */
|
||||||
@ -70,7 +68,8 @@ compare(const BITS32 *ip, Int j USES_REGS) {
|
|||||||
if (it->bmap & b[i]) return;
|
if (it->bmap & b[i]) return;
|
||||||
/* no constraints, nothing to gain */
|
/* no constraints, nothing to gain */
|
||||||
if (!IsAttVar(VarOfTerm(XREGS[i+1]))) return;
|
if (!IsAttVar(VarOfTerm(XREGS[i+1]))) return;
|
||||||
LOCAL_exo_base = it->cls;
|
LOCAL_exo_it = it;
|
||||||
|
LOCAL_exo_base = it->bcls;
|
||||||
LOCAL_exo_arity = it->arity;
|
LOCAL_exo_arity = it->arity;
|
||||||
LOCAL_exo_arg = i;
|
LOCAL_exo_arg = i;
|
||||||
if (!it->key) {
|
if (!it->key) {
|
||||||
@ -99,14 +98,14 @@ compare(const BITS32 *ip, Int j USES_REGS) {
|
|||||||
for (i=0; i < it->hsize; i++) {
|
for (i=0; i < it->hsize; i++) {
|
||||||
if (it->key[i]) {
|
if (it->key[i]) {
|
||||||
BITS32 *s0 = sorted;
|
BITS32 *s0 = sorted;
|
||||||
BITS32 offset = it->key[i]/arity, offset0 = offset;
|
BITS32 offset = it->key[i], offset0 = offset;
|
||||||
|
|
||||||
*sorted++ = 0;
|
*sorted++ = 0;
|
||||||
do {
|
do {
|
||||||
*sorted++ = offset;
|
*sorted++ = offset;
|
||||||
offset = it->links[offset];
|
offset = it->links[offset];
|
||||||
} while (offset);
|
} while (offset);
|
||||||
// S = it->cls+it->arity*offset0; Yap_DebugPlWrite(S[1]);
|
// S = EXO_OFFSET_TO_ADDRESS(it, offset0); Yap_DebugPlWrite(S[0]);
|
||||||
// fprintf(stderr, " key[i]=%d offset=%d %d\n", it->key[i], offset0, (sorted-s0)-1);
|
// fprintf(stderr, " key[i]=%d offset=%d %d\n", it->key[i], offset0, (sorted-s0)-1);
|
||||||
if (sorted-s0 == 2) {
|
if (sorted-s0 == 2) {
|
||||||
it->links[offset0] = 0;
|
it->links[offset0] = 0;
|
||||||
@ -116,6 +115,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
|
|||||||
*s0 = sorted - (s0+1);
|
*s0 = sorted - (s0+1);
|
||||||
qsort(s0+1, (size_t)*s0, sizeof(BITS32), compar);
|
qsort(s0+1, (size_t)*s0, sizeof(BITS32), compar);
|
||||||
it->links[offset0] = s0-sorted0;
|
it->links[offset0] = s0-sorted0;
|
||||||
|
// fprintf(stderr," %d links %d=%d \n", offset0, s0-sorted0, s0[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +156,8 @@ Interval(struct index_t *it, Term min, Term max, Term op, BITS32 off USES_REGS)
|
|||||||
BITS32 *end;
|
BITS32 *end;
|
||||||
Atom at;
|
Atom at;
|
||||||
|
|
||||||
LOCAL_exo_base = it->cls;
|
LOCAL_exo_it = it;
|
||||||
|
LOCAL_exo_base = it->bcls;
|
||||||
LOCAL_exo_arity = it->arity;
|
LOCAL_exo_arity = it->arity;
|
||||||
LOCAL_exo_arg = it->udi_arg;
|
LOCAL_exo_arg = it->udi_arg;
|
||||||
if (!it->links) {
|
if (!it->links) {
|
||||||
@ -169,6 +170,7 @@ Interval(struct index_t *it, Term min, Term max, Term op, BITS32 off USES_REGS)
|
|||||||
n = c[it->links[off]];
|
n = c[it->links[off]];
|
||||||
pt = c+(it->links[off]+1);
|
pt = c+(it->links[off]+1);
|
||||||
end = c+(it->links[off]+n);
|
end = c+(it->links[off]+n);
|
||||||
|
// fprintf(stderr," %d links %d=%d \n", off, it->links[off], n);
|
||||||
} else {
|
} else {
|
||||||
if (!IsVarTerm(min)) {
|
if (!IsVarTerm(min)) {
|
||||||
Int x;
|
Int x;
|
||||||
@ -257,7 +259,7 @@ Interval(struct index_t *it, Term min, Term max, Term op, BITS32 off USES_REGS)
|
|||||||
end = pt1;
|
end = pt1;
|
||||||
}
|
}
|
||||||
if (IsVarTerm(op)) {
|
if (IsVarTerm(op)) {
|
||||||
S = it->cls+it->arity*pt[0];
|
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
|
||||||
if (pt < end ) {
|
if (pt < end ) {
|
||||||
YENV[-2] = (CELL)( pt+1 );
|
YENV[-2] = (CELL)( pt+1 );
|
||||||
YENV[-1] = (CELL)( end );
|
YENV[-1] = (CELL)( end );
|
||||||
@ -268,13 +270,13 @@ Interval(struct index_t *it, Term min, Term max, Term op, BITS32 off USES_REGS)
|
|||||||
}
|
}
|
||||||
at = AtomOfTerm(op);
|
at = AtomOfTerm(op);
|
||||||
if (at == AtomAny || at == AtomMin) {
|
if (at == AtomAny || at == AtomMin) {
|
||||||
S = it->cls+it->arity*pt[0];
|
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
|
||||||
} else if (at == AtomMax) {
|
} else if (at == AtomMax) {
|
||||||
S = it->cls+it->arity*end[0];
|
S = EXO_OFFSET_TO_ADDRESS(it, end[0]);
|
||||||
} else if (at == AtomUnique) {
|
} else if (at == AtomUnique) {
|
||||||
if (end-2 > pt)
|
if (end-2 > pt)
|
||||||
return FAILCODE;
|
return FAILCODE;
|
||||||
S = it->cls+it->arity*pt[0];
|
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
|
||||||
}
|
}
|
||||||
return NEXTOP(NEXTOP(it->code,lp),lp);
|
return NEXTOP(NEXTOP(it->code,lp),lp);
|
||||||
}
|
}
|
||||||
@ -284,7 +286,7 @@ IntervalEnterUDIIndex(struct index_t *it USES_REGS)
|
|||||||
{
|
{
|
||||||
Int i = it->udi_arg;
|
Int i = it->udi_arg;
|
||||||
Term t = XREGS[i+1], a1;
|
Term t = XREGS[i+1], a1;
|
||||||
BITS32 off = EXO_ADDRESS_TO_OFFSET(it, S)/it->arity;
|
BITS32 off = EXO_ADDRESS_TO_OFFSET(it, S);
|
||||||
// printf("off=%d it=%p %p---%p\n", off, it, it->cls, S);
|
// printf("off=%d it=%p %p---%p\n", off, it, it->cls, S);
|
||||||
attvar_record *attv;
|
attvar_record *attv;
|
||||||
|
|
||||||
@ -315,7 +317,7 @@ IntervalRetryUDIIndex(struct index_t *it USES_REGS)
|
|||||||
*pt = (BITS32 *) w[it->arity+1];
|
*pt = (BITS32 *) w[it->arity+1];
|
||||||
BITS32 f = *pt;
|
BITS32 f = *pt;
|
||||||
|
|
||||||
S = it->cls+it->arity*f;
|
S = EXO_OFFSET_TO_ADDRESS(it, f);
|
||||||
if (pt++ == end) return FALSE;
|
if (pt++ == end) return FALSE;
|
||||||
w[it->arity+1] = (CELL)pt;
|
w[it->arity+1] = (CELL)pt;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -172,7 +172,7 @@ typedef struct index_t {
|
|||||||
UInt nentries;
|
UInt nentries;
|
||||||
UInt hsize;
|
UInt hsize;
|
||||||
BITS32 *key;
|
BITS32 *key;
|
||||||
CELL *cls;
|
CELL *cls, *bcls;
|
||||||
BITS32 *links;
|
BITS32 *links;
|
||||||
size_t size;
|
size_t size;
|
||||||
yamop *code;
|
yamop *code;
|
||||||
@ -186,7 +186,7 @@ INLINE_ONLY EXTERN inline BITS32 EXO_ADDRESS_TO_OFFSET(struct index_t *it, CELL
|
|||||||
INLINE_ONLY EXTERN inline BITS32
|
INLINE_ONLY EXTERN inline BITS32
|
||||||
EXO_ADDRESS_TO_OFFSET(struct index_t *it, CELL* ptr)
|
EXO_ADDRESS_TO_OFFSET(struct index_t *it, CELL* ptr)
|
||||||
{
|
{
|
||||||
return 1+(ptr-it->cls);
|
return (ptr-it->cls)/it->arity+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_ONLY EXTERN inline CELL *EXO_OFFSET_TO_ADDRESS(struct index_t *it, BITS32 off);
|
INLINE_ONLY EXTERN inline CELL *EXO_OFFSET_TO_ADDRESS(struct index_t *it, BITS32 off);
|
||||||
@ -196,7 +196,7 @@ EXO_OFFSET_TO_ADDRESS(struct index_t *it, BITS32 off)
|
|||||||
{
|
{
|
||||||
if (off == 0L)
|
if (off == 0L)
|
||||||
return NULL;
|
return NULL;
|
||||||
return (it->cls-1)+off;
|
return (it->cls)+(off-1)*it->arity;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_ONLY EXTERN inline BITS32 ADDRESS_TO_LINK(struct index_t *it, BITS32 *ptr);
|
INLINE_ONLY EXTERN inline BITS32 ADDRESS_TO_LINK(struct index_t *it, BITS32 *ptr);
|
||||||
|
@ -403,6 +403,8 @@
|
|||||||
|
|
||||||
#define LOCAL_ibnds LOCAL->ibnds_
|
#define LOCAL_ibnds LOCAL->ibnds_
|
||||||
#define REMOTE_ibnds(wid) REMOTE(wid)->ibnds_
|
#define REMOTE_ibnds(wid) REMOTE(wid)->ibnds_
|
||||||
|
#define LOCAL_exo_it LOCAL->exo_it_
|
||||||
|
#define REMOTE_exo_it(wid) REMOTE(wid)->exo_it_
|
||||||
#define LOCAL_exo_base LOCAL->exo_base_
|
#define LOCAL_exo_base LOCAL->exo_base_
|
||||||
#define REMOTE_exo_base(wid) REMOTE(wid)->exo_base_
|
#define REMOTE_exo_base(wid) REMOTE(wid)->exo_base_
|
||||||
#define LOCAL_exo_arity LOCAL->exo_arity_
|
#define LOCAL_exo_arity LOCAL->exo_arity_
|
||||||
|
@ -227,7 +227,8 @@ typedef struct worker_local {
|
|||||||
Functor FunctorVar_;
|
Functor FunctorVar_;
|
||||||
|
|
||||||
UInt ibnds_[256];
|
UInt ibnds_[256];
|
||||||
void* exo_base_;
|
struct index_t* exo_it_;
|
||||||
|
CELL* exo_base_;
|
||||||
UInt exo_arity_;
|
UInt exo_arity_;
|
||||||
UInt exo_arg_;
|
UInt exo_arg_;
|
||||||
|
|
||||||
|
@ -227,6 +227,7 @@ static void InitWorker(int wid) {
|
|||||||
REMOTE_FunctorVar(wid) = FunctorVar;
|
REMOTE_FunctorVar(wid) = FunctorVar;
|
||||||
|
|
||||||
|
|
||||||
|
REMOTE_exo_it(wid) = NULL;
|
||||||
REMOTE_exo_base(wid) = NULL;
|
REMOTE_exo_base(wid) = NULL;
|
||||||
REMOTE_exo_arity(wid) = 0;
|
REMOTE_exo_arity(wid) = 0;
|
||||||
REMOTE_exo_arg(wid) = 0;
|
REMOTE_exo_arg(wid) = 0;
|
||||||
|
@ -230,6 +230,7 @@ static void RestoreWorker(int wid USES_REGS) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -255,10 +255,11 @@ yamop *ImportFAILCODE =NULL
|
|||||||
|
|
||||||
Functor FunctorVar =FunctorVar
|
Functor FunctorVar =FunctorVar
|
||||||
|
|
||||||
// exo indexingxb
|
// exo indexing
|
||||||
|
|
||||||
UInt ibnds[256] void
|
UInt ibnds[256] void
|
||||||
BITS32* exo_base =NULL
|
struct index_t* exo_it =NULL
|
||||||
|
CELL* exo_base =NULL
|
||||||
UInt exo_arity =0
|
UInt exo_arity =0
|
||||||
UInt exo_arg =0
|
UInt exo_arg =0
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user