public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcc/109081] New: Confusion between FEATURE_LZCNT and FEATURE_ABM in i386 cpuinfo
@ 2023-03-09 15:09 fabian@ritter-vogt.de
  2023-03-10  1:39 ` [Bug target/109081] " crazylht at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: fabian@ritter-vogt.de @ 2023-03-09 15:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109081

            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 parts
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 == 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
== 0x80000001. The corresponding bit is also defined by cpuid.h, just called
ABM (technically correct as well):

/* Extended Features (%eax == 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 detection
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 == FEATURE_LZCNT.

Is it intentional that this is the case? Is it intentional that bit_LZCNT is
declared in the wrong section as well?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug target/109081] Confusion between FEATURE_LZCNT and FEATURE_ABM in i386 cpuinfo
  2023-03-09 15:09 [Bug libgcc/109081] New: Confusion between FEATURE_LZCNT and FEATURE_ABM in i386 cpuinfo fabian@ritter-vogt.de
@ 2023-03-10  1:39 ` crazylht at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: crazylht at gmail dot com @ 2023-03-10  1:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109081

--- Comment #1 from Hongtao.liu <crazylht at gmail dot com> ---
Here's what I got from wiki for the history of ABM and LZCNT.
https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set

------quoted from wiki-------
Intel and AMD use AMD's ABM flag to indicate LZCNT support (since LZCNT
combined with BMI1 and BMI2 completes the expanded ABM instruction set).
----end -----

So yes, they're exact the same.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-10  1:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 15:09 [Bug libgcc/109081] New: Confusion between FEATURE_LZCNT and FEATURE_ABM in i386 cpuinfo fabian@ritter-vogt.de
2023-03-10  1:39 ` [Bug target/109081] " crazylht at gmail dot com

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