[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200220181236.GC18400@hirez.programming.kicks-ass.net>
Date: Thu, 20 Feb 2020 19:12:36 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Jesse Brandeburg <jesse.brandeburg@...el.com>
Cc: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, x86@...nel.org,
linux-kernel@...r.kernel.org, linux@...musvillemoes.dk,
andriy.shevchenko@...el.com, dan.j.williams@...el.com
Subject: Re: [PATCH v2 1/2] x86: fix bitops.h warning with a moved cast
On Thu, Feb 20, 2020 at 09:37:21AM -0800, Jesse Brandeburg wrote:
> Fix many sparse warnings when building with C=1.
>
> When the kernel is compiled with C=1, there are lots of messages like:
> arch/x86/include/asm/bitops.h:77:37: warning: cast truncates bits from constant value (ffffff7f becomes 7f)
>
> @@ -72,9 +74,11 @@ static __always_inline void
> arch_clear_bit(long nr, volatile unsigned long *addr)
> {
> if (__builtin_constant_p(nr)) {
> + u8 cmaski = ~CONST_MASK(nr);
> +
> asm volatile(LOCK_PREFIX "andb %1,%0"
> : CONST_MASK_ADDR(nr, addr)
> - : "iq" ((u8)~CONST_MASK(nr)));
> + : "iq" (cmaski));
> } else {
> asm volatile(LOCK_PREFIX __ASM_SIZE(btr) " %1,%0"
> : : RLONG_ADDR(addr), "Ir" (nr) : "memory");
Urgh, that's sad. So why doesn't this still generate a warning, ~ should
promote your u8 to int, and then you down-cast to u8 on assignment
again.
So now you have more lines, more ugly casts and exactly the same
generated code; where the win?
Perhaps you should write it like:
: "iq" (0xFF ^ CONST_MASK(nr))
hmm?
Powered by blists - more mailing lists