From 16c1056a015fe45b9cbfae2a3b3bc3fc17e457c4 Mon Sep 17 00:00:00 2001 From: Ricardo Rocha Date: Fri, 23 Apr 2010 04:22:10 +0100 Subject: [PATCH] tabling support for the common global trie is now available by default (macro GLOBAL_TRIE was removed). Use 'yap_flag(tabling_mode,MODE)' to set the storing mode for all tabled predicates to MODE ('local_trie' or 'global_trie). Alternatively, use 'tabling_mode(PRED,MODE)' to set the default tabling mode of predicate PRED to MODE ('local_trie' or 'global_trie'). The default mode for all tabled predicates is 'local_trie'. --- OPTYap/opt.config.h | 14 +- OPTYap/opt.init.c | 12 +- OPTYap/opt.macros.h | 587 +++++++++++----------- OPTYap/opt.preds.c | 179 ++++--- OPTYap/opt.proto.h | 16 +- OPTYap/opt.structs.h | 20 +- OPTYap/tab.macros.h | 26 +- OPTYap/tab.structs.h | 72 ++- OPTYap/tab.tries.c | 1008 +++++++++++++++++--------------------- OPTYap/tab.tries.i | 156 +++--- OPTYap/tab.tries.insts.i | 130 +++-- pl/yapor.yap | 4 +- 12 files changed, 1059 insertions(+), 1165 deletions(-) diff --git a/OPTYap/opt.config.h b/OPTYap/opt.config.h index 8ecc806ea..2d3f58ab3 100644 --- a/OPTYap/opt.config.h +++ b/OPTYap/opt.config.h @@ -51,10 +51,9 @@ ******************************************************/ #define TRIE_COMPACT_PAIRS 1 -/*********************************************************** -** support global trie ? (optional, define one) ** -***********************************************************/ -/* #define GLOBAL_TRIE_FOR_TERMS 1 */ +/************************************************************ +** support global trie for subterms ? (optional) ** +************************************************************/ /* #define GLOBAL_TRIE_FOR_SUBTERMS 1 */ /****************************************************** @@ -189,12 +188,6 @@ #if defined(BFZ_TRAIL_SCHEME) && defined(BBREG_TRAIL_SCHEME) #error Do not define multiple trail schemes #endif /* BFZ_TRAIL_SCHEME && BBREG_TRAIL_SCHEME */ -#if defined(GLOBAL_TRIE_FOR_TERMS) && defined(GLOBAL_TRIE_FOR_SUBTERMS) -#error Do not define multiple global trie schemes -#endif /* GLOBAL_TRIE_FOR_TERMS && GLOBAL_TRIE_FOR_SUBTERMS */ -#if defined(GLOBAL_TRIE_FOR_TERMS) || defined(GLOBAL_TRIE_FOR_SUBTERMS) -#define GLOBAL_TRIE -#endif /* GLOBAL_TRIE_FOR_TERMS || GLOBAL_TRIE_FOR_SUBTERMS */ #endif /* TABLING */ #if defined(YAPOR) && defined(TABLING) @@ -233,7 +226,6 @@ #undef BBREG_TRAIL_SCHEME #undef TABLING_EARLY_COMPLETION #undef TRIE_COMPACT_PAIRS -#undef GLOBAL_TRIE_FOR_TERMS #undef GLOBAL_TRIE_FOR_SUBTERMS #undef DETERMINISTIC_TABLING #undef LIMIT_TABLING diff --git a/OPTYap/opt.init.c b/OPTYap/opt.init.c index 23d1cb0e5..70254370b 100644 --- a/OPTYap/opt.init.c +++ b/OPTYap/opt.init.c @@ -99,17 +99,15 @@ void Yap_init_global(int max_table_size, int n_workers, int sch_loop, int delay_ INIT_PAGES(GLOBAL_PAGES_tg_ans_fr, struct table_subgoal_answer_frame); #endif /* TABLING_INNER_CUTS */ #ifdef TABLING -#ifdef GLOBAL_TRIE - INIT_PAGES(GLOBAL_PAGES_gt_node, struct global_trie_node); - INIT_PAGES(GLOBAL_PAGES_gt_hash, struct global_trie_hash); -#endif /* GLOBAL_TRIE */ INIT_PAGES(GLOBAL_PAGES_tab_ent, struct table_entry); INIT_PAGES(GLOBAL_PAGES_sg_fr, struct subgoal_frame); + INIT_PAGES(GLOBAL_PAGES_dep_fr, struct dependency_frame); INIT_PAGES(GLOBAL_PAGES_sg_node, struct subgoal_trie_node); INIT_PAGES(GLOBAL_PAGES_ans_node, struct answer_trie_node); + INIT_PAGES(GLOBAL_PAGES_gt_node, struct global_trie_node); INIT_PAGES(GLOBAL_PAGES_sg_hash, struct subgoal_trie_hash); INIT_PAGES(GLOBAL_PAGES_ans_hash, struct answer_trie_hash); - INIT_PAGES(GLOBAL_PAGES_dep_fr, struct dependency_frame); + INIT_PAGES(GLOBAL_PAGES_gt_hash, struct global_trie_hash); #endif /* TABLING */ #if defined(YAPOR) && defined(TABLING) INIT_PAGES(GLOBAL_PAGES_susp_fr, struct suspension_frame); @@ -158,10 +156,8 @@ void Yap_init_global(int max_table_size, int n_workers, int sch_loop, int delay_ #ifdef TABLING /* global data related to tabling */ - GLOBAL_root_tab_ent = NULL; -#ifdef GLOBAL_TRIE new_global_trie_node(GLOBAL_root_gt, 0, NULL, NULL, NULL); -#endif /* GLOBAL_TRIE */ + GLOBAL_root_tab_ent = NULL; #ifdef LIMIT_TABLING GLOBAL_first_sg_fr = NULL; GLOBAL_last_sg_fr = NULL; diff --git a/OPTYap/opt.macros.h b/OPTYap/opt.macros.h index f4b14de6a..e2f439fee 100644 --- a/OPTYap/opt.macros.h +++ b/OPTYap/opt.macros.h @@ -45,332 +45,333 @@ extern int Yap_page_size; #ifdef MALLOC_MEMORY_ALLOC_SCHEME -/******************************************************************************************************** -** MALLOC_MEMORY_ALLOC_SCHEME ** -********************************************************************************************************/ -#define ALLOC_BLOCK(STR, SIZE, STR_TYPE) \ - if ((STR = (STR_TYPE *) malloc(SIZE)) == NULL) \ +/************************************************************************************************* +** MALLOC_MEMORY_ALLOC_SCHEME ** +*************************************************************************************************/ +#define ALLOC_BLOCK(STR, SIZE, STR_TYPE) \ + if ((STR = (STR_TYPE *) malloc(SIZE)) == NULL) \ Yap_Error(FATAL_ERROR, TermNil, "ALLOC_BLOCK: malloc error") -#define FREE_BLOCK(STR) \ +#define FREE_BLOCK(STR) \ free(STR) #else -/******************************************************************************************************** -** ! MALLOC_MEMORY_ALLOC_SCHEME ** -********************************************************************************************************/ -#define ALLOC_BLOCK(STR, SIZE, STR_TYPE) \ - { char *block_ptr; \ - if ((block_ptr = Yap_AllocCodeSpace(SIZE + sizeof(CELL))) != NULL) \ - *block_ptr = 'y'; \ - else if ((block_ptr = (char *) malloc(SIZE + sizeof(CELL))) != NULL) \ - *block_ptr = 'm'; \ - else \ - Yap_Error(FATAL_ERROR, TermNil, "ALLOC_BLOCK: malloc error"); \ - block_ptr += sizeof(CELL); \ - STR = (STR_TYPE *) block_ptr; \ +/************************************************************************************************* +** ! MALLOC_MEMORY_ALLOC_SCHEME ** +*************************************************************************************************/ +#define ALLOC_BLOCK(STR, SIZE, STR_TYPE) \ + { char *block_ptr; \ + if ((block_ptr = Yap_AllocCodeSpace(SIZE + sizeof(CELL))) != NULL) \ + *block_ptr = 'y'; \ + else if ((block_ptr = (char *) malloc(SIZE + sizeof(CELL))) != NULL) \ + *block_ptr = 'm'; \ + else \ + Yap_Error(FATAL_ERROR, TermNil, "ALLOC_BLOCK: malloc error"); \ + block_ptr += sizeof(CELL); \ + STR = (STR_TYPE *) block_ptr; \ } -#define FREE_BLOCK(STR) \ - { char *block_ptr = (char *)(STR) - sizeof(CELL); \ - if (block_ptr[0] == 'y') \ - Yap_FreeCodeSpace(block_ptr); \ - else \ - free(block_ptr); \ +#define FREE_BLOCK(STR) \ + { char *block_ptr = (char *)(STR) - sizeof(CELL); \ + if (block_ptr[0] == 'y') \ + Yap_FreeCodeSpace(block_ptr); \ + else \ + free(block_ptr); \ } -#endif /************************************************************************************************/ +#endif /*****************************************************************************************/ #if defined(MALLOC_MEMORY_ALLOC_SCHEME) || defined(YAP_MEMORY_ALLOC_SCHEME) -/******************************************************************************************************** -** MALLOC_MEMORY_ALLOC_SCHEME || YAP_MEMORY_ALLOC_SCHEME ** -********************************************************************************************************/ -#define ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), 1); \ +/************************************************************************************************* +** MALLOC_MEMORY_ALLOC_SCHEME || YAP_MEMORY_ALLOC_SCHEME ** +*************************************************************************************************/ +#define ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), 1); \ ALLOC_BLOCK(STR, sizeof(STR_TYPE), STR_TYPE) -#define ALLOC_NEXT_FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ +#define ALLOC_NEXT_FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) -#define FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), -1); \ +#define FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), -1); \ FREE_BLOCK(STR) #elif SHM_MEMORY_ALLOC_SCHEME #ifdef LIMIT_TABLING -/******************************************************************************************************** -** SHM_MEMORY_ALLOC_SCHEME && LIMIT_TABLING ** -********************************************************************************************************/ -#define INIT_PAGE(PG_HD, STR_PAGES, STR_TYPE) \ - { int i; \ - STR_TYPE *aux_str; \ - PgHd_str_in_use(PG_HD) = 0; \ - PgHd_previous(PG_HD) = NULL; \ - aux_str = (STR_TYPE *) (PG_HD + 1); \ - PgHd_free_str(PG_HD) = (void *) aux_str; \ - for (i = 1; i < Pg_str_per_pg(STR_PAGES); i++) { \ - STRUCT_NEXT(aux_str) = aux_str + 1; \ - aux_str++; \ - } \ - STRUCT_NEXT(aux_str) = NULL; \ - LOCK(Pg_lock(STR_PAGES)); \ - if ((PgHd_next(PG_HD) = Pg_free_pg(STR_PAGES)) != NULL) \ - PgHd_previous(PgHd_next(PG_HD)) = PG_HD; \ - Pg_free_pg(STR_PAGES) = PG_HD; \ - UPDATE_STATS(Pg_pg_alloc(STR_PAGES), 1); \ +/************************************************************************************************* +** SHM_MEMORY_ALLOC_SCHEME && LIMIT_TABLING ** +*************************************************************************************************/ +#define INIT_PAGE(PG_HD, STR_PAGES, STR_TYPE) \ + { int i; \ + STR_TYPE *aux_str; \ + PgHd_str_in_use(PG_HD) = 0; \ + PgHd_previous(PG_HD) = NULL; \ + aux_str = (STR_TYPE *) (PG_HD + 1); \ + PgHd_free_str(PG_HD) = (void *) aux_str; \ + for (i = 1; i < Pg_str_per_pg(STR_PAGES); i++) { \ + STRUCT_NEXT(aux_str) = aux_str + 1; \ + aux_str++; \ + } \ + STRUCT_NEXT(aux_str) = NULL; \ + LOCK(Pg_lock(STR_PAGES)); \ + if ((PgHd_next(PG_HD) = Pg_free_pg(STR_PAGES)) != NULL) \ + PgHd_previous(PgHd_next(PG_HD)) = PG_HD; \ + Pg_free_pg(STR_PAGES) = PG_HD; \ + UPDATE_STATS(Pg_pg_alloc(STR_PAGES), 1); \ } -#define ALLOC_PAGE(PG_HD) \ - { int i, shmid; \ - pg_hd_ptr aux_pg_hd; \ - if ((shmid = shmget(IPC_PRIVATE, SHMMAX, SHM_R|SHM_W)) == -1) \ - Yap_Error(FATAL_ERROR, TermNil, "shmget error (ALLOC_PAGE)"); \ - if ((PG_HD = (pg_hd_ptr) shmat(shmid, NULL, 0)) == (void *) -1) \ - Yap_Error(FATAL_ERROR, TermNil, "shmat error (ALLOC_PAGE)"); \ - if (shmctl(shmid, IPC_RMID, 0) != 0) \ - Yap_Error(FATAL_ERROR, TermNil, "shmctl error (ALLOC_PAGE)"); \ - aux_pg_hd = (pg_hd_ptr)(((void *)PG_HD) + Yap_page_size); \ - Pg_free_pg(GLOBAL_PAGES_void) = aux_pg_hd; \ - for (i = 2; i < SHMMAX / Yap_page_size; i++) { \ - PgHd_next(aux_pg_hd) = (pg_hd_ptr)(((void *)aux_pg_hd) + Yap_page_size); \ - aux_pg_hd = PgHd_next(aux_pg_hd); \ - } \ - PgHd_next(aux_pg_hd) = NULL; \ - UPDATE_STATS(Pg_pg_alloc(GLOBAL_PAGES_void), SHMMAX / Yap_page_size); \ +#define ALLOC_PAGE(PG_HD) \ + { int i, shmid; \ + pg_hd_ptr aux_pg_hd; \ + if ((shmid = shmget(IPC_PRIVATE, SHMMAX, SHM_R|SHM_W)) == -1) \ + Yap_Error(FATAL_ERROR, TermNil, "shmget error (ALLOC_PAGE)"); \ + if ((PG_HD = (pg_hd_ptr) shmat(shmid, NULL, 0)) == (void *) -1) \ + Yap_Error(FATAL_ERROR, TermNil, "shmat error (ALLOC_PAGE)"); \ + if (shmctl(shmid, IPC_RMID, 0) != 0) \ + Yap_Error(FATAL_ERROR, TermNil, "shmctl error (ALLOC_PAGE)"); \ + aux_pg_hd = (pg_hd_ptr)(((void *)PG_HD) + Yap_page_size); \ + Pg_free_pg(GLOBAL_PAGES_void) = aux_pg_hd; \ + for (i = 2; i < SHMMAX / Yap_page_size; i++) { \ + PgHd_next(aux_pg_hd) = (pg_hd_ptr)(((void *)aux_pg_hd) + Yap_page_size); \ + aux_pg_hd = PgHd_next(aux_pg_hd); \ + } \ + PgHd_next(aux_pg_hd) = NULL; \ + UPDATE_STATS(Pg_pg_alloc(GLOBAL_PAGES_void), SHMMAX / Yap_page_size); \ } -#define RECOVER_UNUSED_SPACE(STR_PAGES) \ - { sg_fr_ptr sg_fr = GLOBAL_check_sg_fr; \ - do { \ - if (sg_fr) \ - sg_fr = SgFr_next(sg_fr); \ - else \ - sg_fr = GLOBAL_first_sg_fr; \ - if (sg_fr == NULL) \ - Yap_Error(FATAL_ERROR, TermNil, "no space left (RECOVER_UNUSED_SPACE)"); \ - /* see function 'InteractSIGINT' in file 'sysbits.c' */ \ - /* Yap_Error(PURE_ABORT, TermNil, ""); */ \ - /* restore_absmi_regs(&Yap_standard_regs); */ \ - /* siglongjmp (Yap_RestartEnv, 1); */ \ - if (SgFr_first_answer(sg_fr) && \ - SgFr_first_answer(sg_fr) != SgFr_answer_trie(sg_fr)) { \ - SgFr_state(sg_fr) = ready; \ - free_answer_trie_hash_chain(SgFr_hash_chain(sg_fr)); \ - SgFr_hash_chain(sg_fr) = NULL; \ - SgFr_first_answer(sg_fr) = NULL; \ - SgFr_last_answer(sg_fr) = NULL; \ - free_answer_trie_branch(TrNode_child(SgFr_answer_trie(sg_fr)), TRAVERSE_POSITION_FIRST); \ - TrNode_child(SgFr_answer_trie(sg_fr)) = NULL; \ - } \ - } while (Pg_free_pg(GLOBAL_PAGES_void) == Pg_free_pg(STR_PAGES)); \ - GLOBAL_check_sg_fr = sg_fr; \ +#define RECOVER_UNUSED_SPACE(STR_PAGES) \ + { sg_fr_ptr sg_fr = GLOBAL_check_sg_fr; \ + do { \ + if (sg_fr) \ + sg_fr = SgFr_next(sg_fr); \ + else \ + sg_fr = GLOBAL_first_sg_fr; \ + if (sg_fr == NULL) \ + Yap_Error(FATAL_ERROR, TermNil, "no space left (RECOVER_UNUSED_SPACE)"); \ + /* see function 'InteractSIGINT' in file 'sysbits.c' */ \ + /* Yap_Error(PURE_ABORT, TermNil, ""); */ \ + /* restore_absmi_regs(&Yap_standard_regs); */ \ + /* siglongjmp (Yap_RestartEnv, 1); */ \ + if (SgFr_first_answer(sg_fr) && \ + SgFr_first_answer(sg_fr) != SgFr_answer_trie(sg_fr)) { \ + SgFr_state(sg_fr) = ready; \ + free_answer_hash_chain(SgFr_hash_chain(sg_fr)); \ + SgFr_hash_chain(sg_fr) = NULL; \ + SgFr_first_answer(sg_fr) = NULL; \ + SgFr_last_answer(sg_fr) = NULL; \ + free_answer_trie(TrNode_child(SgFr_answer_trie(sg_fr)), \ + TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); \ + TrNode_child(SgFr_answer_trie(sg_fr)) = NULL; \ + } \ + } while (Pg_free_pg(GLOBAL_PAGES_void) == Pg_free_pg(STR_PAGES)); \ + GLOBAL_check_sg_fr = sg_fr; \ } -#define ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) \ - { pg_hd_ptr pg_hd; \ - LOCK(Pg_lock(STR_PAGES)); \ - pg_hd = Pg_free_pg(STR_PAGES); \ - while (pg_hd == NULL) { \ - UNLOCK(Pg_lock(STR_PAGES)); \ - LOCK(Pg_lock(GLOBAL_PAGES_void)); \ - if (Pg_free_pg(GLOBAL_PAGES_void)) { \ - pg_hd = Pg_free_pg(GLOBAL_PAGES_void); \ - Pg_free_pg(GLOBAL_PAGES_void) = PgHd_next(pg_hd); \ - UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ - UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ - INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ - } else if (GLOBAL_MAX_PAGES != Pg_pg_alloc(GLOBAL_PAGES_void)) { \ - ALLOC_PAGE(pg_hd); \ - UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ - UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ - INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ - } else { \ - UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ - RECOVER_UNUSED_SPACE(STR_PAGES); \ - LOCK(Pg_lock(STR_PAGES)); \ - pg_hd = Pg_free_pg(STR_PAGES); \ - } \ - } \ - PgHd_str_in_use(pg_hd)++; \ - STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ - if ((PgHd_free_str(pg_hd) = (void *) STRUCT_NEXT(STR)) == NULL) \ - if ((Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd)) != NULL) \ - PgHd_previous(PgHd_next(pg_hd)) = NULL; \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), 1); \ - UNLOCK(Pg_lock(STR_PAGES)); \ +#define ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) \ + { pg_hd_ptr pg_hd; \ + LOCK(Pg_lock(STR_PAGES)); \ + pg_hd = Pg_free_pg(STR_PAGES); \ + while (pg_hd == NULL) { \ + UNLOCK(Pg_lock(STR_PAGES)); \ + LOCK(Pg_lock(GLOBAL_PAGES_void)); \ + if (Pg_free_pg(GLOBAL_PAGES_void)) { \ + pg_hd = Pg_free_pg(GLOBAL_PAGES_void); \ + Pg_free_pg(GLOBAL_PAGES_void) = PgHd_next(pg_hd); \ + UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ + UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ + INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ + } else if (GLOBAL_MAX_PAGES != Pg_pg_alloc(GLOBAL_PAGES_void)) { \ + ALLOC_PAGE(pg_hd); \ + UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ + UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ + INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ + } else { \ + UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ + RECOVER_UNUSED_SPACE(STR_PAGES); \ + LOCK(Pg_lock(STR_PAGES)); \ + pg_hd = Pg_free_pg(STR_PAGES); \ + } \ + } \ + PgHd_str_in_use(pg_hd)++; \ + STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ + if ((PgHd_free_str(pg_hd) = (void *) STRUCT_NEXT(STR)) == NULL) \ + if ((Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd)) != NULL) \ + PgHd_previous(PgHd_next(pg_hd)) = NULL; \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), 1); \ + UNLOCK(Pg_lock(STR_PAGES)); \ } -#define ALLOC_NEXT_FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ - if ((STR = LOCAL_next_free_ans_node) == NULL) { \ - pg_hd_ptr pg_hd; \ - LOCK(Pg_lock(STR_PAGES)); \ - pg_hd = Pg_free_pg(STR_PAGES); \ - while (pg_hd == NULL) { \ - UNLOCK(Pg_lock(STR_PAGES)); \ - LOCK(Pg_lock(GLOBAL_PAGES_void)); \ - if (Pg_free_pg(GLOBAL_PAGES_void)) { \ - pg_hd = Pg_free_pg(GLOBAL_PAGES_void); \ - Pg_free_pg(GLOBAL_PAGES_void) = PgHd_next(pg_hd); \ - UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ - UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ - INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ - } else if (GLOBAL_MAX_PAGES != Pg_pg_alloc(GLOBAL_PAGES_void)) { \ - ALLOC_PAGE(pg_hd); \ - UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ - UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ - INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ - } else { \ - UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ - RECOVER_UNUSED_SPACE(STR_PAGES); \ - LOCK(Pg_lock(STR_PAGES)); \ - pg_hd = Pg_free_pg(STR_PAGES); \ - } \ - } \ - PgHd_str_in_use(pg_hd) = Pg_str_per_pg(STR_PAGES); \ - STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ - PgHd_free_str(pg_hd) = NULL; \ - Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd); \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), -PgHd_str_in_use(pg_hd)); \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), Pg_str_per_pg(STR_PAGES)); \ - UNLOCK(Pg_lock(STR_PAGES)); \ - } \ +#define ALLOC_NEXT_FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ + if ((STR = LOCAL_next_free_ans_node) == NULL) { \ + pg_hd_ptr pg_hd; \ + LOCK(Pg_lock(STR_PAGES)); \ + pg_hd = Pg_free_pg(STR_PAGES); \ + while (pg_hd == NULL) { \ + UNLOCK(Pg_lock(STR_PAGES)); \ + LOCK(Pg_lock(GLOBAL_PAGES_void)); \ + if (Pg_free_pg(GLOBAL_PAGES_void)) { \ + pg_hd = Pg_free_pg(GLOBAL_PAGES_void); \ + Pg_free_pg(GLOBAL_PAGES_void) = PgHd_next(pg_hd); \ + UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ + UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ + INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ + } else if (GLOBAL_MAX_PAGES != Pg_pg_alloc(GLOBAL_PAGES_void)) { \ + ALLOC_PAGE(pg_hd); \ + UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ + UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ + INIT_PAGE(pg_hd, STR_PAGES, STR_TYPE); \ + } else { \ + UNLOCK(Pg_lock(GLOBAL_PAGES_void)); \ + RECOVER_UNUSED_SPACE(STR_PAGES); \ + LOCK(Pg_lock(STR_PAGES)); \ + pg_hd = Pg_free_pg(STR_PAGES); \ + } \ + } \ + PgHd_str_in_use(pg_hd) = Pg_str_per_pg(STR_PAGES); \ + STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ + PgHd_free_str(pg_hd) = NULL; \ + Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd); \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), -PgHd_str_in_use(pg_hd)); \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), Pg_str_per_pg(STR_PAGES)); \ + UNLOCK(Pg_lock(STR_PAGES)); \ + } \ LOCAL_next_free_ans_node = STRUCT_NEXT(STR) #else -/******************************************************************************************************** -** SHM_MEMORY_ALLOC_SCHEME && !LIMIT_TABLING ** -********************************************************************************************************/ -#define ALLOC_PAGE(PG_HD) \ - LOCK(Pg_lock(GLOBAL_PAGES_void)); \ - if (Pg_free_pg(GLOBAL_PAGES_void) == NULL) { \ - int i, shmid; \ - pg_hd_ptr pg_hd, aux_pg_hd; \ - if ((shmid = shmget(IPC_PRIVATE, SHMMAX, SHM_R|SHM_W)) == -1) \ - Yap_Error(FATAL_ERROR, TermNil, "shmget error (ALLOC_PAGE)"); \ - if ((pg_hd = (pg_hd_ptr) shmat(shmid, NULL, 0)) == (void *) -1) \ - Yap_Error(FATAL_ERROR, TermNil, "shmat error (ALLOC_PAGE)"); \ - if (shmctl(shmid, IPC_RMID, 0) != 0) \ - Yap_Error(FATAL_ERROR, TermNil, "shmctl error (ALLOC_PAGE)"); \ - Pg_free_pg(GLOBAL_PAGES_void) = pg_hd; \ - for (i = 1; i < SHMMAX / Yap_page_size; i++) { \ - aux_pg_hd = (pg_hd_ptr)(((void *)pg_hd) + Yap_page_size); \ - PgHd_next(pg_hd) = aux_pg_hd; \ - pg_hd = aux_pg_hd; \ - } \ - PgHd_next(pg_hd) = NULL; \ - UPDATE_STATS(Pg_pg_alloc(GLOBAL_PAGES_void), SHMMAX / Yap_page_size); \ - } \ - UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ - PG_HD = Pg_free_pg(GLOBAL_PAGES_void); \ - Pg_free_pg(GLOBAL_PAGES_void) = PgHd_next(PG_HD); \ +/************************************************************************************************* +** SHM_MEMORY_ALLOC_SCHEME && !LIMIT_TABLING ** +*************************************************************************************************/ +#define ALLOC_PAGE(PG_HD) \ + LOCK(Pg_lock(GLOBAL_PAGES_void)); \ + if (Pg_free_pg(GLOBAL_PAGES_void) == NULL) { \ + int i, shmid; \ + pg_hd_ptr pg_hd, aux_pg_hd; \ + if ((shmid = shmget(IPC_PRIVATE, SHMMAX, SHM_R|SHM_W)) == -1) \ + Yap_Error(FATAL_ERROR, TermNil, "shmget error (ALLOC_PAGE)"); \ + if ((pg_hd = (pg_hd_ptr) shmat(shmid, NULL, 0)) == (void *) -1) \ + Yap_Error(FATAL_ERROR, TermNil, "shmat error (ALLOC_PAGE)"); \ + if (shmctl(shmid, IPC_RMID, 0) != 0) \ + Yap_Error(FATAL_ERROR, TermNil, "shmctl error (ALLOC_PAGE)"); \ + Pg_free_pg(GLOBAL_PAGES_void) = pg_hd; \ + for (i = 1; i < SHMMAX / Yap_page_size; i++) { \ + aux_pg_hd = (pg_hd_ptr)(((void *)pg_hd) + Yap_page_size); \ + PgHd_next(pg_hd) = aux_pg_hd; \ + pg_hd = aux_pg_hd; \ + } \ + PgHd_next(pg_hd) = NULL; \ + UPDATE_STATS(Pg_pg_alloc(GLOBAL_PAGES_void), SHMMAX / Yap_page_size); \ + } \ + UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), 1); \ + PG_HD = Pg_free_pg(GLOBAL_PAGES_void); \ + Pg_free_pg(GLOBAL_PAGES_void) = PgHd_next(PG_HD); \ UNLOCK(Pg_lock(GLOBAL_PAGES_void)) -#define ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) \ - { pg_hd_ptr pg_hd; \ - LOCK(Pg_lock(STR_PAGES)); \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), 1); \ - if (Pg_free_pg(STR_PAGES)) { \ - pg_hd = Pg_free_pg(STR_PAGES); \ - PgHd_str_in_use(pg_hd)++; \ - STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ - if ((PgHd_free_str(pg_hd) = (void *) STRUCT_NEXT(STR)) == NULL) \ - if ((Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd)) != NULL) \ - PgHd_previous(PgHd_next(pg_hd)) = NULL; \ - UNLOCK(Pg_lock(STR_PAGES)); \ - } else { \ - int i; \ - UPDATE_STATS(Pg_pg_alloc(STR_PAGES), 1); \ - UNLOCK(Pg_lock(STR_PAGES)); \ - ALLOC_PAGE(pg_hd); \ - PgHd_str_in_use(pg_hd) = 1; \ - PgHd_previous(pg_hd) = NULL; \ - STR = (STR_TYPE *) (pg_hd + 1); \ - PgHd_free_str(pg_hd) = (void *) ++STR; \ - for (i = Pg_str_per_pg(STR_PAGES); i != 2; i--) { \ - STRUCT_NEXT(STR) = STR + 1; \ - STR++; \ - } \ - STRUCT_NEXT(STR) = NULL; \ - STR = (STR_TYPE *) (pg_hd + 1); \ - LOCK(Pg_lock(STR_PAGES)); \ - if ((PgHd_next(pg_hd) = Pg_free_pg(STR_PAGES)) != NULL) \ - PgHd_previous(PgHd_next(pg_hd)) = pg_hd; \ - Pg_free_pg(STR_PAGES) = pg_hd; \ - UNLOCK(Pg_lock(STR_PAGES)); \ - } \ +#define ALLOC_STRUCT(STR, STR_PAGES, STR_TYPE) \ + { pg_hd_ptr pg_hd; \ + LOCK(Pg_lock(STR_PAGES)); \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), 1); \ + if (Pg_free_pg(STR_PAGES)) { \ + pg_hd = Pg_free_pg(STR_PAGES); \ + PgHd_str_in_use(pg_hd)++; \ + STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ + if ((PgHd_free_str(pg_hd) = (void *) STRUCT_NEXT(STR)) == NULL) \ + if ((Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd)) != NULL) \ + PgHd_previous(PgHd_next(pg_hd)) = NULL; \ + UNLOCK(Pg_lock(STR_PAGES)); \ + } else { \ + int i; \ + UPDATE_STATS(Pg_pg_alloc(STR_PAGES), 1); \ + UNLOCK(Pg_lock(STR_PAGES)); \ + ALLOC_PAGE(pg_hd); \ + PgHd_str_in_use(pg_hd) = 1; \ + PgHd_previous(pg_hd) = NULL; \ + STR = (STR_TYPE *) (pg_hd + 1); \ + PgHd_free_str(pg_hd) = (void *) ++STR; \ + for (i = Pg_str_per_pg(STR_PAGES); i != 2; i--) { \ + STRUCT_NEXT(STR) = STR + 1; \ + STR++; \ + } \ + STRUCT_NEXT(STR) = NULL; \ + STR = (STR_TYPE *) (pg_hd + 1); \ + LOCK(Pg_lock(STR_PAGES)); \ + if ((PgHd_next(pg_hd) = Pg_free_pg(STR_PAGES)) != NULL) \ + PgHd_previous(PgHd_next(pg_hd)) = pg_hd; \ + Pg_free_pg(STR_PAGES) = pg_hd; \ + UNLOCK(Pg_lock(STR_PAGES)); \ + } \ } -#define ALLOC_NEXT_FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ - if ((STR = LOCAL_next_free_ans_node) == NULL) { \ - pg_hd_ptr pg_hd; \ - LOCK(Pg_lock(STR_PAGES)); \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), Pg_str_per_pg(STR_PAGES)); \ - if (Pg_free_pg(STR_PAGES)) { \ - pg_hd = Pg_free_pg(STR_PAGES); \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), -PgHd_str_in_use(pg_hd)); \ - PgHd_str_in_use(pg_hd) = Pg_str_per_pg(STR_PAGES); \ - STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ - PgHd_free_str(pg_hd) = NULL; \ - Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd); \ - UNLOCK(Pg_lock(STR_PAGES)); \ - } else { \ - int i; \ - UPDATE_STATS(Pg_pg_alloc(STR_PAGES), 1); \ - UNLOCK(Pg_lock(STR_PAGES)); \ - ALLOC_PAGE(pg_hd); \ - PgHd_str_in_use(pg_hd) = Pg_str_per_pg(STR_PAGES); \ - PgHd_free_str(pg_hd) = NULL; \ - PgHd_previous(pg_hd) = NULL; \ - PgHd_next(pg_hd) = NULL; \ - STR = (STR_TYPE *) (pg_hd + 1); \ - for (i = Pg_str_per_pg(STR_PAGES); i != 1; i--) { \ - STRUCT_NEXT(STR) = STR + 1; \ - STR++; \ - } \ - STRUCT_NEXT(STR) = NULL; \ - STR = (STR_TYPE *) (pg_hd + 1); \ - } \ - } \ +#define ALLOC_NEXT_FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ + if ((STR = LOCAL_next_free_ans_node) == NULL) { \ + pg_hd_ptr pg_hd; \ + LOCK(Pg_lock(STR_PAGES)); \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), Pg_str_per_pg(STR_PAGES)); \ + if (Pg_free_pg(STR_PAGES)) { \ + pg_hd = Pg_free_pg(STR_PAGES); \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), -PgHd_str_in_use(pg_hd)); \ + PgHd_str_in_use(pg_hd) = Pg_str_per_pg(STR_PAGES); \ + STR = (STR_TYPE *) PgHd_free_str(pg_hd); \ + PgHd_free_str(pg_hd) = NULL; \ + Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd); \ + UNLOCK(Pg_lock(STR_PAGES)); \ + } else { \ + int i; \ + UPDATE_STATS(Pg_pg_alloc(STR_PAGES), 1); \ + UNLOCK(Pg_lock(STR_PAGES)); \ + ALLOC_PAGE(pg_hd); \ + PgHd_str_in_use(pg_hd) = Pg_str_per_pg(STR_PAGES); \ + PgHd_free_str(pg_hd) = NULL; \ + PgHd_previous(pg_hd) = NULL; \ + PgHd_next(pg_hd) = NULL; \ + STR = (STR_TYPE *) (pg_hd + 1); \ + for (i = Pg_str_per_pg(STR_PAGES); i != 1; i--) { \ + STRUCT_NEXT(STR) = STR + 1; \ + STR++; \ + } \ + STRUCT_NEXT(STR) = NULL; \ + STR = (STR_TYPE *) (pg_hd + 1); \ + } \ + } \ LOCAL_next_free_ans_node = STRUCT_NEXT(STR) #endif /* LIMIT_TABLING */ -/******************************************************************************************************** -** SHM_MEMORY_ALLOC_SCHEME ** -********************************************************************************************************/ -#define FREE_PAGE(PG_HD) \ - LOCK(Pg_lock(GLOBAL_PAGES_void)); \ - UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), -1); \ - PgHd_next(PG_HD) = Pg_free_pg(GLOBAL_PAGES_void); \ - Pg_free_pg(GLOBAL_PAGES_void) = PG_HD; \ +/************************************************************************************************* +** SHM_MEMORY_ALLOC_SCHEME ** +*************************************************************************************************/ +#define FREE_PAGE(PG_HD) \ + LOCK(Pg_lock(GLOBAL_PAGES_void)); \ + UPDATE_STATS(Pg_str_in_use(GLOBAL_PAGES_void), -1); \ + PgHd_next(PG_HD) = Pg_free_pg(GLOBAL_PAGES_void); \ + Pg_free_pg(GLOBAL_PAGES_void) = PG_HD; \ UNLOCK(Pg_lock(GLOBAL_PAGES_void)) -#define FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ - { pg_hd_ptr pg_hd; \ - pg_hd = PAGE_HEADER(STR); \ - LOCK(Pg_lock(STR_PAGES)); \ - UPDATE_STATS(Pg_str_in_use(STR_PAGES), -1); \ - if (--PgHd_str_in_use(pg_hd) == 0) { \ - UPDATE_STATS(Pg_pg_alloc(STR_PAGES), -1); \ - if (PgHd_previous(pg_hd)) { \ - if ((PgHd_next(PgHd_previous(pg_hd)) = PgHd_next(pg_hd)) != NULL) \ - PgHd_previous(PgHd_next(pg_hd)) = PgHd_previous(pg_hd); \ - } else { \ - if ((Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd)) != NULL) \ - PgHd_previous(PgHd_next(pg_hd)) = NULL; \ - } \ - UNLOCK(Pg_lock(STR_PAGES)); \ - FREE_PAGE(pg_hd); \ - } else { \ - if ((STRUCT_NEXT(STR) = (STR_TYPE *) PgHd_free_str(pg_hd)) == NULL) { \ - PgHd_previous(pg_hd) = NULL; \ - if ((PgHd_next(pg_hd) = Pg_free_pg(STR_PAGES)) != NULL) \ - PgHd_previous(PgHd_next(pg_hd)) = pg_hd; \ - Pg_free_pg(STR_PAGES) = pg_hd; \ - } \ - PgHd_free_str(pg_hd) = (void *) STR; \ - UNLOCK(Pg_lock(STR_PAGES)); \ - } \ +#define FREE_STRUCT(STR, STR_PAGES, STR_TYPE) \ + { pg_hd_ptr pg_hd; \ + pg_hd = PAGE_HEADER(STR); \ + LOCK(Pg_lock(STR_PAGES)); \ + UPDATE_STATS(Pg_str_in_use(STR_PAGES), -1); \ + if (--PgHd_str_in_use(pg_hd) == 0) { \ + UPDATE_STATS(Pg_pg_alloc(STR_PAGES), -1); \ + if (PgHd_previous(pg_hd)) { \ + if ((PgHd_next(PgHd_previous(pg_hd)) = PgHd_next(pg_hd)) != NULL) \ + PgHd_previous(PgHd_next(pg_hd)) = PgHd_previous(pg_hd); \ + } else { \ + if ((Pg_free_pg(STR_PAGES) = PgHd_next(pg_hd)) != NULL) \ + PgHd_previous(PgHd_next(pg_hd)) = NULL; \ + } \ + UNLOCK(Pg_lock(STR_PAGES)); \ + FREE_PAGE(pg_hd); \ + } else { \ + if ((STRUCT_NEXT(STR) = (STR_TYPE *) PgHd_free_str(pg_hd)) == NULL) { \ + PgHd_previous(pg_hd) = NULL; \ + if ((PgHd_next(pg_hd) = Pg_free_pg(STR_PAGES)) != NULL) \ + PgHd_previous(PgHd_next(pg_hd)) = pg_hd; \ + Pg_free_pg(STR_PAGES) = pg_hd; \ + } \ + PgHd_free_str(pg_hd) = (void *) STR; \ + UNLOCK(Pg_lock(STR_PAGES)); \ + } \ } -#endif /************************************************************************************************/ +#endif /*****************************************************************************************/ -#define ALLOC_HASH_BUCKETS(BUCKET_PTR, NUM_BUCKETS) \ - { int i; void **bucket_ptr; \ - ALLOC_BLOCK(bucket_ptr, NUM_BUCKETS * sizeof(void *), void *); \ - BUCKET_PTR = (void *) bucket_ptr; \ - for (i = NUM_BUCKETS; i != 0; i--) \ - *bucket_ptr++ = NULL; \ +#define ALLOC_HASH_BUCKETS(BUCKET_PTR, NUM_BUCKETS) \ + { int i; void **bucket_ptr; \ + ALLOC_BLOCK(bucket_ptr, NUM_BUCKETS * sizeof(void *), void *); \ + BUCKET_PTR = (void *) bucket_ptr; \ + for (i = NUM_BUCKETS; i != 0; i--) \ + *bucket_ptr++ = NULL; \ } #define FREE_HASH_BUCKETS(BUCKET_PTR) FREE_BLOCK(BUCKET_PTR) diff --git a/OPTYap/opt.preds.c b/OPTYap/opt.preds.c index f48921f4f..6ecdc0622 100644 --- a/OPTYap/opt.preds.c +++ b/OPTYap/opt.preds.c @@ -45,12 +45,10 @@ static Int p_abolish_all_tables(void); static Int p_show_tabled_predicates(void); static Int p_show_table(void); static Int p_show_all_tables(void); -#ifdef GLOBAL_TRIE static Int p_show_global_trie(void); -static Int p_show_statistics_global_trie(void); -#endif /* GLOBAL_TRIE */ static Int p_show_statistics_table(void); static Int p_show_statistics_tabling(void); +static Int p_show_statistics_global_trie(void); #endif /* TABLING */ static Int p_yapor_threads(void); #ifdef YAPOR @@ -84,10 +82,8 @@ static inline long show_statistics_subgoal_trie_nodes(void); static inline long show_statistics_answer_trie_nodes(void); static inline long show_statistics_subgoal_trie_hashes(void); static inline long show_statistics_answer_trie_hashes(void); -#ifdef GLOBAL_TRIE static inline long show_statistics_global_trie_nodes(void); static inline long show_statistics_global_trie_hashes(void); -#endif /* GLOBAL_TRIE */ #endif /* TABLING */ #ifdef YAPOR static inline long show_statistics_or_frames(void); @@ -134,12 +130,10 @@ void Yap_init_optyap_preds(void) { Yap_InitCPred("show_tabled_predicates", 0, p_show_tabled_predicates, SafePredFlag|SyncPredFlag); Yap_InitCPred("$c_show_table", 2, p_show_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("show_all_tables", 0, p_show_all_tables, SafePredFlag|SyncPredFlag); -#ifdef GLOBAL_TRIE Yap_InitCPred("show_global_trie", 0, p_show_global_trie, SafePredFlag|SyncPredFlag); - Yap_InitCPred("global_trie_statistics", 0, p_show_statistics_global_trie, SafePredFlag|SyncPredFlag); -#endif /* GLOBAL_TRIE */ Yap_InitCPred("$c_table_statistics", 2, p_show_statistics_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("tabling_statistics", 0, p_show_statistics_tabling, SafePredFlag|SyncPredFlag); + Yap_InitCPred("global_trie_statistics", 0, p_show_statistics_global_trie, SafePredFlag|SyncPredFlag); #endif /* TABLING */ Yap_InitCPred("$c_yapor_threads", 1, p_yapor_threads, SafePredFlag|SyncPredFlag|HiddenPredFlag); #ifdef YAPOR @@ -339,15 +333,20 @@ static Int p_abolish_table(void) { return (FALSE); hash = TabEnt_hash_chain(tab_ent); TabEnt_hash_chain(tab_ent) = NULL; - free_subgoal_trie_hash_chain(hash); + free_subgoal_hash_chain(hash); sg_node = TrNode_child(TabEnt_subgoal_trie(tab_ent)); if (sg_node) { - TrNode_child(TabEnt_subgoal_trie(tab_ent)) = NULL; -#ifdef GLOBAL_TRIE - free_subgoal_trie_branch(sg_node, TabEnt_arity(tab_ent), TRAVERSE_POSITION_FIRST); -#else - free_subgoal_trie_branch(sg_node, TabEnt_arity(tab_ent), 0, TRAVERSE_POSITION_FIRST); -#endif /* GLOBAL_TRIE */ + if (TabEnt_arity(tab_ent)) { + TrNode_child(TabEnt_subgoal_trie(tab_ent)) = NULL; + free_subgoal_trie(sg_node, TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); + } else { + sg_fr_ptr sg_fr = UNTAG_SUBGOAL_LEAF_NODE(sg_node); + FREE_ANSWER_TRIE_NODE(SgFr_answer_trie(sg_fr)); +#ifdef LIMIT_TABLING + remove_from_global_sg_fr_list(sg_fr); +#endif /* LIMIT_TABLING */ + FREE_SUBGOAL_FRAME(sg_fr); + } } return (TRUE); } @@ -362,15 +361,20 @@ static Int p_abolish_all_tables(void) { while(tab_ent) { hash = TabEnt_hash_chain(tab_ent); TabEnt_hash_chain(tab_ent) = NULL; - free_subgoal_trie_hash_chain(hash); + free_subgoal_hash_chain(hash); sg_node = TrNode_child(TabEnt_subgoal_trie(tab_ent)); if (sg_node) { - TrNode_child(TabEnt_subgoal_trie(tab_ent)) = NULL; -#ifdef GLOBAL_TRIE - free_subgoal_trie_branch(sg_node, TabEnt_arity(tab_ent), TRAVERSE_POSITION_FIRST); -#else - free_subgoal_trie_branch(sg_node, TabEnt_arity(tab_ent), 0, TRAVERSE_POSITION_FIRST); -#endif /* GLOBAL_TRIE */ + if (TabEnt_arity(tab_ent)) { + TrNode_child(TabEnt_subgoal_trie(tab_ent)) = NULL; + free_subgoal_trie(sg_node, TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); + } else { + sg_fr_ptr sg_fr = UNTAG_SUBGOAL_LEAF_NODE(sg_node); + FREE_ANSWER_TRIE_NODE(SgFr_answer_trie(sg_fr)); +#ifdef LIMIT_TABLING + remove_from_global_sg_fr_list(sg_fr); +#endif /* LIMIT_TABLING */ + FREE_SUBGOAL_FRAME(sg_fr); + } } tab_ent = TabEnt_next(tab_ent); } @@ -423,18 +427,11 @@ static Int p_show_all_tables(void) { } -#ifdef GLOBAL_TRIE static Int p_show_global_trie(void) { show_global_trie(SHOW_MODE_STRUCTURE); return (TRUE); } -static Int p_show_statistics_global_trie(void) { - show_global_trie(SHOW_MODE_STATISTICS); - return (TRUE); -} -#endif /* GLOBAL_TRIE */ - static Int p_show_statistics_table(void) { Term mod, t; @@ -461,31 +458,29 @@ static Int p_show_statistics_tabling(void) { aux_bytes += show_statistics_table_entries(); aux_bytes += show_statistics_subgoal_frames(); aux_bytes += show_statistics_dependency_frames(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; aux_bytes = 0; - fprintf(Yap_stdout, "\nLocal trie data structures\n"); + fprintf(Yap_stdout, "Local trie data structures\n"); aux_bytes += show_statistics_subgoal_trie_nodes(); aux_bytes += show_statistics_answer_trie_nodes(); aux_bytes += show_statistics_subgoal_trie_hashes(); aux_bytes += show_statistics_answer_trie_hashes(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; -#ifdef GLOBAL_TRIE aux_bytes = 0; - fprintf(Yap_stdout, "\nGlobal trie data structures\n"); + fprintf(Yap_stdout, "Global trie data structures\n"); aux_bytes += show_statistics_global_trie_nodes(); aux_bytes += show_statistics_global_trie_hashes(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (III): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; -#endif /* GLOBAL_TRIE */ #ifdef SHM_MEMORY_ALLOC_SCHEME - fprintf(Yap_stdout, "\nTotal memory in use: %10ld bytes (%ld pages in use)\n", + fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n", total_bytes, Pg_str_in_use(GLOBAL_PAGES_void)); - fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", + fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Pg_pg_alloc(GLOBAL_PAGES_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_PAGES_void)); #else - fprintf(Yap_stdout, "\nTotal memory in use: %10ld bytes\n", total_bytes); + fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return (TRUE); @@ -493,6 +488,12 @@ static Int p_show_statistics_tabling(void) { #endif /* TABLING */ +static Int p_show_statistics_global_trie(void) { + show_global_trie(SHOW_MODE_STATISTICS); + return (TRUE); +} + + /********************************* ** YapOr C Predicates ** @@ -703,21 +704,21 @@ static Int p_show_statistics_or(void) { aux_bytes = 0; fprintf(Yap_stdout, "Execution data structures\n"); aux_bytes += show_statistics_or_frames(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; aux_bytes = 0; - fprintf(Yap_stdout, "\nCut support data structures\n"); + fprintf(Yap_stdout, "Cut support data structures\n"); aux_bytes += show_statistics_query_goal_solution_frames(); aux_bytes += show_statistics_query_goal_answer_frames(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; #ifdef SHM_MEMORY_ALLOC_SCHEME - fprintf(Yap_stdout, "\nTotal memory in use: %10ld bytes (%ld pages in use)\n", + fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n", total_bytes, Pg_str_in_use(GLOBAL_PAGES_void)); - fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", + fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Pg_pg_alloc(GLOBAL_PAGES_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_PAGES_void)); #else - fprintf(Yap_stdout, "\nTotal memory in use: %10ld bytes\n", total_bytes); + fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return (TRUE); @@ -741,41 +742,39 @@ static Int p_show_statistics_opt(void) { aux_bytes += show_statistics_dependency_frames(); aux_bytes += show_statistics_or_frames(); aux_bytes += show_statistics_suspension_frames(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; aux_bytes = 0; - fprintf(Yap_stdout, "\nLocal trie data structures\n"); + fprintf(Yap_stdout, "Local trie data structures\n"); aux_bytes += show_statistics_subgoal_trie_nodes(); aux_bytes += show_statistics_answer_trie_nodes(); aux_bytes += show_statistics_subgoal_trie_hashes(); aux_bytes += show_statistics_answer_trie_hashes(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; -#ifdef GLOBAL_TRIE aux_bytes = 0; - fprintf(Yap_stdout, "\nGlobal trie data structures\n"); + fprintf(Yap_stdout, "Global trie data structures\n"); aux_bytes += show_statistics_global_trie_nodes(); aux_bytes += show_statistics_global_trie_hashes(); - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (III): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; -#endif /* GLOBAL_TRIE */ aux_bytes = 0; - fprintf(Yap_stdout, "\nCut support data structures\n"); + fprintf(Yap_stdout, "Cut support data structures\n"); aux_bytes += show_statistics_query_goal_solution_frames(); aux_bytes += show_statistics_query_goal_answer_frames(); #ifdef TABLING_INNER_CUTS aux_bytes += show_statistics_table_subgoal_solution_frames(); aux_bytes += show_statistics_table_subgoal_answer_frames(); #endif /* TABLING_INNER_CUTS */ - fprintf(Yap_stdout, " Memory in use: %10ld bytes\n", aux_bytes); + fprintf(Yap_stdout, " Memory in use (IV): %10ld bytes\n\n", aux_bytes); total_bytes += aux_bytes; #ifdef SHM_MEMORY_ALLOC_SCHEME - fprintf(Yap_stdout, "\nTotal memory in use: %10ld bytes (%ld pages in use)\n", + fprintf(Yap_stdout, "Total memory in use (I+II+III+IV): %10ld bytes (%ld pages in use)\n", total_bytes, Pg_str_in_use(GLOBAL_PAGES_void)); - fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", + fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Pg_pg_alloc(GLOBAL_PAGES_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_PAGES_void)); #else - fprintf(Yap_stdout, "\nTotal memory in use: %10ld bytes\n", total_bytes); + fprintf(Yap_stdout, "Total memory in use (I+II+III+IV): %10ld bytes\n", total_bytes); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return (TRUE); @@ -798,10 +797,8 @@ static Int p_get_optyap_statistics(void) { bytes += Pg_str_in_use(GLOBAL_PAGES_ans_node) * sizeof(struct answer_trie_node); bytes += Pg_str_in_use(GLOBAL_PAGES_sg_hash) * sizeof(struct subgoal_trie_hash); bytes += Pg_str_in_use(GLOBAL_PAGES_ans_hash) * sizeof(struct answer_trie_hash); -#ifdef GLOBAL_TRIE bytes += Pg_str_in_use(GLOBAL_PAGES_gt_node) * sizeof(struct global_trie_node); bytes += Pg_str_in_use(GLOBAL_PAGES_gt_hash) * sizeof(struct global_trie_hash); -#endif /* GLOBAL_TRIE */ #endif /* TABLING */ #ifdef YAPOR bytes += Pg_str_in_use(GLOBAL_PAGES_or_fr) * sizeof(struct or_frame); @@ -850,7 +847,6 @@ static Int p_get_optyap_statistics(void) { bytes = Pg_str_in_use(GLOBAL_PAGES_ans_hash) * sizeof(struct answer_trie_hash); structs = Pg_str_in_use(GLOBAL_PAGES_ans_hash); } -#ifdef GLOBAL_TRIE if (value == 10) { /* global_trie_nodes */ bytes = Pg_str_in_use(GLOBAL_PAGES_gt_node) * sizeof(struct global_trie_node); structs = Pg_str_in_use(GLOBAL_PAGES_gt_node); @@ -859,7 +855,6 @@ static Int p_get_optyap_statistics(void) { bytes = Pg_str_in_use(GLOBAL_PAGES_gt_hash) * sizeof(struct global_trie_hash); structs = Pg_str_in_use(GLOBAL_PAGES_gt_hash); } -#endif /* GLOBAL_TRIE */ #endif /* TABLING */ #ifdef YAPOR if (value == 4) { /* or_frames */ @@ -1045,10 +1040,10 @@ static inline long show_statistics_table_entries(void) { } TABLING_ERROR_CHECKING(statistics_table_entries, Pg_str_free(GLOBAL_PAGES_tab_ent) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_tab_ent) * sizeof(struct table_entry), Pg_pg_alloc(GLOBAL_PAGES_tab_ent), Pg_str_in_use(GLOBAL_PAGES_tab_ent)); #else - fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_tab_ent) * sizeof(struct table_entry), Pg_str_in_use(GLOBAL_PAGES_tab_ent)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_tab_ent) * sizeof(struct table_entry); @@ -1073,10 +1068,10 @@ static inline long show_statistics_subgoal_frames(void) { } TABLING_ERROR_CHECKING(statistics_subgoal_frames, Pg_str_free(GLOBAL_PAGES_sg_fr) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_sg_fr) * sizeof(struct subgoal_frame), Pg_pg_alloc(GLOBAL_PAGES_sg_fr), Pg_str_in_use(GLOBAL_PAGES_sg_fr)); #else - fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_sg_fr) * sizeof(struct subgoal_frame), Pg_str_in_use(GLOBAL_PAGES_sg_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_sg_fr) * sizeof(struct subgoal_frame); @@ -1101,10 +1096,10 @@ static inline long show_statistics_dependency_frames(void) { } TABLING_ERROR_CHECKING(statistics_dependency_frames, Pg_str_free(GLOBAL_PAGES_dep_fr) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_dep_fr) * sizeof(struct dependency_frame), Pg_pg_alloc(GLOBAL_PAGES_dep_fr), Pg_str_in_use(GLOBAL_PAGES_dep_fr)); #else - fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_dep_fr) * sizeof(struct dependency_frame), Pg_str_in_use(GLOBAL_PAGES_dep_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_dep_fr) * sizeof(struct dependency_frame); @@ -1129,10 +1124,10 @@ static inline long show_statistics_subgoal_trie_nodes(void) { } TABLING_ERROR_CHECKING(statistics_subgoal_trie_nodes, Pg_str_free(GLOBAL_PAGES_sg_node) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_sg_node) * sizeof(struct subgoal_trie_node), Pg_pg_alloc(GLOBAL_PAGES_sg_node), Pg_str_in_use(GLOBAL_PAGES_sg_node)); #else - fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_sg_node) * sizeof(struct subgoal_trie_node), Pg_str_in_use(GLOBAL_PAGES_sg_node)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_sg_node) * sizeof(struct subgoal_trie_node); @@ -1157,10 +1152,10 @@ static inline long show_statistics_answer_trie_nodes(void) { } TABLING_ERROR_CHECKING(statistics_answer_trie_nodes, Pg_str_free(GLOBAL_PAGES_ans_node) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_ans_node) * sizeof(struct answer_trie_node), Pg_pg_alloc(GLOBAL_PAGES_ans_node), Pg_str_in_use(GLOBAL_PAGES_ans_node)); #else - fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_ans_node) * sizeof(struct answer_trie_node), Pg_str_in_use(GLOBAL_PAGES_ans_node)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_ans_node) * sizeof(struct answer_trie_node); @@ -1185,10 +1180,10 @@ static inline long show_statistics_subgoal_trie_hashes(void) { } TABLING_ERROR_CHECKING(statistics_subgoal_trie_hashes, Pg_str_free(GLOBAL_PAGES_sg_hash) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_pg_alloc(GLOBAL_PAGES_sg_hash), Pg_str_in_use(GLOBAL_PAGES_sg_hash)); #else - fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_str_in_use(GLOBAL_PAGES_sg_hash)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_sg_hash) * sizeof(struct subgoal_trie_hash); @@ -1213,17 +1208,16 @@ static inline long show_statistics_answer_trie_hashes(void) { } TABLING_ERROR_CHECKING(statistics_answer_trie_hashes, Pg_str_free(GLOBAL_PAGES_ans_hash) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_ans_hash) * sizeof(struct answer_trie_hash), Pg_pg_alloc(GLOBAL_PAGES_ans_hash), Pg_str_in_use(GLOBAL_PAGES_ans_hash)); #else - fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_ans_hash) * sizeof(struct answer_trie_hash), Pg_str_in_use(GLOBAL_PAGES_ans_hash)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_ans_hash) * sizeof(struct answer_trie_hash); } -#ifdef GLOBAL_TRIE static inline long show_statistics_global_trie_nodes(void) { #ifdef SHM_MEMORY_ALLOC_SCHEME #ifdef DEBUG_TABLING @@ -1242,10 +1236,10 @@ static inline long show_statistics_global_trie_nodes(void) { } TABLING_ERROR_CHECKING(statistics_global_trie_nodes, Pg_str_free(GLOBAL_PAGES_gt_node) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_gt_node) * sizeof(struct global_trie_node), Pg_pg_alloc(GLOBAL_PAGES_gt_node), Pg_str_in_use(GLOBAL_PAGES_gt_node)); #else - fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_gt_node) * sizeof(struct global_trie_node), Pg_str_in_use(GLOBAL_PAGES_gt_node)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_gt_node) * sizeof(struct global_trie_node); @@ -1270,15 +1264,14 @@ static inline long show_statistics_global_trie_hashes(void) { } TABLING_ERROR_CHECKING(statistics_global_trie_hashes, Pg_str_free(GLOBAL_PAGES_gt_hash) != cont); #endif /* DEBUG_TABLING */ - fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_gt_hash) * sizeof(struct global_trie_hash), Pg_pg_alloc(GLOBAL_PAGES_gt_hash), Pg_str_in_use(GLOBAL_PAGES_gt_hash)); #else - fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_gt_hash) * sizeof(struct global_trie_hash), Pg_str_in_use(GLOBAL_PAGES_gt_hash)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_gt_hash) * sizeof(struct global_trie_hash); } -#endif /* GLOBAL_TRIE */ #endif /* TABLING */ @@ -1301,10 +1294,10 @@ static inline long show_statistics_or_frames(void) { } YAPOR_ERROR_CHECKING(statistics_or_frames, Pg_str_free(GLOBAL_PAGES_or_fr) != cont); #endif /* DEBUG_YAPOR */ - fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_or_fr) * sizeof(struct or_frame), Pg_pg_alloc(GLOBAL_PAGES_or_fr), Pg_str_in_use(GLOBAL_PAGES_or_fr)); #else - fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_or_fr) * sizeof(struct or_frame), Pg_str_in_use(GLOBAL_PAGES_or_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_or_fr) * sizeof(struct or_frame); @@ -1329,10 +1322,10 @@ static inline long show_statistics_query_goal_solution_frames(void) { } YAPOR_ERROR_CHECKING(statistics_query_goal_solution_frames, Pg_str_free(GLOBAL_PAGES_qg_sol_fr) != cont); #endif /* DEBUG_YAPOR */ - fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_qg_sol_fr) * sizeof(struct query_goal_solution_frame), Pg_pg_alloc(GLOBAL_PAGES_qg_sol_fr), Pg_str_in_use(GLOBAL_PAGES_qg_sol_fr)); #else - fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_qg_sol_fr) * sizeof(struct query_goal_solution_frame), Pg_str_in_use(GLOBAL_PAGES_qg_sol_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_qg_sol_fr) * sizeof(struct query_goal_solution_frame); @@ -1357,10 +1350,10 @@ static inline long show_statistics_query_goal_answer_frames(void) { } YAPOR_ERROR_CHECKING(statistics_query_goal_answer_frames, Pg_str_free(GLOBAL_PAGES_qg_ans_fr) != cont); #endif /* DEBUG_YAPOR */ - fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_pg_alloc(GLOBAL_PAGES_qg_ans__fr), Pg_str_in_use(GLOBAL_PAGES_qg_ans_fr)); #else - fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_str_in_use(GLOBAL_PAGES_qg_ans_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_qg_ans_fr) * sizeof(struct query_goal_answer_frame); @@ -1387,10 +1380,10 @@ static inline long show_statistics_suspension_frames(void) { } OPTYAP_ERROR_CHECKING(statistics_suspension_frames, Pg_str_free(GLOBAL_PAGES_susp_fr) != cont); #endif /* DEBUG_OPTYAP */ - fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_susp_fr) * sizeof(struct suspension_frame), Pg_pg_alloc(GLOBAL_PAGES_susp_fr), Pg_str_in_use(GLOBAL_PAGES_susp_fr)); #else - fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_susp_fr) * sizeof(struct suspension_frame), Pg_str_in_use(GLOBAL_PAGES_susp_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_susp_fr) * sizeof(struct suspension_frame); @@ -1416,10 +1409,10 @@ static inline long show_statistics_table_subgoal_solution_frames(void) { } OPTYAP_ERROR_CHECKING(statistics_table_subgoal_solution_frames, Pg_str_free(GLOBAL_PAGES_tg_sol_fr) != cont); #endif /* DEBUG_OPTYAP */ - fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_pg_alloc(GLOBAL_PAGES_tg_sol_fr), Pg_str_in_use(GLOBAL_PAGES_tg_sol_fr)); #else - fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_str_in_use(GLOBAL_PAGES_tg_sol_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame); @@ -1444,10 +1437,10 @@ static inline long show_statistics_table_subgoal_answer_frames(void) { } OPTYAP_ERROR_CHECKING(statistics_table_subgoal_answer_frames, Pg_str_free(GLOBAL_PAGES_tg_ans_fr) != cont); #endif /* DEBUG_OPTYAP */ - fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n", + fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_pg_alloc(GLOBAL_PAGES_tg_ans_fr), Pg_str_in_use(GLOBAL_PAGES_tg_ans_fr)); #else - fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld structs in use)\n", + fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld structs in use)\n", Pg_str_in_use(GLOBAL_PAGES_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_str_in_use(GLOBAL_PAGES_tg_ans_fr)); #endif /* SHM_MEMORY_ALLOC_SCHEME */ return Pg_str_in_use(GLOBAL_PAGES_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame); diff --git a/OPTYap/opt.proto.h b/OPTYap/opt.proto.h index 294cdf88c..ac73e3c55 100644 --- a/OPTYap/opt.proto.h +++ b/OPTYap/opt.proto.h @@ -61,22 +61,14 @@ void finish_yapor(void); sg_fr_ptr subgoal_search(yamop *, CELL **); ans_node_ptr answer_search(sg_fr_ptr, CELL *); void load_answer(ans_node_ptr, CELL *); -#ifdef GLOBAL_TRIE CELL *exec_substitution(gt_node_ptr, CELL *); -#endif /* GLOBAL_TRIE */ void update_answer_trie(sg_fr_ptr); -#ifndef GLOBAL_TRIE -void free_subgoal_trie_branch(sg_node_ptr, int, int, int); -#else /* GLOBAL_TRIE */ -void free_subgoal_trie_branch(sg_node_ptr, int, int); -#endif /* GLOBAL_TRIE */ -void free_answer_trie_branch(ans_node_ptr, int); -void free_subgoal_trie_hash_chain(sg_hash_ptr); -void free_answer_trie_hash_chain(ans_hash_ptr); +void free_subgoal_trie(sg_node_ptr, int, int); +void free_answer_trie(ans_node_ptr, int, int); +void free_subgoal_hash_chain(sg_hash_ptr); +void free_answer_hash_chain(ans_hash_ptr); void show_table(tab_ent_ptr, int); -#ifdef GLOBAL_TRIE void show_global_trie(int); -#endif /* GLOBAL_TRIE */ #endif /* TABLING */ diff --git a/OPTYap/opt.structs.h b/OPTYap/opt.structs.h index 1d8d7a5d6..837c9def4 100644 --- a/OPTYap/opt.structs.h +++ b/OPTYap/opt.structs.h @@ -111,17 +111,15 @@ struct global_pages { struct pages table_subgoal_answer_frame_pages; #endif /* TABLING_INNER_CUTS */ #ifdef TABLING -#ifdef GLOBAL_TRIE - struct pages global_trie_node_pages; - struct pages global_trie_hash_pages; -#endif /* GLOBAL_TRIE */ struct pages table_entry_pages; struct pages subgoal_frame_pages; + struct pages dependency_frame_pages; struct pages subgoal_trie_node_pages; struct pages answer_trie_node_pages; + struct pages global_trie_node_pages; struct pages subgoal_trie_hash_pages; struct pages answer_trie_hash_pages; - struct pages dependency_frame_pages; + struct pages global_trie_hash_pages; #endif /* TABLING */ #if defined(YAPOR) && defined(TABLING) struct pages suspension_frame_pages; @@ -203,10 +201,8 @@ struct global_data{ #ifdef TABLING /* global data related to tabling */ - struct table_entry *root_table_entry; -#ifdef GLOBAL_TRIE struct global_trie_node *root_global_trie; -#endif /* GLOBAL_TRIE */ + struct table_entry *root_table_entry; #ifdef LIMIT_TABLING struct subgoal_frame *first_subgoal_frame; struct subgoal_frame *last_subgoal_frame; @@ -230,15 +226,15 @@ struct global_data{ #define GLOBAL_PAGES_qg_ans_fr (GLOBAL.pages.query_goal_answer_frame_pages) #define GLOBAL_PAGES_tg_sol_fr (GLOBAL.pages.table_subgoal_solution_frame_pages) #define GLOBAL_PAGES_tg_ans_fr (GLOBAL.pages.table_subgoal_answer_frame_pages) -#define GLOBAL_PAGES_gt_node (GLOBAL.pages.global_trie_node_pages) -#define GLOBAL_PAGES_gt_hash (GLOBAL.pages.global_trie_hash_pages) #define GLOBAL_PAGES_tab_ent (GLOBAL.pages.table_entry_pages) #define GLOBAL_PAGES_sg_fr (GLOBAL.pages.subgoal_frame_pages) +#define GLOBAL_PAGES_dep_fr (GLOBAL.pages.dependency_frame_pages) #define GLOBAL_PAGES_sg_node (GLOBAL.pages.subgoal_trie_node_pages) #define GLOBAL_PAGES_ans_node (GLOBAL.pages.answer_trie_node_pages) +#define GLOBAL_PAGES_gt_node (GLOBAL.pages.global_trie_node_pages) #define GLOBAL_PAGES_sg_hash (GLOBAL.pages.subgoal_trie_hash_pages) #define GLOBAL_PAGES_ans_hash (GLOBAL.pages.answer_trie_hash_pages) -#define GLOBAL_PAGES_dep_fr (GLOBAL.pages.dependency_frame_pages) +#define GLOBAL_PAGES_gt_hash (GLOBAL.pages.global_trie_hash_pages) #define GLOBAL_PAGES_susp_fr (GLOBAL.pages.suspension_frame_pages) #define SCHEDULER_LOOP (GLOBAL.scheduler_loop) #define DELAYED_RELEASE_LOAD (GLOBAL.delayed_release_load) @@ -279,8 +275,8 @@ struct global_data{ #define GLOBAL_branch(worker, depth) (GLOBAL.branch[worker][depth]) #define PARALLEL_EXECUTION_MODE (GLOBAL.parallel_execution_mode) #define GLOBAL_answers (GLOBAL.answers) -#define GLOBAL_root_tab_ent (GLOBAL.root_table_entry) #define GLOBAL_root_gt (GLOBAL.root_global_trie) +#define GLOBAL_root_tab_ent (GLOBAL.root_table_entry) #define GLOBAL_first_sg_fr (GLOBAL.first_subgoal_frame) #define GLOBAL_last_sg_fr (GLOBAL.last_subgoal_frame) #define GLOBAL_check_sg_fr (GLOBAL.check_subgoal_frame) diff --git a/OPTYap/tab.macros.h b/OPTYap/tab.macros.h index 0f44e4608..dd4b5122d 100644 --- a/OPTYap/tab.macros.h +++ b/OPTYap/tab.macros.h @@ -89,8 +89,6 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int); #define SHOW_MODE_STRUCTURE 0 #define SHOW_MODE_STATISTICS 1 -#define TRAVERSE_TYPE_SUBGOAL 0 -#define TRAVERSE_TYPE_ANSWER 1 #define TRAVERSE_MODE_NORMAL 0 #define TRAVERSE_MODE_DOUBLE 1 #define TRAVERSE_MODE_DOUBLE2 2 @@ -98,6 +96,11 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int); #define TRAVERSE_MODE_LONGINT 4 #define TRAVERSE_MODE_LONGINT_END 5 /* do not change order !!! */ +#define TRAVERSE_TYPE_SUBGOAL 0 +#define TRAVERSE_TYPE_ANSWER 1 +#define TRAVERSE_TYPE_GT_SUBGOAL 2 +#define TRAVERSE_TYPE_GT_ANSWER 3 +/* do not change order !!! */ #define TRAVERSE_POSITION_NEXT 0 #define TRAVERSE_POSITION_FIRST 1 #define TRAVERSE_POSITION_LAST 2 @@ -131,22 +134,23 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int); #define IS_BATCHED_GEN_CP(CP) (GEN_CP(CP)->cp_dep_fr == NULL) #endif /* DETERMINISTIC_TABLING */ -#define TAG_AS_ANSWER_LEAF_NODE(NODE) TrNode_parent(NODE) = (ans_node_ptr)((unsigned long int) TrNode_parent(NODE) | 0x1) -#define UNTAG_ANSWER_LEAF_NODE(NODE) ((ans_node_ptr)((unsigned long int) (NODE) & ~(0x1))) -#define IS_ANSWER_LEAF_NODE(NODE) ((unsigned long int) TrNode_parent(NODE) & 0x1) +#define TAG_AS_SUBGOAL_LEAF_NODE(NODE) TrNode_child(NODE) = (sg_node_ptr)((unsigned long int) TrNode_child(NODE) | 0x1) +#define UNTAG_SUBGOAL_LEAF_NODE(NODE) ((sg_fr_ptr)((unsigned long int) (NODE) & ~(0x1))) +#define IS_SUBGOAL_LEAF_NODE(NODE) ((unsigned long int) TrNode_child(NODE) & 0x1) +#define TAG_AS_ANSWER_LEAF_NODE(NODE) TrNode_parent(NODE) = (ans_node_ptr)((unsigned long int) TrNode_parent(NODE) | 0x1) +#define UNTAG_ANSWER_LEAF_NODE(NODE) ((ans_node_ptr)((unsigned long int) (NODE) & ~(0x1))) +#define IS_ANSWER_LEAF_NODE(NODE) ((unsigned long int) TrNode_parent(NODE) & 0x1) #define MAX_NODES_PER_TRIE_LEVEL 8 #define MAX_NODES_PER_BUCKET (MAX_NODES_PER_TRIE_LEVEL / 2) #define BASE_HASH_BUCKETS 64 #define HASH_ENTRY(ENTRY, SEED) ((((unsigned long int) ENTRY) >> NumberOfLowTagBits) & (SEED)) -#ifdef GLOBAL_TRIE -#define GLOBAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS)) -#define IS_GLOBAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == GLOBAL_TRIE_HASH_MARK) -#endif /* GLOBAL_TRIE */ #define SUBGOAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS)) #define IS_SUBGOAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == SUBGOAL_TRIE_HASH_MARK) #define ANSWER_TRIE_HASH_MARK 0 #define IS_ANSWER_TRIE_HASH(NODE) (TrNode_instr(NODE) == ANSWER_TRIE_HASH_MARK) +#define GLOBAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS)) +#define IS_GLOBAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == GLOBAL_TRIE_HASH_MARK) #define HASH_TABLE_LOCK(NODE) ((((unsigned long int) (NODE)) >> 5) & (TABLE_LOCK_BUCKETS - 1)) #define LOCK_TABLE(NODE) LOCK(GLOBAL_table_lock(HASH_TABLE_LOCK(NODE))) @@ -660,14 +664,14 @@ static inline void abolish_incomplete_subgoals(choiceptr prune_cp) { #else ans_node_ptr node; SgFr_state(sg_fr) = ready; - free_answer_trie_hash_chain(SgFr_hash_chain(sg_fr)); + free_answer_hash_chain(SgFr_hash_chain(sg_fr)); SgFr_hash_chain(sg_fr) = NULL; SgFr_first_answer(sg_fr) = NULL; SgFr_last_answer(sg_fr) = NULL; node = TrNode_child(SgFr_answer_trie(sg_fr)); TrNode_child(SgFr_answer_trie(sg_fr)) = NULL; UNLOCK(SgFr_lock(sg_fr)); - free_answer_trie_branch(node, TRAVERSE_POSITION_FIRST); + free_answer_trie(node, TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); #endif /* INCOMPLETE_TABLING */ } #ifdef LIMIT_TABLING diff --git a/OPTYap/tab.structs.h b/OPTYap/tab.structs.h index 2d18e0d8a..3057c7a4b 100644 --- a/OPTYap/tab.structs.h +++ b/OPTYap/tab.structs.h @@ -49,18 +49,6 @@ typedef struct table_entry { ** global_trie_node, subgoal_trie_node and answer_trie_node ** ***********************************************************************/ -#ifdef GLOBAL_TRIE -typedef struct global_trie_node { - Term entry; - struct global_trie_node *parent; - struct global_trie_node *child; - struct global_trie_node *next; -#ifdef TABLE_LOCK_AT_NODE_LEVEL - lockvar lock; -#endif /* TABLE_LOCK_AT_NODE_LEVEL */ -} *gt_node_ptr; -#endif /* GLOBAL_TRIE */ - typedef struct subgoal_trie_node { Term entry; struct subgoal_trie_node *parent; @@ -85,14 +73,24 @@ typedef struct answer_trie_node { #endif /* TABLE_LOCK_AT_NODE_LEVEL */ } *ans_node_ptr; -#define TrNode_instr(X) ((X)->trie_instruction) -#define TrNode_or_arg(X) ((X)->or_arg) -#define TrNode_entry(X) ((X)->entry) -#define TrNode_parent(X) ((X)->parent) -#define TrNode_child(X) ((X)->child) -#define TrNode_sg_fr(X) ((X)->child) -#define TrNode_next(X) ((X)->next) -#define TrNode_lock(X) ((X)->lock) +typedef struct global_trie_node { + Term entry; + struct global_trie_node *parent; + struct global_trie_node *child; + struct global_trie_node *next; +#ifdef TABLE_LOCK_AT_NODE_LEVEL + lockvar lock; +#endif /* TABLE_LOCK_AT_NODE_LEVEL */ +} *gt_node_ptr; + +#define TrNode_instr(X) ((X)->trie_instruction) +#define TrNode_or_arg(X) ((X)->or_arg) +#define TrNode_entry(X) ((X)->entry) +#define TrNode_parent(X) ((X)->parent) +#define TrNode_child(X) ((X)->child) +#define TrNode_sg_fr(X) ((X)->child) +#define TrNode_next(X) ((X)->next) +#define TrNode_lock(X) ((X)->lock) @@ -100,17 +98,6 @@ typedef struct answer_trie_node { ** global_trie_hash, subgoal_trie_hash and answer_trie_hash ** ***********************************************************************/ -#ifdef GLOBAL_TRIE -typedef struct global_trie_hash { - /* the first field is used for compatibility ** - ** with the global_trie_node data structure */ - Term mark; - int number_of_buckets; - struct global_trie_node **buckets; - int number_of_nodes; -} *gt_hash_ptr; -#endif /* GLOBAL_TRIE */ - typedef struct subgoal_trie_hash { /* the first field is used for compatibility ** ** with the subgoal_trie_node data structure */ @@ -131,13 +118,22 @@ typedef struct answer_trie_hash { struct answer_trie_hash *next; } *ans_hash_ptr; -#define Hash_mark(X) ((X)->mark) -#define Hash_num_buckets(X) ((X)->number_of_buckets) -#define Hash_seed(X) ((X)->number_of_buckets - 1) -#define Hash_buckets(X) ((X)->buckets) -#define Hash_bucket(X,N) ((X)->buckets + N) -#define Hash_num_nodes(X) ((X)->number_of_nodes) -#define Hash_next(X) ((X)->next) +typedef struct global_trie_hash { + /* the first field is used for compatibility ** + ** with the global_trie_node data structure */ + Term mark; + int number_of_buckets; + struct global_trie_node **buckets; + int number_of_nodes; +} *gt_hash_ptr; + +#define Hash_mark(X) ((X)->mark) +#define Hash_num_buckets(X) ((X)->number_of_buckets) +#define Hash_seed(X) ((X)->number_of_buckets - 1) +#define Hash_buckets(X) ((X)->buckets) +#define Hash_bucket(X,N) ((X)->buckets + N) +#define Hash_num_nodes(X) ((X)->number_of_nodes) +#define Hash_next(X) ((X)->next) diff --git a/OPTYap/tab.tries.c b/OPTYap/tab.tries.c index b7bfc3bd2..c8738491f 100644 --- a/OPTYap/tab.tries.c +++ b/OPTYap/tab.tries.c @@ -27,37 +27,29 @@ #include "tab.macros.h" static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr, sg_node_ptr, Term); -static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr, ans_node_ptr, Term, int); -static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr, sg_node_ptr, Term, int *, CELL **); -static inline ans_node_ptr answer_search_loop(sg_fr_ptr, ans_node_ptr, Term, int *); -static inline CELL *load_answer_loop(ans_node_ptr); - -#ifdef GLOBAL_TRIE -static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr, Term); static inline sg_node_ptr subgoal_trie_check_insert_gt_entry(tab_ent_ptr, sg_node_ptr, Term); +static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr, ans_node_ptr, Term, int); static inline ans_node_ptr answer_trie_check_insert_gt_entry(sg_fr_ptr, ans_node_ptr, Term, int); -#ifdef GLOBAL_TRIE_FOR_TERMS -static inline gt_node_ptr subgoal_search_loop_gt_term(Term, int *, CELL **); -static inline gt_node_ptr answer_search_loop_gt_term(Term, int *); -#elif GLOBAL_TRIE_FOR_SUBTERMS +static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr, Term); +#ifdef GLOBAL_TRIE_FOR_SUBTERMS static inline gt_node_ptr global_trie_check_insert_gt_entry(gt_node_ptr, Term); -static inline gt_node_ptr subgoal_search_loop_gt_subterm(Term, int *, CELL **, CELL *); -static inline gt_node_ptr answer_search_loop_gt_subterm(Term, int *, CELL *); +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ + +static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr, sg_node_ptr, Term, int *, CELL **); +static inline sg_node_ptr subgoal_search_terms_loop(tab_ent_ptr, sg_node_ptr, Term, int *, CELL **); +static inline ans_node_ptr answer_search_loop(sg_fr_ptr, ans_node_ptr, Term, int *); +static inline ans_node_ptr answer_search_terms_loop(sg_fr_ptr, ans_node_ptr, Term, int *); +#ifdef GLOBAL_TRIE_FOR_SUBTERMS +static inline gt_node_ptr subgoal_search_global_trie_terms_loop(Term, int *, CELL **, CELL *); +static inline gt_node_ptr answer_search_global_trie_terms_loop(Term, int *, CELL *); +#else +static inline gt_node_ptr subgoal_search_global_trie_loop(Term, int *, CELL **); +static inline gt_node_ptr answer_search_global_trie_loop(Term, int *); #endif /* GLOBAL_TRIE_MODE */ +static inline CELL *load_answer_loop(ans_node_ptr); static inline CELL *load_substitution_loop(gt_node_ptr, int *, CELL *); static inline CELL *exec_substitution_loop(gt_node_ptr, CELL **, CELL *); -#ifdef GLOBAL_TRIE_FOR_TERMS -static void free_global_trie_branch(gt_node_ptr); -#elif GLOBAL_TRIE_FOR_SUBTERMS -static void free_global_trie_branch(gt_node_ptr, int); -#endif /* GLOBAL_TRIE_MODE */ -static void traverse_global_trie(gt_node_ptr, char *, int, int *, int, int); -static void traverse_global_trie_for_term(gt_node_ptr, char *, int *, int *, int *, int); -#endif /* GLOBAL_TRIE */ -static void traverse_subgoal_trie(sg_node_ptr, char *, int, int *, int, int); -static void traverse_answer_trie(ans_node_ptr, char *, int, int *, int, int, int); -static inline void traverse_trie_node(Term, char *, int *, int *, int *, int); #ifdef YAPOR #ifdef TABLING_INNER_CUTS static int update_answer_trie_branch(ans_node_ptr, ans_node_ptr); @@ -67,7 +59,18 @@ static int update_answer_trie_branch(ans_node_ptr); #else /* ! YAPOR */ static void update_answer_trie_branch(ans_node_ptr, int); #endif +#ifdef GLOBAL_TRIE_FOR_SUBTERMS +static void free_global_trie_branch(gt_node_ptr, int); +#else +static void free_global_trie_branch(gt_node_ptr); +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ +static void traverse_subgoal_trie(sg_node_ptr, char *, int, int *, int, int); +static void traverse_answer_trie(ans_node_ptr, char *, int, int *, int, int, int); +static void traverse_global_trie(gt_node_ptr, char *, int, int *, int, int); +static void traverse_global_trie_for_term(gt_node_ptr, char *, int *, int *, int *, int); +static inline void traverse_trie_node(Term, char *, int *, int *, int *, int); +static inline void traverse_update_arity(char *, int *, int *); /******************************* @@ -86,11 +89,9 @@ static struct trie_statistics{ long answers_true; long answers_no; long answer_trie_nodes; -#ifdef GLOBAL_TRIE long global_trie_terms; long global_trie_nodes; long global_trie_references; -#endif /* GLOBAL_TRIE */ } trie_stats; #define TrStat_show trie_stats.show @@ -111,28 +112,23 @@ static struct trie_statistics{ if (TrStat_show == SHOW_MODE_STRUCTURE) \ fprintf(Yap_stdout, MESG, ##ARGS) -#ifndef GLOBAL_TRIE -#define DECREMENT_GLOBAL_TRIE_REFERENCE(REF) -#else /* GLOBAL_TRIE */ -#define DECREMENT_GLOBAL_TRIE_REFERENCE(REF) \ - if (IsVarTerm(REF) && REF > VarIndexOfTableTerm(MAX_TABLE_VARS)) { \ - register gt_node_ptr gt_node = (gt_node_ptr) (REF); \ - TrNode_child(gt_node) = (gt_node_ptr) ((unsigned long int) TrNode_child(gt_node) - 1); \ - if (TrNode_child(gt_node) == 0) \ - FREE_GLOBAL_TRIE_BRANCH(gt_node,TRAVERSE_MODE_NORMAL); \ +#define CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) \ + if (MODE == TRAVERSE_MODE_NORMAL && IsVarTerm(REF) && REF > VarIndexOfTableTerm(MAX_TABLE_VARS)) { \ + register gt_node_ptr gt_node = (gt_node_ptr) (REF); \ + TrNode_child(gt_node) = (gt_node_ptr) ((unsigned long int) TrNode_child(gt_node) - 1); \ + if (TrNode_child(gt_node) == 0) \ + FREE_GLOBAL_TRIE_BRANCH(gt_node,TRAVERSE_MODE_NORMAL); \ } -#endif /* GLOBAL_TRIE */ #ifdef GLOBAL_TRIE_FOR_SUBTERMS -#define CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) \ - if (MODE == TRAVERSE_MODE_NORMAL) \ - DECREMENT_GLOBAL_TRIE_REFERENCE(REF) -#define FREE_GLOBAL_TRIE_BRANCH(NODE,MODE) \ +#define CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(REF,MODE) \ + CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) +#define FREE_GLOBAL_TRIE_BRANCH(NODE,MODE) \ free_global_trie_branch(NODE,MODE) #else -#define CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) -#define FREE_GLOBAL_TRIE_BRANCH(NODE,MODE) \ +#define CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(REF,MODE) +#define FREE_GLOBAL_TRIE_BRANCH(NODE,MODE) \ free_global_trie_branch(NODE) -#endif /* GLOBAL_TRIE_FOR_SUBTEMRS */ +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ @@ -142,40 +138,49 @@ static struct trie_statistics{ #define INCLUDE_SUBGOAL_TRIE_CHECK_INSERT /* subgoal_trie_check_insert_entry */ #define INCLUDE_ANSWER_TRIE_CHECK_INSERT /* answer_trie_check_insert_entry */ -#ifdef GLOBAL_TRIE #define INCLUDE_GLOBAL_TRIE_CHECK_INSERT /* global_trie_check_insert_entry */ -#endif /* GLOBAL_TRIE */ -#define INCLUDE_SUBGOAL_SEARCH_LOOP /* subgoal_search_loop */ -#define INCLUDE_ANSWER_SEARCH_LOOP /* answer_search_loop */ -#define INCLUDE_LOAD_ANSWER_LOOP /* load_answer_loop */ #include "tab.tries.i" -#undef INCLUDE_SUBGOAL_TRIE_CHECK_INSERT -#undef INCLUDE_ANSWER_TRIE_CHECK_INSERT #undef INCLUDE_GLOBAL_TRIE_CHECK_INSERT -#undef INCLUDE_SUBGOAL_SEARCH_LOOP -#undef INCLUDE_ANSWER_SEARCH_LOOP -#undef INCLUDE_LOAD_ANSWER_LOOP +#undef INCLUDE_ANSWER_TRIE_CHECK_INSERT +#undef INCLUDE_SUBGOAL_TRIE_CHECK_INSERT -#ifdef GLOBAL_TRIE #define MODE_GLOBAL_TRIE_ENTRY -#define MODE_GLOBAL_TRIE_LOOP #define INCLUDE_SUBGOAL_TRIE_CHECK_INSERT /* subgoal_trie_check_insert_gt_entry */ #define INCLUDE_ANSWER_TRIE_CHECK_INSERT /* answer_trie_check_insert_gt_entry */ #ifdef GLOBAL_TRIE_FOR_SUBTERMS #define INCLUDE_GLOBAL_TRIE_CHECK_INSERT /* global_trie_check_insert_gt_entry */ #endif /* GLOBAL_TRIE_FOR_SUBTERMS */ -#define INCLUDE_SUBGOAL_SEARCH_LOOP /* subgoal_search_loop_gt_(sub)terms */ -#define INCLUDE_ANSWER_SEARCH_LOOP /* answer_search_loop_gt_(sub)terms */ +#include "tab.tries.i" +#undef INCLUDE_GLOBAL_TRIE_CHECK_INSERT +#undef INCLUDE_ANSWER_TRIE_CHECK_INSERT +#undef INCLUDE_SUBGOAL_TRIE_CHECK_INSERT +#undef MODE_GLOBAL_TRIE_ENTRY + +#define INCLUDE_SUBGOAL_SEARCH_LOOP /* subgoal_search_loop */ +#define INCLUDE_ANSWER_SEARCH_LOOP /* answer_search_loop */ +#define INCLUDE_LOAD_ANSWER_LOOP /* load_answer_loop */ +#include "tab.tries.i" +#undef INCLUDE_LOAD_ANSWER_LOOP +#undef INCLUDE_ANSWER_SEARCH_LOOP +#undef INCLUDE_SUBGOAL_SEARCH_LOOP + +#define MODE_TERMS_LOOP +#define INCLUDE_SUBGOAL_SEARCH_LOOP /* subgoal_search_terms_loop */ +#define INCLUDE_ANSWER_SEARCH_LOOP /* answer_search_terms_loop */ +#include "tab.tries.i" +#undef INCLUDE_ANSWER_SEARCH_LOOP +#undef INCLUDE_SUBGOAL_SEARCH_LOOP +#undef MODE_TERMS_LOOP + +#define MODE_GLOBAL_TRIE_LOOP +#define INCLUDE_SUBGOAL_SEARCH_LOOP /* subgoal_search_global_trie_(terms)_loop */ +#define INCLUDE_ANSWER_SEARCH_LOOP /* answer_search_global_trie_(terms)_loop */ #define INCLUDE_LOAD_ANSWER_LOOP /* load_substitution_loop */ #include "tab.tries.i" -#undef MODE_GLOBAL_TRIE_ENTRY -#undef MODE_GLOBAL_TRIE_LOOP -#undef INCLUDE_SUBGOAL_TRIE_CHECK_INSERT -#undef INCLUDE_ANSWER_TRIE_CHECK_INSERT -#undef INCLUDE_GLOBAL_TRIE_CHECK_INSERT -#undef INCLUDE_SUBGOAL_SEARCH_LOOP -#undef INCLUDE_ANSWER_SEARCH_LOOP #undef INCLUDE_LOAD_ANSWER_LOOP +#undef INCLUDE_ANSWER_SEARCH_LOOP +#undef INCLUDE_SUBGOAL_SEARCH_LOOP +#undef MODE_GLOBAL_TRIE_LOOP static inline CELL *exec_substitution_loop(gt_node_ptr current_node, CELL **stack_vars_ptr, CELL *stack_terms) { @@ -350,107 +355,6 @@ static inline CELL *exec_substitution_loop(gt_node_ptr current_node, CELL **stac } -#ifdef GLOBAL_TRIE_FOR_TERMS -static void free_global_trie_branch(gt_node_ptr current_node) { -#elif GLOBAL_TRIE_FOR_SUBTERMS -static void free_global_trie_branch(gt_node_ptr current_node, int mode) { - Term t = TrNode_entry(current_node); -#endif - gt_node_ptr parent_node, child_node; - - parent_node = TrNode_parent(current_node); - child_node = TrNode_child(parent_node); - if (IS_GLOBAL_TRIE_HASH(child_node)) { - gt_hash_ptr hash = (gt_hash_ptr) child_node; - gt_node_ptr *bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(current_node), Hash_seed(hash))); - int num_nodes = --Hash_num_nodes(hash); - child_node = *bucket; - if (child_node != current_node) { - while (TrNode_next(child_node) != current_node) - child_node = TrNode_next(child_node); - TrNode_next(child_node) = TrNode_next(current_node); - CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(t,mode); - FREE_GLOBAL_TRIE_NODE(current_node); - } else { - *bucket = TrNode_next(current_node); - CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(t,mode); - FREE_GLOBAL_TRIE_NODE(current_node); - if (num_nodes == 0) { - FREE_HASH_BUCKETS(Hash_buckets(hash)); - FREE_GLOBAL_TRIE_HASH(hash); - if (parent_node != GLOBAL_root_gt) { -#ifdef GLOBAL_TRIE_FOR_SUBTERMS - if (mode == TRAVERSE_MODE_NORMAL) { - if (IsApplTerm(t)) { - Functor f = (Functor) RepAppl(t); - if (f == FunctorDouble) - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_DOUBLE); - else if (f == FunctorLongInt) - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_LONGINT); - else - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_NORMAL); - } else - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_NORMAL); - } else if (mode == TRAVERSE_MODE_LONGINT) - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_LONGINT_END); - else if (mode == TRAVERSE_MODE_DOUBLE) -#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_DOUBLE2); - else if (mode == TRAVERSE_MODE_DOUBLE2) -#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_DOUBLE_END); - else -#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_NORMAL); - } else - TrNode_child(parent_node) = NULL; - } - } - } else if (child_node != current_node) { - while (TrNode_next(child_node) != current_node) - child_node = TrNode_next(child_node); - TrNode_next(child_node) = TrNode_next(current_node); - CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(t,mode); - FREE_GLOBAL_TRIE_NODE(current_node); - } else if (TrNode_next(current_node) == NULL) { - CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(t,mode); - FREE_GLOBAL_TRIE_NODE(current_node); - if (parent_node != GLOBAL_root_gt) { -#ifdef GLOBAL_TRIE_FOR_SUBTERMS - if (mode == TRAVERSE_MODE_NORMAL) { - if (IsApplTerm(t)) { - Functor f = (Functor) RepAppl(t); - if (f == FunctorDouble) - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_DOUBLE); - else if (f == FunctorLongInt) - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_LONGINT); - else - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_NORMAL); - } else - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_NORMAL); - } else if (mode == TRAVERSE_MODE_LONGINT) - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_LONGINT_END); - else if (mode == TRAVERSE_MODE_DOUBLE) -#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_DOUBLE2); - else if (mode == TRAVERSE_MODE_DOUBLE2) -#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_DOUBLE_END); - else -#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ - FREE_GLOBAL_TRIE_BRANCH(parent_node,TRAVERSE_MODE_NORMAL); - } else - TrNode_child(parent_node) = NULL; - } else { - TrNode_child(parent_node) = TrNode_next(current_node); - CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(t,mode); - FREE_GLOBAL_TRIE_NODE(current_node); - } - return; -} -#endif /* GLOBAL_TRIE */ - - #ifdef YAPOR #ifdef TABLING_INNER_CUTS static int update_answer_trie_branch(ans_node_ptr previous_node, ans_node_ptr current_node) { @@ -533,263 +437,123 @@ static void update_answer_trie_branch(ans_node_ptr current_node, int position) { #endif /* YAPOR */ -static inline void traverse_trie_node(Term t, char *str, int *str_index_ptr, int *arity, int *mode_ptr, int type) { - int mode = *mode_ptr; - int str_index = *str_index_ptr; +#ifdef GLOBAL_TRIE_FOR_SUBTERMS +static void free_global_trie_branch(gt_node_ptr current_node, int mode) { + Term t = TrNode_entry(current_node); +#else +static void free_global_trie_branch(gt_node_ptr current_node) { +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ + gt_node_ptr parent_node, child_node; - /* test the node type */ - if (mode == TRAVERSE_MODE_DOUBLE) { + parent_node = TrNode_parent(current_node); + child_node = TrNode_child(parent_node); + if (IS_GLOBAL_TRIE_HASH(child_node)) { + gt_hash_ptr hash = (gt_hash_ptr) child_node; + gt_node_ptr *bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(current_node), Hash_seed(hash))); + int num_nodes = --Hash_num_nodes(hash); + child_node = *bucket; + if (child_node != current_node) { + while (TrNode_next(child_node) != current_node) + child_node = TrNode_next(child_node); + TrNode_next(child_node) = TrNode_next(current_node); + CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(t, mode); + FREE_GLOBAL_TRIE_NODE(current_node); + } else { + *bucket = TrNode_next(current_node); + CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(t, mode); + FREE_GLOBAL_TRIE_NODE(current_node); + if (num_nodes == 0) { + FREE_HASH_BUCKETS(Hash_buckets(hash)); + FREE_GLOBAL_TRIE_HASH(hash); + if (parent_node != GLOBAL_root_gt) { +#ifdef GLOBAL_TRIE_FOR_SUBTERMS + if (mode == TRAVERSE_MODE_NORMAL) { + if (IsApplTerm(t)) { + Functor f = (Functor) RepAppl(t); + if (f == FunctorDouble) + mode = TRAVERSE_MODE_DOUBLE; + else if (f == FunctorLongInt) + mode = TRAVERSE_MODE_LONGINT; + else + mode = TRAVERSE_MODE_NORMAL; + } else + mode = TRAVERSE_MODE_NORMAL; + } else if (mode == TRAVERSE_MODE_LONGINT) + mode = TRAVERSE_MODE_LONGINT_END; + else if (mode == TRAVERSE_MODE_DOUBLE) #if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P - arity[0]++; - arity[arity[0]] = (int) t; - mode = TRAVERSE_MODE_DOUBLE2; - } else if (mode == TRAVERSE_MODE_DOUBLE2) { - volatile Float dbl; - volatile Term *t_dbl = (Term *)((void *) &dbl); - t_dbl[0] = t; - t_dbl[1] = (Term) arity[arity[0]]; - arity[0]--; -#else /* SIZEOF_DOUBLE == SIZEOF_INT_P */ - volatile Float dbl; - volatile Term *t_dbl = (Term *)((void *) &dbl); - t_dbl[0] = t; + mode = TRAVERSE_MODE_DOUBLE2; + else if (mode == TRAVERSE_MODE_DOUBLE2) #endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ - str_index += sprintf(& str[str_index], "%.15g", dbl); - while (arity[0]) { - if (arity[arity[0]] > 0) { - arity[arity[0]]--; - if (arity[arity[0]] == 0) { - str_index += sprintf(& str[str_index], ")"); - arity[0]--; - } else { - str_index += sprintf(& str[str_index], ","); - break; - } - } else { - if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_PAIRS - str_index += sprintf(& str[str_index], ","); -#else - str_index += sprintf(& str[str_index], "|"); - arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_PAIRS */ - break; - } else { - str_index += sprintf(& str[str_index], "]"); - arity[0]--; - } + mode = TRAVERSE_MODE_DOUBLE_END; + else + mode = TRAVERSE_MODE_NORMAL; +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ + FREE_GLOBAL_TRIE_BRANCH(parent_node, mode); + } else + TrNode_child(parent_node) = NULL; } } -#ifndef GLOBAL_TRIE - if (type == TRAVERSE_TYPE_SUBGOAL) - mode = TRAVERSE_MODE_NORMAL; - else /* type == TRAVERSE_TYPE_ANSWER */ -#endif /* GLOBAL_TRIE */ - mode = TRAVERSE_MODE_DOUBLE_END; - } else if (mode == TRAVERSE_MODE_DOUBLE_END) { - mode = TRAVERSE_MODE_NORMAL; - } else if (mode == TRAVERSE_MODE_LONGINT) { - Int li = (Int) t; -#if SHORT_INTS - str_index += sprintf(& str[str_index], "%ld", li); -#else - str_index += sprintf(& str[str_index], "%d", li); -#endif /* SHORT_INTS */ - while (arity[0]) { - if (arity[arity[0]] > 0) { - arity[arity[0]]--; - if (arity[arity[0]] == 0) { - str_index += sprintf(& str[str_index], ")"); - arity[0]--; - } else { - str_index += sprintf(& str[str_index], ","); - break; - } - } else { - if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_PAIRS - str_index += sprintf(& str[str_index], ","); -#else - str_index += sprintf(& str[str_index], "|"); - arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_PAIRS */ - break; - } else { - str_index += sprintf(& str[str_index], "]"); - arity[0]--; - } - } - } -#ifndef GLOBAL_TRIE - if (type == TRAVERSE_TYPE_SUBGOAL) - mode = TRAVERSE_MODE_NORMAL; - else /* type == TRAVERSE_TYPE_ANSWER */ -#endif /* GLOBAL_TRIE */ - mode = TRAVERSE_MODE_LONGINT_END; - } else if (mode == TRAVERSE_MODE_LONGINT_END) { - mode = TRAVERSE_MODE_NORMAL; - } else if (IsVarTerm(t)) { -#ifdef GLOBAL_TRIE - if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) { - TrStat_gt_refs++; - traverse_global_trie_for_term((gt_node_ptr) t, str, &str_index, arity, &mode, type); + } else if (child_node != current_node) { + while (TrNode_next(child_node) != current_node) + child_node = TrNode_next(child_node); + TrNode_next(child_node) = TrNode_next(current_node); + CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(t, mode); + FREE_GLOBAL_TRIE_NODE(current_node); + } else if (TrNode_next(current_node) == NULL) { + CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(t, mode); + FREE_GLOBAL_TRIE_NODE(current_node); + if (parent_node != GLOBAL_root_gt) { +#ifdef GLOBAL_TRIE_FOR_SUBTERMS + if (mode == TRAVERSE_MODE_NORMAL) { + if (IsApplTerm(t)) { + Functor f = (Functor) RepAppl(t); + if (f == FunctorDouble) + mode = TRAVERSE_MODE_DOUBLE; + else if (f == FunctorLongInt) + mode = TRAVERSE_MODE_LONGINT; + else + mode = TRAVERSE_MODE_NORMAL; + } else + mode = TRAVERSE_MODE_NORMAL; + } else if (mode == TRAVERSE_MODE_LONGINT) + mode = TRAVERSE_MODE_LONGINT_END; + else if (mode == TRAVERSE_MODE_DOUBLE) +#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P + mode = TRAVERSE_MODE_DOUBLE2; + else if (mode == TRAVERSE_MODE_DOUBLE2) +#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ + mode = TRAVERSE_MODE_DOUBLE_END; + else + mode = TRAVERSE_MODE_NORMAL; +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ + FREE_GLOBAL_TRIE_BRANCH(parent_node, mode); } else -#endif /* GLOBAL_TRIE */ - { - if (type == TRAVERSE_TYPE_SUBGOAL) - str_index += sprintf(& str[str_index], "VAR%d", VarIndexOfTableTerm(t)); - else /* type == TRAVERSE_TYPE_ANSWER */ - str_index += sprintf(& str[str_index], "ANSVAR%d", VarIndexOfTableTerm(t)); - while (arity[0]) { - if (arity[arity[0]] > 0) { - arity[arity[0]]--; - if (arity[arity[0]] == 0) { - str_index += sprintf(& str[str_index], ")"); - arity[0]--; - } else { - str_index += sprintf(& str[str_index], ","); - break; - } - } else { - if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_PAIRS - str_index += sprintf(& str[str_index], ","); -#else - str_index += sprintf(& str[str_index], "|"); - arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_PAIRS */ - break; - } else { - str_index += sprintf(& str[str_index], "]"); - arity[0]--; - } - } - } - } - } else if (IsIntTerm(t)) { -#if SHORT_INTS - str_index += sprintf(& str[str_index], "%ld", IntOfTerm(t)); -#else - str_index += sprintf(& str[str_index], "%d", IntOfTerm(t)); -#endif /* SHORT_INTS */ - while (arity[0]) { - if (arity[arity[0]] > 0) { - arity[arity[0]]--; - if (arity[arity[0]] == 0) { - str_index += sprintf(& str[str_index], ")"); - arity[0]--; - } else { - str_index += sprintf(& str[str_index], ","); - break; - } - } else { - if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_PAIRS - str_index += sprintf(& str[str_index], ","); -#else - str_index += sprintf(& str[str_index], "|"); - arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_PAIRS */ - break; - } else { - str_index += sprintf(& str[str_index], "]"); - arity[0]--; - } - } - } - } else if (IsAtomTerm(t)) { -#ifndef TRIE_COMPACT_PAIRS - if (arity[arity[0]] == -1 && t == TermNil) { - str[str_index - 1] = ']'; - arity[0]--; - } else -#endif /* TRIE_COMPACT_PAIRS */ - str_index += sprintf(& str[str_index], "%s", AtomName(AtomOfTerm(t))); - while (arity[0]) { - if (arity[arity[0]] > 0) { - arity[arity[0]]--; - if (arity[arity[0]] == 0) { - str_index += sprintf(& str[str_index], ")"); - arity[0]--; - } else { - str_index += sprintf(& str[str_index], ","); - break; - } - } else { - if (arity[arity[0]] == -2) { -#ifdef TRIE_COMPACT_PAIRS - str_index += sprintf(& str[str_index], ","); -#else - str_index += sprintf(& str[str_index], "|"); - arity[arity[0]] = -1; -#endif /* TRIE_COMPACT_PAIRS */ - break; - } else { - str_index += sprintf(& str[str_index], "]"); - arity[0]--; - } - } - } - } else if (IsPairTerm(t)) { -#ifdef TRIE_COMPACT_PAIRS - if (t == CompactPairEndList) - arity[arity[0]] = -1; - else if (t == CompactPairEndTerm) { - str[str_index - 1] = '|'; - arity[arity[0]] = -1; -#else - if (arity[arity[0]] == -1) { - str[str_index - 1] = ','; - arity[arity[0]] = -2; -#endif /* TRIE_COMPACT_PAIRS */ - } else { - str_index += sprintf(& str[str_index], "["); - arity[0]++; - arity[arity[0]] = -2; - } - } else if (IsApplTerm(t)) { - Functor f = (Functor) RepAppl(t); - if (f == FunctorDouble) { - mode = TRAVERSE_MODE_DOUBLE; - } else if (f == FunctorLongInt) { - mode = TRAVERSE_MODE_LONGINT; - } else { - str_index += sprintf(& str[str_index], "%s(", AtomName(NameOfFunctor(f))); - arity[0]++; - arity[arity[0]] = ArityOfFunctor(f); - } + TrNode_child(parent_node) = NULL; + } else { + TrNode_child(parent_node) = TrNode_next(current_node); + CHECK_DECREMENT_GLOBAL_TRIE_FOR_SUBTERMS_REFERENCE(t, mode); + FREE_GLOBAL_TRIE_NODE(current_node); } - - *mode_ptr = mode; - *str_index_ptr = str_index; return; } -#ifdef GLOBAL_TRIE -static void traverse_global_trie_for_term(gt_node_ptr current_node, char *str, int *str_index, int *arity, int *mode, int type) { - if (TrNode_parent(current_node) != GLOBAL_root_gt) - traverse_global_trie_for_term(TrNode_parent(current_node), str, str_index, arity, mode, type); - traverse_trie_node(TrNode_entry(current_node), str, str_index, arity, mode, type); - return; -} - - -static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_index, int *arity, int mode, int position) { +static void traverse_subgoal_trie(sg_node_ptr current_node, char *str, int str_index, int *arity, int mode, int position) { int *current_arity = NULL, current_str_index = 0, current_mode = 0; /* test if hashing */ - if (IS_GLOBAL_TRIE_HASH(current_node)) { - gt_node_ptr *bucket, *last_bucket; - gt_hash_ptr hash; - hash = (gt_hash_ptr) current_node; + if (IS_SUBGOAL_TRIE_HASH(current_node)) { + sg_node_ptr *bucket, *last_bucket; + sg_hash_ptr hash; + hash = (sg_hash_ptr) current_node; bucket = Hash_buckets(hash); last_bucket = bucket + Hash_num_buckets(hash); current_arity = (int *) malloc(sizeof(int) * (arity[0] + 1)); memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); do { if (*bucket) { - traverse_global_trie(*bucket, str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); + traverse_subgoal_trie(*bucket, str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); #ifdef TRIE_COMPACT_PAIRS if (arity[arity[0]] == -2 && str[str_index - 1] != '[') @@ -813,18 +577,39 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_in } /* process current trie node */ - TrStat_gt_nodes++; + TrStat_sg_nodes++; traverse_trie_node(TrNode_entry(current_node), str, &str_index, arity, &mode, TRAVERSE_TYPE_SUBGOAL); - /* continue with child node ... */ - if (arity[0] != 0 || mode != TRAVERSE_MODE_NORMAL) - traverse_global_trie(TrNode_child(current_node), str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); - /* ... or show term */ - else { - TrStat_gt_terms++; + /* show answers ... */ + if (IS_SUBGOAL_LEAF_NODE(current_node)) { + sg_fr_ptr sg_fr = UNTAG_SUBGOAL_LEAF_NODE(TrNode_sg_fr(current_node)); + TrStat_subgoals++; str[str_index] = 0; - SHOW_TABLE_STRUCTURE(" TERMx%ld: %s\n", (unsigned long int) TrNode_child(current_node), str); + SHOW_TABLE_STRUCTURE("%s.\n", str); + TrStat_ans_nodes++; + if (SgFr_first_answer(sg_fr) == NULL) { + if (SgFr_state(sg_fr) < complete) { + TrStat_sg_incomplete++; + SHOW_TABLE_STRUCTURE(" ---> INCOMPLETE\n"); + } else { + TrStat_answers_no++; + SHOW_TABLE_STRUCTURE(" NO\n"); + } + } else if (SgFr_first_answer(sg_fr) == SgFr_answer_trie(sg_fr)) { + TrStat_answers_true++; + SHOW_TABLE_STRUCTURE(" TRUE\n"); + } else { + arity[0] = 0; + traverse_answer_trie(TrNode_child(SgFr_answer_trie(sg_fr)), &str[str_index], 0, arity, 0, TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); + if (SgFr_state(sg_fr) < complete) { + TrStat_sg_incomplete++; + SHOW_TABLE_STRUCTURE(" ---> INCOMPLETE\n"); + } + } } + /* ... or continue with child node */ + else + traverse_subgoal_trie(TrNode_child(current_node), str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); /* restore the initial state and continue with sibling nodes */ if (position == TRAVERSE_POSITION_FIRST) { @@ -840,7 +625,7 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_in if (arity[arity[0]] == -1) str[str_index - 1] = '|'; #endif /* TRIE_COMPACT_PAIRS */ - traverse_global_trie(current_node, str, str_index, arity, mode, TRAVERSE_POSITION_NEXT); + traverse_subgoal_trie(current_node, str, str_index, arity, mode, TRAVERSE_POSITION_NEXT); current_node = TrNode_next(current_node); } free(current_arity); @@ -848,7 +633,6 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_in return; } -#endif /* GLOBAL_TRIE */ static void traverse_answer_trie(ans_node_ptr current_node, char *str, int str_index, int *arity, int var_index, int mode, int position) { @@ -941,21 +725,21 @@ static void traverse_answer_trie(ans_node_ptr current_node, char *str, int str_i } -static void traverse_subgoal_trie(sg_node_ptr current_node, char *str, int str_index, int *arity, int mode, int position) { +static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_index, int *arity, int mode, int position) { int *current_arity = NULL, current_str_index = 0, current_mode = 0; /* test if hashing */ - if (IS_SUBGOAL_TRIE_HASH(current_node)) { - sg_node_ptr *bucket, *last_bucket; - sg_hash_ptr hash; - hash = (sg_hash_ptr) current_node; + if (IS_GLOBAL_TRIE_HASH(current_node)) { + gt_node_ptr *bucket, *last_bucket; + gt_hash_ptr hash; + hash = (gt_hash_ptr) current_node; bucket = Hash_buckets(hash); last_bucket = bucket + Hash_num_buckets(hash); current_arity = (int *) malloc(sizeof(int) * (arity[0] + 1)); memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1)); do { if (*bucket) { - traverse_subgoal_trie(*bucket, str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); + traverse_global_trie(*bucket, str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1)); #ifdef TRIE_COMPACT_PAIRS if (arity[arity[0]] == -2 && str[str_index - 1] != '[') @@ -979,38 +763,17 @@ static void traverse_subgoal_trie(sg_node_ptr current_node, char *str, int str_i } /* process current trie node */ - TrStat_sg_nodes++; - traverse_trie_node(TrNode_entry(current_node), str, &str_index, arity, &mode, TRAVERSE_TYPE_SUBGOAL); + TrStat_gt_nodes++; + traverse_trie_node(TrNode_entry(current_node), str, &str_index, arity, &mode, TRAVERSE_TYPE_GT_SUBGOAL); /* continue with child node ... */ if (arity[0] != 0 || mode != TRAVERSE_MODE_NORMAL) - traverse_subgoal_trie(TrNode_child(current_node), str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); - /* ... or show answers */ + traverse_global_trie(TrNode_child(current_node), str, str_index, arity, mode, TRAVERSE_POSITION_FIRST); + /* ... or show term */ else { - sg_fr_ptr sg_fr = (sg_fr_ptr) TrNode_sg_fr(current_node); - TrStat_subgoals++; + TrStat_gt_terms++; str[str_index] = 0; - SHOW_TABLE_STRUCTURE("%s.\n", str); - TrStat_ans_nodes++; - if (SgFr_first_answer(sg_fr) == NULL) { - if (SgFr_state(sg_fr) < complete) { - TrStat_sg_incomplete++; - SHOW_TABLE_STRUCTURE(" ---> INCOMPLETE\n"); - } else { - TrStat_answers_no++; - SHOW_TABLE_STRUCTURE(" NO\n"); - } - } else if (SgFr_first_answer(sg_fr) == SgFr_answer_trie(sg_fr)) { - TrStat_answers_true++; - SHOW_TABLE_STRUCTURE(" TRUE\n"); - } else { - arity[0] = 0; - traverse_answer_trie(TrNode_child(SgFr_answer_trie(sg_fr)), &str[str_index], 0, arity, 0, TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); - if (SgFr_state(sg_fr) < complete) { - TrStat_sg_incomplete++; - SHOW_TABLE_STRUCTURE(" ---> INCOMPLETE\n"); - } - } + SHOW_TABLE_STRUCTURE(" TERMx%ld: %s\n", (unsigned long int) TrNode_child(current_node), str); } /* restore the initial state and continue with sibling nodes */ @@ -1027,7 +790,7 @@ static void traverse_subgoal_trie(sg_node_ptr current_node, char *str, int str_i if (arity[arity[0]] == -1) str[str_index - 1] = '|'; #endif /* TRIE_COMPACT_PAIRS */ - traverse_subgoal_trie(current_node, str, str_index, arity, mode, TRAVERSE_POSITION_NEXT); + traverse_global_trie(current_node, str, str_index, arity, mode, TRAVERSE_POSITION_NEXT); current_node = TrNode_next(current_node); } free(current_arity); @@ -1037,6 +800,166 @@ static void traverse_subgoal_trie(sg_node_ptr current_node, char *str, int str_i } +static void traverse_global_trie_for_term(gt_node_ptr current_node, char *str, int *str_index, int *arity, int *mode, int type) { + if (TrNode_parent(current_node) != GLOBAL_root_gt) + traverse_global_trie_for_term(TrNode_parent(current_node), str, str_index, arity, mode, type); + traverse_trie_node(TrNode_entry(current_node), str, str_index, arity, mode, type); + return; +} + + +static inline void traverse_trie_node(Term t, char *str, int *str_index_ptr, int *arity, int *mode_ptr, int type) { + int mode = *mode_ptr; + int str_index = *str_index_ptr; + + /* test the node type */ + if (mode == TRAVERSE_MODE_DOUBLE) { +#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P + arity[0]++; + arity[arity[0]] = (int) t; + mode = TRAVERSE_MODE_DOUBLE2; + } else if (mode == TRAVERSE_MODE_DOUBLE2) { + volatile Float dbl = 0; + volatile Term *t_dbl = (Term *)((void *) &dbl); + t_dbl[0] = t; + t_dbl[1] = (Term) arity[arity[0]]; + arity[0]--; +#else /* SIZEOF_DOUBLE == SIZEOF_INT_P */ + volatile Float dbl; + volatile Term *t_dbl = (Term *)((void *) &dbl); + t_dbl[0] = t; +#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ + str_index += sprintf(& str[str_index], "%.15g", dbl); + traverse_update_arity(str, &str_index, arity); + if (type == TRAVERSE_TYPE_SUBGOAL) + mode = TRAVERSE_MODE_NORMAL; + else /* TRAVERSE_TYPE_ANSWER || TRAVERSE_TYPE_GT_SUBGOAL || TRAVERSE_TYPE_GT_ANSWER */ + mode = TRAVERSE_MODE_DOUBLE_END; + } else if (mode == TRAVERSE_MODE_DOUBLE_END) { + mode = TRAVERSE_MODE_NORMAL; + } else if (mode == TRAVERSE_MODE_LONGINT) { + Int li = (Int) t; +#if SHORT_INTS + str_index += sprintf(& str[str_index], "%ld", li); +#else + str_index += sprintf(& str[str_index], "%d", li); +#endif /* SHORT_INTS */ + traverse_update_arity(str, &str_index, arity); + if (type == TRAVERSE_TYPE_SUBGOAL) + mode = TRAVERSE_MODE_NORMAL; + else /* TRAVERSE_TYPE_ANSWER || TRAVERSE_TYPE_GT_SUBGOAL || TRAVERSE_TYPE_GT_ANSWER */ + mode = TRAVERSE_MODE_LONGINT_END; + } else if (mode == TRAVERSE_MODE_LONGINT_END) { + mode = TRAVERSE_MODE_NORMAL; + } else if (IsVarTerm(t)) { + if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) { + TrStat_gt_refs++; + /* (type % 2 + 2): TRAVERSE_TYPE_ANSWER --> TRAVERSE_TYPE_GT_ANSWER */ + /* (type % 2 + 2): TRAVERSE_TYPE_SUBGOAL --> TRAVERSE_TYPE_GT_SUBGOAL */ + traverse_global_trie_for_term((gt_node_ptr) t, str, &str_index, arity, &mode, type % 2 + 2); + } else { + if (type == TRAVERSE_TYPE_SUBGOAL || type == TRAVERSE_TYPE_GT_SUBGOAL) + str_index += sprintf(& str[str_index], "VAR%d", VarIndexOfTableTerm(t)); + else /* TRAVERSE_TYPE_ANSWER || TRAVERSE_TYPE_GT_ANSWER */ + str_index += sprintf(& str[str_index], "ANSVAR%d", VarIndexOfTableTerm(t)); + traverse_update_arity(str, &str_index, arity); + } + } else if (IsIntTerm(t)) { +#if SHORT_INTS + str_index += sprintf(& str[str_index], "%ld", IntOfTerm(t)); +#else + str_index += sprintf(& str[str_index], "%d", IntOfTerm(t)); +#endif /* SHORT_INTS */ + traverse_update_arity(str, &str_index, arity); + } else if (IsAtomTerm(t)) { +#ifndef TRIE_COMPACT_PAIRS + if (arity[arity[0]] == -1 && t == TermNil) { + str[str_index - 1] = ']'; + arity[0]--; + } else +#endif /* TRIE_COMPACT_PAIRS */ + str_index += sprintf(& str[str_index], "%s", AtomName(AtomOfTerm(t))); + traverse_update_arity(str, &str_index, arity); + } else if (IsPairTerm(t)) { +#ifdef TRIE_COMPACT_PAIRS + if (t == CompactPairEndList) + arity[arity[0]] = -1; + else if (t == CompactPairEndTerm) { + str[str_index - 1] = '|'; + arity[arity[0]] = -1; +#else + if (arity[arity[0]] == -1) { + str[str_index - 1] = ','; + arity[arity[0]] = -2; +#endif /* TRIE_COMPACT_PAIRS */ + } else { + str_index += sprintf(& str[str_index], "["); + arity[0]++; + arity[arity[0]] = -2; + } + } else if (IsApplTerm(t)) { + Functor f = (Functor) RepAppl(t); + if (f == FunctorDouble) { + mode = TRAVERSE_MODE_DOUBLE; + } else if (f == FunctorLongInt) { + mode = TRAVERSE_MODE_LONGINT; + } else if (f == FunctorComma) { + if (arity[arity[0]] != -3) { + str_index += sprintf(& str[str_index], "("); + arity[0]++; + } + arity[arity[0]] = -4; + } else { + str_index += sprintf(& str[str_index], "%s(", AtomName(NameOfFunctor(f))); + arity[0]++; + arity[arity[0]] = ArityOfFunctor(f); + } + } + + *mode_ptr = mode; + *str_index_ptr = str_index; + return; +} + + +static inline void traverse_update_arity(char *str, int *str_index_ptr, int *arity) { + int str_index = *str_index_ptr; + while (arity[0]) { + if (arity[arity[0]] > 0) { + arity[arity[0]]--; + if (arity[arity[0]] == 0) { + str_index += sprintf(& str[str_index], ")"); + arity[0]--; + } else { + str_index += sprintf(& str[str_index], ","); + break; + } + } else { + if (arity[arity[0]] == -4) { + str_index += sprintf(& str[str_index], ","); + arity[arity[0]] = -3; + break; + } else if (arity[arity[0]] == -3) { + str_index += sprintf(& str[str_index], ")"); + arity[0]--; + } else if (arity[arity[0]] == -2) { +#ifdef TRIE_COMPACT_PAIRS + str_index += sprintf(& str[str_index], ","); +#else + str_index += sprintf(& str[str_index], "|"); + arity[arity[0]] = -1; +#endif /* TRIE_COMPACT_PAIRS */ + break; + } else if (arity[arity[0]] == -1) { + str_index += sprintf(& str[str_index], "]"); + arity[0]--; + } + } + } + *str_index_ptr = str_index; +} + + /******************************* ** Global functions ** @@ -1058,8 +981,12 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) { LOCK(TabEnt_lock(tab_ent)); #endif /* TABLE_LOCK_LEVEL */ - for (i = 1; i <= pred_arity; i++) { - current_sg_node = subgoal_search_loop(tab_ent, current_sg_node, Deref(XREGS[i]), &subs_arity, &stack_vars); + if (IsMode_GlobalTrie(TabEnt_mode(tab_ent))) { + for (i = 1; i <= pred_arity; i++) + current_sg_node = subgoal_search_terms_loop(tab_ent, current_sg_node, Deref(XREGS[i]), &subs_arity, &stack_vars); + } else { + for (i = 1; i <= pred_arity; i++) + current_sg_node = subgoal_search_loop(tab_ent, current_sg_node, Deref(XREGS[i]), &subs_arity, &stack_vars); } STACK_PUSH_UP(subs_arity, stack_vars); @@ -1079,8 +1006,9 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) { /* new tabled subgoal */ new_subgoal_frame(sg_fr, preg); TrNode_sg_fr(current_sg_node) = (sg_node_ptr) sg_fr; + TAG_AS_SUBGOAL_LEAF_NODE(current_sg_node); } else { - sg_fr = (sg_fr_ptr) TrNode_sg_fr(current_sg_node); + sg_fr = UNTAG_SUBGOAL_LEAF_NODE(TrNode_sg_fr(current_sg_node)); #ifdef LIMIT_TABLING if (SgFr_state(sg_fr) <= ready) { /* incomplete or ready */ remove_from_global_sg_fr_list(sg_fr); @@ -1107,9 +1035,16 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) { vars_arity = 0; current_ans_node = SgFr_answer_trie(sg_fr); - for (i = subs_arity; i >= 1; i--) { - TABLING_ERROR_CHECKING(answer search, IsNonVarTerm(subs_ptr[i])); - current_ans_node = answer_search_loop(sg_fr, current_ans_node, Deref(subs_ptr[i]), &vars_arity); + if (IsMode_GlobalTrie(TabEnt_mode(SgFr_tab_ent(sg_fr)))) { + for (i = subs_arity; i >= 1; i--) { + TABLING_ERROR_CHECKING(answer search, IsNonVarTerm(subs_ptr[i])); + current_ans_node = answer_search_terms_loop(sg_fr, current_ans_node, Deref(subs_ptr[i]), &vars_arity); + } + } else { + for (i = subs_arity; i >= 1; i--) { + TABLING_ERROR_CHECKING(answer search, IsNonVarTerm(subs_ptr[i])); + current_ans_node = answer_search_loop(sg_fr, current_ans_node, Deref(subs_ptr[i]), &vars_arity); + } } /* reset variables */ @@ -1146,7 +1081,6 @@ void load_answer(ans_node_ptr current_ans_node, CELL *subs_ptr) { } -#ifdef GLOBAL_TRIE CELL *exec_substitution(gt_node_ptr current_node, CELL *aux_stack) { #define subs_arity *subs_ptr CELL *stack_terms, *subs_ptr; @@ -1165,13 +1099,12 @@ CELL *exec_substitution(gt_node_ptr current_node, CELL *aux_stack) { return aux_stack; #undef subs_arity } -#endif /* GLOBAL_TRIE */ void update_answer_trie(sg_fr_ptr sg_fr) { ans_node_ptr current_node; - free_answer_trie_hash_chain(SgFr_hash_chain(sg_fr)); + free_answer_hash_chain(SgFr_hash_chain(sg_fr)); SgFr_hash_chain(sg_fr) = NULL; SgFr_state(sg_fr) += 2; /* complete --> compiled : complete_in_use --> compiled_in_use */ current_node = TrNode_child(SgFr_answer_trie(sg_fr)); @@ -1191,129 +1124,112 @@ void update_answer_trie(sg_fr_ptr sg_fr) { } -#ifdef GLOBAL_TRIE -void free_subgoal_trie_branch(sg_node_ptr current_node, int nodes_left, int position) { - if (nodes_left) { - free_subgoal_trie_branch(TrNode_child(current_node), nodes_left - 1, TRAVERSE_POSITION_FIRST); -#else -void free_subgoal_trie_branch(sg_node_ptr current_node, int nodes_left, int nodes_extra, int position) { - if (nodes_left) { - int current_nodes_left = 0, current_nodes_extra = 0; - - /* save current state if first sibling node */ - if (position == TRAVERSE_POSITION_FIRST) { - current_nodes_left = nodes_left; - current_nodes_extra = nodes_extra; - } - - if (nodes_extra) { -#ifdef TRIE_COMPACT_PAIRS - if (nodes_extra < 0) { - Term t = TrNode_entry(current_node); - if (IsPairTerm(t)) { - if (t == CompactPairInit) - nodes_extra--; - else /* CompactPairEndList / CompactPairEndTerm */ - nodes_extra++; - } - } else -#endif /* TRIE_COMPACT_PAIRS */ - if (--nodes_extra == 0) - nodes_left--; - } else { +void free_subgoal_trie(sg_node_ptr current_node, int mode, int position) { + if (! IS_SUBGOAL_LEAF_NODE(current_node)) { + int child_mode; + if (mode == TRAVERSE_MODE_NORMAL) { Term t = TrNode_entry(current_node); - if (IsVarTerm(t) || IsAtomOrIntTerm(t)) - nodes_left--; - else if (IsPairTerm(t)) -#ifdef TRIE_COMPACT_PAIRS - /* CompactPairInit */ - nodes_extra = -1; -#else - nodes_left++; -#endif /* TRIE_COMPACT_PAIRS */ - else if (IsApplTerm(t)) { + if (IsApplTerm(t)) { Functor f = (Functor) RepAppl(t); if (f == FunctorDouble) -#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P - nodes_extra = 2; -#else - nodes_extra = 1; -#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ + child_mode = TRAVERSE_MODE_DOUBLE; else if (f == FunctorLongInt) - nodes_extra = 1; + child_mode = TRAVERSE_MODE_LONGINT; else - nodes_left += ArityOfFunctor(f) - 1; - } - } - free_subgoal_trie_branch(TrNode_child(current_node), nodes_left, nodes_extra, TRAVERSE_POSITION_FIRST); -#endif /* GLOBAL_TRIE */ - if (position == TRAVERSE_POSITION_FIRST) { - sg_node_ptr next_node = TrNode_next(current_node); - DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node)); - FREE_SUBGOAL_TRIE_NODE(current_node); -#ifndef GLOBAL_TRIE - /* restore the initial state */ - nodes_left = current_nodes_left; - nodes_extra = current_nodes_extra; -#endif /* GLOBAL_TRIE */ - while (next_node) { - current_node = next_node; - next_node = TrNode_next(current_node); -#ifdef GLOBAL_TRIE - free_subgoal_trie_branch(current_node, nodes_left, TRAVERSE_POSITION_NEXT); -#else - free_subgoal_trie_branch(current_node, nodes_left, nodes_extra, TRAVERSE_POSITION_NEXT); -#endif /* GLOBAL_TRIE */ - } - } else { - DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node)); - FREE_SUBGOAL_TRIE_NODE(current_node); - } + child_mode = TRAVERSE_MODE_NORMAL; + } else + child_mode = TRAVERSE_MODE_NORMAL; + } else if (mode == TRAVERSE_MODE_LONGINT) + child_mode = TRAVERSE_MODE_LONGINT_END; + else if (mode == TRAVERSE_MODE_DOUBLE) +#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P + child_mode = TRAVERSE_MODE_DOUBLE2; + else if (mode == TRAVERSE_MODE_DOUBLE2) +#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ + child_mode = TRAVERSE_MODE_DOUBLE_END; + else + child_mode = TRAVERSE_MODE_NORMAL; + free_subgoal_trie(TrNode_child(current_node), child_mode, TRAVERSE_POSITION_FIRST); } else { sg_fr_ptr sg_fr; ans_node_ptr ans_node; - sg_fr = (sg_fr_ptr) current_node; - free_answer_trie_hash_chain(SgFr_hash_chain(sg_fr)); + sg_fr = UNTAG_SUBGOAL_LEAF_NODE(TrNode_sg_fr(current_node)); + free_answer_hash_chain(SgFr_hash_chain(sg_fr)); ans_node = SgFr_answer_trie(sg_fr); if (TrNode_child(ans_node)) - free_answer_trie_branch(TrNode_child(ans_node), TRAVERSE_POSITION_FIRST); + free_answer_trie(TrNode_child(ans_node), TRAVERSE_MODE_NORMAL, TRAVERSE_POSITION_FIRST); FREE_ANSWER_TRIE_NODE(ans_node); #ifdef LIMIT_TABLING remove_from_global_sg_fr_list(sg_fr); #endif /* LIMIT_TABLING */ FREE_SUBGOAL_FRAME(sg_fr); } - + if (position == TRAVERSE_POSITION_FIRST) { + sg_node_ptr next_node = TrNode_next(current_node); + CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node), mode); + FREE_SUBGOAL_TRIE_NODE(current_node); + while (next_node) { + current_node = next_node; + next_node = TrNode_next(current_node); + free_subgoal_trie(current_node, mode, TRAVERSE_POSITION_NEXT); + } + } else { + CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node), mode); + FREE_SUBGOAL_TRIE_NODE(current_node); + } return; } -void free_answer_trie_branch(ans_node_ptr current_node, int position) { +void free_answer_trie(ans_node_ptr current_node, int mode, int position) { #ifdef TABLING_INNER_CUTS - if (! IS_ANSWER_LEAF_NODE(current_node) && TrNode_child(current_node)) + if (! IS_ANSWER_LEAF_NODE(current_node) && TrNode_child(current_node)) { #else - if (! IS_ANSWER_LEAF_NODE(current_node)) + if (! IS_ANSWER_LEAF_NODE(current_node)) { #endif /* TABLING_INNER_CUTS */ - free_answer_trie_branch(TrNode_child(current_node), TRAVERSE_POSITION_FIRST); - + int child_mode; + if (mode == TRAVERSE_MODE_NORMAL) { + Term t = TrNode_entry(current_node); + if (IsApplTerm(t)) { + Functor f = (Functor) RepAppl(t); + if (f == FunctorDouble) + child_mode = TRAVERSE_MODE_DOUBLE; + else if (f == FunctorLongInt) + child_mode = TRAVERSE_MODE_LONGINT; + else + child_mode = TRAVERSE_MODE_NORMAL; + } else + child_mode = TRAVERSE_MODE_NORMAL; + } else if (mode == TRAVERSE_MODE_LONGINT) + child_mode = TRAVERSE_MODE_LONGINT_END; + else if (mode == TRAVERSE_MODE_DOUBLE) +#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P + child_mode = TRAVERSE_MODE_DOUBLE2; + else if (mode == TRAVERSE_MODE_DOUBLE2) +#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */ + child_mode = TRAVERSE_MODE_DOUBLE_END; + else + child_mode = TRAVERSE_MODE_NORMAL; + free_answer_trie(TrNode_child(current_node), child_mode, TRAVERSE_POSITION_FIRST); + } if (position == TRAVERSE_POSITION_FIRST) { ans_node_ptr next_node = TrNode_next(current_node); - DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node)); + CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node), mode); FREE_ANSWER_TRIE_NODE(current_node); while (next_node) { current_node = next_node; next_node = TrNode_next(current_node); - free_answer_trie_branch(current_node, TRAVERSE_POSITION_NEXT); + free_answer_trie(current_node, mode, TRAVERSE_POSITION_NEXT); } } else { - DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node)); + CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(TrNode_entry(current_node), mode); FREE_ANSWER_TRIE_NODE(current_node); } return; } -void free_subgoal_trie_hash_chain(sg_hash_ptr hash) { +void free_subgoal_hash_chain(sg_hash_ptr hash) { while (hash) { sg_node_ptr chain_node, *bucket, *last_bucket; sg_hash_ptr next_hash; @@ -1341,7 +1257,7 @@ void free_subgoal_trie_hash_chain(sg_hash_ptr hash) { } -void free_answer_trie_hash_chain(ans_hash_ptr hash) { +void free_answer_hash_chain(ans_hash_ptr hash) { while (hash) { ans_node_ptr chain_node, *bucket, *last_bucket; ans_hash_ptr next_hash; @@ -1384,9 +1300,7 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) { TrStat_answers_pruned = 0; #endif /* TABLING_INNER_CUTS */ TrStat_ans_nodes = 0; -#ifdef GLOBAL_TRIE TrStat_gt_refs = 0; -#endif /* GLOBAL_TRIE */ fprintf(Yap_stdout, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent)); } else { /* SHOW_MODE_STRUCTURE */ fprintf(Yap_stdout, "Table structure for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent)); @@ -1403,7 +1317,7 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) { free(str); free(arity); } else { - sg_fr_ptr sg_fr = (sg_fr_ptr) sg_node; + sg_fr_ptr sg_fr = UNTAG_SUBGOAL_LEAF_NODE(sg_node); TrStat_subgoals++; SHOW_TABLE_STRUCTURE(" ?- %s.\n", AtomName(TabEnt_atom(tab_ent))); TrStat_ans_nodes++; @@ -1435,15 +1349,12 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) { fprintf(Yap_stdout, " Answers 'TRUE': %ld\n", TrStat_answers_true); fprintf(Yap_stdout, " Answers 'NO': %ld\n", TrStat_answers_no); fprintf(Yap_stdout, " Answer trie nodes: %ld\n", TrStat_ans_nodes); -#ifdef GLOBAL_TRIE fprintf(Yap_stdout, " Global trie references: %ld\n", TrStat_gt_refs); -#endif /* GLOBAL_TRIE */ } return; } -#ifdef GLOBAL_TRIE void show_global_trie(int show_mode) { TrStat_show = show_mode; if (show_mode == SHOW_MODE_STATISTICS) { @@ -1470,5 +1381,4 @@ void show_global_trie(int show_mode) { } return; } -#endif /* GLOBAL_TRIE */ #endif /* TABLING */ diff --git a/OPTYap/tab.tries.i b/OPTYap/tab.tries.i index bc0d36eff..0a64cb48f 100644 --- a/OPTYap/tab.tries.i +++ b/OPTYap/tab.tries.i @@ -773,18 +773,22 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node /************************************************************************ -** subgoal_search_loop(_gt_(sub)term) ** +** subgoal_search(_global_trie)(_terms)_loop ** ************************************************************************/ #ifdef INCLUDE_SUBGOAL_SEARCH_LOOP #ifdef MODE_GLOBAL_TRIE_LOOP -#ifdef GLOBAL_TRIE_FOR_TERMS -static inline gt_node_ptr subgoal_search_loop_gt_term(Term t, int *subs_arity_ptr, CELL **stack_vars_ptr) { -#elif GLOBAL_TRIE_FOR_SUBTERMS -static inline gt_node_ptr subgoal_search_loop_gt_subterm(Term t, int *subs_arity_ptr, CELL **stack_vars_ptr, CELL *stack_terms) { -#endif +#ifdef GLOBAL_TRIE_FOR_SUBTERMS +static inline gt_node_ptr subgoal_search_global_trie_terms_loop(Term t, int *subs_arity_ptr, CELL **stack_vars_ptr, CELL *stack_terms) { +#else +static inline gt_node_ptr subgoal_search_global_trie_loop(Term t, int *subs_arity_ptr, CELL **stack_vars_ptr) { +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ +#else +#ifdef MODE_TERMS_LOOP +static inline sg_node_ptr subgoal_search_terms_loop(tab_ent_ptr tab_ent, sg_node_ptr current_node, Term t, int *subs_arity_ptr, CELL **stack_vars_ptr) { #else static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr current_node, Term t, int *subs_arity_ptr, CELL **stack_vars_ptr) { +#endif /* MODE_TERMS_LOOP */ #endif /* MODE_GLOBAL_TRIE_LOOP */ /************************************************************************ =========== @@ -830,13 +834,18 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c #endif /* MODE_GLOBAL_TRIE_LOOP */ int subs_arity = *subs_arity_ptr; CELL *stack_vars = *stack_vars_ptr; -#if !defined(MODE_GLOBAL_TRIE_LOOP) || !defined(GLOBAL_TRIE_FOR_SUBTERMS) +#if ! defined(MODE_GLOBAL_TRIE_LOOP) || ! defined(GLOBAL_TRIE_FOR_SUBTERMS) CELL *stack_terms = (CELL *) Yap_TrailTop; #endif /* ! MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE_FOR_SUBTERMS */ CELL *stack_terms_limit = (CELL *) TR; AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1); /* + 1 because initially we stiil haven't done any STACK_POP_DOWN */ STACK_PUSH_UP(NULL, stack_terms); +#if defined(MODE_GLOBAL_TRIE_LOOP) + /* for the global trie, it is safe to skip the IsVarTerm() and IsAtomOrIntTerm() tests in the first iteration */ + goto subgoal_search_loop_non_atomic; +#endif /* MODE_GLOBAL_TRIE_LOOP */ + do { if (IsVarTerm(t)) { if (IsTableVarTerm(t)) { @@ -844,7 +853,7 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, t); } else { if (subs_arity == MAX_TABLE_VARS) - Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop(_gt_(sub)term): MAX_TABLE_VARS exceeded"); + Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop: MAX_TABLE_VARS exceeded"); STACK_PUSH_UP(t, stack_vars); *((CELL *)t) = GLOBAL_table_var_enumerator(subs_arity); t = MakeTableVarTerm(subs_arity); @@ -853,19 +862,23 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c } } else if (IsAtomOrIntTerm(t)) { SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, t); -#if !defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE) +#ifdef MODE_TERMS_LOOP } else { gt_node_ptr entry_node; -#ifdef GLOBAL_TRIE_FOR_TERMS - entry_node = subgoal_search_loop_gt_term(t, &subs_arity, &stack_vars); -#elif GLOBAL_TRIE_FOR_SUBTERMS - entry_node = subgoal_search_loop_gt_subterm(t, &subs_arity, &stack_vars, stack_terms); -#endif +#ifdef GLOBAL_TRIE_FOR_SUBTERMS + entry_node = subgoal_search_global_trie_terms_loop(t, &subs_arity, &stack_vars, stack_terms); +#else + entry_node = subgoal_search_global_trie_loop(t, &subs_arity, &stack_vars); +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ current_node = subgoal_trie_check_insert_gt_entry(tab_ent, current_node, (Term) entry_node); - } -#else /* MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE */ +#else /* ! MODE_TERMS_LOOP */ + } else +#if defined(MODE_GLOBAL_TRIE_LOOP) + /* for the global trie, it is safe to start here in the first iteration */ + subgoal_search_loop_non_atomic: +#endif /* MODE_GLOBAL_TRIE_LOOP */ #ifdef TRIE_COMPACT_PAIRS - } else if (IsPairTerm(t)) { + if (IsPairTerm(t)) { CELL *aux_pair = RepPair(t); if (aux_pair == PairTermMark) { t = STACK_POP_DOWN(stack_terms); @@ -888,7 +901,7 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c } #if defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE_FOR_SUBTERMS) } else if (current_node != GLOBAL_root_gt) { - gt_node_ptr entry_node = subgoal_search_loop_gt_subterm(t, &subs_arity, &stack_vars, stack_terms); + gt_node_ptr entry_node = subgoal_search_global_trie_terms_loop(t, &subs_arity, &stack_vars, stack_terms); current_node = global_trie_check_insert_gt_entry(current_node, (Term) entry_node); #endif /* MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE_FOR_SUBTERMS */ } else { @@ -905,16 +918,17 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c } #if defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE_FOR_SUBTERMS) } else if (current_node != GLOBAL_root_gt) { - gt_node_ptr entry_node = subgoal_search_loop_gt_subterm(t, &subs_arity, &stack_vars, stack_terms); + gt_node_ptr entry_node = subgoal_search_global_trie_terms_loop(t, &subs_arity, &stack_vars, stack_terms); current_node = global_trie_check_insert_gt_entry(current_node, (Term) entry_node); #endif /* MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE_FOR_SUBTERMS */ -#else +#else /* ! TRIE_COMPACT_PAIRS */ #if defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE_FOR_SUBTERMS) - } else if (current_node != GLOBAL_root_gt) { - gt_node_ptr entry_node = subgoal_search_loop_gt_subterm(t, &subs_arity, &stack_vars, stack_terms); + if (current_node != GLOBAL_root_gt) { + gt_node_ptr entry_node = subgoal_search_global_trie_terms_loop(t, &subs_arity, &stack_vars, stack_terms); current_node = global_trie_check_insert_gt_entry(current_node, (Term) entry_node); + } else #endif /* MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE_FOR_SUBTERMS */ - } else if (IsPairTerm(t)) { + if (IsPairTerm(t)) { CELL *aux_pair = RepPair(t); SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, AbsPair(NULL)); AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1); @@ -942,9 +956,9 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c SUBGOAL_CHECK_INSERT_ENTRY(tab_ent, current_node, AbsAppl((Term *)f)); #endif /* MODE_GLOBAL_TRIE_LOOP */ } else if (f == FunctorDBRef) { - Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop(_gt_(sub)term): unsupported type tag FunctorDBRef"); + Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop: unsupported type tag FunctorDBRef"); } else if (f == FunctorBigInt) { - Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop(_gt_(sub)term): unsupported type tag FunctorBigInt"); + Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop: unsupported type tag FunctorBigInt"); } else { int i; CELL *aux_appl = RepAppl(t); @@ -954,9 +968,9 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c STACK_PUSH_UP(Deref(aux_appl[i]), stack_terms); } } else { - Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop(_gt_(sub)term): unknown type tag"); + Yap_Error(INTERNAL_ERROR, TermNil, "subgoal_search_loop: unknown type tag"); +#endif /* MODE_TERMS_LOOP */ } -#endif /* MODE_GLOBAL_TRIE_LOOP + GLOBAL_TRIE + */ t = STACK_POP_DOWN(stack_terms); } while (t); @@ -969,18 +983,22 @@ static inline sg_node_ptr subgoal_search_loop(tab_ent_ptr tab_ent, sg_node_ptr c /************************************************************************ -** answer_search_loop(_gt_(sub)term) ** +** answer_search(_global_trie)(_terms)_loop ** ************************************************************************/ #ifdef INCLUDE_ANSWER_SEARCH_LOOP #ifdef MODE_GLOBAL_TRIE_LOOP -#ifdef GLOBAL_TRIE_FOR_TERMS -static inline gt_node_ptr answer_search_loop_gt_term(Term t, int *vars_arity_ptr) { -#elif GLOBAL_TRIE_FOR_SUBTERMS -static inline gt_node_ptr answer_search_loop_gt_subterm(Term t, int *vars_arity_ptr, CELL *stack_terms) { -#endif +#ifdef GLOBAL_TRIE_FOR_SUBTERMS +static inline gt_node_ptr answer_search_global_trie_terms_loop(Term t, int *vars_arity_ptr, CELL *stack_terms) { +#else +static inline gt_node_ptr answer_search_global_trie_loop(Term t, int *vars_arity_ptr) { +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ +#else +#ifdef MODE_TERMS_LOOP +static inline ans_node_ptr answer_search_terms_loop(sg_fr_ptr sg_fr, ans_node_ptr current_node, Term t, int *vars_arity_ptr) { #else static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr current_node, Term t, int *vars_arity_ptr) { +#endif /* MODE_TERMS_LOOP */ #endif /* MODE_GLOBAL_TRIE_LOOP */ /************************************************************************ =========== @@ -1015,7 +1033,7 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr gt_node_ptr current_node = GLOBAL_root_gt; #endif /* MODE_GLOBAL_TRIE_LOOP */ int vars_arity = *vars_arity_ptr; -#if !defined(MODE_GLOBAL_TRIE_LOOP) || !defined(GLOBAL_TRIE_FOR_SUBTERMS) +#if ! defined(MODE_GLOBAL_TRIE_LOOP) || ! defined(GLOBAL_TRIE_FOR_SUBTERMS) CELL *stack_terms = (CELL *) Yap_TrailTop; #endif /* ! MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE_FOR_SUBTERMS */ CELL *stack_vars_base = (CELL *) TR; @@ -1028,6 +1046,11 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1); /* + 1 because initially we stiil haven't done any STACK_POP_DOWN */ STACK_PUSH_UP(NULL, stack_terms); +#if defined(MODE_GLOBAL_TRIE_LOOP) + /* for the global trie, it is safe to skip the IsVarTerm() and IsAtomOrIntTerm() tests in the first iteration */ + goto answer_search_loop_non_atomic; +#endif /* MODE_GLOBAL_TRIE_LOOP */ + do { if (IsVarTerm(t)) { t = Deref(t); @@ -1036,7 +1059,7 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, t, _trie_retry_val + in_pair); } else { if (vars_arity == MAX_TABLE_VARS) - Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop(_gt_(sub)term): MAX_TABLE_VARS exceeded"); + Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop: MAX_TABLE_VARS exceeded"); stack_vars_base[vars_arity] = t; *((CELL *)t) = GLOBAL_table_var_enumerator(vars_arity); t = MakeTableVarTerm(vars_arity); @@ -1048,20 +1071,26 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr #endif /* TRIE_COMPACT_PAIRS */ } else if (IsAtomOrIntTerm(t)) { ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, t, _trie_retry_atom + in_pair); -#if !defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE) - } else { - gt_node_ptr entry_node; -#ifdef GLOBAL_TRIE_FOR_TERMS - entry_node = answer_search_loop_gt_term(t, &vars_arity); -#elif GLOBAL_TRIE_FOR_SUBTERMS - entry_node = answer_search_loop_gt_subterm(t, &vars_arity, stack_terms); -#endif - current_node = answer_trie_check_insert_gt_entry(sg_fr, current_node, (Term) entry_node, _trie_retry_gterm + in_pair); - } -#else /* MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE */ #ifdef TRIE_COMPACT_PAIRS in_pair = 0; - } else if (IsPairTerm(t)) { +#endif /* TRIE_COMPACT_PAIRS */ +#ifdef MODE_TERMS_LOOP + } else { + gt_node_ptr entry_node; +#ifdef GLOBAL_TRIE_FOR_SUBTERMS + entry_node = answer_search_global_trie_terms_loop(t, &vars_arity, stack_terms); +#else + entry_node = answer_search_global_trie_loop(t, &vars_arity); +#endif /* GLOBAL_TRIE_FOR_SUBTERMS */ + current_node = answer_trie_check_insert_gt_entry(sg_fr, current_node, (Term) entry_node, _trie_retry_gterm + in_pair); +#else /* ! MODE_TERMS_LOOP */ + } else +#if defined(MODE_GLOBAL_TRIE_LOOP) + /* for the global trie, it is safe to start here in the first iteration */ + answer_search_loop_non_atomic: +#endif /* MODE_GLOBAL_TRIE_LOOP */ +#ifdef TRIE_COMPACT_PAIRS + if (IsPairTerm(t)) { CELL *aux_pair = RepPair(t); if (aux_pair == PairTermMark) { t = STACK_POP_DOWN(stack_terms); @@ -1085,7 +1114,7 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr } #if defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE_FOR_SUBTERMS) } else if (current_node != GLOBAL_root_gt) { - gt_node_ptr entry_node = answer_search_loop_gt_subterm(t, &vars_arity, stack_terms); + gt_node_ptr entry_node = answer_search_global_trie_terms_loop(t, &vars_arity, stack_terms); current_node = global_trie_check_insert_gt_entry(current_node, (Term) entry_node); #endif /* MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE_FOR_SUBTERMS */ } else { @@ -1104,16 +1133,17 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr } #if defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE_FOR_SUBTERMS) } else if (current_node != GLOBAL_root_gt) { - gt_node_ptr entry_node = answer_search_loop_gt_subterm(t, &vars_arity, stack_terms); + gt_node_ptr entry_node = answer_search_global_trie_terms_loop(t, &vars_arity, stack_terms); current_node = global_trie_check_insert_gt_entry(current_node, (Term) entry_node); #endif /* MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE_FOR_SUBTERMS */ -#else +#else /* ! TRIE_COMPACT_PAIRS */ #if defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE_FOR_SUBTERMS) - } else if (current_node != GLOBAL_root_gt) { - gt_node_ptr entry_node = answer_search_loop_gt_subterm(t, &vars_arity, stack_terms); + if (current_node != GLOBAL_root_gt) { + gt_node_ptr entry_node = answer_search_global_trie_terms_loop(t, &vars_arity, stack_terms); current_node = global_trie_check_insert_gt_entry(current_node, (Term) entry_node); + } else #endif /* MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE_FOR_SUBTERMS */ - } else if (IsPairTerm(t)) { + if (IsPairTerm(t)) { CELL *aux_pair = RepPair(t); ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, AbsPair(NULL), _trie_retry_pair); AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1); @@ -1137,9 +1167,9 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, li, _trie_retry_extension); ANSWER_CHECK_INSERT_ENTRY(sg_fr, current_node, AbsAppl((Term *)f), _trie_retry_longint); } else if (f == FunctorDBRef) { - Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop(_gt_(sub)term): unsupported type tag FunctorDBRef"); + Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop: unsupported type tag FunctorDBRef"); } else if (f == FunctorBigInt) { - Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop(_gt_(sub)term): unsupported type tag FunctorBigInt"); + Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop: unsupported type tag FunctorBigInt"); } else { int i; CELL *aux_appl = RepAppl(t); @@ -1152,9 +1182,9 @@ static inline ans_node_ptr answer_search_loop(sg_fr_ptr sg_fr, ans_node_ptr curr in_pair = 0; #endif /* TRIE_COMPACT_PAIRS */ } else { - Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop(_gt_(sub)term): unknown type tag"); + Yap_Error(INTERNAL_ERROR, TermNil, "answer_search_loop: unknown type tag"); +#endif /* MODE_TERMS_LOOP */ } -#endif /* MODE_GLOBAL_TRIE_LOOP + GLOBAL_TRIE */ t = STACK_POP_DOWN(stack_terms); } while (t); @@ -1215,10 +1245,10 @@ static inline CELL *load_answer_loop(ans_node_ptr current_node) { #endif /* MODE_GLOBAL_TRIE_LOOP */ CELL *stack_vars_base = (CELL *) TR; #define stack_terms_limit (stack_vars_base + vars_arity) -#if defined(TRIE_COMPACT_PAIRS) && (defined(MODE_GLOBAL_TRIE_LOOP) || !defined(GLOBAL_TRIE)) +#ifdef TRIE_COMPACT_PAIRS #define stack_terms_base ((CELL *) Yap_TrailTop) int stack_terms_pair_offset = 0; -#endif /* TRIE_COMPACT_PAIRS && (MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE) */ +#endif /* TRIE_COMPACT_PAIRS */ Term t = TrNode_entry(current_node); #ifdef MODE_GLOBAL_TRIE_LOOP current_node = TrNode_parent(current_node); @@ -1228,11 +1258,11 @@ static inline CELL *load_answer_loop(ans_node_ptr current_node) { do { if (IsVarTerm(t)) { -#if (!defined(MODE_GLOBAL_TRIE_LOOP) && defined(GLOBAL_TRIE)) || defined(GLOBAL_TRIE_FOR_SUBTERMS) +#if ! defined(MODE_GLOBAL_TRIE_LOOP) || defined(GLOBAL_TRIE_FOR_SUBTERMS) if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) { stack_terms = load_substitution_loop((gt_node_ptr) t, &vars_arity, stack_terms); } else -#endif /* (! MODE_GLOBAL_TRIE_LOOP && GLOBAL_TRIE) || GLOBAL_TRIE_FOR_SUBTERMS */ +#endif /* ! MODE_GLOBAL_TRIE_LOOP || GLOBAL_TRIE_FOR_SUBTERMS */ { int var_index = VarIndexOfTableTerm(t); AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit - vars_arity + var_index + 1); if (var_index >= vars_arity) { @@ -1246,7 +1276,6 @@ static inline CELL *load_answer_loop(ans_node_ptr current_node) { } else if (IsAtomOrIntTerm(t)) { AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit); STACK_PUSH_UP(t, stack_terms); -#if defined(MODE_GLOBAL_TRIE_LOOP) || !defined(GLOBAL_TRIE) } else if (IsPairTerm(t)) { #ifdef TRIE_COMPACT_PAIRS if (t == CompactPairInit) { @@ -1269,7 +1298,7 @@ static inline CELL *load_answer_loop(ans_node_ptr current_node) { STACK_PUSH_UP(TermNil, stack_terms); STACK_PUSH_UP(last, stack_terms); } -#else +#else /* ! TRIE_COMPACT_PAIRS */ Term head = STACK_POP_DOWN(stack_terms); Term tail = STACK_POP_DOWN(stack_terms); t = MkPairTerm(head, tail); @@ -1302,7 +1331,6 @@ static inline CELL *load_answer_loop(ans_node_ptr current_node) { } AUX_STACK_CHECK_EXPAND(stack_terms, stack_terms_limit); STACK_PUSH_UP(t, stack_terms); -#endif /* MODE_GLOBAL_TRIE_LOOP || ! GLOBAL_TRIE */ } t = TrNode_entry(current_node); current_node = TrNode_parent(current_node); diff --git a/OPTYap/tab.tries.insts.i b/OPTYap/tab.tries.insts.i index 7a852696c..e7e34c041 100644 --- a/OPTYap/tab.tries.insts.i +++ b/OPTYap/tab.tries.insts.i @@ -14,31 +14,31 @@ /************************************************************************ ** Trie instructions: auxiliary stack organization ** ************************************************************************* - ------------------- - | ha = heap_arity | - ------------------- -- - | heap ptr 1 | | - ------------------- | - | ... | -- heap_arity (0 if GLOBAL_TRIE) - ------------------- | - | heap ptr ha | | - ------------------- -- - | va = vars_arity | - ------------------- -- - | var ptr va | | - ------------------- | - | ... | -- vars_arity - ------------------- | - | var ptr 1 | | - ------------------- -- - | sa = subs_arity | - ------------------- -- - | subs ptr sa | | - ------------------- | - | ... | -- subs_arity - ------------------- | - | subs ptr 1 | | - ------------------- -- + ------------------- + | ha = heap_arity | + ------------------- -- + | heap ptr 1 | | + ------------------- | + | ... | -- heap_arity (0 if in global trie) + ------------------- | + | heap ptr ha | | + ------------------- -- + | va = vars_arity | + ------------------- -- + | var ptr va | | + ------------------- | + | ... | -- vars_arity + ------------------- | + | var ptr 1 | | + ------------------- -- + | sa = subs_arity | + ------------------- -- + | subs ptr sa | | + ------------------- | + | ... | -- subs_arity + ------------------- | + | subs ptr 1 | | + ------------------- -- ************************************************************************/ @@ -458,7 +458,7 @@ PBOp(trie_do_var_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -468,12 +468,12 @@ aux_stack_var_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_do_var_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_trust_var_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -484,12 +484,12 @@ aux_stack_var_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_var_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_try_var_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -500,12 +500,12 @@ aux_stack_var_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_var_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_retry_var_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -516,7 +516,7 @@ aux_stack_var_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_var_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -572,7 +572,7 @@ PBOp(trie_do_val_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -583,12 +583,12 @@ aux_stack_val_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_do_val_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_trust_val_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -600,12 +600,12 @@ aux_stack_val_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_val_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_try_val_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -617,12 +617,12 @@ aux_stack_val_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_val_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_retry_val_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -634,7 +634,7 @@ aux_stack_val_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_val_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -690,7 +690,7 @@ PBOp(trie_do_atom_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -700,12 +700,12 @@ aux_stack_term_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_do_atom_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_trust_atom_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -716,12 +716,12 @@ aux_stack_term_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_atom_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_try_atom_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -732,12 +732,12 @@ aux_stack_term_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_atom_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); PBOp(trie_retry_atom_in_pair, e) -#if defined(TRIE_COMPACT_PAIRS) && !defined(GLOBAL_TRIE) +#ifdef TRIE_COMPACT_PAIRS register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = aux_stack[HEAP_ARITY_ENTRY]; @@ -748,7 +748,7 @@ aux_stack_term_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_atom_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -806,7 +806,7 @@ aux_stack_new_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_do_null_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -822,7 +822,7 @@ aux_stack_new_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_null_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -838,7 +838,7 @@ aux_stack_new_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_null_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -854,7 +854,7 @@ aux_stack_new_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_null_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -973,7 +973,7 @@ aux_stack_appl_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_do_appl_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -991,7 +991,7 @@ aux_stack_appl_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_appl_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -1009,7 +1009,7 @@ aux_stack_appl_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_appl_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -1027,7 +1027,7 @@ aux_stack_appl_in_pair_instr(); #else Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_appl_in_pair: invalid instruction"); -#endif /* TRIE_COMPACT_PAIRS && ! GLOBAL_TRIE */ +#endif /* TRIE_COMPACT_PAIRS */ ENDPBOp(); @@ -1148,7 +1148,6 @@ PBOp(trie_do_gterm, e) -#ifdef GLOBAL_TRIE register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = 0; @@ -1157,14 +1156,10 @@ TOP_STACK = exec_substitution((gt_node_ptr)TrNode_entry(node), aux_stack); next_instruction(subs_arity - 1 , node); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "trie_do_gterm: invalid instruction"); -#endif /* GLOBAL_TRIE */ ENDPBOp(); PBOp(trie_trust_gterm, e) -#ifdef GLOBAL_TRIE register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = 0; @@ -1174,14 +1169,10 @@ pop_trie_node(); TOP_STACK = exec_substitution((gt_node_ptr)TrNode_entry(node), aux_stack); next_instruction(subs_arity - 1 , node); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "trie_trust_gterm: invalid instruction"); -#endif /* GLOBAL_TRIE */ ENDPBOp(); PBOp(trie_try_gterm, e) -#ifdef GLOBAL_TRIE register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = TOP_STACK; int heap_arity = 0; @@ -1191,14 +1182,10 @@ store_trie_node(TrNode_next(node)); TOP_STACK = exec_substitution((gt_node_ptr)TrNode_entry(node), aux_stack); next_instruction(subs_arity - 1, node); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "trie_try_gterm: invalid instruction"); -#endif /* GLOBAL_TRIE */ ENDPBOp(); PBOp(trie_retry_gterm, e) -#ifdef GLOBAL_TRIE register ans_node_ptr node = (ans_node_ptr) PREG; register CELL *aux_stack = (CELL *) (B + 1); int heap_arity = 0; @@ -1208,7 +1195,4 @@ restore_trie_node(TrNode_next(node)); TOP_STACK = exec_substitution((gt_node_ptr)TrNode_entry(node), aux_stack); next_instruction(subs_arity - 1, node); -#else - Yap_Error(INTERNAL_ERROR, TermNil, "trie_retry_gterm: invalid instruction"); -#endif /* GLOBAL_TRIE */ ENDPBOp(); diff --git a/pl/yapor.yap b/pl/yapor.yap index 385a9f290..75f53b58a 100644 --- a/pl/yapor.yap +++ b/pl/yapor.yap @@ -22,6 +22,7 @@ %% or_statistics/2 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% should match with code in OPTYap/opt.preds.c or_statistics(total_memory,[BytesInUse,BytesAllocated]) :- '$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated). or_statistics(or_frames,[BytesInUse,StructsInUse]) :- @@ -37,6 +38,7 @@ or_statistics(query_goal_answer_frames,[BytesInUse,StructsInUse]) :- %% opt_statistics/2 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% should match with code in OPTYap/opt.preds.c opt_statistics(total_memory,[BytesInUse,BytesAllocated]) :- '$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated). opt_statistics(table_entries,[BytesInUse,StructsInUse]) :- @@ -225,4 +227,4 @@ default_sequential(_). '$parallelizable'(use_module(_)) :- !, fail. '$parallelizable'(_). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ No newline at end of file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%