speedup between

more exo stuff.
This commit is contained in:
Vitor Santos Costa 2013-04-30 15:23:01 -05:00
parent 64a61e2479
commit 923be33404
16 changed files with 104 additions and 35 deletions

View File

@ -118,6 +118,27 @@ AttVarToTerm(CELL *orig)
return attv->Atts;
}
static int
IsEmptyWakeUp(Term atts)
{
Atom name = NameOfFunctor(FunctorOfTerm(atts));
Atom *pt = EmptyWakeups;
int i = 0;
while (i < MaxEmptyWakeups) {
if (pt[i++] == name) return TRUE;
}
return FALSE;
}
void
Yap_MkEmptyWakeUp(Atom mod)
{
if (MaxEmptyWakeups == MAX_EMPTY_WAKEUPS)
Yap_Error(SYSTEM_ERROR, TermNil, "too many modules that do not wake up");
EmptyWakeups[MaxEmptyWakeups++] = mod;
}
static int
TermToAttVar(Term attvar, Term to USES_REGS)
{
@ -165,6 +186,11 @@ WakeAttVar(CELL* pt1, CELL reg2 USES_REGS)
return;
}
}
if (IsEmptyWakeUp(attv->Atts)) {
Bind_Global_NonAtt(&(attv->Value), reg2);
Bind_Global_NonAtt(&(attv->Done), attv->Value);
return;
}
if (!IsVarTerm(attv->Value) || !IsUnboundVar(&attv->Value)) {
/* oops, our goal is on the queue to be woken */
if (!Yap_unify(attv->Value, reg2)) {

View File

@ -229,16 +229,15 @@ static Int cont_between( USES_REGS1 )
Term t2 = EXTRA_CBACK_ARG(3,2);
Yap_unify(ARG3, t1);
if (IsIntegerTerm(t1) && (IsIntegerTerm(t2) || IsAtomTerm(t2))) {
if (IsIntegerTerm(t1)) {
Int i1;
Term tn;
if (t1 == t2)
cut_succeed();
i1 = IntegerOfTerm(t1);
i1++;
tn = MkIntegerTerm(i1);
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm(i1);
tn = add_int(i1, 1 PASS_REGS);
EXTRA_CBACK_ARG(3,1) = tn;
HB = B->cp_h = H;
return TRUE;
} else {

View File

@ -119,6 +119,8 @@ compare(const BITS32 *ip, Int j USES_REGS) {
}
}
}
sz = sizeof(BITS32)*(sorted-sorted0);
it->udi_data = (BITS32 *)realloc(it->udi_data, sz);
}
it->is_udi = i+1;
code = it->code;
@ -329,12 +331,12 @@ static int IntervalUdiDestroy(void *control)
void Yap_udi_Interval_init(void) {
UdiControlBlock cb = &IntervalCB;
Atom name = Yap_LookupAtom("exo_interval");
memset((void *) cb,0, sizeof(*cb));
/*TODO: ask vitor why this gives a warning*/
cb->decl=Yap_LookupAtom("exo_interval");
cb->decl= name;
Yap_MkEmptyWakeUp(name);
cb->init= IntervalUdiInit;
cb->insert=IntervalUdiInsert;
cb->search=NULL;

View File

@ -2308,9 +2308,13 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose
nargs = rtp->u.OtILl.d->ClPred->ArityOfPE+1;
break;
case _retry_exo:
case _retry_exo_udi:
case _retry_all_exo:
nargs = rtp->u.lp.p->ArityOfPE;
break;
case _retry_udi:
nargs = rtp->u.p.p->ArityOfPE;
break;
#ifdef DEBUG
case _retry_me:
case _trust_me:
@ -3227,7 +3231,11 @@ sweep_choicepoints(choiceptr gc_B USES_REGS)
case _retry4:
sweep_b(gc_B, 4 PASS_REGS);
break;
case _retry_udi:
sweep_b(gc_B, rtp->u.p.p->ArityOfPE PASS_REGS);
break;
case _retry_exo:
case _retry_exo_udi:
case _retry_all_exo:
sweep_b(gc_B, rtp->u.lp.p->ArityOfPE PASS_REGS);
break;

View File

@ -1022,6 +1022,11 @@ InitSWIAtoms(void)
ATOM_ = PL_new_atom("");
}
static void
InitEmptyWakeups(void)
{
}
static void
InitAtoms(void)
{

View File

@ -542,6 +542,8 @@ typedef enum
GPROF_NEW_EXPAND_BLOCK
} gprof_info;
#define MAX_EMPTY_WAKEUPS 16
/*************************************************************************************************
prototypes

View File

@ -102,6 +102,7 @@ void Yap_InitArrayPreds(void);
/* attvar.c */
void Yap_InitAttVarPreds(void);
void Yap_MkEmptyWakeUp(Atom mod);
/* bb.c */
void Yap_InitBBPreds(void);

View File

@ -19,31 +19,6 @@
*
*/
inline static int
add_overflow(Int x, Int i, Int j)
{
return ((i & j & ~x) | (~i & ~j & x)) < 0;
}
inline static Term
add_int(Int i, Int j USES_REGS)
{
Int x = i+j;
#if USE_GMP
/* Integer overflow, we need to use big integers */
Int overflow = (i & j & ~x) | (~i & ~j & x);
if (overflow < 0) {
return(Yap_gmp_add_ints(i, j));
}
#endif
#ifdef BEAM
RINT(x);
return( MkIntegerTerm (x));
#else
RINT(x);
#endif
}
inline static int
sub_overflow(Int x, Int i, Int j)
{

View File

@ -298,6 +298,8 @@
#define SWI_Atoms Yap_heap_regs->swi_atoms
#define SWI_Functors Yap_heap_regs->swi_functors
#define SWI_ReverseHash Yap_heap_regs->swi_reverse_hash
#define EmptyWakeups Yap_heap_regs->empty_wakeups
#define MaxEmptyWakeups Yap_heap_regs->max_empty_wakeups
#define SWI_BlobTypes Yap_heap_regs->swi_blob_types
#define SWI_Blobs Yap_heap_regs->swi_blobs

View File

@ -337,3 +337,28 @@ __Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS)
}
inline static int
add_overflow(Int x, Int i, Int j)
{
return ((i & j & ~x) | (~i & ~j & x)) < 0;
}
inline static Term
add_int(Int i, Int j USES_REGS)
{
Int x = i+j;
#if USE_GMP
/* Integer overflow, we need to use big integers */
Int overflow = (i & j & ~x) | (~i & ~j & x);
if (overflow < 0) {
return(Yap_gmp_add_ints(i, j));
}
#endif
#ifdef BEAM
RINT(x);
return( MkIntegerTerm (x));
#else
RINT(x);
#endif
}

View File

@ -298,6 +298,8 @@
Atom swi_atoms[N_SWI_ATOMS];
Functor swi_functors[N_SWI_FUNCTORS];
struct swi_reverse_hash swi_reverse_hash[N_SWI_HASH];
Atom empty_wakeups[MAX_EMPTY_WAKEUPS];
int max_empty_wakeups;
struct PL_blob_t *swi_blob_types;
struct AtomEntryStruct *swi_blobs;

View File

@ -298,6 +298,8 @@
InitSWIAtoms();
InitEmptyWakeups();
MaxEmptyWakeups = 0;
SWI_BlobTypes = NULL;
SWI_Blobs = NULL;

View File

@ -547,6 +547,15 @@ RestoreDBTerm(DBTerm *dbr, int attachments USES_REGS)
/* Restoring the heap */
static void
RestoreEmptyWakeups(void)
{
int i;
for (i=0; i < MaxEmptyWakeups; i++) {
EmptyWakeups[i] = AtomAdjust(EmptyWakeups[i]);
}
}
/* Restores a prolog clause, in its compiled form */
static void
RestoreStaticClause(StaticClause *cl USES_REGS)

View File

@ -298,6 +298,8 @@
RestoreSWIAtoms();
RestoreEmptyWakeups();
RestoreSWIBlobTypes();
RestoreSWIBlobs();

View File

@ -340,6 +340,9 @@ Atom swi_atoms[N_SWI_ATOMS] SWI_Atoms InitSWIAtoms() RestoreSWIAtoms()
Functor swi_functors[N_SWI_FUNCTORS] SWI_Functors void void
struct swi_reverse_hash swi_reverse_hash[N_SWI_HASH] SWI_ReverseHash void void
Atom empty_wakeups[MAX_EMPTY_WAKEUPS] EmptyWakeups InitEmptyWakeups() RestoreEmptyWakeups()
int max_empty_wakeups MaxEmptyWakeups =0
/* SWI blobs */
struct PL_blob_t *swi_blob_types SWI_BlobTypes =NULL RestoreSWIBlobTypes()
struct AtomEntryStruct *swi_blobs SWI_Blobs =NULL RestoreSWIBlobs()

View File

@ -21,8 +21,9 @@
:- dynamic dbloading/6, dbprocess/2.
dbload_from_stream(R, M0, Type) :-
repeat,
read(R,T),
( T = end_of_file -> !, close_dbload(R, Type);
( T == end_of_file -> !, close_dbload(R, Type);
dbload_count(T, M0),
fail
).
@ -166,8 +167,13 @@ load_exofacts.
exodb_add_facts(R, M) :-
repeat,
catch(read(R,T), _, fail),
( T = end_of_file -> !;
catch(protected_exodb_add_fact(R, M), _, fail),
!.
protected_exodb_add_fact(R, M) :-
repeat,
read(R,T),
( T == end_of_file -> !;
exodb_add_fact(T, M),
fail
).