public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Anshuman Khandual" <anshuman.khandual@arm.com>,
	linux-kernel@vger.kernel.org
Cc: "Ard Biesheuvel" <ardb@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	Linux-Arch <linux-arch@vger.kernel.org>
Subject: Re: [PATCH V3 1/2] uapi: Define GENMASK_U128
Date: Mon, 19 Aug 2024 09:13:08 +0200	[thread overview]
Message-ID: <3b219e52-1d2a-4e6d-adff-efbab3e2282d@app.fastmail.com> (raw)
In-Reply-To: <090eb237-10f4-4358-be07-1eb8d30c3ec1@arm.com>

On Fri, Aug 16, 2024, at 08:28, Anshuman Khandual wrote:
>
> This is caused by ((unsigned __int128)(1) << (128)) which is generated
> via (h + 1) element in __GENMASK_U128().
>
> #define _BIT128(x)	((unsigned __int128)(1) << (x))
> #define __GENMASK_U128(h, l) \
> 	((_BIT128((h) + 1)) - (_BIT128(l)))

Right, makes sense.

>
> The most significant bit in the generate mask can be added separately
> , thus voiding that extra shift. The following patch solves the build
> problem.
>
> diff --git a/include/uapi/linux/bits.h b/include/uapi/linux/bits.h
> index 4d4b7b08003c..4e50f635c6d9 100644
> --- a/include/uapi/linux/bits.h
> +++ b/include/uapi/linux/bits.h
> @@ -13,6 +13,6 @@
>           (~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
> 
>  #define __GENMASK_U128(h, l) \
> -       ((_BIT128((h) + 1)) - (_BIT128(l)))
> +       (((_BIT128(h)) - (_BIT128(l))) | (_BIT128(h)))

This could probably use a comment then, as it's less intuitive.

Another solution might be to use a double shift, as in

#define __GENMASK_U128(h, l) \
       ((_BIT128((h)) << 1) - (_BIT128(l)))

but I have not checked if this is correct for all inputs
or if it avoids the warning. Your version looks fine to
me otherwise.

    Arnd

  parent reply	other threads:[~2024-08-19  7:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-01  7:16 [PATCH V3 0/2] uapi: Add support for GENMASK_U128() Anshuman Khandual
2024-08-01  7:16 ` [PATCH V3 1/2] uapi: Define GENMASK_U128 Anshuman Khandual
2024-08-16  6:28   ` Anshuman Khandual
2024-08-17 13:57     ` Yury Norov
2024-08-19  3:18       ` Anshuman Khandual
2024-08-19  7:13     ` Arnd Bergmann [this message]
2024-08-20  1:25       ` Anshuman Khandual
2024-08-20  6:35         ` Arnd Bergmann
2024-08-01  7:16 ` [PATCH V3 2/2] lib/test_bits.c: Add tests for GENMASK_U128() Anshuman Khandual
2024-08-20  3:36   ` Anshuman Khandual
2024-08-01 14:43 ` [PATCH V3 0/2] uapi: Add support " Yury Norov
2024-08-02  1:30   ` Anshuman Khandual
2024-08-02 17:34     ` Yury Norov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b219e52-1d2a-4e6d-adff-efbab3e2282d@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=ardb@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox