This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support for Runtime CPU type detection via builtins (issue5754058)


On Tue, Apr 24, 2012 at 5:10 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Hi,
>
> ? Thanks for all the comments. I have made all the changes as
> mentioned and submiited the patch. Summary of changes made:
>
> * Add support for AVX
> * Fix documentation in extend.texi
> * Make it thread-safe according to H.J.'s comments.
>
> I have attached the patch. Boot-strapped and checked for test parity
> with pristine build.
>
> ? ? ? * config/i386/i386.c (build_processor_model_struct): New function.
> ? ? ? ?(make_var_decl): New function.
> ? ? ? ?(fold_builtin_cpu): New function.
> ? ? ? ?(ix86_fold_builtin): New function.
> ? ? ? ?(make_cpu_type_builtin): New function.
> ? ? ? ?(ix86_init_platform_type_builtins): New function.
> ? ? ? ?(ix86_expand_builtin): Expand new builtins by folding them.
> ? ? ? ?(ix86_init_builtins): Make new builtins to detect CPU type.
> ? ? ? ?(TARGET_FOLD_BUILTIN): New macro.
> ? ? ? ?(IX86_BUILTIN_CPU_INIT): New enum value.
> ? ? ? ?(IX86_BUILTIN_CPU_IS): New enum value.
> ? ? ? ?(IX86_BUILTIN_CPU_SUPPORTS): New enum value.
> ? ? ? ?* config/i386/i386-builtin-types.def: New function type.
> ? ? ? ?* testsuite/gcc.target/builtin_target.c: New testcase.
> ? ? ? ?* doc/extend.texi: Document builtins.
>
> ? ? ? ?* libgcc/config/i386/i386-cpuinfo.c: New file.
> ? ? ? ?* libgcc/config/i386/t-cpuinfo: New file.
> ? ? ? ?* libgcc/config.host: Include t-cpuinfo.
> ? ? ? ?* libgcc/config/i386/libgcc-glibc.ver: Version symbol __cpu_model.
>
>

+  /* This function needs to run just once.  */
+  if (__cpu_model.__cpu_vendor)
+    return 0;
+
+  /* Assume cpuid insn present. Run in level 0 to get vendor id. */
+  if (!__get_cpuid_output (0, &eax, &ebx, &ecx, &edx))
+    return -1;

If __get_cpuid_output returns non-zero, it will be called
repeatedly.  I think you should set __cpu_model.__cpu_vendor
to non-zero in this case.

Otherwise, it looks good to me.

Thanks.


-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]