Skip to content

Commit

Permalink
ENHANCED: Simplify generating a joined key for multiple arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWielemaker committed Jan 4, 2025
1 parent 720359e commit 7b25563
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/pl-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 1985-2024, University of Amsterdam
Copyright (c) 1985-2025, University of Amsterdam
VU University Amsterdam
SWI-Prolog Solutions b.v.
All rights reserved.
Expand Down Expand Up @@ -392,20 +392,26 @@ setClauseChoice(DECL_LD ClauseChoice chp, ClauseRef cref, gen_t generation)
}


static inline word
join_multi_arg_keys(const word *key, unsigned int len)
{ word k = MurmurHashAligned2(key, sizeof(word)*len, MURMUR_SEED);
return clean_index_key(k);
}

static inline word
indexKeyFromArgv(ClauseIndex ci, Word argv)
{ if ( likely(ci->args[1] == 0) )
{ return indexOfWord(argv[ci->args[0]-1]);
} else
{ word key[MAX_MULTI_INDEX];
int harg;
unsigned int harg;

for(harg=0; ci->args[harg]; harg++)
{ if ( !(key[harg] = indexOfWord(argv[ci->args[harg]-1])) )
return 0;
}

return murmur_key(key, sizeof(word)*harg);
return join_multi_arg_keys(key, harg);
}
}

Expand Down Expand Up @@ -1438,7 +1444,7 @@ indexKeyFromClause(ClauseIndex ci, Clause cl, Code *end)
return key;
return 0;
} else
{ word key[MAX_MULTI_INDEX]; /* TBD: special case for 1 arg */
{ word key[MAX_MULTI_INDEX];
int pcarg = 1;
int harg;

Expand All @@ -1452,7 +1458,7 @@ indexKeyFromClause(ClauseIndex ci, Clause cl, Code *end)
return 0;
}

return murmur_key(key, sizeof(word)*harg);
return join_multi_arg_keys(key, harg);
}
}

Expand Down Expand Up @@ -2624,7 +2630,7 @@ assess_scan_clauses(ClauseList clist, iarg_t ac,
if ( isvar )
a->var_count++;
else
assessAddKey(a, murmur_key(key, sizeof(word)*harg), false);
assessAddKey(a, join_multi_arg_keys(key, harg), false);
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/pl-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,13 @@ mask) and may never be 0.

#define KEY_INDEX_MAX 4

static inline word
clean_index_key(word key)
{ key &= ~((word)STG_GLOBAL);
if ( !key ) key = 1;
return key;
}

static inline word
murmur_key(const void *ptr, size_t n)
{ word k;
Expand All @@ -770,10 +777,7 @@ murmur_key(const void *ptr, size_t n)
{ k = MurmurHashAligned2(ptr, n, MURMUR_SEED);
}

k &= ~((word)STG_GLOBAL);
if ( !k ) k = 1;

return k;
return clean_index_key(k);
}

/*******************************
Expand Down

0 comments on commit 7b25563

Please sign in to comment.