[PATCH v2 1/3] lib/math/gcd: Use static key to select implementation at runtime
Andrew Morton
akpm at linux-foundation.org
Wed Jun 4 16:01:31 PDT 2025
On Sat, 24 May 2025 23:55:17 +0800 Kuan-Wei Chiu <visitorckw at gmail.com> wrote:
> On platforms like RISC-V, the compiler may generate hardware FFS
> instructions even if the underlying CPU does not actually support them.
> Currently, the GCD implementation is chosen at compile time based on
> CONFIG_CPU_NO_EFFICIENT_FFS, which can result in suboptimal behavior on
> such systems.
>
> Introduce a static key, efficient_ffs_key, to enable runtime selection
> between the binary GCD (using ffs) and the odd-even GCD implementation.
> This allows the kernel to default to the faster binary GCD when FFS is
> efficient, while retaining the ability to fall back when needed.
>
> ...
>
> @@ -54,6 +58,11 @@ unsigned long gcd(unsigned long a, unsigned long b)
> if (!a || !b)
> return r;
Both binary_gcd() and gcd() perform the above. Seems unnecessary?
I can merge this series if the riscv team are OK with it?
More information about the linux-riscv
mailing list