public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Tune hash function for cross-reference entries
Date: Mon,  7 Nov 2022 09:41:47 +0100	[thread overview]
Message-ID: <20221107084147.152022-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 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.
-- 
2.34.1


                 reply	other threads:[~2022-11-07  8:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221107084147.152022-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).