Hi,

After my Intel processor name cleanup,

__attribute__ ((target("arch=corei7"))) is translated to PROCESSOR_NEHALEM
mapped to M_INTEL_COREI7_NEHALEM. We used to hav

e __attribute__ ((target("arch=corei7")))

to cover M_INTEL_COREI7_XXXX. Now it only covers M_INTEL_COREI7_NEHALEM.
We have PROCESSOR_SANDYBRIDGE and PROCESSOR_HASWELL.  But there is nothing
to mark Westmere and Ivy Bridge.  Since function versioning doesn't support
extra ISAs in Westmere and Ivy Bridge, we don't lose anything. The solution
is to map

__attribute__ ((target("arch=corei7")))

and

__attribute__ ((target("arch=nehalem")))

to M_INTEL_COREI7.  I tested mv14.C and mv15.C on Nehalem, Westmere,
Sandy Bride and Ivy Bridge.  OK to install?

Thanks.

H.J.
----
gcc/

2013-12-26   H.J. Lu  <hongjiu...@intel.com>

        PR target/59601
        * config/i386/i386.c (get_builtin_code_for_version): Map
        PROCESSOR_NEHALEM to "corei7".

gcc/testsuite/

2013-12-26   Uros Bizjak  <ubiz...@gmail.com>
             H.J. Lu  <hongjiu...@intel.com>

        PR target/59601
        * g++.dg/ext/mv14.C: New tests.
        * g++.dg/ext/mv15.C: Likewise.

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 37bb656..e3d693a 100644
--- a/gcc/config/i386/i386.c
++ b/gcc/config/i386/i386.c
@@ -30010,7 +30010,10 @@ get_builtin_code_for_version (tree decl, tree 
*predicate_list)
              priority = P_PROC_SSSE3;
              break;
            case PROCESSOR_NEHALEM:
-             arg_str = "nehalem";
+             /* We translate "arch=corei7" and "arch=nehelam" to
+                "corei7" so that it will be mapped to M_INTEL_COREI7
+                as cpu type to cover all M_INTEL_COREI7_XXXs.  */
+             arg_str = "corei7";
              priority = P_PROC_SSE4_2;
              break;
            case PROCESSOR_SANDYBRIDGE:
diff --git a/gcc/testsuite/g++.dg/ext/mv14.C b/gcc/testsuite/g++.dg/ext/mv14.C
new file mode 100644
index 0000000..e36e08d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/mv14.C
@@ -0,0 +1,40 @@
+/* Test case to check if Multiversioning works.  */
+/* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
+/* { dg-options "-O2 -fPIC" } */
+
+#include <assert.h>
+
+/* Default version.  */
+int foo (); // Extra declaration that is merged with the second one.
+int foo () __attribute__ ((target("default")));
+
+int foo () __attribute__ ((target("arch=corei7")));
+
+int (*p)() = &foo;
+int main ()
+{
+  int val = foo ();
+  assert (val ==  (*p)());
+
+  /* Check in the exact same order in which the dispatching
+     is expected to happen.  */
+  if (__builtin_cpu_is ("corei7"))
+    assert (val == 5);
+  else
+    assert (val == 0);
+  
+  return 0;
+}
+
+int __attribute__ ((target("default")))
+foo ()
+{
+  return 0;
+}
+
+int __attribute__ ((target("arch=corei7")))
+foo ()
+{
+  return 5;
+}
diff --git a/gcc/testsuite/g++.dg/ext/mv15.C b/gcc/testsuite/g++.dg/ext/mv15.C
new file mode 100644
index 0000000..42e39d2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/mv15.C
@@ -0,0 +1,40 @@
+/* Test case to check if Multiversioning works.  */
+/* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
+/* { dg-options "-O2 -fPIC" } */
+
+#include <assert.h>
+
+/* Default version.  */
+int foo (); // Extra declaration that is merged with the second one.
+int foo () __attribute__ ((target("default")));
+
+int foo () __attribute__ ((target("arch=nehalem")));
+
+int (*p)() = &foo;
+int main ()
+{
+  int val = foo ();
+  assert (val ==  (*p)());
+
+  /* Check in the exact same order in which the dispatching
+     is expected to happen.  */
+  if (__builtin_cpu_is ("corei7"))
+    assert (val == 5);
+  else
+    assert (val == 0);
+  
+  return 0;
+}
+
+int __attribute__ ((target("default")))
+foo ()
+{
+  return 0;
+}
+
+int __attribute__ ((target("arch=nehalem")))
+foo ()
+{
+  return 5;
+}

Reply via email to