|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] x86: move arch_generic_hweightl() to arch-specific library
commit b85c5260ee7246a34b826881fecbfa8312d37239
Author: Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed Dec 10 08:51:27 2025 +0100
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Dec 10 08:51:27 2025 +0100
x86: move arch_generic_hweightl() to arch-specific library
Introduce arch/x86/lib/, and make it the home for the somewhat misplaced
x86-specific file that lived in the arch-independent lib/.
Introduce ARCH_LIBS-y as a make variable, to arrange for arch-specific
libraries to (generally) come ahead of generic one(s) when linking. Should
any library be intended to come after the generic one(s), it can be
appended to $(ALL_LIBS-y).
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
xen/Makefile | 4 +-
xen/arch/x86/Makefile | 1 +
xen/arch/x86/arch.mk | 2 +
xen/arch/x86/lib/Makefile | 1 +
xen/arch/x86/lib/generic-hweightl.c | 75 +++++++++++++++++++++++++++++++++++++
xen/lib/Makefile | 1 -
xen/lib/x86-generic-hweightl.c | 75 -------------------------------------
7 files changed, 82 insertions(+), 77 deletions(-)
diff --git a/xen/Makefile b/xen/Makefile
index e6cf287425..13e336ba54 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -461,6 +461,7 @@ ALL_OBJS-y += xsm/built_in.o
ALL_OBJS-y += arch/$(SRCARCH)/built_in.o
ALL_OBJS-$(CONFIG_CRYPTO) += crypto/built_in.o
+ARCH_LIBS-y :=
ALL_LIBS-y := lib/lib.a
all-symbols-y :=
@@ -620,7 +621,8 @@ $(TARGET): outputmakefile asm-generic FORCE
$(Q)$(MAKE) $(build)=arch/$(SRCARCH) include
$(Q)$(MAKE) $(build)=. arch/$(SRCARCH)/include/asm/asm-offsets.h
$(Q)$(MAKE) $(build)=. MKRELOC=$(MKRELOC) 'ALL_OBJS=$(ALL_OBJS-y)' \
- 'ALL_LIBS=$(ALL_LIBS-y)' 'all_symbols=$(all-symbols-y)' $@
+ 'ALL_LIBS=$(ARCH_LIBS-y) $(ALL_LIBS-y)' \
+ 'all_symbols=$(all-symbols-y)' $@
SUBDIRS = xsm arch common crypto drivers lib test
define all_sources
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 300cc67407..61e2293a46 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -5,6 +5,7 @@ obj-y += efi/
obj-y += genapic/
obj-$(CONFIG_GUEST) += guest/
obj-$(CONFIG_HVM) += hvm/
+obj-y += lib/
obj-y += mm/
obj-$(CONFIG_XENOPROF) += oprofile/
obj-$(CONFIG_PV) += pv/
diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk
index 16368a498b..0203138a81 100644
--- a/xen/arch/x86/arch.mk
+++ b/xen/arch/x86/arch.mk
@@ -3,6 +3,8 @@
export XEN_IMG_OFFSET := 0x200000
+ARCH_LIBS-y += arch/x86/lib/lib.a
+
CFLAGS += -DXEN_IMG_OFFSET=$(XEN_IMG_OFFSET)
# Prevent floating-point variables from creeping into Xen.
diff --git a/xen/arch/x86/lib/Makefile b/xen/arch/x86/lib/Makefile
new file mode 100644
index 0000000000..ddf7e19bdc
--- /dev/null
+++ b/xen/arch/x86/lib/Makefile
@@ -0,0 +1 @@
+lib-y += generic-hweightl.o
diff --git a/xen/arch/x86/lib/generic-hweightl.c
b/xen/arch/x86/lib/generic-hweightl.c
new file mode 100644
index 0000000000..1cab68952a
--- /dev/null
+++ b/xen/arch/x86/lib/generic-hweightl.c
@@ -0,0 +1,75 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/bitops.h>
+#include <xen/init.h>
+#include <xen/self-tests.h>
+
+/*
+ * An implementation of generic_hweightl() used on hardware without the POPCNT
+ * instruction.
+ *
+ * This function is called from within an ALTERNATIVE in arch_hweightl().
+ * i.e. behind the back of the compiler. Therefore all registers are callee
+ * preserved.
+ *
+ * The ASM is what GCC-12 emits for generic_hweightl() in a release build of
+ * Xen, with spilling of %rdi/%rdx to preserve the callers registers.
+ *
+ * Note: When we can use __attribute__((no_caller_saved_registers))
+ * unconditionally (GCC 7, Clang 5), we can implement this in plain C.
+ */
+asm (
+ ".type arch_generic_hweightl, STT_FUNC\n\t"
+ ".globl arch_generic_hweightl\n\t"
+ ".hidden arch_generic_hweightl\n\t"
+ ".balign " STR(CONFIG_FUNCTION_ALIGNMENT) ", 0x90\n" /* CODE_FILL */
+ "arch_generic_hweightl:\n\t"
+
+ "push %rdi\n\t"
+ "push %rdx\n\t"
+
+ "movabs $0x5555555555555555, %rdx\n\t"
+ "mov %rdi, %rax\n\t"
+ "shr $1, %rax\n\t"
+ "and %rdx, %rax\n\t"
+ "sub %rax, %rdi\n\t"
+ "movabs $0x3333333333333333, %rax\n\t"
+ "mov %rdi, %rdx\n\t"
+ "shr $2, %rdi\n\t"
+ "and %rax, %rdx\n\t"
+ "and %rax, %rdi\n\t"
+ "add %rdi, %rdx\n\t"
+ "mov %rdx, %rax\n\t"
+ "shr $4, %rax\n\t"
+ "add %rdx, %rax\n\t"
+ "movabs $0x0f0f0f0f0f0f0f0f, %rdx\n\t"
+ "and %rdx, %rax\n\t"
+ "movabs $0x0101010101010101, %rdx\n\t"
+ "imul %rdx, %rax\n\t"
+ "shr $" STR(BITS_PER_LONG) "- 8, %rax\n\t"
+
+ "pop %rdx\n\t"
+ "pop %rdi\n\t"
+
+#ifdef CONFIG_RETURN_THUNK
+ "jmp __x86_return_thunk\n\t"
+#else
+ "ret\n\t"
+#endif
+
+ ".size arch_generic_hweightl, . - arch_generic_hweightl\n\t"
+);
+
+#ifdef CONFIG_SELF_TESTS
+static void __init __constructor test_arch_generic_hweightl(void)
+{
+ RUNTIME_CHECK(arch_generic_hweightl, 0, 0);
+ RUNTIME_CHECK(arch_generic_hweightl, 1, 1);
+ RUNTIME_CHECK(arch_generic_hweightl, 3, 2);
+ RUNTIME_CHECK(arch_generic_hweightl, 7, 3);
+ RUNTIME_CHECK(arch_generic_hweightl, 0xff, 8);
+
+ RUNTIME_CHECK(arch_generic_hweightl, 1 | (1UL << (BITS_PER_LONG - 1)), 2);
+ RUNTIME_CHECK(arch_generic_hweightl, -1UL, BITS_PER_LONG);
+}
+#endif
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index 954d9216a3..efca830d92 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -39,7 +39,6 @@ lib-y += strtol.o
lib-y += strtoll.o
lib-y += strtoul.o
lib-y += strtoull.o
-lib-$(CONFIG_X86) += x86-generic-hweightl.o
lib-$(CONFIG_X86) += xxhash32.o
lib-$(CONFIG_X86) += xxhash64.o
diff --git a/xen/lib/x86-generic-hweightl.c b/xen/lib/x86-generic-hweightl.c
deleted file mode 100644
index 1cab68952a..0000000000
--- a/xen/lib/x86-generic-hweightl.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#include <xen/bitops.h>
-#include <xen/init.h>
-#include <xen/self-tests.h>
-
-/*
- * An implementation of generic_hweightl() used on hardware without the POPCNT
- * instruction.
- *
- * This function is called from within an ALTERNATIVE in arch_hweightl().
- * i.e. behind the back of the compiler. Therefore all registers are callee
- * preserved.
- *
- * The ASM is what GCC-12 emits for generic_hweightl() in a release build of
- * Xen, with spilling of %rdi/%rdx to preserve the callers registers.
- *
- * Note: When we can use __attribute__((no_caller_saved_registers))
- * unconditionally (GCC 7, Clang 5), we can implement this in plain C.
- */
-asm (
- ".type arch_generic_hweightl, STT_FUNC\n\t"
- ".globl arch_generic_hweightl\n\t"
- ".hidden arch_generic_hweightl\n\t"
- ".balign " STR(CONFIG_FUNCTION_ALIGNMENT) ", 0x90\n" /* CODE_FILL */
- "arch_generic_hweightl:\n\t"
-
- "push %rdi\n\t"
- "push %rdx\n\t"
-
- "movabs $0x5555555555555555, %rdx\n\t"
- "mov %rdi, %rax\n\t"
- "shr $1, %rax\n\t"
- "and %rdx, %rax\n\t"
- "sub %rax, %rdi\n\t"
- "movabs $0x3333333333333333, %rax\n\t"
- "mov %rdi, %rdx\n\t"
- "shr $2, %rdi\n\t"
- "and %rax, %rdx\n\t"
- "and %rax, %rdi\n\t"
- "add %rdi, %rdx\n\t"
- "mov %rdx, %rax\n\t"
- "shr $4, %rax\n\t"
- "add %rdx, %rax\n\t"
- "movabs $0x0f0f0f0f0f0f0f0f, %rdx\n\t"
- "and %rdx, %rax\n\t"
- "movabs $0x0101010101010101, %rdx\n\t"
- "imul %rdx, %rax\n\t"
- "shr $" STR(BITS_PER_LONG) "- 8, %rax\n\t"
-
- "pop %rdx\n\t"
- "pop %rdi\n\t"
-
-#ifdef CONFIG_RETURN_THUNK
- "jmp __x86_return_thunk\n\t"
-#else
- "ret\n\t"
-#endif
-
- ".size arch_generic_hweightl, . - arch_generic_hweightl\n\t"
-);
-
-#ifdef CONFIG_SELF_TESTS
-static void __init __constructor test_arch_generic_hweightl(void)
-{
- RUNTIME_CHECK(arch_generic_hweightl, 0, 0);
- RUNTIME_CHECK(arch_generic_hweightl, 1, 1);
- RUNTIME_CHECK(arch_generic_hweightl, 3, 2);
- RUNTIME_CHECK(arch_generic_hweightl, 7, 3);
- RUNTIME_CHECK(arch_generic_hweightl, 0xff, 8);
-
- RUNTIME_CHECK(arch_generic_hweightl, 1 | (1UL << (BITS_PER_LONG - 1)), 2);
- RUNTIME_CHECK(arch_generic_hweightl, -1UL, BITS_PER_LONG);
-}
-#endif
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |