From 923be33404444bbd174020838595cfdf347c62c3 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 30 Apr 2013 15:23:01 -0500 Subject: [PATCH] speedup between more exo stuff. --- C/attvar.c | 26 ++++++++++++++++++++++++++ C/eval.c | 7 +++---- C/exo_udi.c | 8 +++++--- C/heapgc.c | 8 ++++++++ C/init.c | 5 +++++ H/Yap.h | 2 ++ H/Yapproto.h | 1 + H/arith2.h | 25 ------------------------- H/dhstruct.h | 2 ++ H/eval.h | 25 +++++++++++++++++++++++++ H/hstruct.h | 2 ++ H/ihstruct.h | 2 ++ H/rheap.h | 9 +++++++++ H/rhstruct.h | 2 ++ misc/HEAPFIELDS | 3 +++ pl/dbload.yap | 12 +++++++++--- 16 files changed, 104 insertions(+), 35 deletions(-) diff --git a/C/attvar.c b/C/attvar.c index 1173381e9..fa27f2f14 100644 --- a/C/attvar.c +++ b/C/attvar.c @@ -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)) { diff --git a/C/eval.c b/C/eval.c index f51ce1ff1..4750aecaf 100644 --- a/C/eval.c +++ b/C/eval.c @@ -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 { diff --git a/C/exo_udi.c b/C/exo_udi.c index aef754e36..e0133a971 100644 --- a/C/exo_udi.c +++ b/C/exo_udi.c @@ -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; diff --git a/C/heapgc.c b/C/heapgc.c index a04ba31b0..5194feba1 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -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; diff --git a/C/init.c b/C/init.c index 1ecb37e74..c385c0341 100755 --- a/C/init.c +++ b/C/init.c @@ -1022,6 +1022,11 @@ InitSWIAtoms(void) ATOM_ = PL_new_atom(""); } +static void +InitEmptyWakeups(void) +{ +} + static void InitAtoms(void) { diff --git a/H/Yap.h b/H/Yap.h index 04457def9..21dbd344e 100755 --- a/H/Yap.h +++ b/H/Yap.h @@ -542,6 +542,8 @@ typedef enum GPROF_NEW_EXPAND_BLOCK } gprof_info; +#define MAX_EMPTY_WAKEUPS 16 + /************************************************************************************************* prototypes diff --git a/H/Yapproto.h b/H/Yapproto.h index 3d02c3d3f..5a30d728d 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -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); diff --git a/H/arith2.h b/H/arith2.h index b3691801b..9a996a4a5 100755 --- a/H/arith2.h +++ b/H/arith2.h @@ -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) { diff --git a/H/dhstruct.h b/H/dhstruct.h index d7bf6e30b..6d705b956 100644 --- a/H/dhstruct.h +++ b/H/dhstruct.h @@ -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 diff --git a/H/eval.h b/H/eval.h index 3300ecc35..54ca42910 100644 --- a/H/eval.h +++ b/H/eval.h @@ -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 +} diff --git a/H/hstruct.h b/H/hstruct.h index 5ca04cef0..a13deaddf 100644 --- a/H/hstruct.h +++ b/H/hstruct.h @@ -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; diff --git a/H/ihstruct.h b/H/ihstruct.h index a91b32da0..3f5d3e958 100644 --- a/H/ihstruct.h +++ b/H/ihstruct.h @@ -298,6 +298,8 @@ InitSWIAtoms(); + InitEmptyWakeups(); + MaxEmptyWakeups = 0; SWI_BlobTypes = NULL; SWI_Blobs = NULL; diff --git a/H/rheap.h b/H/rheap.h index b16c11b9b..6b7c7b5fa 100644 --- a/H/rheap.h +++ b/H/rheap.h @@ -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) diff --git a/H/rhstruct.h b/H/rhstruct.h index 47ff43a52..5eac3e469 100644 --- a/H/rhstruct.h +++ b/H/rhstruct.h @@ -298,6 +298,8 @@ RestoreSWIAtoms(); + RestoreEmptyWakeups(); + RestoreSWIBlobTypes(); RestoreSWIBlobs(); diff --git a/misc/HEAPFIELDS b/misc/HEAPFIELDS index ed10fa125..4b70c98b7 100644 --- a/misc/HEAPFIELDS +++ b/misc/HEAPFIELDS @@ -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() diff --git a/pl/dbload.yap b/pl/dbload.yap index 7f513fe29..7d528f3f8 100644 --- a/pl/dbload.yap +++ b/pl/dbload.yap @@ -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 ).