public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3745] ada: Tune hash function for cross-reference entries
@ 2022-11-07  8:40 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2022-11-07  8:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bcb3f09ec6cb9b2c6e58243d05b5a0fc33e909f1

commit r13-3745-gbcb3f09ec6cb9b2c6e58243d05b5a0fc33e909f1
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Tue Oct 18 09:33:38 2022 +0200

    ada: Tune hash function for cross-reference entries
    
    Tune the hash function that combines entity identifiers with source
    locations of where those entities are referenced. Previously the source
    location was multiplied by 2 ** 7 (i.e. shifted left by 7 bits), then
    added to the entity identifier, and finally divided modulo 2 ** 16 (i.e.
    masked to only use the lowest 16 bits). This hash routine caused
    collisions that could make some tests up to twice slower.
    
    With a large entity number the source location was only contributing few
    bits to the hash value. This large entity number might correspond to
    entity like Ada.Characters.Latin_1.NUL that occurs thousands of times in
    generated code.
    
    gcc/ada/
    
            * lib-xref.adb (Hash): Tune hash function.

Diff:
---
 gcc/ada/lib-xref.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/lib-xref.adb b/gcc/ada/lib-xref.adb
index 043444c0ea3..5a1538e523c 100644
--- a/gcc/ada/lib-xref.adb
+++ b/gcc/ada/lib-xref.adb
@@ -1271,10 +1271,10 @@ package body Lib.Xref is
       XE : Xref_Entry renames Xrefs.Table (F);
       type M is mod 2**32;
 
-      H : constant M := M (XE.Key.Ent) + 2 ** 7 * M (abs XE.Key.Loc);
+      H : constant M := 3 * M (XE.Key.Ent) + 5 * M (abs XE.Key.Loc);
       --  It would be more natural to write:
       --
-      --    H : constant M := M'Mod (XE.Key.Ent) + 2**7 * M'Mod (XE.Key.Loc);
+      --    H : constant M := 3 * M'Mod (XE.Key.Ent) + 5 * M'Mod (XE.Key.Loc);
       --
       --  But we can't use M'Mod, because it prevents bootstrapping with older
       --  compilers. Loc can be negative, so we do "abs" before converting.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-07  8:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07  8:40 [gcc r13-3745] ada: Tune hash function for cross-reference entries Marc Poulhi?s

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).