mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem()
__iter_div_u64_rem() open-codes an empty asm() to keep the compiler from turning the subtraction loop into a modulo operation. That is what OPTIMIZER_HIDE_VAR() is for, so use it and reflow the comment. The macro lives in linux/compiler.h, which this header did not include. vdso/math64.h is reached from linux/math64.h, whose includes are linux/types.h, linux/math.h, asm/div64.h and vdso/math64.h; none of them guarantees linux/compiler.h. x86 happens to get it through asm/div64.h -> linux/log2.h, m68k's asm/div64.h only pulls in asm-generic/div64.h and linux/types.h, so the macro is undeclared there and the build fails with -Werror=implicit-function-declaration. Include linux/compiler.h so the header no longer depends on its includer. This is a no-op for the vDSO, where lib/vdso/gettimeofday.c already gets it through linux/build_bug.h, and vdso/unaligned.h sets the same precedent by including linux/compiler_types.h. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261002153104.1347978-2-zhanxusheng@xiaomi.com Closes: https://lore.kernel.org/oe-kbuild-all/202609300626.zwNjKaO6-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202609301300.uAawkHuh-lkp@intel.com/
This commit is contained in:
parent
5062889371
commit
c1b910b270
|
|
@ -2,15 +2,18 @@
|
|||
#ifndef __VDSO_MATH64_H
|
||||
#define __VDSO_MATH64_H
|
||||
|
||||
static __always_inline u32
|
||||
__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
|
||||
#include <linux/compiler.h>
|
||||
|
||||
static __always_inline u32 __iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
while (dividend >= divisor) {
|
||||
/* The following asm() prevents the compiler from
|
||||
optimising this loop into a modulo operation. */
|
||||
asm("" : "+rm"(dividend));
|
||||
/*
|
||||
* Prevent the compiler from optimising this loop into a
|
||||
* modulo operation.
|
||||
*/
|
||||
OPTIMIZER_HIDE_VAR(dividend);
|
||||
|
||||
dividend -= divisor;
|
||||
ret++;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user