From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2C6EE3858C5E; Thu, 9 Mar 2023 15:09:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C6EE3858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678374550; bh=26Xi9EVAliAQZ5Sojd56gc8zOeeAvToszBb45SAefIg=; h=From:To:Subject:Date:From; b=AWWUAehuQedjHFCqDKghXh6yqAh00YZ1U9W7gZ1Vce2FqRUIX9fibGoXQhCNHPALp qzfwVAorV1W//FFf+ToQgoZQZ2Wci42Pw3o83UkhLIbCg6de9zb/qAjByGl9GpA/AY HmryWdzsakxF+VuyecZNKnpBxnUe4FX/t5/jnVD8= From: "fabian@ritter-vogt.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug libgcc/109081] New: Confusion between FEATURE_LZCNT and FEATURE_ABM in i386 cpuinfo Date: Thu, 09 Mar 2023 15:09:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libgcc X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fabian@ritter-vogt.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109081 Bug ID: 109081 Summary: Confusion between FEATURE_LZCNT and FEATURE_ABM in i386 cpuinfo Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcc Assignee: unassigned at gcc dot gnu.org Reporter: fabian@ritter-vogt.de Target Milestone: --- For detecting the x86_64 microarchitecture level in RPM I tried to reuse pa= rts from libgcc to avoid mistakes: https://github.com/rpm-software-management/rpm/pull/2315 I did stumble upon some oddities around the LZCNT identification: gcc/config/i386/cpuid.h puts bit_LZCNT among other bits for CPUID %eax =3D= =3D 1: /* %ecx */ #define bit_SSE3 (1 << 0) #define bit_PCLMUL (1 << 1) #define bit_LZCNT (1 << 5) #define bit_SSSE3 (1 << 9) #define bit_FMA (1 << 12) However, bit 5 there actually stands for VMX. Presence of LZCNT is indicated (according to Intel and AMD docs) in CPUID %= eax =3D=3D 0x80000001. The corresponding bit is also defined by cpuid.h, just c= alled ABM (technically correct as well): /* Extended Features (%eax =3D=3D 0x80000001) */ /* %ecx */ #define bit_LAHF_LM (1 << 0) #define bit_ABM (1 << 5) #define bit_SSE4a (1 << 6) While the cpuid.h header defines bit_LZCNT in the wrong section, the detect= ion code in gcc/common/config/i386/cpuinfo.h actually uses it correctly: __cpuid (0x80000001, eax, ebx, ecx, edx); if (ecx & bit_SSE4a) set_feature (FEATURE_SSE4_A); if (ecx & bit_LAHF_LM) set_feature (FEATURE_LAHF_LM); if (ecx & bit_ABM) set_feature (FEATURE_ABM); if (ecx & bit_LWP) set_feature (FEATURE_LWP); if (ecx & bit_TBM) set_feature (FEATURE_TBM); if (ecx & bit_LZCNT) set_feature (FEATURE_LZCNT); However, because both bit_ABM and bit_LZCNT are (1 << 5), this means FEATURE_ABM =3D=3D FEATURE_LZCNT. Is it intentional that this is the case? Is it intentional that bit_LZCNT is declared in the wrong section as well?=