aboutsummaryrefslogtreecommitdiff
path: root/sim/common/sim-bits.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-09-16 07:04:46 +0000
committerAndrew Cagney <cagney@redhat.com>1997-09-16 07:04:46 +0000
commitaa5e6a5a78de10c59df0cbe86bcfb8aba756b00d (patch)
tree5c499a851f1bc35015a7357ed2f6404111d97e49 /sim/common/sim-bits.c
parent3f33acd039b11975b17d05ed20cad7e71c433754 (diff)
downloadgdb-aa5e6a5a78de10c59df0cbe86bcfb8aba756b00d.zip
gdb-aa5e6a5a78de10c59df0cbe86bcfb8aba756b00d.tar.gz
gdb-aa5e6a5a78de10c59df0cbe86bcfb8aba756b00d.tar.bz2
Add {LS,MS}SEXT and {LS,MS}INSERTED macros. Eliminates bug in SEXT.
Diffstat (limited to 'sim/common/sim-bits.c')
-rw-r--r--sim/common/sim-bits.c73
1 files changed, 56 insertions, 17 deletions
diff --git a/sim/common/sim-bits.c b/sim/common/sim-bits.c
index 9187cf5..a200fa5 100644
--- a/sim/common/sim-bits.c
+++ b/sim/common/sim-bits.c
@@ -101,24 +101,47 @@ MSEXTRACTED (unsigned_word val,
INLINE_SIM_BITS\
(unsigned_word)
-INSERTED (unsigned_word val,
- int start,
- int stop)
+LSINSERTED (unsigned_word val,
+ int start,
+ int stop)
+{
+ ASSERT (start >= stop);
+#if (WITH_TARGET_WORD_BITSIZE == 64)
+ return LSINSERTED64 (val, start, stop);
+#endif
+#if (WITH_TARGET_WORD_BITSIZE == 32)
+ /* Bit numbers are 63..0, even for 32 bit targets.
+ On 32 bit targets we ignore 63..32 */
+ if (stop >= 32)
+ return 0;
+ else
+ {
+ val <<= stop;
+ val &= LSMASK (start, stop);
+ return val;
+ }
+#endif
+}
+
+INLINE_SIM_BITS\
+(unsigned_word)
+MSINSERTED (unsigned_word val,
+ int start,
+ int stop)
{
- ASSERT ((WITH_TARGET_WORD_MSB == 0 && start <= stop)
- || (WITH_TARGET_WORD_MSB != 0 && start >= stop));
+ ASSERT (start <= stop);
#if (WITH_TARGET_WORD_BITSIZE == 64)
- return INSERTED64 (val, start, stop);
+ return MSINSERTED64 (val, start, stop);
#endif
#if (WITH_TARGET_WORD_BITSIZE == 32)
/* Bit numbers are 0..63, even for 32 bit targets.
On 32 bit targets we ignore 0..31. */
- if (_LSB_SHIFT (64, stop) >= 32)
+ if (stop < 32)
return 0;
else
{
- val &= LSMASK (_MAKE_WIDTH (start, stop), 0);
- val <<= _LSB_SHIFT (64, stop);
+ val <<= ((64 - 1) - stop);
+ val &= MSMASK (start, stop);
return val;
}
#endif
@@ -128,21 +151,37 @@ INSERTED (unsigned_word val,
INLINE_SIM_BITS\
(unsigned_word)
-SEXT (signed_word val,
- int sign_bit)
+LSSEXT (signed_word val,
+ int sign_bit)
+{
+ ASSERT (sign_bit < 64);
+#if (WITH_TARGET_WORD_BITSIZE == 64)
+ return LSSEXT64 (val, sign_bit);
+#endif
+#if (WITH_TARGET_WORD_BITSIZE == 32)
+ if (sign_bit >= 32)
+ return val;
+ else {
+ val = LSSEXT32 (val, sign_bit);
+ return val;
+ }
+#endif
+}
+
+INLINE_SIM_BITS\
+(unsigned_word)
+MSSEXT (signed_word val,
+ int sign_bit)
{
- /* make the sign-bit most significant and then smear it back into
- position */
ASSERT (sign_bit < 64);
#if (WITH_TARGET_WORD_BITSIZE == 64)
- return SEXT64 (val, sign_bit);
+ return MSSEXT64 (val, sign_bit);
#endif
#if (WITH_TARGET_WORD_BITSIZE == 32)
- if (_MSB_SHIFT (64, sign_bit) < 32)
+ if (sign_bit < 32)
return val;
else {
- val <<= (_MSB_SHIFT (64, sign_bit) - 32);
- val >>= (_MSB_SHIFT (64, sign_bit) - 32);
+ val = MSSEXT32 (val, sign_bit - 32);
return val;
}
#endif