Patchwork Support for Runtime CPU type detection via builtins (issue5754058)

login
register
mail settings
Submitter Sriraman Tallam
Date April 25, 2012, 2:06 a.m.
Message ID <CAAs8HmyG3gDQc08vfJu1DSV3HxNcz24zMPoTJOEzCXC+ZJhYLw@mail.gmail.com>
Download mbox | patch
Permalink /patch/154778/
State New
Headers show

Comments

Sriraman Tallam - April 25, 2012, 2:06 a.m.
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.




Thanks,
-Sri.


>
> Otherwise, it looks good to me.
>
> Thanks.
>
>
> --
> H.J.
H.J. Lu - April 25, 2012, 2:39 a.m.
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?
Sriraman Tallam - April 25, 2012, 9:25 p.m.
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.
H.J. Lu - April 25, 2012, 9:28 p.m.
On Wed, Apr 25, 2012 at 2:25 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> 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.
>

You can download an AVX2 emulator (SDE) from

http://software.intel.com/en-us/avx/

to test AVX2 binaries.
Sriraman Tallam - April 25, 2012, 9:45 p.m.
On Wed, Apr 25, 2012 at 2:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Apr 25, 2012 at 2:25 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>> 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.
>>
>
> You can download an AVX2 emulator (SDE) from
>
> http://software.intel.com/en-us/avx/
>
> to test AVX2 binaries.

Ok thanks, I will prepare a patch.

-Sri.

>
> --
> H.J.
Marc Glisse - April 26, 2012, 6:09 a.m.
On Wed, 25 Apr 2012, H.J. Lu wrote:

> You can download an AVX2 emulator (SDE) from
>
> http://software.intel.com/en-us/avx/
>
> to test AVX2 binaries.

Hello,

not related to this specific patch, but do you have a dejagnu board 
description that you could share that enables running the compiler 
normally and running the compiled test programs through SDE? Doing make 
check inside the emulator is possible but takes forever, while using the 
emulator just for execution tests seems like it should be manageable.

Patch

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;