From 7b2556304cc52aad683270fd0fa19e999c8591c8 Mon Sep 17 00:00:00 2001 From: Jan Wielemaker Date: Fri, 3 Jan 2025 15:23:47 +0100 Subject: [PATCH] ENHANCED: Simplify generating a joined key for multiple arguments. --- src/pl-index.c | 18 ++++++++++++------ src/pl-inline.h | 12 ++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/pl-index.c b/src/pl-index.c index 7ad0db88e1..b0eb39f48b 100644 --- a/src/pl-index.c +++ b/src/pl-index.c @@ -3,7 +3,7 @@ Author: Jan Wielemaker E-mail: J.Wielemaker@vu.nl 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. @@ -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); } } @@ -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; @@ -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); } } @@ -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); } } } diff --git a/src/pl-inline.h b/src/pl-inline.h index d20868ba2a..77f2f9719e 100644 --- a/src/pl-inline.h +++ b/src/pl-inline.h @@ -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; @@ -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); } /*******************************