x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE
Commit Message
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
@@ -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)
new file mode 100644
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-1-lazy.c"
new file mode 100644
@@ -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>
new file mode 100644
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-1-lazy.c"
new file mode 100644
@@ -0,0 +1 @@
+#include "tst-ifunc-platform-2-lazy.c"
new file mode 100644
@@ -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>
new file mode 100644
@@ -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")));