more fixes to exo compilation.
This commit is contained in:
parent
6cd778f70b
commit
649fae4294
70
C/exo.c
70
C/exo.c
@ -32,19 +32,28 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//static int exo_write=FALSE;
|
||||||
|
|
||||||
|
//void do_write(void) { exo_write=TRUE;}
|
||||||
|
|
||||||
#define NEXTOP(V,TYPE) ((yamop *)(&((V)->u.TYPE.next)))
|
#define NEXTOP(V,TYPE) ((yamop *)(&((V)->u.TYPE.next)))
|
||||||
|
|
||||||
#define MAX_ARITY 256
|
#define MAX_ARITY 256
|
||||||
|
|
||||||
|
|
||||||
/* Simple hash function */
|
/* Simple hash function:
|
||||||
|
first component is the base key.
|
||||||
|
hash0 spreads extensions coming from different elements.
|
||||||
|
spread over j quadrants.
|
||||||
|
*/
|
||||||
static UInt
|
static UInt
|
||||||
HASH(UInt hash0, UInt j, CELL *cl, struct index_t *it)
|
HASH(UInt hash0, UInt j, CELL *cl, struct index_t *it)
|
||||||
{
|
{
|
||||||
Term t = cl[j];
|
Term t = cl[j];
|
||||||
|
UInt sz = it->hsize;
|
||||||
if (IsIntTerm(t))
|
if (IsIntTerm(t))
|
||||||
return (IntOfTerm(t) *257 + hash0 ) % (it->nels*2);
|
return (IntOfTerm(t) * 17* (hash0+1)*(j+1) ) % sz;
|
||||||
return ((t >> 3) *257 + hash0 ) % (it->nels*2);
|
return (((UInt)AtomOfTerm(t) >> 5)* 17*(hash0+1)*(j+1) ) % sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* search for matching elements */
|
/* search for matching elements */
|
||||||
@ -62,6 +71,12 @@ MATCH(CELL *clp, CELL *kvp, UInt j, struct index_t *it)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static UInt
|
||||||
|
NEXT(UInt hash, Term t, UInt j, struct index_t *it)
|
||||||
|
{
|
||||||
|
return (hash+(t>>4)+j+1) % (it->hsize);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
|
ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
|
||||||
{
|
{
|
||||||
@ -79,12 +94,6 @@ ADD_TO_TRY_CHAIN(CELL *kvp, CELL *cl, struct index_t *it)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static UInt
|
|
||||||
NEXT(UInt hash, struct index_t *it, UInt j)
|
|
||||||
{
|
|
||||||
return (hash+hash/3+j*257+1) % (it->nels*2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is the critical routine, it builds the hash table *
|
/* This is the critical routine, it builds the hash table *
|
||||||
* each HT field stores a key pointer which is actually
|
* each HT field stores a key pointer which is actually
|
||||||
* a pointer to the point in the clause where one can find the element.
|
* a pointer to the point in the clause where one can find the element.
|
||||||
@ -116,12 +125,13 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0)
|
|||||||
/* j is the firs bound element */
|
/* j is the firs bound element */
|
||||||
/* check if we match */
|
/* check if we match */
|
||||||
hash = hash0 = HASH(hash0, j, cl, it);
|
hash = hash0 = HASH(hash0, j, cl, it);
|
||||||
// printf("h=%ld j=%ld %lx\n", hash, j, cl[j]);
|
//if (exo_write) printf("h=%ld j=%ld %lx\n", hash, j, cl[j]);
|
||||||
next:
|
next:
|
||||||
/* loop to insert element */
|
/* loop to insert element */
|
||||||
kvp = it->key[hash];
|
kvp = it->key[hash];
|
||||||
if (kvp == NULL) {
|
if (kvp == NULL) {
|
||||||
/* simple case, new entry */
|
/* simple case, new entry */
|
||||||
|
it->nentries++;
|
||||||
it->key[hash] = cl+j;
|
it->key[hash] = cl+j;
|
||||||
return;
|
return;
|
||||||
} else if (MATCH(cl+j, kvp, j, it)) {
|
} else if (MATCH(cl+j, kvp, j, it)) {
|
||||||
@ -138,12 +148,13 @@ INSERT(CELL *cl, struct index_t *it, UInt arity, UInt base, UInt hash0)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it->ncols++;
|
it->ntrys++;
|
||||||
ADD_TO_TRY_CHAIN(kvp, cl, it);
|
ADD_TO_TRY_CHAIN(kvp, cl, it);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
hash = NEXT(hash, it, j);
|
it->ncollisions++;
|
||||||
// printf("N=%ld\n", hash);
|
hash = NEXT(hash, cl[j], j, it);
|
||||||
|
//if (exo_write) printf("N=%ld\n", hash);
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +196,7 @@ LOOKUP(struct index_t *it, UInt arity, UInt j)
|
|||||||
return NEXTOP(NEXTOP(it->code,lp),lp);
|
return NEXTOP(NEXTOP(it->code,lp),lp);
|
||||||
} else {
|
} else {
|
||||||
/* collision */
|
/* collision */
|
||||||
hash = NEXT(hash, it, j);
|
hash = NEXT(hash, XREGS[j+1], j, it);
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +212,7 @@ fill_hash(UInt bmap, struct index_t *it)
|
|||||||
INSERT(cl, it, arity, 0, 0);
|
INSERT(cl, it, arity, 0, 0);
|
||||||
cl += arity;
|
cl += arity;
|
||||||
}
|
}
|
||||||
for (i=0; i < it->nels*2; i++) {
|
for (i=0; i < it->hsize; i++) {
|
||||||
if (it->key[i]) {
|
if (it->key[i]) {
|
||||||
UInt offset = (it->key[i]-it->cls)/arity;
|
UInt offset = (it->key[i]-it->cls)/arity;
|
||||||
UInt last = it->links[offset];
|
UInt last = it->links[offset];
|
||||||
@ -232,17 +243,6 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
|
|||||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (count) {
|
|
||||||
if (!(base = (CELL *)Yap_AllocCodeSpace(3*sizeof(CELL)*ncls))) {
|
|
||||||
CACHE_REGS
|
|
||||||
save_machine_regs();
|
|
||||||
LOCAL_Error_Size = 3*ncls*sizeof(CELL);
|
|
||||||
LOCAL_ErrorMessage = "not enough space to index";
|
|
||||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
bzero(base, 3*sizeof(CELL)*ncls);
|
|
||||||
}
|
|
||||||
i->next = *ip;
|
i->next = *ip;
|
||||||
i->prev = NULL;
|
i->prev = NULL;
|
||||||
i->nels = ncls;
|
i->nels = ncls;
|
||||||
@ -251,15 +251,27 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
|
|||||||
i->bmap = bmap;
|
i->bmap = bmap;
|
||||||
i->is_key = FALSE;
|
i->is_key = FALSE;
|
||||||
i->hsize = 2*ncls;
|
i->hsize = 2*ncls;
|
||||||
|
if (count) {
|
||||||
|
if (!(base = (CELL *)Yap_AllocCodeSpace(sizeof(CELL)*(ncls+i->hsize)))) {
|
||||||
|
CACHE_REGS
|
||||||
|
save_machine_regs();
|
||||||
|
LOCAL_Error_Size = 3*ncls*sizeof(CELL);
|
||||||
|
LOCAL_ErrorMessage = "not enough space to generate indices";
|
||||||
|
Yap_FreeCodeSpace((void *)i);
|
||||||
|
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
bzero(base, 3*sizeof(CELL)*ncls);
|
||||||
|
}
|
||||||
i->key = (CELL **)base;
|
i->key = (CELL **)base;
|
||||||
i->links = (CELL *)(base+2*ncls);
|
i->links = (CELL *)(base+2*ncls);
|
||||||
i->hsize = 2*ncls;
|
i->ncollisions = i->nentries = i->ntrys = 0;
|
||||||
i->ncols = 0;
|
|
||||||
i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *));
|
i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *));
|
||||||
*ip = i;
|
*ip = i;
|
||||||
if (count) {
|
if (count) {
|
||||||
fill_hash(bmap, i);
|
fill_hash(bmap, i);
|
||||||
if (!i->ncols) {
|
printf("entries=%ld collisions=%ld trys=%ld\n", i->nentries, i->ncollisions, i->ntrys);
|
||||||
|
if (!i->ntrys) {
|
||||||
i->is_key = TRUE;
|
i->is_key = TRUE;
|
||||||
if (base != realloc(base, 2*sizeof(CELL)*ncls))
|
if (base != realloc(base, 2*sizeof(CELL)*ncls))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -166,7 +166,9 @@ typedef struct index_t {
|
|||||||
PredEntry *ap;
|
PredEntry *ap;
|
||||||
CELL bmap;
|
CELL bmap;
|
||||||
int is_key;
|
int is_key;
|
||||||
UInt ncols;
|
UInt ncollisions;
|
||||||
|
UInt ntrys;
|
||||||
|
UInt nentries;
|
||||||
UInt hsize;
|
UInt hsize;
|
||||||
CELL **key;
|
CELL **key;
|
||||||
CELL *cls;
|
CELL *cls;
|
||||||
|
Reference in New Issue
Block a user