more ezo stuff

This commit is contained in:
Vitor Santos Costa 2013-06-28 21:15:03 -05:00
parent ec5f7ebb28
commit 459ab89d7d
4 changed files with 53 additions and 44 deletions

View File

@ -159,7 +159,7 @@ Yap_AllocCodeSpace(size_t size)
} }
static inline char * static inline char *
call_realloc(char *p, unsigned long int size) call_realloc(char *p, size_t size)
{ {
CACHE_REGS CACHE_REGS
char *out; char *out;

View File

@ -186,13 +186,13 @@ HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz);
spread over j quadrants. spread over j quadrants.
*/ */
extern inline BITS32 extern inline BITS32
HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz) HASH_FVN_1A(UInt ar, CELL *cl, UInt bnds[], UInt sz)
{ {
UInt hash; UInt hash;
UInt j=0; UInt j=0;
hash = FNV32_OFFSET; hash = FNV32_OFFSET;
while (j < arity) { while (j < ar) {
if (bnds[j]) { if (bnds[j]) {
unsigned char *i=(unsigned char*)(cl+j); unsigned char *i=(unsigned char*)(cl+j);
unsigned char *m=(unsigned char*)(cl+(j+1)); unsigned char *m=(unsigned char*)(cl+(j+1));

View File

@ -137,7 +137,7 @@ IntervalUDIRefitIndex(struct index_t **ip, UInt b[] USES_REGS)
/* it is bound, use hash */ /* it is bound, use hash */
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(Deref(XREGS[i+1])))) return;
LOCAL_exo_it = it; LOCAL_exo_it = it;
LOCAL_exo_base = it->bcls; LOCAL_exo_base = it->bcls;
LOCAL_exo_arity = it->arity; LOCAL_exo_arity = it->arity;
@ -161,9 +161,9 @@ IntervalUDIRefitIndex(struct index_t **ip, UInt b[] USES_REGS)
/* be conservative */ /* be conservative */
if (it->udi_free_args) if (it->udi_free_args)
sz = sizeof(BITS32)*(3*it->ntrys+2*it->nentries); sz = sizeof(BITS32)*(3*it->ntrys+3*it->nentries);
else else
sz = sizeof(BITS32)*(2*it->ntrys+it->nentries); sz = sizeof(BITS32)*(2*it->ntrys+2*it->nentries);
/* allocate space */ /* allocate space */
if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz))) if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz)))
return; return;
@ -364,36 +364,44 @@ Interval(struct index_t *it, Term min, Term max, Term op, BITS32 off USES_REGS)
} else if (at == AtomMin) { } else if (at == AtomMin) {
Int x0, xe, x; Int x0, xe, x;
x0 = pt-pt0; if (!(it->udi_free_args)) {
xe = end-pt0; S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]); } else {
x = NEXT_DIFFERENT(x0, x0, end0, xe); x0 = pt-pt0;
if (x < xe ) { xe = end-pt0;
YENV[-5] = (CELL)( pt0 ); // base for array of pointed pointers S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
YENV[-4] = MkIntegerTerm( x ); // where we are in pt0 array x = NEXT_DIFFERENT(x0, x0, end0, xe);
YENV[-3] = MkIntegerTerm( xe ); // our visit will end here if (x < xe ) {
YENV[-2] = MkIntegerTerm( x0 ); // our visit started here YENV[-5] = (CELL)( pt0 ); // base for array of pointed pointers
YENV[-1] = (CELL)( end0 ); // base for array into pt YENV[-4] = MkIntegerTerm( x ); // where we are in pt0 array
YENV -= 5; YENV[-3] = MkIntegerTerm( xe ); // our visit will end here
return it->code; YENV[-2] = MkIntegerTerm( x0 ); // our visit started here
YENV[-1] = (CELL)( end0 ); // base for array into pt
YENV -= 5;
return it->code;
}
} }
return NEXTOP(NEXTOP(it->code,lp),lp); return NEXTOP(NEXTOP(it->code,lp),lp);
} else if (at == AtomMax) { } else if (at == AtomMax) {
Int x0, xe, x, y; Int x0, xe, x, y;
x0 = pt-pt0; if (!(it->udi_free_args)) {
xe = end-pt0; S = EXO_OFFSET_TO_ADDRESS(it, end[0]);
y = BIGGEST_EL( x0, end0, xe ); } else {
S = EXO_OFFSET_TO_ADDRESS(it, pt[0]); x0 = pt-pt0;
x = NEXT_DIFFERENT(x0, x0, end0, xe); xe = end-pt0;
if (x < xe ) { y = BIGGEST_EL( x0, end0, xe );
YENV[-5] = (CELL)( pt0 ); // base for array of pointed pointers S = EXO_OFFSET_TO_ADDRESS(it, pt[0]);
YENV[-4] = MkIntegerTerm( -x ); // where we are in pt0 array x = NEXT_DIFFERENT(x0, x0, end0, xe);
YENV[-3] = MkIntegerTerm( xe ); // our visit will end here if (x < xe ) {
YENV[-2] = MkIntegerTerm( x0 ); // our visit started here YENV[-5] = (CELL)( pt0 ); // base for array of pointed pointers
YENV[-1] = (CELL)( end0 ); // base for array into pt YENV[-4] = MkIntegerTerm( -x ); // where we are in pt0 array
YENV -= 5; YENV[-3] = MkIntegerTerm( xe ); // our visit will end here
return it->code; YENV[-2] = MkIntegerTerm( x0 ); // our visit started here
YENV[-1] = (CELL)( end0 ); // base for array into pt
YENV -= 5;
return it->code;
}
} }
return NEXTOP(NEXTOP(it->code,lp),lp); return NEXTOP(NEXTOP(it->code,lp),lp);
} }

View File

@ -9,13 +9,12 @@
:- module(exo_interval, :- module(exo_interval,
[max/2, [max/2,
min/2, min/2,
any/2,
max/1, max/1,
min/1, min/1,
any/2, maximum/1,
minimum/1,
any/1, any/1,
max/3,
min/3,
any/3,
(#<)/2, (#<)/2,
(#>)/2, (#>)/2,
(#=<)/2, (#=<)/2,
@ -27,31 +26,33 @@
op(700, xfx, (#=<)), op(700, xfx, (#=<)),
op(700, xfx, (#=))]). op(700, xfx, (#=))]).
:- meta_predicate max(?,0,?), min(?,0,?), any(?,0,?). :- meta_predicate max(?,0), min(?,0), any(?,0).
max(X, G, X) :- max(X, G) :-
insert_atts(X, i(_,_,max)), insert_atts(X, i(_,_,max)),
call(G). call(G).
min(X, G, X) :- min(X, G) :-
insert_atts(X, i(_,_,min)), insert_atts(X, i(_,_,min)),
call(G). call(G).
max(X, X) :-
insert_atts(X, i(_,_,max)).
min(X, X) :-
insert_atts(X, i(_,_,min)).
max(X) :- max(X) :-
insert_atts(X, i(_,_,max)). insert_atts(X, i(_,_,max)).
maximum(X) :-
insert_atts(X, i(_,_,maximum)).
any(X) :- any(X) :-
insert_atts(X, i(_,_,any)). insert_atts(X, i(_,_,any)).
min(X) :- min(X) :-
insert_atts(X, i(_,_,min)). insert_atts(X, i(_,_,min)).
minimum(X) :-
insert_atts(X, i(_,_,minimum)).
least(X) :-
insert_atts(X, i(_,_,least)).
X #> Y :- X #> Y :-
( var(X) -> insert_atts(X, i(Y,_,_)) ( var(X) -> insert_atts(X, i(Y,_,_))