[PATCH 3/4] alpha: add multiarch infrastructure for IFUNC dispatch
Matt Turner
mattst88@gmail.com
Sun Sep 6 19:06:08 GMT 2026
Add the framework for runtime CPU-based dispatch on alpha.
init-arch.h wraps the implver and amask instructions, which resolvers
use directly rather than going through AT_HWCAP: both are unprivileged,
so a resolver can ask the processor what it is without help from the
kernel. IS_EV6_OR_LATER tests implver for the 21264 family,
IS_EV7_OR_LATER for the 21364, and HAS_CIX asks amask for the count
extension the 21264A introduced. The wrappers reach the instructions
through __builtin_alpha_implver/__builtin_alpha_amask rather than inline
asm: GCC has modeled both for alpha for a long time, so it knows their
real semantics directly instead of us hand-writing asm constraints.
configure inserts <machine>/multiarch immediately before <machine> for
each term of the Implies chain, so a multiarch directory shadows only
the assembly in its own directory. sysdeps/alpha/multiarch therefore
sits after sysdeps/alpha/alphaev6 and sysdeps/alpha/alphaev67 in
sysnames, and an --host=alphaev6 or later build picks the CPU assembly
over the dispatchers, leaving IFUNC dispatch inert on exactly the
configurations that have the tuned implementations. Give the two levels
that carry assembly an Implies-only multiarch directory chaining down to
sysdeps/alpha/multiarch, as powerpc does for its per-CPU directories,
which places the dispatchers ahead of the assembly. A
--disable-multi-arch build is unaffected: no multiarch directory enters
sysnames and the assembly is used directly.
The dispatchers themselves follow in the next patch.
---
sysdeps/alpha/alphaev6/multiarch/Implies | 1 +
sysdeps/alpha/alphaev67/multiarch/Implies | 1 +
sysdeps/alpha/multiarch/init-arch.h | 65 +++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+)
diff --git a/sysdeps/alpha/alphaev6/multiarch/Implies b/sysdeps/alpha/alphaev6/multiarch/Implies
new file mode 100644
index 0000000000..c07181098c
--- /dev/null
+++ b/sysdeps/alpha/alphaev6/multiarch/Implies
@@ -0,0 +1 @@
+alpha/multiarch
diff --git a/sysdeps/alpha/alphaev67/multiarch/Implies b/sysdeps/alpha/alphaev67/multiarch/Implies
new file mode 100644
index 0000000000..fb91f5988c
--- /dev/null
+++ b/sysdeps/alpha/alphaev67/multiarch/Implies
@@ -0,0 +1 @@
+alpha/alphaev6/multiarch
diff --git a/sysdeps/alpha/multiarch/init-arch.h b/sysdeps/alpha/multiarch/init-arch.h
new file mode 100644
index 0000000000..25ed0df178
--- /dev/null
+++ b/sysdeps/alpha/multiarch/init-arch.h
@@ -0,0 +1,65 @@
+/* Define IFUNC resolver CPU detection for Alpha.
+ Copyright (C) 2026 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/>. */
+
+#ifndef _ALPHA_INIT_ARCH_H
+#define _ALPHA_INIT_ARCH_H
+
+/* implver returns:
+ 0 = EV4 (21064)
+ 1 = EV5 (21164)
+ 2 = EV6 (21264)
+ 3 = EV7 (21364) */
+
+static inline unsigned long
+__attribute__ ((always_inline))
+alpha_implver (void)
+{
+ return __builtin_alpha_implver ();
+}
+
+/* amask tests for optional extensions. Returns zero bits for
+ supported features. Known bits:
+ 0x01 = BWX (byte/word extensions, EV56+)
+ 0x02 = FIX (sqrt/ftoi extensions, EV6+)
+ 0x04 = CIX (count extensions, EV67+)
+ 0x100 = MVI (multimedia extensions, PCA56+) */
+
+static inline unsigned long
+__attribute__ ((always_inline))
+alpha_amask (unsigned long mask)
+{
+ return __builtin_alpha_amask (mask);
+}
+
+#define ALPHA_IMPL_EV4 0
+#define ALPHA_IMPL_EV5 1
+#define ALPHA_IMPL_EV6 2
+#define ALPHA_IMPL_EV7 3
+
+#define ALPHA_AMASK_BWX 0x01
+#define ALPHA_AMASK_FIX 0x02
+#define ALPHA_AMASK_CIX 0x04
+#define ALPHA_AMASK_MVI 0x100
+
+#define IS_EV6_OR_LATER (alpha_implver () >= ALPHA_IMPL_EV6)
+#define IS_EV7_OR_LATER (alpha_implver () >= ALPHA_IMPL_EV7)
+#define HAS_CIX (!(alpha_amask (ALPHA_AMASK_CIX)))
+
+#define INIT_ARCH()
+
+#endif /* _ALPHA_INIT_ARCH_H */
--
2.54.0
More information about the Libc-alpha
mailing list