[4/6] x86: slightly simplify offset_in_range()

Message ID 9cdbd052-04d7-4953-abc4-1215f9e489ea@suse.com
State New
Headers show
Series
  • x86: further value overflow diagnostic adjustments
Related show

Commit Message

H.J. Lu via Binutils June 14, 2021, 10:26 a.m.
Applying a mask with all bits set (or its inverse, with hence all bits
clear) won't alter the result (or won't trigger the warning). Re-arrange
the code to eliminate two more of the somewhat odd (2 << width_minus_1)
constructs.

gas/
2021-06-XX  Jan Beulich  <jbeulich@suse.com>

	* config/tc-i386.c (offset_in_range): Bail early when mask would
	cover all bits anyway.

Comments

H.J. Lu via Binutils June 17, 2021, 2:46 p.m. | #1
On Mon, Jun 14, 2021 at 3:26 AM Jan Beulich <jbeulich@suse.com> wrote:
>

> Applying a mask with all bits set (or its inverse, with hence all bits

> clear) won't alter the result (or won't trigger the warning). Re-arrange

> the code to eliminate two more of the somewhat odd (2 << width_minus_1)

> constructs.

>

> gas/

> 2021-06-XX  Jan Beulich  <jbeulich@suse.com>

>

>         * config/tc-i386.c (offset_in_range): Bail early when mask would

>         cover all bits anyway.

>

> --- a/gas/config/tc-i386.c

> +++ b/gas/config/tc-i386.c

> @@ -2556,10 +2556,10 @@ offset_in_range (offsetT val, int size)

>      {

>      case 1: mask = ((addressT) 1 <<  8) - 1; break;

>      case 2: mask = ((addressT) 1 << 16) - 1; break;

> -    case 4: mask = ((addressT) 2 << 31) - 1; break;

>  #ifdef BFD64

> -    case 8: mask = ((addressT) 2 << 63) - 1; break;

> +    case 4: mask = ((addressT) 1 << 32) - 1; break;

>  #endif

> +    case sizeof (val): return val;

>      default: abort ();

>      }

>

>


OK.

Thanks.

-- 
H.J.

Patch

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2556,10 +2556,10 @@  offset_in_range (offsetT val, int size)
     {
     case 1: mask = ((addressT) 1 <<  8) - 1; break;
     case 2: mask = ((addressT) 1 << 16) - 1; break;
-    case 4: mask = ((addressT) 2 << 31) - 1; break;
 #ifdef BFD64
-    case 8: mask = ((addressT) 2 << 63) - 1; break;
+    case 4: mask = ((addressT) 1 << 32) - 1; break;
 #endif
+    case sizeof (val): return val;
     default: abort ();
     }