Have single bit macros return an unsigned result. Avoids risk (and
authorAndrew Cagney <cagney@redhat.com>
Mon, 20 Oct 1997 07:27:55 +0000 (07:27 +0000)
committerAndrew Cagney <cagney@redhat.com>
Mon, 20 Oct 1997 07:27:55 +0000 (07:27 +0000)
need) of sign extending results.

sim/common/ChangeLog
sim/common/sim-bits.h

index d38904b01743e263abab9e4cc1578d6955386d7f..2be05ff902a5c8b1f2e930d645ec68ceb59d3a55 100644 (file)
@@ -1,3 +1,10 @@
+Mon Oct 20 17:23:58 1997  Andrew Cagney  <cagney@b1.cygnus.com>
+
+       * sim-bits.h (LSBIT, MSBIT, BIT): Force result to type
+       unsigned_word.
+       (LSBIT8, LSBIT16, LSBIT32, LSBIT64, MSBIT8, MSBIT16, MSBIT32,
+       MSBIT64): Force result to unsignedN.
+
 Thu Oct 16 11:38:56 1997  Andrew Cagney  <cagney@b1.cygnus.com>
 
        * sim-alu.h (ALU16_BEGIN, ALU32_BEGIN, ALU64_BEGIN): Drop opening
index 00a8842b621ff1b1a3f72b42c22c0a26b91b106f..3170c61c4dc31a30fba36d74941f55806b60da1e 100644 (file)
 
 /* LS/MS Bit operations */
 
-#define LSBIT8(POS)  ((natural8) 1 << (POS))
-#define LSBIT16(POS) ((natural16)1 << (POS))
-#define LSBIT32(POS) ((natural32)1 << (POS))
-#define LSBIT64(POS) ((natural64)1 << (POS))
+#define LSBIT8(POS)  ((unsigned8) 1 << (POS))
+#define LSBIT16(POS) ((unsigned16)1 << (POS))
+#define LSBIT32(POS) ((unsigned32)1 << (POS))
+#define LSBIT64(POS) ((unsigned64)1 << (POS))
 
 #if (WITH_TARGET_WORD_BITSIZE == 64)
 #define LSBIT(POS) LSBIT64 (POS)
 #else
-#define LSBIT(POS) ((POS) >= 32 \
-                   ? 0 \
-                   : (1 << ((POS) >= 32 ? 0 : (POS))))
+#define LSBIT(POS) ((unsigned32)((POS) >= 32 \
+                                ? 0 \
+                                : (1 << ((POS) >= 32 ? 0 : (POS)))))
 #endif
 
 
-#define MSBIT8(POS)  ((natural8) 1 << ( 8 - 1 - (POS)))
-#define MSBIT16(POS) ((natural16)1 << (16 - 1 - (POS)))
-#define MSBIT32(POS) ((natural32)1 << (32 - 1 - (POS)))
-#define MSBIT64(POS) ((natural64)1 << (64 - 1 - (POS)))
+#define MSBIT8(POS)  ((unsigned8) 1 << ( 8 - 1 - (POS)))
+#define MSBIT16(POS) ((unsigned16)1 << (16 - 1 - (POS)))
+#define MSBIT32(POS) ((unsigned32)1 << (32 - 1 - (POS)))
+#define MSBIT64(POS) ((unsigned64)1 << (64 - 1 - (POS)))
 
 #if (WITH_TARGET_WORD_BITSIZE == 64)
 #define MSBIT(POS) MSBIT64 (POS)
 #else
-#define MSBIT(POS) ((POS) < 32 \
-                   ? 0 \
-                   : (1 << ((POS) < 32 ? 0 : (64 - 1) - (POS))))
+#define MSBIT(POS) ((unsigned32)((POS) < 32 \
+                                ? 0 \
+                                : (1 << ((POS) < 32 ? 0 : (64 - 1) - (POS)))))
 #endif
 
 
@@ -406,7 +406,7 @@ INLINE_SIM_BITS(unsigned_word) MSEXTRACTED (unsigned_word val, int start, int st
 #define SHUFFLED(WORD, OLD, NEW) _SHUFFLEDn (_word, WORD, OLD, NEW)
 
 
-/* move a group of bits around */
+/* Insert a group of bits into a bit position */
 
 INLINE_SIM_BITS(unsigned8)  LSINSERTED8  (unsigned8  val, int start, int stop);
 INLINE_SIM_BITS(unsigned16) LSINSERTED16 (unsigned16 val, int start, int stop);
@@ -436,9 +436,19 @@ INLINE_SIM_BITS(unsigned_word) MSINSERTED (unsigned_word val, int start, int sto
 
 
 
+/* MOVE bits from one loc to another (combination of extract/insert) */
+
+#define MOVED8(VAL,OH,OL,NH,NL)  INSERTED8 (EXTRACTED8 ((VAL), OH, OL), NH, NL)
+#define MOVED16(VAL,OH,OL,NH,NL) INSERTED16(EXTRACTED16((VAL), OH, OL), NH, NL)
+#define MOVED32(VAL,OH,OL,NH,NL) INSERTED32(EXTRACTED32((VAL), OH, OL), NH, NL)
+#define MOVED64(VAL,OH,OL,NH,NL) INSERTED64(EXTRACTED64((VAL), OH, OL), NH, NL)
+#define MOVED(VAL,OH,OL,NH,NL)   INSERTED  (EXTRACTED  ((VAL), OH, OL), NH, NL)
+
+
+
 /* Sign extend the quantity to the targets natural word size */
 
-#define EXTEND8(X) ((signed_word)(signed8)(X))
+#define EXTEND8(X)  ((signed_word)(signed8)(X))
 #define EXTEND16(X) ((signed_word)(signed16)(X))
 #define EXTEND32(X) ((signed_word)(signed32)(X))
 #define EXTEND64(X) ((signed_word)(signed64)(X))