public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101696] New: Function multiversioning not usable with new x86-64-v*
@ 2021-07-30 15:26 h2+bugs at fsfe dot org
  2021-08-02  8:26 ` [Bug target/101696] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: h2+bugs at fsfe dot org @ 2021-07-30 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101696
           Summary: Function multiversioning not usable with new x86-64-v*
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: h2+bugs at fsfe dot org
  Target Milestone: ---

I really like the new feature levels, so I have created the respective binaries
for an application. I now want to dispatch to the correct one, so I thought the
easiest thing would be to have a small "arch_detect" program that gives me the
feature level as return value:

__attribute__ ((target ("default")))
int foo ()
{
    // The default version of foo.
    return 0;
}

__attribute__ ((target ("arch=x86-64")))
int foo ()
{
    return 1;
}

__attribute__ ((target ("arch=x86-64-v2")))
int foo ()
{
    return 2;
}
__attribute__ ((target ("arch=x86-64-v3")))
int foo ()
{
    return 3;
}

__attribute__ ((target ("arch=x86-64-v4")))
int foo ()
{
    return 4;
}

int main ()
{
    return foo();
}


This builds fine but always returns 0 -- independent of whether I build the
binary without -march or with -march=x86-64-v4.

Curiously, if I add the following overload:

__attribute__ ((target ("sse4.2")))
int foo ()
{
    // The default version of foo.
    return 7;
}

it will no longer build without -march=x86-64-v4, complaining that "no
dispatcher was found for the versioning attributes". If I add -march=x86-64-v4,
it will build without errors but always return 7 and not the feature level.

What am I missing?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
@ 2021-08-02  8:26 ` rguenth at gcc dot gnu.org
  2021-08-03  9:38 ` h2+bugs at fsfe dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-02  8:26 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
It doesn't work this way, see the target_clones and ifunc attribute
documentation.  You could eventually use __builtin_cpu_is or
__builtin_cpu_supports.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
  2021-08-02  8:26 ` [Bug target/101696] " rguenth at gcc dot gnu.org
@ 2021-08-03  9:38 ` h2+bugs at fsfe dot org
  2021-08-03 11:00 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: h2+bugs at fsfe dot org @ 2021-08-03  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Hannes Hauswedell <h2+bugs at fsfe dot org> ---
What do you mean with "It doesn't work this way"?

Maybe I wasn't clear in my original post; I am not interested in a dispatching
mechanism for the application, I just want to have an mini-application that
returns 0, 1, 2, 3 or 4 depending on which feature level is available on the
current computer.

How is my example different from
https://gcc.gnu.org/onlinedocs/gcc/Function-Multiversioning.html (other than
using the new feature levels)?

Thanks

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
  2021-08-02  8:26 ` [Bug target/101696] " rguenth at gcc dot gnu.org
  2021-08-03  9:38 ` h2+bugs at fsfe dot org
@ 2021-08-03 11:00 ` rguenth at gcc dot gnu.org
  2021-08-03 11:30 ` marxin at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-03 11:00 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-08-03
             Status|RESOLVED                    |NEW
         Resolution|INVALID                     |---

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ah, this only works with the C++ frontend.  I can confirm your observation, it
looks like the arch=x86-64-vN handling is incomplete.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (2 preceding siblings ...)
  2021-08-03 11:00 ` rguenth at gcc dot gnu.org
@ 2021-08-03 11:30 ` marxin at gcc dot gnu.org
  2021-08-11 12:10 ` marxin at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-03 11:30 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |marxin at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
I can handle this issue.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (3 preceding siblings ...)
  2021-08-03 11:30 ` marxin at gcc dot gnu.org
@ 2021-08-11 12:10 ` marxin at gcc dot gnu.org
  2021-08-11 14:30 ` hjl.tools at gmail dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-11 12:10 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
                 CC|                            |hjl.tools at gmail dot com
           Assignee|marxin at gcc dot gnu.org          |unassigned at gcc dot gnu.org

--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
Right now, the x86-64* are defined as aliases to k8:

  {"x86-64", PROCESSOR_K8, CPU_K8, PTA_X86_64_BASELINE, 0, P_NONE},
  {"x86-64-v2", PROCESSOR_K8, CPU_GENERIC, PTA_X86_64_V2 | PTA_NO_TUNE,
   0, P_NONE},
  {"x86-64-v3", PROCESSOR_K8, CPU_GENERIC, PTA_X86_64_V3 | PTA_NO_TUNE,
   0, P_NONE},
  {"x86-64-v4", PROCESSOR_K8, CPU_GENERIC, PTA_X86_64_V4 | PTA_NO_TUNE,
   0, P_NONE},

and it has the corresponding pta info:

(gdb) p *arch_info
$10 = {
  name = 0x1f96cdc "x86-64",
  processor = PROCESSOR_K8,
  schedule = CPU_K8,
  flags = {
    low = 0,
    high = 137445326852
  },
  model = 0,
  priority = P_NONE
}

thus we end up with:
pr101696.c:16:5: error: no dispatcher found for the versioning attributes
   16 | int foo ()
      |     ^~~

So first step that needs to be done is adding support for the march names in:
__builtin_cpu_is.
@H.J. Can you please add that?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (4 preceding siblings ...)
  2021-08-11 12:10 ` marxin at gcc dot gnu.org
@ 2021-08-11 14:30 ` hjl.tools at gmail dot com
  2021-08-11 14:34 ` marxin at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2021-08-11 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Martin Liška from comment #5)
> Right now, the x86-64* are defined as aliases to k8:
> 
>   {"x86-64", PROCESSOR_K8, CPU_K8, PTA_X86_64_BASELINE, 0, P_NONE},
>   {"x86-64-v2", PROCESSOR_K8, CPU_GENERIC, PTA_X86_64_V2 | PTA_NO_TUNE,
>    0, P_NONE},
>   {"x86-64-v3", PROCESSOR_K8, CPU_GENERIC, PTA_X86_64_V3 | PTA_NO_TUNE,
>    0, P_NONE},
>   {"x86-64-v4", PROCESSOR_K8, CPU_GENERIC, PTA_X86_64_V4 | PTA_NO_TUNE,
>    0, P_NONE},
> 
> and it has the corresponding pta info:
> 
> (gdb) p *arch_info
> $10 = {
>   name = 0x1f96cdc "x86-64",
>   processor = PROCESSOR_K8,
>   schedule = CPU_K8,
>   flags = {
>     low = 0,
>     high = 137445326852
>   },
>   model = 0,
>   priority = P_NONE
> }
> 
> thus we end up with:
> pr101696.c:16:5: error: no dispatcher found for the versioning attributes
>    16 | int foo ()
>       |     ^~~
> 
> So first step that needs to be done is adding support for the march names in:
> __builtin_cpu_is.
> @H.J. Can you please add that?

It is very difficult to add them to __builtin_cpu_is since there are no
such processors.  However, add them to __builtin_cpu_supports is possible.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (5 preceding siblings ...)
  2021-08-11 14:30 ` hjl.tools at gmail dot com
@ 2021-08-11 14:34 ` marxin at gcc dot gnu.org
  2021-08-11 15:07 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-11 14:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
> It is very difficult to add them to __builtin_cpu_is since there are no
> such processors.

I see!

> However, add them to __builtin_cpu_supports is possible.

Please do so we can then leverage that in the target attribute.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (6 preceding siblings ...)
  2021-08-11 14:34 ` marxin at gcc dot gnu.org
@ 2021-08-11 15:07 ` hjl.tools at gmail dot com
  2021-08-12 14:23 ` marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2021-08-11 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 51290
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51290&action=edit
A patch

Try this.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (7 preceding siblings ...)
  2021-08-11 15:07 ` hjl.tools at gmail dot com
@ 2021-08-12 14:23 ` marxin at gcc dot gnu.org
  2021-08-16 11:37 ` marxin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-12 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
             Status|NEW                         |ASSIGNED

--- Comment #9 from Martin Liška <marxin at gcc dot gnu.org> ---
I've just sent patch to ML:
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577275.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (8 preceding siblings ...)
  2021-08-12 14:23 ` marxin at gcc dot gnu.org
@ 2021-08-16 11:37 ` marxin at gcc dot gnu.org
  2021-09-13 15:26 ` cvs-commit at gcc dot gnu.org
  2021-09-13 15:27 ` marxin at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-16 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (9 preceding siblings ...)
  2021-08-16 11:37 ` marxin at gcc dot gnu.org
@ 2021-09-13 15:26 ` cvs-commit at gcc dot gnu.org
  2021-09-13 15:27 ` marxin at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-13 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:8ea292591e42aa4d52b4b7a00b86335bfd2e2e85

commit r12-3494-g8ea292591e42aa4d52b4b7a00b86335bfd2e2e85
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Aug 12 15:20:43 2021 +0200

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

    As mentioned in the PR, we do miss supports target micro-architectures
    in target and target_clone attribute. While the levels
    x86-64 x86-64-v2 x86-64-v3 x86-64-v4 are supported values by -march
    option, they are actually only aliases for k8 CPU. That said, they are more
    closer to __builtin_cpu_supports function and we decided to implement
    it there.

            PR target/101696

    gcc/ChangeLog:

            * common/config/i386/cpuinfo.h (cpu_indicator_init): Add support
            for x86-64 micro levels for __builtin_cpu_supports.
            * common/config/i386/i386-cpuinfo.h (enum feature_priority):
            Add priorities for the micro-arch levels.
            (enum processor_features): Add new features.
            * common/config/i386/i386-isas.h: Add micro-arch features.
            * config/i386/i386-builtins.c (get_builtin_code_for_version):
            Support the micro-arch levels by callsing
            __builtin_cpu_supports.
            * doc/extend.texi: Document that the levels are support by
              __builtin_cpu_supports.

    gcc/testsuite/ChangeLog:

            * g++.target/i386/mv30.C: New test.
            * gcc.target/i386/mvc16.c: New test.
            * gcc.target/i386/builtin_target.c (CHECK___builtin_cpu_supports):
            New.

    Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/101696] Function multiversioning not usable with new x86-64-v*
  2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
                   ` (10 preceding siblings ...)
  2021-09-13 15:26 ` cvs-commit at gcc dot gnu.org
@ 2021-09-13 15:27 ` marxin at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-09-13 15:27 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #11 from Martin Liška <marxin at gcc dot gnu.org> ---
Implemented on master.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-09-13 15:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 15:26 [Bug c/101696] New: Function multiversioning not usable with new x86-64-v* h2+bugs at fsfe dot org
2021-08-02  8:26 ` [Bug target/101696] " rguenth at gcc dot gnu.org
2021-08-03  9:38 ` h2+bugs at fsfe dot org
2021-08-03 11:00 ` rguenth at gcc dot gnu.org
2021-08-03 11:30 ` marxin at gcc dot gnu.org
2021-08-11 12:10 ` marxin at gcc dot gnu.org
2021-08-11 14:30 ` hjl.tools at gmail dot com
2021-08-11 14:34 ` marxin at gcc dot gnu.org
2021-08-11 15:07 ` hjl.tools at gmail dot com
2021-08-12 14:23 ` marxin at gcc dot gnu.org
2021-08-16 11:37 ` marxin at gcc dot gnu.org
2021-09-13 15:26 ` cvs-commit at gcc dot gnu.org
2021-09-13 15:27 ` marxin at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).