[PATCH] i386: support micro-levels in target{,_clone} attrs [PR101696]

Martin Liška mliska@suse.cz
Thu Aug 12 15:22:55 GMT 2021


On 8/12/21 4:51 PM, H.J. Lu wrote:
> On Thu, Aug 12, 2021 at 7:39 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> On 8/12/21 4:25 PM, H.J. Lu wrote:
>>> Please send out the v2 patch with the enclosed patch.  I added some tests.
>>
>> Thanks, there's patch which includes your changes.
>>
>> Martin
> 
> diff --git a/gcc/common/config/i386/i386-isas.h
> b/gcc/common/config/i386/i386-isas.h
> index 898c18f3dda..cd9523b8fbc 100644
> --- a/gcc/common/config/i386/i386-isas.h
> +++ b/gcc/common/config/i386/i386-isas.h
> @@ -169,4 +169,8 @@ ISA_NAMES_TABLE_START
>     ISA_NAMES_TABLE_ENTRY("aeskle", FEATURE_AESKLE, P_NONE, NULL)
>     ISA_NAMES_TABLE_ENTRY("widekl", FEATURE_WIDEKL, P_NONE, "-mwidekl")
>     ISA_NAMES_TABLE_ENTRY("avxvnni", FEATURE_AVXVNNI, P_NONE, "-mavxvnni")
> +  ISA_NAMES_TABLE_ENTRY("x86-64", FEATURE_X86_64_BASELINE, P_NONE, NULL)
> +  ISA_NAMES_TABLE_ENTRY("x86-64-v2", FEATURE_X86_64_V2, P_NONE, NULL)
> +  ISA_NAMES_TABLE_ENTRY("x86-64-v3", FEATURE_X86_64_V3, P_NONE, NULL)
> +  ISA_NAMES_TABLE_ENTRY("x86-64-v4", FEATURE_X86_64_V4, P_NONE, NULL)
> 
> If they have proper feature_priority, can you avoid

I don't think so. First we likely want supporting "arch=x86-64-v3" rather than
"x86-64-v3" in e.g. 'target' attribute. That means a special handling by the code
I added.

The following fails as there's no corresponding -m$option.

pr101696.c:5:45: error: attribute ‘x86-64-v4’ argument ‘target’ is unknown

     5 | __attribute__ ((target ("x86-64-v4"))) void foo () {  __builtin_printf ("arch=x86-64-v4\n"); }

       |                                             ^~~


Or do I miss something and we can do it in a simpler way?

Cheers,
Martin

> 
> iff --git a/gcc/config/i386/i386-builtins.c b/gcc/config/i386/i386-builtins.c
> index 204e2903126..492873bb076 100644
> --- a/gcc/config/i386/i386-builtins.c
> +++ b/gcc/config/i386/i386-builtins.c
> @@ -1904,8 +1904,24 @@ get_builtin_code_for_version (tree decl, tree
> *predicate_list)
>    return 0;
>         new_target = TREE_TARGET_OPTION (target_node);
>         gcc_assert (new_target);
> -
> -      if (new_target->arch_specified && new_target->arch > 0)
> +      enum ix86_builtins builtin_fn = IX86_BUILTIN_CPU_IS;
> +
> +      /* Special case x86-64 micro-level architectures.  */
> +      const char *arch_name = attrs_str + strlen ("arch=");
> +      if (startswith (arch_name, "x86-64"))
> + {
> +   arg_str = arch_name;
> +   builtin_fn = IX86_BUILTIN_CPU_SUPPORTS;
> +   if (strcmp (arch_name, "x86-64") == 0)
> +     priority = P_X86_64_BASELINE;
> +   else if (strcmp (arch_name, "x86-64-v2") == 0)
> +     priority = P_X86_64_V2;
> +   else if (strcmp (arch_name, "x86-64-v3") == 0)
> +     priority = P_X86_64_V3;
> +   else if (strcmp (arch_name, "x86-64-v4") == 0)
> +     priority = P_X86_64_V4;
> + }
> 
>         if (predicate_list)
>    {
> -          predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_IS];
> +   predicate_decl = ix86_builtins [(int) builtin_fn];
> 
> Is this required?
> 



More information about the Gcc-patches mailing list