[binutils-gdb] gas alpha sign extension macros

Alan Modra amodra@sourceware.org
Wed Jul 9 00:07:07 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4df44a4aead61b5d46c35c5ddf2b96ac07948794

commit 4df44a4aead61b5d46c35c5ddf2b96ac07948794
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jul 9 09:09:23 2025 +0930

    gas alpha sign extension macros
    
    Use standard sign extend and range checking using unsigned
    expressions that don't rely on implementation defined right shifts or
    size of short and int.

Diff:
---
 gas/config/tc-alpha.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)

diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c
index 99f4bc6ae6e..a91db143ab9 100644
--- a/gas/config/tc-alpha.c
+++ b/gas/config/tc-alpha.c
@@ -170,33 +170,13 @@ struct alpha_macro
 #define note_fpreg(R)		(alpha_fprmask |= (1 << (R)))
 
 /* Predicates for 16- and 32-bit ranges */
-/* XXX: The non-shift version appears to trigger a compiler bug when
-   cross-assembling from x86 w/ gcc 2.7.2.  */
-
-#if 1
-#define range_signed_16(x) \
-	(((offsetT) (x) >> 15) == 0 || ((offsetT) (x) >> 15) == -1)
-#define range_signed_32(x) \
-	(((offsetT) (x) >> 31) == 0 || ((offsetT) (x) >> 31) == -1)
-#else
-#define range_signed_16(x)	((offsetT) (x) >= -(offsetT) 0x8000 &&	\
-				 (offsetT) (x) <=  (offsetT) 0x7FFF)
-#define range_signed_32(x)	((offsetT) (x) >= -(offsetT) 0x80000000 && \
-				 (offsetT) (x) <=  (offsetT) 0x7FFFFFFF)
-#endif
+#define range_signed_16(x)	((valueT) (x) + 0x8000 <= 0xFFFF)
+#define range_signed_32(x)	((valueT) (x) + 0x80000000 <= 0xFFFFFFFF)
 
 /* Macros for sign extending from 16- and 32-bits.  */
-/* XXX: The cast macros will work on all the systems that I care about,
-   but really a predicate should be found to use the non-cast forms.  */
-
-#if 1
-#define sign_extend_16(x)	((short) (x))
-#define sign_extend_32(x)	((int) (x))
-#else
-#define sign_extend_16(x)	((offsetT) (((x) & 0xFFFF) ^ 0x8000) - 0x8000)
-#define sign_extend_32(x)	((offsetT) (((x) & 0xFFFFFFFF) \
-					   ^ 0x80000000) - 0x80000000)
-#endif
+#define sign_extend_16(x)	((((valueT) (x) & 0xFFFF) ^ 0x8000) - 0x8000)
+#define sign_extend_32(x)	((((valueT) (x) & 0xFFFFFFFF) ^ 0x80000000) \
+				 - 0x80000000)
 
 /* Macros to build tokens.  */


More information about the Binutils-cvs mailing list