V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-21 Thread H.J. Lu via Gcc-patches
On Wed, May 20, 2020 at 4:21 AM H.J. Lu  wrote:
>
> On Tue, May 19, 2020 at 11:10 PM Uros Bizjak  wrote:
> >
> > On Tue, May 19, 2020 at 11:40 PM H.J. Lu  wrote:
> >
> > > > > > > > > > I will take a look to see if we share the same CPU 
> > > > > > > > > > detection code between
> > > > > > > > > > libgcc and config/i386/driver-i386.c.
> > > > > > > > >
> > > > > > > > > I don't think it will bring any benefit, this is mainly one 
> > > > > > > > > huge
> > > > > > > > > switch statement that maps to different stuff in libgcc and
> > > > > > > > > driver-i386.
> > > > > > > >
> > > > > > > > libgcc and config/i386/driver-i386.c differ even before my 
> > > > > > > > patch.
> > > > > > > > I think we can do better.
> > > > > > > >
> > > > > > >
> > > > > > > Move cpuinfo.h from libgcc to common/config/i386 so that 
> > > > > > > get_intel_cpu
> > > > > > > can be shared by libgcc, GCC driver, 
> > > > > > > gcc.target/i386/builtin_target.c
> > > > > > > and libgfortran to detect the specific type of Intel CPU.  Update
> > > > > > > libgfortran to use has_cpu_feature to detect x86 CPU features.
> > > > > > >
> > > > > > > Tested on Linux/x86 and Linux/x86-64.  OK for master?
> > > > > >
> > > > > > Handling only Intel targets and not others is a sure way for patch 
> > > > > > to
> > > > > > be ignored.
> > > > > >
> > > > >
> > > > > Here is the updated patch to cover AMD CPU.  It also fixes:
> > > > >
> > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95212
> > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95220
> > > > >
> > > > > OK for master?
> > > >
> > > > Huh... I didn't think the solution will be this messy... I have to
> > > > rethink the approach a bit.
> > >
> > > That is what will happen when we have the same info in more than one place
> > > There should only one place for CPU info.
> >
> > Looking at the patch, it is clear that cpuinfo.c and driver-i386.c
> > should stay apart. They are two different things, and they are
> > orthogonal to each other; one can be updated without affecting the
> > other one. driver-i386.c handles way more targets than cpuinfo.c and
> > your patch only handles a subset of them. The unification does not
> > bring any benefit, it even complicates things more.
>
> There should one place to check a CPU feature, not 2.  It can
> be done with a proper cpuinfo.h.
>

This updated patch does it.   It removes duplicated codes and
simplifies the implementation.  With this patch, we just to update
a single place to add the new ISA support.


--
H.J.
From 719fe259432fdea0b2880a92549934e6c5dcca24 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Mon, 18 May 2020 05:58:41 -0700
Subject: [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
can be shared by libgcc, GCC driver and gcc.target/i386/builtin_target.c
to detect the specific type of Intel and AMD CPUs:

1. Use the same enum processor_features in libgcc and x86 backend.
2. Add more processor features to enum processor_features.
3. Add M_VENDOR, M_CPU_TYPE and M_CPU_SUBTYPE in i386-builtins.c to
avoid duplication in.
4. Use cpu_indicator_init, has_cpu_feature, get_amd_cpu and get_intel_cpu
in driver-i386.c and builtin_target.c.

gcc/

	PR target/95259
	* common/config/i386/cpuinfo.h: Moved from libgcc/config/i386.
	(processor_vendor): Add VENDOR_CENTAUR, VENDOR_CYRIX, VENDOR_NSC
	and BUILTIN_VENDOR_MAX.
	(processor_types): Add BUILTIN_CPU_TYPE_MAX.
	(processor_features): Add FEATURE_3DNOW, FEATURE_3DNOWP,
	FEATURE_ADX, FEATURE_ABM, FEATURE_CLDEMOTE, FEATURE_CLFLUSHOPT,
	FEATURE_CLWB, FEATURE_CLZERO, FEATURE_CMPXCHG16B,
	FEATURE_CMPXCHG8B, FEATURE_ENQCMD, FEATURE_F16C,
	FEATURE_FSGSBASE, FEATURE_FXSAVE, FEATURE_HLE, FEATURE_IBT,
	FEATURE_LAHF_LM, FEATURE_LM, FEATURE_LWP, FEATURE_LZCNT,
	FEATURE_MOVBE, FEATURE_MOVDIR64B, FEATURE_MOVDIRI,
	FEATURE_MWAITX, FEATURE_OSPKE, FEATURE_OSXSAVE, FEATURE_PCONFIG,
	FEATURE_PKU, FEATURE_PREFETCHWT1, FEATURE_PRFCHW,
	FEATURE_PTWRITE, FEATURE_RDPID, FEATURE_RDRND, FEATURE_RDSEED,
	FEATURE_RTM, FEATURE_SERIALIZE, FEATURE_SGX, FEATURE_SHA,
	FEATURE_SHSTK, FEATURE_TBM, FEATURE_TSXLDTRK, FEATURE_VAES,
	FEATURE_WAITPKG, FEATURE_WBNOINVD, FEATURE_XSAVE, FEATURE_XSAVEC,
	FEATURE_XSAVEOPT and FEATURE_XSAVES
	(__processor_model2): New.
	(__cpu_model): Removed.
	(__cpu_features2): Likewise.
	(SIZE_OF_CPU_FEATURES): New.
	(CHECK___builtin_cpu_is): New.  Defined as empty if not defined.
	(has_cpu_feature): New function.
	(set_cpu_feature): Likewise.
	(get_amd_cpu): Moved from libgcc/config/i386/cpuinfo.c.  Use
	CHECK___builtin_cpu_is.  Return AMD CPU name.
	(get_intel_cpu): Moved from libgcc/config/i386/cpuinfo.c.  Use
	Use CHECK___builtin_cpu_is.  Return Intel CPU name.
	(get_available_features): Moved from libgcc/config/i386/cpuinfo.c.
	Also check FEATURE_3DNOW, FEATURE_3DNOWP, FEATURE_ADX,
	FEATURE_ABM, FEATURE_CLDEMOTE, FEATURE_CLFLUSHOPT, FEATURE_CLWB,
	FEATURE_CLZERO, FEATURE_CMPXCHG16B, FEATURE_CMPXCHG8B,

Re: V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-20 Thread H.J. Lu via Gcc-patches
On Tue, May 19, 2020 at 11:10 PM Uros Bizjak  wrote:
>
> On Tue, May 19, 2020 at 11:40 PM H.J. Lu  wrote:
>
> > > > > > > > > I will take a look to see if we share the same CPU detection 
> > > > > > > > > code between
> > > > > > > > > libgcc and config/i386/driver-i386.c.
> > > > > > > >
> > > > > > > > I don't think it will bring any benefit, this is mainly one huge
> > > > > > > > switch statement that maps to different stuff in libgcc and
> > > > > > > > driver-i386.
> > > > > > >
> > > > > > > libgcc and config/i386/driver-i386.c differ even before my patch.
> > > > > > > I think we can do better.
> > > > > > >
> > > > > >
> > > > > > Move cpuinfo.h from libgcc to common/config/i386 so that 
> > > > > > get_intel_cpu
> > > > > > can be shared by libgcc, GCC driver, 
> > > > > > gcc.target/i386/builtin_target.c
> > > > > > and libgfortran to detect the specific type of Intel CPU.  Update
> > > > > > libgfortran to use has_cpu_feature to detect x86 CPU features.
> > > > > >
> > > > > > Tested on Linux/x86 and Linux/x86-64.  OK for master?
> > > > >
> > > > > Handling only Intel targets and not others is a sure way for patch to
> > > > > be ignored.
> > > > >
> > > >
> > > > Here is the updated patch to cover AMD CPU.  It also fixes:
> > > >
> > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95212
> > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95220
> > > >
> > > > OK for master?
> > >
> > > Huh... I didn't think the solution will be this messy... I have to
> > > rethink the approach a bit.
> >
> > That is what will happen when we have the same info in more than one place
> > There should only one place for CPU info.
>
> Looking at the patch, it is clear that cpuinfo.c and driver-i386.c
> should stay apart. They are two different things, and they are
> orthogonal to each other; one can be updated without affecting the
> other one. driver-i386.c handles way more targets than cpuinfo.c and
> your patch only handles a subset of them. The unification does not
> bring any benefit, it even complicates things more.

There should one place to check a CPU feature, not 2.  It can
be done with a proper cpuinfo.h.

> I think that unifying libgcc and i386-builtins.c is the way to go.
> libgfortran should benefit from this unification, too.
>

libgfortran shouldn't include cpuinfo.h.  It should use __builtin_cpu_is
and  __builtin_cpu_supports.

-- 
H.J.


Re: V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-20 Thread Uros Bizjak via Gcc-patches
On Tue, May 19, 2020 at 11:40 PM H.J. Lu  wrote:

> > > > > > > > I will take a look to see if we share the same CPU detection 
> > > > > > > > code between
> > > > > > > > libgcc and config/i386/driver-i386.c.
> > > > > > >
> > > > > > > I don't think it will bring any benefit, this is mainly one huge
> > > > > > > switch statement that maps to different stuff in libgcc and
> > > > > > > driver-i386.
> > > > > >
> > > > > > libgcc and config/i386/driver-i386.c differ even before my patch.
> > > > > > I think we can do better.
> > > > > >
> > > > >
> > > > > Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
> > > > > can be shared by libgcc, GCC driver, gcc.target/i386/builtin_target.c
> > > > > and libgfortran to detect the specific type of Intel CPU.  Update
> > > > > libgfortran to use has_cpu_feature to detect x86 CPU features.
> > > > >
> > > > > Tested on Linux/x86 and Linux/x86-64.  OK for master?
> > > >
> > > > Handling only Intel targets and not others is a sure way for patch to
> > > > be ignored.
> > > >
> > >
> > > Here is the updated patch to cover AMD CPU.  It also fixes:
> > >
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95212
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95220
> > >
> > > OK for master?
> >
> > Huh... I didn't think the solution will be this messy... I have to
> > rethink the approach a bit.
>
> That is what will happen when we have the same info in more than one place
> There should only one place for CPU info.

Looking at the patch, it is clear that cpuinfo.c and driver-i386.c
should stay apart. They are two different things, and they are
orthogonal to each other; one can be updated without affecting the
other one. driver-i386.c handles way more targets than cpuinfo.c and
your patch only handles a subset of them. The unification does not
bring any benefit, it even complicates things more.

I think that unifying libgcc and i386-builtins.c is the way to go.
libgfortran should benefit from this unification, too.

Uros.


Re: V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-19 Thread H.J. Lu via Gcc-patches
On Tue, May 19, 2020 at 2:07 PM Uros Bizjak  wrote:
>
> On Tue, May 19, 2020 at 9:58 PM H.J. Lu  wrote:
> >
> > On Mon, May 18, 2020 at 10:56 PM Uros Bizjak  wrote:
> > >
> > > On Tue, May 19, 2020 at 4:17 AM H.J. Lu  wrote:
> > > >
> > > > On Mon, May 18, 2020 at 5:57 AM H.J. Lu  wrote:
> > > > >
> > > > > On Mon, May 18, 2020 at 5:43 AM Uros Bizjak  wrote:
> > > > > >
> > > > > > On Mon, May 18, 2020 at 2:34 PM H.J. Lu  wrote:
> > > > > > >
> > > > > > > On Mon, May 18, 2020 at 5:18 AM Uros Bizjak  
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > On Mon, May 18, 2020 at 1:58 PM H.J. Lu  
> > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > Add cpu model numbers for Intel Airmont, Tremont, Comet Lake, 
> > > > > > > > > Ice Lake
> > > > > > > > > and Tiger Lake processor families.
> > > > > > > > >
> > > > > > > > > OK for master?
> > > > > > > >
> > > > > > > > OK.
> > > > > > >
> > > > > > > I am checking in my patch.
> > > > > > >
> > > > > > > > Please also update cpuinfo.c from libgcc and corresponding
> > > > > > >
> > > > > > > I will take a look to see if we share the same CPU detection code 
> > > > > > > between
> > > > > > > libgcc and config/i386/driver-i386.c.
> > > > > >
> > > > > > I don't think it will bring any benefit, this is mainly one huge
> > > > > > switch statement that maps to different stuff in libgcc and
> > > > > > driver-i386.
> > > > >
> > > > > libgcc and config/i386/driver-i386.c differ even before my patch.
> > > > > I think we can do better.
> > > > >
> > > >
> > > > Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
> > > > can be shared by libgcc, GCC driver, gcc.target/i386/builtin_target.c
> > > > and libgfortran to detect the specific type of Intel CPU.  Update
> > > > libgfortran to use has_cpu_feature to detect x86 CPU features.
> > > >
> > > > Tested on Linux/x86 and Linux/x86-64.  OK for master?
> > >
> > > Handling only Intel targets and not others is a sure way for patch to
> > > be ignored.
> > >
> >
> > Here is the updated patch to cover AMD CPU.  It also fixes:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95212
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95220
> >
> > OK for master?
>
> Huh... I didn't think the solution will be this messy... I have to
> rethink the approach a bit.
>

These can avoid duplication in i386-builtins.c:

/* These are the values for vendor types, cpu types and subtypes in
   cpuinfo.h.  Cpu types and subtypes should be subtracted by the
   corresponding start value.  */

#define M_CPU_TYPE_START (BUILTIN_VENDOR_MAX)
#define M_CPU_SUBTYPE_START \
  (M_CPU_TYPE_START + BUILTIN_CPU_TYPE_MAX)
#define M_VENDOR(a) (a)
#define M_CPU_TYPE(a) (M_CPU_TYPE_START + a)
#define M_CPU_SUBTYPE(a) (M_CPU_SUBTYPE_START + a)

static const _arch_names_table arch_names_table[] =
{
  {"amd", M_VENDOR (VENDOR_AMD)},
  {"intel", M_VENDOR (VENDOR_INTEL)},
  {"atom", M_CPU_TYPE (INTEL_BONNELL)},
  {"slm", M_CPU_TYPE (INTEL_SILVERMONT)},
  {"core2", M_CPU_TYPE (INTEL_CORE2)},
  {"corei7", M_CPU_TYPE (INTEL_COREI7)},
  {"nehalem", M_CPU_SUBTYPE (INTEL_COREI7_NEHALEM)},
  {"westmere", M_CPU_SUBTYPE (INTEL_COREI7_WESTMERE)},
  {"sandybridge", M_CPU_SUBTYPE (INTEL_COREI7_SANDYBRIDGE)},
  {"ivybridge", M_CPU_SUBTYPE (INTEL_COREI7_IVYBRIDGE)},
  {"haswell", M_CPU_SUBTYPE (INTEL_COREI7_HASWELL)},
  {"broadwell", M_CPU_SUBTYPE (INTEL_COREI7_BROADWELL)},
  {"skylake", M_CPU_SUBTYPE (INTEL_COREI7_SKYLAKE)},
  {"skylake-avx512", M_CPU_SUBTYPE (INTEL_COREI7_SKYLAKE_AVX512)},
  {"cannonlake", M_CPU_SUBTYPE (INTEL_COREI7_CANNONLAKE)},
  {"icelake-client", M_CPU_SUBTYPE (INTEL_COREI7_ICELAKE_CLIENT)},
  {"icelake-server", M_CPU_SUBTYPE (INTEL_COREI7_ICELAKE_SERVER)},
  {"cascadelake", M_CPU_SUBTYPE (INTEL_COREI7_CASCADELAKE)},
  {"tigerlake", M_CPU_SUBTYPE (INTEL_COREI7_TIGERLAKE)},
  {"cooperlake", M_CPU_SUBTYPE (INTEL_COREI7_COOPERLAKE)},
  {"bonnell", M_CPU_TYPE (INTEL_BONNELL)},
  {"silvermont", M_CPU_TYPE (INTEL_SILVERMONT)},
  {"goldmont", M_CPU_TYPE (INTEL_GOLDMONT)},
  {"goldmont-plus", M_CPU_TYPE (INTEL_GOLDMONT_PLUS)},
  {"tremont", M_CPU_TYPE (INTEL_TREMONT)},
  {"knl", M_CPU_TYPE (INTEL_KNL)},
  {"knm", M_CPU_TYPE (INTEL_KNM)},
  {"amdfam10h", M_CPU_TYPE (AMDFAM10H)},
  {"barcelona", M_CPU_SUBTYPE (AMDFAM10H_BARCELONA)},
  {"shanghai", M_CPU_SUBTYPE (AMDFAM10H_SHANGHAI)},
  {"istanbul", M_CPU_SUBTYPE (AMDFAM10H_ISTANBUL)},
  {"btver1", M_CPU_TYPE (AMD_BTVER1)},
  {"amdfam15h", M_CPU_TYPE (AMDFAM15H)},
  {"bdver1", M_CPU_SUBTYPE (AMDFAM15H_BDVER1)},
  {"bdver2", M_CPU_SUBTYPE (AMDFAM15H_BDVER2)},
  {"bdver3", M_CPU_SUBTYPE (AMDFAM15H_BDVER3)},
  {"bdver4", M_CPU_SUBTYPE (AMDFAM15H_BDVER4)},
  {"btver2", M_CPU_TYPE (AMD_BTVER2)},
  {"amdfam17h", M_CPU_TYPE (AMDFAM17H)},
  {"znver1", M_CPU_SUBTYPE (AMDFAM17H_ZNVER1)},
  {"znver2", M_CPU_SUBTYPE (AMDFAM17H_ZNVER2)},
};


-- 
H.J.


Re: V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-19 Thread H.J. Lu via Gcc-patches
On Tue, May 19, 2020 at 2:07 PM Uros Bizjak  wrote:
>
> On Tue, May 19, 2020 at 9:58 PM H.J. Lu  wrote:
> >
> > On Mon, May 18, 2020 at 10:56 PM Uros Bizjak  wrote:
> > >
> > > On Tue, May 19, 2020 at 4:17 AM H.J. Lu  wrote:
> > > >
> > > > On Mon, May 18, 2020 at 5:57 AM H.J. Lu  wrote:
> > > > >
> > > > > On Mon, May 18, 2020 at 5:43 AM Uros Bizjak  wrote:
> > > > > >
> > > > > > On Mon, May 18, 2020 at 2:34 PM H.J. Lu  wrote:
> > > > > > >
> > > > > > > On Mon, May 18, 2020 at 5:18 AM Uros Bizjak  
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > On Mon, May 18, 2020 at 1:58 PM H.J. Lu  
> > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > Add cpu model numbers for Intel Airmont, Tremont, Comet Lake, 
> > > > > > > > > Ice Lake
> > > > > > > > > and Tiger Lake processor families.
> > > > > > > > >
> > > > > > > > > OK for master?
> > > > > > > >
> > > > > > > > OK.
> > > > > > >
> > > > > > > I am checking in my patch.
> > > > > > >
> > > > > > > > Please also update cpuinfo.c from libgcc and corresponding
> > > > > > >
> > > > > > > I will take a look to see if we share the same CPU detection code 
> > > > > > > between
> > > > > > > libgcc and config/i386/driver-i386.c.
> > > > > >
> > > > > > I don't think it will bring any benefit, this is mainly one huge
> > > > > > switch statement that maps to different stuff in libgcc and
> > > > > > driver-i386.
> > > > >
> > > > > libgcc and config/i386/driver-i386.c differ even before my patch.
> > > > > I think we can do better.
> > > > >
> > > >
> > > > Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
> > > > can be shared by libgcc, GCC driver, gcc.target/i386/builtin_target.c
> > > > and libgfortran to detect the specific type of Intel CPU.  Update
> > > > libgfortran to use has_cpu_feature to detect x86 CPU features.
> > > >
> > > > Tested on Linux/x86 and Linux/x86-64.  OK for master?
> > >
> > > Handling only Intel targets and not others is a sure way for patch to
> > > be ignored.
> > >
> >
> > Here is the updated patch to cover AMD CPU.  It also fixes:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95212
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95220
> >
> > OK for master?
>
> Huh... I didn't think the solution will be this messy... I have to
> rethink the approach a bit.

That is what will happen when we have the same info in more than one place
There should only one place for CPU info.

> Can you in the meantime please prepare a simple patch to fix the above
> mentioned PRs and eventually backport it to other release branches? It
> should be simple enough to be committed under obvious rule.
>

Done:

https://gcc.gnu.org/pipermail/gcc-patches/2020-May/546088.html

-- 
H.J.


Re: V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-19 Thread Uros Bizjak via Gcc-patches
On Tue, May 19, 2020 at 9:58 PM H.J. Lu  wrote:
>
> On Mon, May 18, 2020 at 10:56 PM Uros Bizjak  wrote:
> >
> > On Tue, May 19, 2020 at 4:17 AM H.J. Lu  wrote:
> > >
> > > On Mon, May 18, 2020 at 5:57 AM H.J. Lu  wrote:
> > > >
> > > > On Mon, May 18, 2020 at 5:43 AM Uros Bizjak  wrote:
> > > > >
> > > > > On Mon, May 18, 2020 at 2:34 PM H.J. Lu  wrote:
> > > > > >
> > > > > > On Mon, May 18, 2020 at 5:18 AM Uros Bizjak  
> > > > > > wrote:
> > > > > > >
> > > > > > > On Mon, May 18, 2020 at 1:58 PM H.J. Lu  
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > Add cpu model numbers for Intel Airmont, Tremont, Comet Lake, 
> > > > > > > > Ice Lake
> > > > > > > > and Tiger Lake processor families.
> > > > > > > >
> > > > > > > > OK for master?
> > > > > > >
> > > > > > > OK.
> > > > > >
> > > > > > I am checking in my patch.
> > > > > >
> > > > > > > Please also update cpuinfo.c from libgcc and corresponding
> > > > > >
> > > > > > I will take a look to see if we share the same CPU detection code 
> > > > > > between
> > > > > > libgcc and config/i386/driver-i386.c.
> > > > >
> > > > > I don't think it will bring any benefit, this is mainly one huge
> > > > > switch statement that maps to different stuff in libgcc and
> > > > > driver-i386.
> > > >
> > > > libgcc and config/i386/driver-i386.c differ even before my patch.
> > > > I think we can do better.
> > > >
> > >
> > > Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
> > > can be shared by libgcc, GCC driver, gcc.target/i386/builtin_target.c
> > > and libgfortran to detect the specific type of Intel CPU.  Update
> > > libgfortran to use has_cpu_feature to detect x86 CPU features.
> > >
> > > Tested on Linux/x86 and Linux/x86-64.  OK for master?
> >
> > Handling only Intel targets and not others is a sure way for patch to
> > be ignored.
> >
>
> Here is the updated patch to cover AMD CPU.  It also fixes:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95212
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95220
>
> OK for master?

Huh... I didn't think the solution will be this messy... I have to
rethink the approach a bit.

Can you in the meantime please prepare a simple patch to fix the above
mentioned PRs and eventually backport it to other release branches? It
should be simple enough to be committed under obvious rule.

Thanks,
Uros.


V2 [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

2020-05-19 Thread H.J. Lu via Gcc-patches
On Mon, May 18, 2020 at 10:56 PM Uros Bizjak  wrote:
>
> On Tue, May 19, 2020 at 4:17 AM H.J. Lu  wrote:
> >
> > On Mon, May 18, 2020 at 5:57 AM H.J. Lu  wrote:
> > >
> > > On Mon, May 18, 2020 at 5:43 AM Uros Bizjak  wrote:
> > > >
> > > > On Mon, May 18, 2020 at 2:34 PM H.J. Lu  wrote:
> > > > >
> > > > > On Mon, May 18, 2020 at 5:18 AM Uros Bizjak  wrote:
> > > > > >
> > > > > > On Mon, May 18, 2020 at 1:58 PM H.J. Lu  wrote:
> > > > > > >
> > > > > > > Add cpu model numbers for Intel Airmont, Tremont, Comet Lake, Ice 
> > > > > > > Lake
> > > > > > > and Tiger Lake processor families.
> > > > > > >
> > > > > > > OK for master?
> > > > > >
> > > > > > OK.
> > > > >
> > > > > I am checking in my patch.
> > > > >
> > > > > > Please also update cpuinfo.c from libgcc and corresponding
> > > > >
> > > > > I will take a look to see if we share the same CPU detection code 
> > > > > between
> > > > > libgcc and config/i386/driver-i386.c.
> > > >
> > > > I don't think it will bring any benefit, this is mainly one huge
> > > > switch statement that maps to different stuff in libgcc and
> > > > driver-i386.
> > >
> > > libgcc and config/i386/driver-i386.c differ even before my patch.
> > > I think we can do better.
> > >
> >
> > Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
> > can be shared by libgcc, GCC driver, gcc.target/i386/builtin_target.c
> > and libgfortran to detect the specific type of Intel CPU.  Update
> > libgfortran to use has_cpu_feature to detect x86 CPU features.
> >
> > Tested on Linux/x86 and Linux/x86-64.  OK for master?
>
> Handling only Intel targets and not others is a sure way for patch to
> be ignored.
>

Here is the updated patch to cover AMD CPU.  It also fixes:

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

OK for master?

Thanks.

-- 
H.J.
From 113c797d59102d400b3a7342192f68b789bba0de Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Mon, 18 May 2020 05:58:41 -0700
Subject: [PATCH] x86: Move cpuinfo.h from libgcc to common/config/i386

Move cpuinfo.h from libgcc to common/config/i386 so that get_intel_cpu
can be shared by libgcc, GCC driver, gcc.target/i386/builtin_target.c
and libgfortran to detect the specific type of Intel and AMD CPUs.  Use
the same enum processor_features in libgcc and x86 backend.  Add static
assert to x86 backend to verify that libgcc and x86 backend are in sync.

Update processor feature check in in libgcc:

1. Update FEATURE_GFNI check to support SSE, AVX and AVX512 versions of
GFNI.
2. Add missing FEATURE_AVX512VP2INTERSECT.
3. Add FEATURE_XSAVEOPT, FEATURE_CLWB and FEATURE_CLZERO for get_amd_cpu.
4. Always set __cpu_features2 for has_cpu_feature.

Update libgfortran to use has_cpu_feature to detect x86 CPU features.

gcc/

	PR target/95212
	PR target/95220
	* common/config/i386/cpuinfo.h: Moved from libgcc/config/i386.
	(processor_features): Add FEATURE_AVX512VP2INTERSECT,
	FEATURE_XSAVEOPT, FEATURE_CLWB and FEATURE_CLZERO.
	(CHECK___builtin_cpu_is): New.  Defined as empty if not defined.
	(get_amd_cpu): Moved from libgcc/config/i386/cpuinfo.c.  Add
	arguments for BMI, AVX2, XOP, XSAVEOPT, CLWB and CLZERO.  Use
	CHECK___builtin_cpu_is.  Return AMD CPU name.
	(get_intel_cpu): Moved from libgcc/config/i386/cpuinfo.c.  Add
	an argument for AVX512VNNI.  Use CHECK___builtin_cpu_is.  Return
	Intel CPU name.
	(has_cpu_feature): New function.
	* config/i386/driver-i386.c: Include
	"common/config/i386/cpuinfo.h".
	(host_detect_local_cpu): Call get_amd_cpu to get AMD CPU name.
	Call get_intel_cpu to get Intel CPU name.
	* config/i386/i386-builtins.c: Include
	"common/config/i386/cpuinfo.h".
	(processor_features): Removed.  Replace F_XXX with FEATURE_XXX.
	(isa_names_table): Add xsaveopt, clwb and clzero.
	(CHECK_processor_vendor, CHECK_processor_types,
	CHECK_processor_subtypes): New.  Add static assert to x86
	backend to verify that libgcc and x86 backend are in sync.

gcc/testsuite/

	PR target/95212
	PR target/95220
	* gcc.target/i386/builtin_target.c: Include  and
	../../../common/config/i386/cpuinfo.h.
	(CHECK___builtin_cpu_is): New.
	(inline): New.  Defined as empty.
	(check_amd_cpu_model): Removed.
	(check_intel_cpu_model): Likewise,
	(check_detailed): Call get_amd_cpu instead of check_amd_cpu_model.
	Call get_intel_cpu instead of check_intel_cpu_model.

libgcc/

	PR target/95212
	PR target/95220
	* config/i386/cpuinfo.h: Moved to ... gcc/common/config/i386.
	* config/i386/cpuinfo.c: Include "common/config/i386/cpuinfo.h".
	(__cpu_features2): Make it static in libgcc_s.so.1.
	(get_amd_cpu): Moved to ... gcc/common/config/i386/cpuinfo.h.
	(get_intel_cpu): Moved to ... gcc/common/config/i386/cpuinfo.h.
	(get_available_features): Fix FEATURE_GFNI check.  Also check
	FEATURE_AVX512VP2INTERSECT, FEATURE_XSAVEOPT, FEATURE_CLWB and
	FEATURE_CLZERO.  Always set __cpu_features2.
	(__cpu_indicator_init): Call get_available_features before
	calling get_amd_cpu.  Pass has_cpu_feature