* [PATCH 1/2] lib: mul_u64_add_u64_div_u64: Fix addition of large constants
2026-08-03 9:47 [PATCH 0/2] x86: Use "er" asm constriant for add/sub David Laight
@ 2026-08-03 9:47 ` David Laight
2026-08-03 10:08 ` H. Peter Anvin
2026-08-03 9:47 ` [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values David Laight
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: David Laight @ 2026-08-03 9:47 UTC (permalink / raw)
To: Borislav Betkov, Ingo Molnar, Thomas Gleinxer, Dave Hansen, x86,
Andrew Morton, linux-kernel
Cc: David Laight, Nicolas Pitre, H. Peter Anvin, Peter Zijlstra,
Uwe Kleine-König, rodrigo.alencar, jic23
Adding constants over 2^31 fails to compile because the ADD instruction
only supports 32bit signed immediates.
Replace the "irm" constraint with "erm" so that the compiler loads
large constants into a register.
Found by a patch to drivers/iio/frequency/ad9910.c
Fixes: 6480241f31f5 ("lib: add mul_u64_add_u64_div_u64() and mul_u64_u64_div_u64_roundup()")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
arch/x86/include/asm/div64.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
index 30fd06ede751..8a2d343f977e 100644
--- a/arch/x86/include/asm/div64.h
+++ b/arch/x86/include/asm/div64.h
@@ -111,7 +111,7 @@ static inline u64 mul_u64_add_u64_div_u64(u64 rax, u64 mul, u64 add, u64 div)
if (!statically_true(!add))
asm ("addq %[add], %[lo]; adcq $0, %[hi]" :
- [lo] "+r" (rax), [hi] "+r" (rdx) : [add] "irm" (add));
+ [lo] "+r" (rax), [hi] "+r" (rdx) : [add] "erm" (add));
asm ("divq %[div]" : "+a" (rax), "+d" (rdx) : [div] "rm" (div));
--
2.39.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] lib: mul_u64_add_u64_div_u64: Fix addition of large constants
2026-08-03 9:47 ` [PATCH 1/2] lib: mul_u64_add_u64_div_u64: Fix addition of large constants David Laight
@ 2026-08-03 10:08 ` H. Peter Anvin
0 siblings, 0 replies; 9+ messages in thread
From: H. Peter Anvin @ 2026-08-03 10:08 UTC (permalink / raw)
To: David Laight, Borislav Betkov, Ingo Molnar, Thomas Gleinxer,
Dave Hansen, x86, Andrew Morton, linux-kernel
Cc: Nicolas Pitre, Peter Zijlstra, Uwe Kleine-König,
rodrigo.alencar, jic23
On 2026-08-03 02:47, David Laight wrote:
> Adding constants over 2^31 fails to compile because the ADD instruction
> only supports 32bit signed immediates.
>
> Replace the "irm" constraint with "erm" so that the compiler loads
> large constants into a register.
>
> Found by a patch to drivers/iio/frequency/ad9910.c
>
> Fixes: 6480241f31f5 ("lib: add mul_u64_add_u64_div_u64() and mul_u64_u64_div_u64_roundup()")
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
So it is.
Reviewed-by: H. Peter Anvin <hpa@zytor.com>
> ---
> arch/x86/include/asm/div64.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
> index 30fd06ede751..8a2d343f977e 100644
> --- a/arch/x86/include/asm/div64.h
> +++ b/arch/x86/include/asm/div64.h
> @@ -111,7 +111,7 @@ static inline u64 mul_u64_add_u64_div_u64(u64 rax, u64 mul, u64 add, u64 div)
>
> if (!statically_true(!add))
> asm ("addq %[add], %[lo]; adcq $0, %[hi]" :
> - [lo] "+r" (rax), [hi] "+r" (rdx) : [add] "irm" (add));
> + [lo] "+r" (rax), [hi] "+r" (rdx) : [add] "erm" (add));
>
> asm ("divq %[div]" : "+a" (rax), "+d" (rdx) : [div] "rm" (div));
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values
2026-08-03 9:47 [PATCH 0/2] x86: Use "er" asm constriant for add/sub David Laight
2026-08-03 9:47 ` [PATCH 1/2] lib: mul_u64_add_u64_div_u64: Fix addition of large constants David Laight
@ 2026-08-03 9:47 ` David Laight
2026-08-03 10:01 ` Peter Zijlstra
2026-08-03 10:07 ` H. Peter Anvin
2026-08-03 9:59 ` [PATCH 0/2] x86: Use "er" asm constriant for add/sub Peter Zijlstra
2026-08-03 14:49 ` Nicolas Pitre
3 siblings, 2 replies; 9+ messages in thread
From: David Laight @ 2026-08-03 9:47 UTC (permalink / raw)
To: Borislav Betkov, Ingo Molnar, Thomas Gleinxer, Dave Hansen, x86,
Andrew Morton, linux-kernel
Cc: David Laight, Nicolas Pitre, H. Peter Anvin, Peter Zijlstra,
Uwe Kleine-König, rodrigo.alencar, jic23
Replace the "ir" constraint with "er" so that constants over 2^31
get loaded into a register.
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
arch/x86/include/asm/local.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
index 4957018fef3e..68af7b74450a 100644
--- a/arch/x86/include/asm/local.h
+++ b/arch/x86/include/asm/local.h
@@ -32,14 +32,14 @@ static inline void local_add(long i, local_t *l)
{
asm volatile(_ASM_ADD "%1,%0"
: "+m" (l->a.counter)
- : "ir" (i));
+ : "er" (i));
}
static inline void local_sub(long i, local_t *l)
{
asm volatile(_ASM_SUB "%1,%0"
: "+m" (l->a.counter)
- : "ir" (i));
+ : "er" (i));
}
/**
--
2.39.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values
2026-08-03 9:47 ` [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values David Laight
@ 2026-08-03 10:01 ` Peter Zijlstra
2026-08-03 10:07 ` H. Peter Anvin
1 sibling, 0 replies; 9+ messages in thread
From: Peter Zijlstra @ 2026-08-03 10:01 UTC (permalink / raw)
To: David Laight
Cc: Borislav Betkov, Ingo Molnar, Thomas Gleinxer, Dave Hansen, x86,
Andrew Morton, linux-kernel, Nicolas Pitre, H. Peter Anvin,
Uwe Kleine-König, rodrigo.alencar, jic23
On Mon, Aug 03, 2026 at 10:47:02AM +0100, David Laight wrote:
> Replace the "ir" constraint with "er" so that constants over 2^31
> get loaded into a register.
>
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
> arch/x86/include/asm/local.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
> index 4957018fef3e..68af7b74450a 100644
> --- a/arch/x86/include/asm/local.h
> +++ b/arch/x86/include/asm/local.h
> @@ -32,14 +32,14 @@ static inline void local_add(long i, local_t *l)
> {
> asm volatile(_ASM_ADD "%1,%0"
> : "+m" (l->a.counter)
> - : "ir" (i));
> + : "er" (i));
> }
>
> static inline void local_sub(long i, local_t *l)
> {
> asm volatile(_ASM_SUB "%1,%0"
> : "+m" (l->a.counter)
> - : "ir" (i));
> + : "er" (i));
> }
And the other two sites already have "er", how inconsistent :/
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values
2026-08-03 9:47 ` [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values David Laight
2026-08-03 10:01 ` Peter Zijlstra
@ 2026-08-03 10:07 ` H. Peter Anvin
1 sibling, 0 replies; 9+ messages in thread
From: H. Peter Anvin @ 2026-08-03 10:07 UTC (permalink / raw)
To: David Laight, Borislav Betkov, Ingo Molnar, Thomas Gleinxer,
Dave Hansen, x86, Andrew Morton, linux-kernel
Cc: Nicolas Pitre, Peter Zijlstra, Uwe Kleine-König,
rodrigo.alencar, jic23
On 2026-08-03 02:47, David Laight wrote:
> Replace the "ir" constraint with "er" so that constants over 2^31
> get loaded into a register.
>
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
Yep, that's right.
Reviewed-by: H. Peter Anvin <hpa@zytor.com>
> ---
> arch/x86/include/asm/local.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
> index 4957018fef3e..68af7b74450a 100644
> --- a/arch/x86/include/asm/local.h
> +++ b/arch/x86/include/asm/local.h
> @@ -32,14 +32,14 @@ static inline void local_add(long i, local_t *l)
> {
> asm volatile(_ASM_ADD "%1,%0"
> : "+m" (l->a.counter)
> - : "ir" (i));
> + : "er" (i));
> }
>
> static inline void local_sub(long i, local_t *l)
> {
> asm volatile(_ASM_SUB "%1,%0"
> : "+m" (l->a.counter)
> - : "ir" (i));
> + : "er" (i));
> }
>
> /**
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] x86: Use "er" asm constriant for add/sub
2026-08-03 9:47 [PATCH 0/2] x86: Use "er" asm constriant for add/sub David Laight
2026-08-03 9:47 ` [PATCH 1/2] lib: mul_u64_add_u64_div_u64: Fix addition of large constants David Laight
2026-08-03 9:47 ` [PATCH 2/2] x86/local: local_add/local_sub: Support large immediate values David Laight
@ 2026-08-03 9:59 ` Peter Zijlstra
2026-08-03 14:49 ` Nicolas Pitre
3 siblings, 0 replies; 9+ messages in thread
From: Peter Zijlstra @ 2026-08-03 9:59 UTC (permalink / raw)
To: David Laight
Cc: Borislav Betkov, Ingo Molnar, Thomas Gleinxer, Dave Hansen, x86,
Andrew Morton, linux-kernel, Nicolas Pitre, H. Peter Anvin,
Uwe Kleine-König, rodrigo.alencar, jic23
On Mon, Aug 03, 2026 at 10:47:00AM +0100, David Laight wrote:
> The x86 instruction set only supports 32bit signed immediate values
> for add/sub.
> Replace the "ir" constraint with "er" to avoid build errors.
>
> Found by a patch that added used mul_u64_add_u64_div_u64() to
> do a rounding divide by 2^32 (perhaps not the best way to do this).
>
> A quick grep only found one other affected file.
I suppose the percpu stuff works because of __pcpu_cast_4 truncating the
value to u32 and then ignoring the whole signed/unsigned business. And
__pcpu_reg_imm_8 has "re".
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] x86: Use "er" asm constriant for add/sub
2026-08-03 9:47 [PATCH 0/2] x86: Use "er" asm constriant for add/sub David Laight
` (2 preceding siblings ...)
2026-08-03 9:59 ` [PATCH 0/2] x86: Use "er" asm constriant for add/sub Peter Zijlstra
@ 2026-08-03 14:49 ` Nicolas Pitre
2026-08-03 15:39 ` David Laight
3 siblings, 1 reply; 9+ messages in thread
From: Nicolas Pitre @ 2026-08-03 14:49 UTC (permalink / raw)
To: David Laight
Cc: Borislav Betkov, Ingo Molnar, Thomas Gleinxer, Dave Hansen, x86,
Andrew Morton, linux-kernel, H. Peter Anvin, Peter Zijlstra,
Uwe Kleine-König, rodrigo.alencar, jic23
On Mon, 3 Aug 2026, David Laight wrote:
> The x86 instruction set only supports 32bit signed immediate values
> for add/sub.
> Replace the "ir" constraint with "er" to avoid build errors.
>
> Found by a patch that added used mul_u64_add_u64_div_u64() to
> do a rounding divide by 2^32 (perhaps not the best way to do this).
>
> A quick grep only found one other affected file.
Would be a good idea adding those cases to the test module.
Nicolas
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 0/2] x86: Use "er" asm constriant for add/sub
2026-08-03 14:49 ` Nicolas Pitre
@ 2026-08-03 15:39 ` David Laight
0 siblings, 0 replies; 9+ messages in thread
From: David Laight @ 2026-08-03 15:39 UTC (permalink / raw)
To: Nicolas Pitre
Cc: Borislav Betkov, Ingo Molnar, Thomas Gleinxer, Dave Hansen, x86,
Andrew Morton, linux-kernel, H. Peter Anvin, Peter Zijlstra,
Uwe Kleine-König, rodrigo.alencar, jic23
On Mon, 3 Aug 2026 10:49:40 -0400 (EDT)
Nicolas Pitre <nico@fluxnic.net> wrote:
> On Mon, 3 Aug 2026, David Laight wrote:
>
> > The x86 instruction set only supports 32bit signed immediate values
> > for add/sub.
> > Replace the "ir" constraint with "er" to avoid build errors.
> >
> > Found by a patch that added used mul_u64_add_u64_div_u64() to
> > do a rounding divide by 2^32 (perhaps not the best way to do this).
> >
> > A quick grep only found one other affected file.
>
> Would be a good idea adding those cases to the test module.
They fail to compile so it isn't a big deal.
David
>
>
> Nicolas
^ permalink raw reply [flat|nested] 9+ messages in thread