Skip to content

Commit b10d2d2

Browse files
author
Eric Biggers
committed
lib/crc: loongarch: Migrate optimized CRC code into lib/crc/
Move the loongarch-optimized CRC code from arch/loongarch/lib/crc* into its new location in lib/crc/loongarch/, and wire it up in the new way. This new way of organizing the CRC code eliminates the need to artificially split the code for each CRC variant into separate arch and generic modules, enabling better inlining and dead code elimination. For more details, see "lib/crc: Prepare for arch-optimized code in subdirs of lib/crc/". Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com> Acked-by: Ingo Molnar <mingo@kernel.org> Acked-by: "Jason A. Donenfeld" <Jason@zx2c4.com> Link: https://lore.kernel.org/r/20250607200454.73587-6-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 2b7531b commit b10d2d2

4 files changed

Lines changed: 7 additions & 30 deletions

File tree

arch/loongarch/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ config LOONGARCH
1515
select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
1616
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
1717
select ARCH_HAS_CPU_FINALIZE_INIT
18-
select ARCH_HAS_CRC32
1918
select ARCH_HAS_CURRENT_STACK_POINTER
2019
select ARCH_HAS_DEBUG_VM_PGTABLE
2120
select ARCH_HAS_FAST_MULTIPLIER

arch/loongarch/lib/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ obj-$(CONFIG_ARCH_SUPPORTS_INT128) += tishift.o
1111
obj-$(CONFIG_CPU_HAS_LSX) += xor_simd.o xor_simd_glue.o
1212

1313
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
14-
15-
obj-$(CONFIG_CRC32_ARCH) += crc32-loongarch.o

lib/crc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ config CRC32_ARCH
6868
depends on CRC32 && CRC_OPTIMIZATIONS
6969
default y if ARM && KERNEL_MODE_NEON
7070
default y if ARM64
71+
default y if LOONGARCH
7172

7273
config CRC64
7374
tristate
Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
*/
1111

1212
#include <asm/cpu-features.h>
13-
#include <linux/crc32.h>
14-
#include <linux/export.h>
15-
#include <linux/module.h>
1613
#include <linux/unaligned.h>
1714

1815
#define _CRC32(crc, value, size, type) \
@@ -29,7 +26,7 @@ do { \
2926

3027
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_crc32);
3128

32-
u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
29+
static inline u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
3330
{
3431
if (!static_branch_likely(&have_crc32))
3532
return crc32_le_base(crc, p, len);
@@ -64,9 +61,8 @@ u32 crc32_le_arch(u32 crc, const u8 *p, size_t len)
6461

6562
return crc;
6663
}
67-
EXPORT_SYMBOL(crc32_le_arch);
6864

69-
u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
65+
static inline u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
7066
{
7167
if (!static_branch_likely(&have_crc32))
7268
return crc32c_base(crc, p, len);
@@ -101,36 +97,19 @@ u32 crc32c_arch(u32 crc, const u8 *p, size_t len)
10197

10298
return crc;
10399
}
104-
EXPORT_SYMBOL(crc32c_arch);
105100

106-
u32 crc32_be_arch(u32 crc, const u8 *p, size_t len)
107-
{
108-
return crc32_be_base(crc, p, len);
109-
}
110-
EXPORT_SYMBOL(crc32_be_arch);
101+
#define crc32_be_arch crc32_be_base /* not implemented on this arch */
111102

112-
static int __init crc32_loongarch_init(void)
103+
#define crc32_mod_init_arch crc32_mod_init_arch
104+
static inline void crc32_mod_init_arch(void)
113105
{
114106
if (cpu_has_crc32)
115107
static_branch_enable(&have_crc32);
116-
return 0;
117108
}
118-
subsys_initcall(crc32_loongarch_init);
119109

120-
static void __exit crc32_loongarch_exit(void)
121-
{
122-
}
123-
module_exit(crc32_loongarch_exit);
124-
125-
u32 crc32_optimizations(void)
110+
static inline u32 crc32_optimizations_arch(void)
126111
{
127112
if (static_key_enabled(&have_crc32))
128113
return CRC32_LE_OPTIMIZATION | CRC32C_OPTIMIZATION;
129114
return 0;
130115
}
131-
EXPORT_SYMBOL(crc32_optimizations);
132-
133-
MODULE_AUTHOR("Min Zhou <zhoumin@loongson.cn>");
134-
MODULE_AUTHOR("Huacai Chen <chenhuacai@loongson.cn>");
135-
MODULE_DESCRIPTION("CRC32 and CRC32C using LoongArch crc* instructions");
136-
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)