PATCH] int128: Check __SIZEOF_INT128__ instead of __WORDSIZE == 32

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Dec 1 13:37:09 GMT 2025



On 29/11/25 01:23, H.J. Lu wrote:
> commit 8cd6efca5b3796193ef3ff60d9dbf6e5572b2b73
> Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> Date:   Thu Nov 20 15:30:06 2025 -0300
> 
>     Add add_ssaaaa and sub_ssaaaa to gmp-arch.h
> 
> checks __WORDSIZE == 32 to decide if int128 can be used, which breaks
> x32 which has int128 and __WORDSIZE == 32.  Check __SIZEOF_INT128__,
> instead of __WORDSIZE == 32, for int128.  This fixes BZ #33677.
> 
> 
> From 3babb25aaed29070ff9091798dc5469ec84fa8a2 Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Sat, 29 Nov 2025 11:33:56 +0800
> Subject: [PATCH] int128: Check __SIZEOF_INT128__ instead of __WORDSIZE == 32
> 
> commit 8cd6efca5b3796193ef3ff60d9dbf6e5572b2b73
> Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> Date:   Thu Nov 20 15:30:06 2025 -0300
> 
>     Add add_ssaaaa and sub_ssaaaa to gmp-arch.h
> 
> checks __WORDSIZE == 32 to decide if int128 can be used, which breaks
> x32 which has int128 and __WORDSIZE == 32.  Check __SIZEOF_INT128__,
> instead of __WORDSIZE == 32, for int128.  This fixes BZ #33677.
> 
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  sysdeps/generic/gmp-arch.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/generic/gmp-arch.h b/sysdeps/generic/gmp-arch.h
> index b3004c90ed..8b328eeb69 100644
> --- a/sysdeps/generic/gmp-arch.h
> +++ b/sysdeps/generic/gmp-arch.h
> @@ -43,7 +43,7 @@ ll_highpart (mp_limb_t t)
>  static __always_inline void
>  umul_ppmm_generic (mp_limb_t *w1, mp_limb_t *w0, mp_limb_t u, mp_limb_t v)
>  {
> -#if __WORDSIZE == 32
> +#ifndef __SIZEOF_INT128__

The uint128 usage here should be conventionalized whether mp_limp_t is 64-bit,
which internally is defined by _LONG_LONG_LIMB.

So maybe use BITS_PER_MP_LIMB here:

#if BITS_PER_MP_LIMB == 32
  // use 64-bit operations;
#elif BITS_PER_MP_LIMB == 64
  // use 128-bit operations
#endif

>    uint64_t t0 = (uint64_t)u * v;
>    *w1 = t0 >> 32;
>    *w0 = t0;
> @@ -131,7 +131,7 @@ static __always_inline void
>  add_ssaaaa_generic (mp_limb_t *sh, mp_limb_t *sl, mp_limb_t ah,
>  		    mp_limb_t al,  mp_limb_t bh,  mp_limb_t bl)
>  {
> -#if __WORDSIZE == 32
> +#ifndef __SIZEOF_INT128__
>    uint64_t a = (uint64_t)ah << 32 | al;
>    uint64_t b = (uint64_t)bh << 32 | bl;
>    uint64_t r = a + b;
> @@ -157,7 +157,7 @@ static __always_inline void
>  sub_ddmmss_generic (mp_limb_t *sh, mp_limb_t *sl, mp_limb_t ah,
>  		    mp_limb_t al,  mp_limb_t bh,  mp_limb_t bl)
>  {
> -#if __WORDSIZE == 32
> +#ifndef __SIZEOF_INT128__
>    uint64_t a = (uint64_t)ah << 32 | al;
>    uint64_t b = (uint64_t)bh << 32 | bl;
>    uint64_t r = a - b;
> -- 




More information about the Libc-alpha mailing list