libgcc: Fix BIL_TYPE_SIZE == 32 support in _BitInt <-> dfp support

Message ID ZcdG00SyQ0FPjsKW@tucnak
State Unresolved
Headers
Series libgcc: Fix BIL_TYPE_SIZE == 32 support in _BitInt <-> dfp support |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Feb. 10, 2024, 9:50 a.m. UTC
  Hi!

I've tried last night to enable _BitInt support for i?86-linux, and
a few spots in libgcc emitted -Wshift-count-overflow warnings and clearly
didn't do what it was supposed to do.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux
(together with patch which enabled the bitint support there), ok for trunk?

2024-02-10  Jakub Jelinek  <jakub@redhat.com>

	* soft-fp/fixddbitint.c (__bid_fixddbitint): Fix up
	BIL_TYPE_SIZE == 32 shifts.
	* soft-fp/fixsdbitint.c (__bid_fixsdbitint): Likewise.
	* soft-fp/fixtdbitint.c (__bid_fixtdbitint): Likewise.
	* soft-fp/floatbitintdd.c (__bid_floatbitintdd): Likewise.
	* soft-fp/floatbitinttd.c (__bid_floatbitinttd): Likewise.


	Jakub
  

Comments

Richard Biener Feb. 10, 2024, 11:38 a.m. UTC | #1
> Am 10.02.2024 um 10:50 schrieb Jakub Jelinek <jakub@redhat.com>:
> 
> Hi!
> 
> I've tried last night to enable _BitInt support for i?86-linux, and
> a few spots in libgcc emitted -Wshift-count-overflow warnings and clearly
> didn't do what it was supposed to do.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux
> (together with patch which enabled the bitint support there), ok for trunk?

Ok

Richard 

> 2024-02-10  Jakub Jelinek  <jakub@redhat.com>
> 
>    * soft-fp/fixddbitint.c (__bid_fixddbitint): Fix up
>    BIL_TYPE_SIZE == 32 shifts.
>    * soft-fp/fixsdbitint.c (__bid_fixsdbitint): Likewise.
>    * soft-fp/fixtdbitint.c (__bid_fixtdbitint): Likewise.
>    * soft-fp/floatbitintdd.c (__bid_floatbitintdd): Likewise.
>    * soft-fp/floatbitinttd.c (__bid_floatbitinttd): Likewise.
> 
> --- libgcc/soft-fp/fixddbitint.c.jj    2023-09-06 17:34:04.976510473 +0200
> +++ libgcc/soft-fp/fixddbitint.c    2024-02-09 17:05:40.009794653 +0100
> @@ -103,7 +103,7 @@ __bid_fixddbitint (UBILtype *r, SItype r
> #if BIL_TYPE_SIZE == 64
>       d = limbs[0];
> #elif BIL_TYPE_SIZE == 32
> -      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
> +      d = (UDItype) limbs[BITINT_END (0, 1)] << 32 | limbs[BITINT_END (1, 0)];
> #else
> # error Unsupported BIL_TYPE_SIZE
> #endif
> --- libgcc/soft-fp/fixsdbitint.c.jj    2023-09-06 17:34:04.977510460 +0200
> +++ libgcc/soft-fp/fixsdbitint.c    2024-02-09 17:05:58.104542321 +0100
> @@ -104,7 +104,7 @@ __bid_fixsdbitint (UBILtype *r, SItype r
> #if BIL_TYPE_SIZE == 64
>       d = limbs[0];
> #elif BIL_TYPE_SIZE == 32
> -      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
> +      d = (UDItype) limbs[BITINT_END (0, 1)] << 32 | limbs[BITINT_END (1, 0)];
> #else
> # error Unsupported BIL_TYPE_SIZE
> #endif
> --- libgcc/soft-fp/fixtdbitint.c.jj    2023-09-06 17:34:04.977510460 +0200
> +++ libgcc/soft-fp/fixtdbitint.c    2024-02-09 17:06:15.781295825 +0100
> @@ -126,9 +126,9 @@ __bid_fixtdbitint (UBILtype *r, SItype r
>       mantissalo = limbs[BITINT_END (5, 4)];
>       rem = limbs[6] | limbs[7];
> #elif BIL_TYPE_SIZE == 32
> -      mantissahi = limbs[BITINT_END (8, 11)] << 32;
> +      mantissahi = (UDItype) limbs[BITINT_END (8, 11)] << 32;
>       mantissahi |= limbs[BITINT_END (9, 10)];
> -      mantissalo = limbs[BITINT_END (10, 9)] << 32;
> +      mantissalo = (UDItype) limbs[BITINT_END (10, 9)] << 32;
>       mantissalo |= limbs[BITINT_END (11, 8)];
>       rem = limbs[12] | limbs[13] | limbs[14] | limbs[15];
> #endif
> --- libgcc/soft-fp/floatbitintdd.c.jj    2023-09-06 17:34:04.977510460 +0200
> +++ libgcc/soft-fp/floatbitintdd.c    2024-02-09 17:11:47.095675716 +0100
> @@ -132,7 +132,7 @@ __bid_floatbitintdd (const UBILtype *i,
> #if BIL_TYPE_SIZE == 64
>       m = buf[BITINT_END (1, 0)];
> #elif BIL_TYPE_SIZE == 32
> -      m = ((UDItype) buf[1] << 32) | buf[BITINT_END (2, 0)];
> +      m = (UDItype) buf[1] << 32 | buf[BITINT_END (2, 0)];
> #else
> # error Unsupported BIL_TYPE_SIZE
> #endif
> @@ -212,7 +212,8 @@ __bid_floatbitintdd (const UBILtype *i,
>      mantissa = buf[q_limbs + pow10_limbs * 2 + 1];
> #else
>      mantissa
> -        = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)] << 32)
> +        = ((UDItype)
> +           buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)] << 32
>           | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)]);
> #endif
>    }
> @@ -220,8 +221,7 @@ __bid_floatbitintdd (const UBILtype *i,
> #if BIL_TYPE_SIZE == 64
>    mantissa = buf[BITINT_END (1, 0)];
> #else
> -    mantissa
> -      = ((buf[1] << 32) | buf[BITINT_END (2, 0)]);
> +    mantissa = (UDItype) buf[1] << 32 | buf[BITINT_END (2, 0)];
> #endif
>     }
>   else
> @@ -232,7 +232,7 @@ __bid_floatbitintdd (const UBILtype *i,
>       if (in == 1)
>    mantissa = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
>       else
> -    mantissa = ((msb << 32) | i[BITINT_END (1, 0)]);
> +    mantissa = (UDItype) msb << 32 | i[BITINT_END (1, 0)];
> #endif
>       if (iprec < 0)
>    mantissa = -mantissa;
> --- libgcc/soft-fp/floatbitinttd.c.jj    2023-09-06 17:34:04.978510447 +0200
> +++ libgcc/soft-fp/floatbitinttd.c    2024-02-09 17:14:17.485578556 +0100
> @@ -196,10 +196,12 @@ __bid_floatbitinttd (const UBILtype *i,
>      mantissalo = buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)];
> #else
>      mantissahi
> -        = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 3)] << 32)
> +        = ((UDItype)
> +           buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 3)] << 32
>           | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 2)]);
>      mantissalo
> -        = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (2, 1)] << 32)
> +        = ((UDItype)
> +           buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (2, 1)] << 32
>           | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (3, 0)]);
> #endif
>    }
> @@ -209,8 +211,10 @@ __bid_floatbitinttd (const UBILtype *i,
>      mantissahi = buf[BITINT_END (0, 1)];
>      mantissalo = buf[BITINT_END (1, 0)];
> #else
> -      mantissahi = (buf[BITINT_END (0, 3)] << 32) | buf[BITINT_END (1, 2)];
> -      mantissalo = (buf[BITINT_END (2, 1)] << 32) | buf[BITINT_END (3, 0)];
> +      mantissahi = ((UDItype) buf[BITINT_END (0, 3)] << 32
> +            | buf[BITINT_END (1, 2)]);
> +      mantissalo = ((UDItype) buf[BITINT_END (2, 1)] << 32
> +            | buf[BITINT_END (3, 0)]);
> #endif
>    }
>     }
> @@ -231,15 +235,15 @@ __bid_floatbitinttd (const UBILtype *i,
>      if (in == 1)
>        mantissalo = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
>      else
> -        mantissalo = (msb << 32) | i[BITINT_END (1, 0)];
> +        mantissalo = (UDItype) msb << 32 | i[BITINT_END (1, 0)];
>    }
>       else
>    {
>      if (in == 3)
>        mantissahi = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
>      else
> -        mantissahi = (msb << 32) | i[BITINT_END (1, 2)];
> -      mantissalo = ((i[BITINT_END (in - 2, 1)] << 32)
> +        mantissahi = (UDItype) msb << 32 | i[BITINT_END (1, 2)];
> +      mantissalo = ((UDItype) i[BITINT_END (in - 2, 1)] << 32
>            | i[BITINT_END (in - 1, 0)]);
>    }
> #endif
> 
>    Jakub
>
  

Patch

--- libgcc/soft-fp/fixddbitint.c.jj	2023-09-06 17:34:04.976510473 +0200
+++ libgcc/soft-fp/fixddbitint.c	2024-02-09 17:05:40.009794653 +0100
@@ -103,7 +103,7 @@  __bid_fixddbitint (UBILtype *r, SItype r
 #if BIL_TYPE_SIZE == 64
       d = limbs[0];
 #elif BIL_TYPE_SIZE == 32
-      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
+      d = (UDItype) limbs[BITINT_END (0, 1)] << 32 | limbs[BITINT_END (1, 0)];
 #else
 # error Unsupported BIL_TYPE_SIZE
 #endif
--- libgcc/soft-fp/fixsdbitint.c.jj	2023-09-06 17:34:04.977510460 +0200
+++ libgcc/soft-fp/fixsdbitint.c	2024-02-09 17:05:58.104542321 +0100
@@ -104,7 +104,7 @@  __bid_fixsdbitint (UBILtype *r, SItype r
 #if BIL_TYPE_SIZE == 64
       d = limbs[0];
 #elif BIL_TYPE_SIZE == 32
-      d = (limbs[BITINT_END (0, 1)] << 32) | limbs[BITINT_END (1, 0)];
+      d = (UDItype) limbs[BITINT_END (0, 1)] << 32 | limbs[BITINT_END (1, 0)];
 #else
 # error Unsupported BIL_TYPE_SIZE
 #endif
--- libgcc/soft-fp/fixtdbitint.c.jj	2023-09-06 17:34:04.977510460 +0200
+++ libgcc/soft-fp/fixtdbitint.c	2024-02-09 17:06:15.781295825 +0100
@@ -126,9 +126,9 @@  __bid_fixtdbitint (UBILtype *r, SItype r
       mantissalo = limbs[BITINT_END (5, 4)];
       rem = limbs[6] | limbs[7];
 #elif BIL_TYPE_SIZE == 32
-      mantissahi = limbs[BITINT_END (8, 11)] << 32;
+      mantissahi = (UDItype) limbs[BITINT_END (8, 11)] << 32;
       mantissahi |= limbs[BITINT_END (9, 10)];
-      mantissalo = limbs[BITINT_END (10, 9)] << 32;
+      mantissalo = (UDItype) limbs[BITINT_END (10, 9)] << 32;
       mantissalo |= limbs[BITINT_END (11, 8)];
       rem = limbs[12] | limbs[13] | limbs[14] | limbs[15];
 #endif
--- libgcc/soft-fp/floatbitintdd.c.jj	2023-09-06 17:34:04.977510460 +0200
+++ libgcc/soft-fp/floatbitintdd.c	2024-02-09 17:11:47.095675716 +0100
@@ -132,7 +132,7 @@  __bid_floatbitintdd (const UBILtype *i,
 #if BIL_TYPE_SIZE == 64
       m = buf[BITINT_END (1, 0)];
 #elif BIL_TYPE_SIZE == 32
-      m = ((UDItype) buf[1] << 32) | buf[BITINT_END (2, 0)];
+      m = (UDItype) buf[1] << 32 | buf[BITINT_END (2, 0)];
 #else
 # error Unsupported BIL_TYPE_SIZE
 #endif
@@ -212,7 +212,8 @@  __bid_floatbitintdd (const UBILtype *i,
 	  mantissa = buf[q_limbs + pow10_limbs * 2 + 1];
 #else
 	  mantissa
-	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)] << 32)
+	    = ((UDItype)
+	       buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 1)] << 32
 	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)]);
 #endif
 	}
@@ -220,8 +221,7 @@  __bid_floatbitintdd (const UBILtype *i,
 #if BIL_TYPE_SIZE == 64
 	mantissa = buf[BITINT_END (1, 0)];
 #else
-	mantissa
-	  = ((buf[1] << 32) | buf[BITINT_END (2, 0)]);
+	mantissa = (UDItype) buf[1] << 32 | buf[BITINT_END (2, 0)];
 #endif
     }
   else
@@ -232,7 +232,7 @@  __bid_floatbitintdd (const UBILtype *i,
       if (in == 1)
 	mantissa = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
       else
-	mantissa = ((msb << 32) | i[BITINT_END (1, 0)]);
+	mantissa = (UDItype) msb << 32 | i[BITINT_END (1, 0)];
 #endif
       if (iprec < 0)
 	mantissa = -mantissa;
--- libgcc/soft-fp/floatbitinttd.c.jj	2023-09-06 17:34:04.978510447 +0200
+++ libgcc/soft-fp/floatbitinttd.c	2024-02-09 17:14:17.485578556 +0100
@@ -196,10 +196,12 @@  __bid_floatbitinttd (const UBILtype *i,
 	  mantissalo = buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 0)];
 #else
 	  mantissahi
-	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 3)] << 32)
+	    = ((UDItype)
+	       buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (0, 3)] << 32
 	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (1, 2)]);
 	  mantissalo
-	    = ((buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (2, 1)] << 32)
+	    = ((UDItype)
+	       buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (2, 1)] << 32
 	       | buf[q_limbs + pow10_limbs * 2 + 1 + BITINT_END (3, 0)]);
 #endif
 	}
@@ -209,8 +211,10 @@  __bid_floatbitinttd (const UBILtype *i,
 	  mantissahi = buf[BITINT_END (0, 1)];
 	  mantissalo = buf[BITINT_END (1, 0)];
 #else
-	  mantissahi = (buf[BITINT_END (0, 3)] << 32) | buf[BITINT_END (1, 2)];
-	  mantissalo = (buf[BITINT_END (2, 1)] << 32) | buf[BITINT_END (3, 0)];
+	  mantissahi = ((UDItype) buf[BITINT_END (0, 3)] << 32
+			| buf[BITINT_END (1, 2)]);
+	  mantissalo = ((UDItype) buf[BITINT_END (2, 1)] << 32
+			| buf[BITINT_END (3, 0)]);
 #endif
 	}
     }
@@ -231,15 +235,15 @@  __bid_floatbitinttd (const UBILtype *i,
 	  if (in == 1)
 	    mantissalo = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
 	  else
-	    mantissalo = (msb << 32) | i[BITINT_END (1, 0)];
+	    mantissalo = (UDItype) msb << 32 | i[BITINT_END (1, 0)];
 	}
       else
 	{
 	  if (in == 3)
 	    mantissahi = iprec < 0 ? (UDItype) (BILtype) msb : (UDItype) msb;
 	  else
-	    mantissahi = (msb << 32) | i[BITINT_END (1, 2)];
-	  mantissalo = ((i[BITINT_END (in - 2, 1)] << 32)
+	    mantissahi = (UDItype) msb << 32 | i[BITINT_END (1, 2)];
+	  mantissalo = ((UDItype) i[BITINT_END (in - 2, 1)] << 32
 			| i[BITINT_END (in - 1, 0)]);
 	}
 #endif