* [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE
@ 2020-12-24 23:02 H.J. Lu
2020-12-25 3:25 ` V2 " H.J. Lu
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2020-12-24 23:02 UTC (permalink / raw)
To: libc-alpha
Add tests for IFUNC resolver using CPU_FEATURE_USABLE with and without
lazy binding.
---
sysdeps/x86/Makefile | 22 +++++-
sysdeps/x86/tst-ifunc-platform-1-bindnow.c | 1 +
sysdeps/x86/tst-ifunc-platform-1-lazy.c | 89 ++++++++++++++++++++++
sysdeps/x86/tst-ifunc-platform-1-static.c | 1 +
sysdeps/x86/tst-ifunc-platform-2-bindnow.c | 1 +
sysdeps/x86/tst-ifunc-platform-2-lazy.c | 52 +++++++++++++
sysdeps/x86/tst-ifunc-platform-mod-2.c | 65 ++++++++++++++++
7 files changed, 229 insertions(+), 2 deletions(-)
create mode 100644 sysdeps/x86/tst-ifunc-platform-1-bindnow.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-1-lazy.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-1-static.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-2-bindnow.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-2-lazy.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-mod-2.c
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 00109ded11..441e11687b 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -7,8 +7,26 @@ sysdep-dl-routines += dl-get-cpu-features
sysdep_headers += bits/platform/x86.h sys/platform/x86.h
tests += tst-get-cpu-features tst-get-cpu-features-static \
- tst-cpu-features-cpuinfo tst-cpu-features-supports
-tests-static += tst-get-cpu-features-static
+ tst-cpu-features-cpuinfo tst-cpu-features-supports \
+ tst-ifunc-platform-1-bindnow \
+ tst-ifunc-platform-1-lazy \
+ tst-ifunc-platform-1-static \
+ tst-ifunc-platform-2-bindnow \
+ tst-ifunc-platform-2-lazy
+tests-static += tst-get-cpu-features-static \
+ tst-ifunc-platform-1-static
+
+modules-names += tst-ifunc-platform-mod-2
+
+LDFLAGS-tst-ifunc-platform-1-lazy = -Wl,-z,lazy
+LDFLAGS-tst-ifunc-platform-1-bindnow = -Wl,-z,now
+tst-ifunc-platform-1-bindnow-ENV = LD_BIND_NOW=1
+LDFLAGS-tst-ifunc-platform-2-lazy = -Wl,-z,lazy
+LDFLAGS-tst-ifunc-platform-2-bindnow = -Wl,-z,now
+tst-ifunc-platform-2-bindnow-ENV = LD_BIND_NOW=1
+
+$(objpfx)tst-ifunc-platform-2-bindnow: $(objpfx)tst-ifunc-platform-mod-2.so
+$(objpfx)tst-ifunc-platform-2-lazy: $(objpfx)tst-ifunc-platform-mod-2.so
endif
ifeq ($(subdir),math)
diff --git a/sysdeps/x86/tst-ifunc-platform-1-bindnow.c b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c
new file mode 100644
index 0000000000..f8391048ae
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-1-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-1-lazy.c b/sysdeps/x86/tst-ifunc-platform-1-lazy.c
new file mode 100644
index 0000000000..fcb192d68d
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-1-lazy.c
@@ -0,0 +1,89 @@
+/* Program with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/platform/x86.h>
+#include <support/check.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+static enum isa
+none (void)
+{
+ return has_none;
+}
+
+static enum isa
+sse2 (void)
+{
+ return has_sse2;
+}
+
+static enum isa
+avx2 (void)
+{
+ return has_avx2;
+}
+
+static enum isa
+avx512f (void)
+{
+ return has_avx512f;
+}
+
+static __typeof__ (avx2) *
+resolver (void)
+{
+ if (CPU_FEATURE_USABLE (AVX512F))
+ return avx512f;
+ else if (CPU_FEATURE_USABLE (AVX2))
+ return avx2;
+ else if (CPU_FEATURE_USABLE (SSE2))
+ return sse2;
+ return none;
+}
+
+static enum isa cpuid (void) __attribute__ ((ifunc ("resolver")));
+
+static int
+do_test (void)
+{
+ enum isa has_isa = cpuid ();
+ switch (has_isa)
+ {
+ case has_none:
+ break;
+ case has_sse2:
+ TEST_VERIFY_EXIT (__builtin_cpu_supports ("sse2"));
+ break;
+ case has_avx2:
+ TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx2"));
+ break;
+ case has_avx512f:
+ TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx512f"));
+ break;
+ }
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-ifunc-platform-1-static.c b/sysdeps/x86/tst-ifunc-platform-1-static.c
new file mode 100644
index 0000000000..f8391048ae
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-1-static.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-1-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-2-bindnow.c b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c
new file mode 100644
index 0000000000..7c2455c2a0
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-2-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-2-lazy.c b/sysdeps/x86/tst-ifunc-platform-2-lazy.c
new file mode 100644
index 0000000000..65b5f5e314
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-2-lazy.c
@@ -0,0 +1,52 @@
+/* Program with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <support/check.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+extern enum isa cpuid (void);
+
+static int
+do_test (void)
+{
+ enum isa has_isa = cpuid ();
+ switch (has_isa)
+ {
+ case has_none:
+ break;
+ case has_sse2:
+ TEST_VERIFY_EXIT (__builtin_cpu_supports ("sse2"));
+ break;
+ case has_avx2:
+ TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx2"));
+ break;
+ case has_avx512f:
+ TEST_VERIFY_EXIT (__builtin_cpu_supports ("avx512f"));
+ break;
+ }
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-ifunc-platform-mod-2.c b/sysdeps/x86/tst-ifunc-platform-mod-2.c
new file mode 100644
index 0000000000..c302277be4
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-mod-2.c
@@ -0,0 +1,65 @@
+/* Shared object with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/platform/x86.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+static enum isa
+none (void)
+{
+ return has_none;
+}
+
+static enum isa
+sse2 (void)
+{
+ return has_sse2;
+}
+
+static enum isa
+avx2 (void)
+{
+ return has_avx2;
+}
+
+static enum isa
+avx512f (void)
+{
+ return has_avx512f;
+}
+
+static __typeof__ (avx2) *
+resolver (void)
+{
+ if (CPU_FEATURE_USABLE (AVX512F))
+ return avx512f;
+ else if (CPU_FEATURE_USABLE (AVX2))
+ return avx2;
+ else if (CPU_FEATURE_USABLE (SSE2))
+ return sse2;
+ return none;
+}
+
+enum isa cpuid (void) __attribute__ ((ifunc ("resolver")));
--
2.29.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* V2 [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE
2020-12-24 23:02 [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE H.J. Lu
@ 2020-12-25 3:25 ` H.J. Lu
0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2020-12-25 3:25 UTC (permalink / raw)
To: GNU C Library, Florian Weimer
[-- Attachment #1: Type: text/plain, Size: 771 bytes --]
On Thu, Dec 24, 2020 at 3:02 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Add tests for IFUNC resolver using CPU_FEATURE_USABLE with and without
> lazy binding.
Update tests to properly check IFUNC resolver.
Florian, your patch failed:
FAIL: elf/tst-ifunc-platform-3-bindnow
FAIL: elf/tst-ifunc-platform-3-lazy
due to
[hjl@gnu-cfl-2 build-x86_64-linux]$ readelf -rW
elf/tst-ifunc-platform-mod-3.so | grep __x86_cpu_array
0000000000003fe0 0000000200000006 R_X86_64_GLOB_DAT
0000000000000000 __x86_cpu_array@GLIBC_2.33 + 0
[hjl@gnu-cfl-2 build-x86_64-linux]$ readelf -rW
elf/tst-ifunc-platform-3-lazy | grep __x86_cpu_array
0000000000406d80 0000003600000005 R_X86_64_COPY
0000000000406d80 __x86_cpu_array@GLIBC_2.33 + 0
[hjl@gnu-cfl-2 build-x86_64-linux]$
--
H.J.
[-- Attachment #2: 0001-x86-Add-tests-for-IFUNC-resolver-with-CPU_FEATURE_US.patch --]
[-- Type: text/x-patch, Size: 12413 bytes --]
From 67db31ec5a3f570a6a2bbf40f61014c267c42798 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 24 Dec 2020 14:06:30 -0800
Subject: [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE
Add tests for IFUNC resolver using CPU_FEATURE_USABLE with and without
lazy binding.
---
sysdeps/x86/Makefile | 30 +++++++-
sysdeps/x86/tst-ifunc-platform-1-bindnow.c | 1 +
sysdeps/x86/tst-ifunc-platform-1-lazy.c | 87 ++++++++++++++++++++++
sysdeps/x86/tst-ifunc-platform-1-static.c | 1 +
sysdeps/x86/tst-ifunc-platform-2-bindnow.c | 1 +
sysdeps/x86/tst-ifunc-platform-2-lazy.c | 51 +++++++++++++
sysdeps/x86/tst-ifunc-platform-3-bindnow.c | 1 +
sysdeps/x86/tst-ifunc-platform-3-lazy.c | 1 +
sysdeps/x86/tst-ifunc-platform-mod-2.c | 65 ++++++++++++++++
sysdeps/x86/tst-ifunc-platform-mod-3.c | 71 ++++++++++++++++++
10 files changed, 307 insertions(+), 2 deletions(-)
create mode 100644 sysdeps/x86/tst-ifunc-platform-1-bindnow.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-1-lazy.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-1-static.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-2-bindnow.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-2-lazy.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-3-bindnow.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-3-lazy.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-mod-2.c
create mode 100644 sysdeps/x86/tst-ifunc-platform-mod-3.c
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 00109ded11..cd752b9bd6 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -7,8 +7,34 @@ sysdep-dl-routines += dl-get-cpu-features
sysdep_headers += bits/platform/x86.h sys/platform/x86.h
tests += tst-get-cpu-features tst-get-cpu-features-static \
- tst-cpu-features-cpuinfo tst-cpu-features-supports
-tests-static += tst-get-cpu-features-static
+ tst-cpu-features-cpuinfo tst-cpu-features-supports \
+ tst-ifunc-platform-1-bindnow \
+ tst-ifunc-platform-1-lazy \
+ tst-ifunc-platform-1-static \
+ tst-ifunc-platform-2-bindnow \
+ tst-ifunc-platform-2-lazy \
+ tst-ifunc-platform-3-bindnow \
+ tst-ifunc-platform-3-lazy
+tests-static += tst-get-cpu-features-static \
+ tst-ifunc-platform-1-static
+
+modules-names += tst-ifunc-platform-mod-2 \
+ tst-ifunc-platform-mod-3
+
+LDFLAGS-tst-ifunc-platform-1-lazy = -Wl,-z,lazy
+LDFLAGS-tst-ifunc-platform-1-bindnow = -Wl,-z,now
+tst-ifunc-platform-1-bindnow-ENV = LD_BIND_NOW=1
+LDFLAGS-tst-ifunc-platform-2-lazy = -Wl,-z,lazy
+LDFLAGS-tst-ifunc-platform-2-bindnow = -Wl,-z,now
+tst-ifunc-platform-2-bindnow-ENV = LD_BIND_NOW=1
+LDFLAGS-tst-ifunc-platform-3-lazy = -Wl,-z,lazy
+LDFLAGS-tst-ifunc-platform-3-bindnow = -Wl,-z,now
+tst-ifunc-platform-3-bindnow-ENV = LD_BIND_NOW=1
+
+$(objpfx)tst-ifunc-platform-2-bindnow: $(objpfx)tst-ifunc-platform-mod-2.so
+$(objpfx)tst-ifunc-platform-2-lazy: $(objpfx)tst-ifunc-platform-mod-2.so
+$(objpfx)tst-ifunc-platform-3-bindnow: $(objpfx)tst-ifunc-platform-mod-3.so
+$(objpfx)tst-ifunc-platform-3-lazy: $(objpfx)tst-ifunc-platform-mod-3.so
endif
ifeq ($(subdir),math)
diff --git a/sysdeps/x86/tst-ifunc-platform-1-bindnow.c b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c
new file mode 100644
index 0000000000..f8391048ae
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-1-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-1-lazy.c b/sysdeps/x86/tst-ifunc-platform-1-lazy.c
new file mode 100644
index 0000000000..2556c23f3c
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-1-lazy.c
@@ -0,0 +1,87 @@
+/* Program with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/platform/x86.h>
+#include <support/check.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+static enum isa
+none (void)
+{
+ return has_none;
+}
+
+static enum isa
+sse2 (void)
+{
+ return has_sse2;
+}
+
+static enum isa
+avx2 (void)
+{
+ return has_avx2;
+}
+
+static enum isa
+avx512f (void)
+{
+ return has_avx512f;
+}
+
+static __typeof__ (avx2) *
+resolver (void)
+{
+ if (CPU_FEATURE_USABLE (AVX512F))
+ return avx512f;
+ else if (CPU_FEATURE_USABLE (AVX2))
+ return avx2;
+ else if (CPU_FEATURE_USABLE (SSE2))
+ return sse2;
+ return none;
+}
+
+static enum isa cpuid (void) __attribute__ ((ifunc ("resolver")));
+
+static int
+do_test (void)
+{
+ enum isa has_isa = cpuid ();
+ TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (SSE2)
+ == !!__builtin_cpu_supports ("sse2"));
+ TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX2)
+ == !!__builtin_cpu_supports ("avx2"));
+ TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX512F)
+ == !!__builtin_cpu_supports ("avx512f"));
+ if (__builtin_cpu_supports ("avx512f"))
+ TEST_VERIFY_EXIT (has_isa == has_avx512f);
+ else if (__builtin_cpu_supports ("avx2"))
+ TEST_VERIFY_EXIT (has_isa == has_avx2);
+ else if (__builtin_cpu_supports ("sse2"))
+ TEST_VERIFY_EXIT (has_isa == has_sse2);
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-ifunc-platform-1-static.c b/sysdeps/x86/tst-ifunc-platform-1-static.c
new file mode 100644
index 0000000000..f8391048ae
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-1-static.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-1-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-2-bindnow.c b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c
new file mode 100644
index 0000000000..7c2455c2a0
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-2-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-2-lazy.c b/sysdeps/x86/tst-ifunc-platform-2-lazy.c
new file mode 100644
index 0000000000..db3cc5e123
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-2-lazy.c
@@ -0,0 +1,51 @@
+/* Program with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/platform/x86.h>
+#include <support/check.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+extern enum isa cpuid (void);
+
+static int
+do_test (void)
+{
+ enum isa has_isa = cpuid ();
+ TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (SSE2)
+ == !!__builtin_cpu_supports ("sse2"));
+ TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX2)
+ == !!__builtin_cpu_supports ("avx2"));
+ TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX512F)
+ == !!__builtin_cpu_supports ("avx512f"));
+ if (__builtin_cpu_supports ("avx512f"))
+ TEST_VERIFY_EXIT (has_isa == has_avx512f);
+ else if (__builtin_cpu_supports ("avx2"))
+ TEST_VERIFY_EXIT (has_isa == has_avx2);
+ else if (__builtin_cpu_supports ("sse2"))
+ TEST_VERIFY_EXIT (has_isa == has_sse2);
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/x86/tst-ifunc-platform-3-bindnow.c b/sysdeps/x86/tst-ifunc-platform-3-bindnow.c
new file mode 100644
index 0000000000..7c2455c2a0
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-3-bindnow.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-2-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-3-lazy.c b/sysdeps/x86/tst-ifunc-platform-3-lazy.c
new file mode 100644
index 0000000000..7c2455c2a0
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-3-lazy.c
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-2-lazy.c"
diff --git a/sysdeps/x86/tst-ifunc-platform-mod-2.c b/sysdeps/x86/tst-ifunc-platform-mod-2.c
new file mode 100644
index 0000000000..c302277be4
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-mod-2.c
@@ -0,0 +1,65 @@
+/* Shared object with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/platform/x86.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+static enum isa
+none (void)
+{
+ return has_none;
+}
+
+static enum isa
+sse2 (void)
+{
+ return has_sse2;
+}
+
+static enum isa
+avx2 (void)
+{
+ return has_avx2;
+}
+
+static enum isa
+avx512f (void)
+{
+ return has_avx512f;
+}
+
+static __typeof__ (avx2) *
+resolver (void)
+{
+ if (CPU_FEATURE_USABLE (AVX512F))
+ return avx512f;
+ else if (CPU_FEATURE_USABLE (AVX2))
+ return avx2;
+ else if (CPU_FEATURE_USABLE (SSE2))
+ return sse2;
+ return none;
+}
+
+enum isa cpuid (void) __attribute__ ((ifunc ("resolver")));
diff --git a/sysdeps/x86/tst-ifunc-platform-mod-3.c b/sysdeps/x86/tst-ifunc-platform-mod-3.c
new file mode 100644
index 0000000000..1002c444ab
--- /dev/null
+++ b/sysdeps/x86/tst-ifunc-platform-mod-3.c
@@ -0,0 +1,71 @@
+/* Shared object with local IFUNC resolver and <sys/platform/x86.h>.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/platform/x86.h>
+
+enum isa
+{
+ has_none,
+ has_sse2,
+ has_avx2,
+ has_avx512f
+};
+
+static enum isa
+none (void)
+{
+ return has_none;
+}
+
+static enum isa
+sse2 (void)
+{
+ return has_sse2;
+}
+
+static enum isa
+avx2 (void)
+{
+ return has_avx2;
+}
+
+static enum isa
+avx512f (void)
+{
+ return has_avx512f;
+}
+
+static __typeof__ (avx2) *
+resolver (void)
+{
+ if (CPU_FEATURE_USABLE (AVX512F))
+ return avx512f;
+ else if (CPU_FEATURE_USABLE (AVX2))
+ return avx2;
+ else if (CPU_FEATURE_USABLE (SSE2))
+ return sse2;
+ return none;
+}
+
+static enum isa cpuid_local (void) __attribute__ ((ifunc ("resolver")));
+
+enum isa
+cpuid (void)
+{
+ return cpuid_local ();
+}
--
2.29.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-25 3:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24 23:02 [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE H.J. Lu
2020-12-25 3:25 ` V2 " H.J. Lu
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).