From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id BBD6238576BB for ; Mon, 7 Nov 2022 08:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BBD6238576BB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32e.google.com with SMTP id t4so6386487wmj.5 for ; Mon, 07 Nov 2022 00:41:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uj5BaDz4LAc1UoxmXbBgaRveRcffxi8Nm31rguWpFNc=; b=Y1qJEdBgICjVY7uA7sIgEA9KeI0OtB3LUp38n++L5jaCVSH10uZ1XK6+0Cz009d1Ya 9bYR0YFGsbWH+VCHZzyqCpnVo/YuQZjbf26mlETU4mOjI1jP2uVBHQ+3uzJ2p/ymSoLa J1vELKCTOvqyztcm7TlT/W1cbMensXT2hcgQviCHDwVHDb4hKilFx/APuui4frJznboe JfkwNDsejX1Yj0wJ8cyeQtMUs1CzLvvsxjtHk6InLbH0Kj5mwgvPCLulosEkyzr2WktY nKS4mbMEfocW+LV/fk04D7/uTfa2h06jlFMu0XqsIo3/bKBUWLjqCQdeL2S1hxlOsoYa DHYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uj5BaDz4LAc1UoxmXbBgaRveRcffxi8Nm31rguWpFNc=; b=faGjcgxJ0vYATdJ1G8eTFQk5G9GHz7QA28c73rlOy87jWV2OwbpKk5CMC+7k3eoUUJ PuLiGhsdO6HPIHWb9PnN5cZUgUQ8cbs0YlUjSNYDi30cXpazywtrg2GEmQOKhzeYqdXR DUmp01rx/6sERw37LqTtIhYjcFWFXub/AuBwyN2i6K0Bbfph+rWH+X1Wsb+EiBH/oI31 jSWGt9VmRJJIb3r1ZwVKCoaP3xRlygeXUbnHMe/ssSLodQxHwkzCzeRieDRRmQXQmE7E XuuZfqGjQYq48wFhYU/kU+ulRGhTyPfEv9abnjBjB1NqEnuw/YqEJBKZ1PVpagWd+mLd 80aw== X-Gm-Message-State: ACrzQf20vg4qTUgP76wBayx0i5qO73pkgXi/z2Qo/KK5soOlumLO1+ut mqPDtq4VYtOtnT2ypkBTrjHcRibXUs0Vfw== X-Google-Smtp-Source: AMsMyM5JLMAZCTeSN3n82PEMLPyI5YWnARj5RncLjg0bFTxrNPKpuayslKfAcS5bFkV+Bbhp19Ll5Q== X-Received: by 2002:a05:600c:554b:b0:3cf:84ea:3097 with SMTP id iz11-20020a05600c554b00b003cf84ea3097mr18903174wmb.100.1667810510532; Mon, 07 Nov 2022 00:41:50 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id f10-20020a05600c154a00b003a2f2bb72d5sm14333202wmg.45.2022.11.07.00.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 00:41:50 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Tune hash function for cross-reference entries Date: Mon, 7 Nov 2022 09:41:47 +0100 Message-Id: <20221107084147.152022-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Piotr Trojanek 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