Generic Linux architectural discussions
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Anshuman Khandual" <anshuman.khandual@arm.com>,
	linux-kernel@vger.kernel.org
Cc: "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 1/2] uapi: Define GENMASK_U128
Date: Wed, 24 Jul 2024 13:03:09 +0200	[thread overview]
Message-ID: <d0fadaa3-94d4-4600-8e92-a8fe5b0f141b@app.fastmail.com> (raw)
In-Reply-To: <20240724103142.165693-2-anshuman.khandual@arm.com>

On Wed, Jul 24, 2024, at 12:31, Anshuman Khandual wrote:
> --- a/include/uapi/asm-generic/bitsperlong.h
> +++ b/include/uapi/asm-generic/bitsperlong.h
> @@ -28,4 +28,8 @@
>  #define __BITS_PER_LONG_LONG 64
>  #endif
> 
> +#ifndef __BITS_PER_U128
> +#define __BITS_PER_U128 128
> +#endif

I would hope we don't need this definition. Not that it
hurts at all, but __BITS_PER_LONG_LONG was already kind
of pointless since we don't run on anything else and
__BITS_PER_U128 clearly can't have any other sensible
definition than a plain 128.

>  #define __AC(X,Y)	(X##Y)
>  #define _AC(X,Y)	__AC(X,Y)
>  #define _AT(T,X)	((T)(X))
> +#define _AC128(X)	((unsigned __int128)(X))

I just tried using this syntax and it doesn't seem to do
what you expected. gcc silently truncates the constant
to a 64-bit value here, while clang fails the build.
See also https://godbolt.org/z/rzEqra7nY
https://stackoverflow.com/questions/63328802/unsigned-int128-literal-gcc

The __GENMASK_U128() macro however seems to work correctly
since you start out with a smaller number and then shift
it after the type conversion.

     Arnd

  reply	other threads:[~2024-07-24 11:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-24 10:31 [PATCH 0/2] uapi: Add support for GENMASK_U128() Anshuman Khandual
2024-07-24 10:31 ` [PATCH 1/2] uapi: Define GENMASK_U128 Anshuman Khandual
2024-07-24 11:03   ` Arnd Bergmann [this message]
2024-07-24 11:59     ` Anshuman Khandual
2024-07-24 12:37       ` Arnd Bergmann
2024-07-24 10:31 ` [PATCH 2/2] lib/test_bits.c: Add tests for GENMASK_U128() Anshuman Khandual
2024-07-24 10:45   ` Arnd Bergmann
2024-07-24 12:00     ` Anshuman Khandual
2024-07-25  1:04   ` kernel test robot
2024-07-25  4:19     ` Anshuman Khandual
2024-07-24 10:33 ` [PATCH 0/2] uapi: Add support " Ard Biesheuvel

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=d0fadaa3-94d4-4600-8e92-a8fe5b0f141b@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --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