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 7:39 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Apr 24, 2012 at 7:06 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>> On Tue, Apr 24, 2012 at 5:24 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> 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.
>>
>> Done now.
>>
>> 2012-04-24 ?Sriraman Tallam ?<tmsriram@google.com>
>>
>> ? ? ? ?* libgcc/config/i386/i386-cpuinfo.c: Set __cpu_vendor always.
>>
>>
>> Index: libgcc/config/i386/i386-cpuinfo.c
>> ===================================================================
>> --- libgcc/config/i386/i386-cpuinfo.c ? (revision 186789)
>> +++ libgcc/config/i386/i386-cpuinfo.c ? (working copy)
>> @@ -256,16 +256,25 @@ __cpu_indicator_init (void)
>>
>> ? /* Assume cpuid insn present. Run in level 0 to get vendor id. */
>> ? if (!__get_cpuid_output (0, &eax, &ebx, &ecx, &edx))
>> - ? ?return -1;
>> + ? ?{
>> + ? ? ?__cpu_model.__cpu_vendor = VENDOR_OTHER;
>> + ? ? ?return -1;
>> + ? ?}
>>
>> ? vendor = ebx;
>> ? max_level = eax;
>>
>> ? if (max_level < 1)
>> - ? ?return -1;
>> + ? ?{
>> + ? ? ?__cpu_model.__cpu_vendor = VENDOR_OTHER;
>> + ? ? ?return -1;
>> + ? ?}
>>
>> ? if (!__get_cpuid_output (1, &eax, &ebx, &ecx, &edx))
>> - ? ?return -1;
>> + ? ?{
>> + ? ? ?__cpu_model.__cpu_vendor = VENDOR_OTHER;
>> + ? ? ?return -1;
>> + ? ?}
>>
>> ? model = (eax >> 4) & 0x0f;
>> ? family = (eax >> 8) & 0x0f;
>>
>>
>> Thanks,
>
> Should you also handle AVX2?

 I cannot test it and thought will wait till I get access to a
processor with AVX2.

Thanks,
-Sri.


>
>
> --
> H.J.


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