#define _SIM_BITS_H_
-/* bit manipulation routines:
+/* Bit manipulation routines:
Bit numbering: The bits are numbered according to the target ISA's
convention. That being controlled by WITH_TARGET_WORD_MSB. For
NB: Use EXTRACTED, MSEXTRACTED and LSEXTRACTED as a guideline for
naming. LSMASK and LSMASKED are wrong.
- BIT*(POS): Constant with just 1 bit set.
+ BIT*(POS): `*' bit constant with just 1 bit set.
- LSBIT*(OFFSET): Constant with just 1 bit set - LS bit is zero.
+ LSBIT*(OFFSET): `*' bit constant with just 1 bit set - LS bit is
+ zero.
- MSBIT*(OFFSET): Constant with just 1 bit set - MS bit is zero.
+ MSBIT*(OFFSET): `*' bit constant with just 1 bit set - MS bit is
+ zero.
- MASK*(FIRST, LAST): Constant with bits [FIRST .. LAST] set. The
- <MACRO> (no size) version permits FIRST >= LAST and generates a
- wrapped bit mask vis ([0..LAST] | [FIRST..LSB]).
+ MASK*(FIRST, LAST): `*' bit constant with bits [FIRST .. LAST]
+ set. The <MACRO> (no size) version permits FIRST >= LAST and
+ generates a wrapped bit mask vis ([0..LAST] | [FIRST..LSB]).
- LSMASK*(NR_BITS): Like MASK only NR least significant bits are set.
+ LSMASK*(FIRST, LAST): Like MASK - LS bit is zero.
- MSMASK*(NR_BITS): Like MASK only NR most significant bits are set.
+ MSMASK*(FIRST, LAST): Like MASK - LS bit is zero.
MASKED*(VALUE, FIRST, LAST): Masks out all but bits [FIRST
.. LAST].
- LSMASKED*(VALUE, NR_BITS): Mask out all but the least significant
- NR_BITS of the value.
+ LSMASKED*(VALUE, FIRST, LAST): Like MASKED - LS bit is zero.
- MSMASKED*(VALUE, NR_BITS): Mask out all but the most significant
- NR_BITS of the value.
+ MSMASKED*(VALUE, FIRST, LAST): Like MASKED - MS bit is zero.
EXTRACTED*(VALUE, FIRST, LAST): Masks out bits [FIRST .. LAST] but
also right shifts the masked value so that bit LAST becomes the
IEA_MASKED(SHOULD_MASK, ADDR): Convert the address to the targets
natural size. If in 32bit mode, discard the high 32bits.
- EXTENDED(VALUE): Convert VALUE (32bits of it) to the targets
- natural size. If in 64bit mode, sign extend the value.
+ EXTEND*(VALUE): Convert the `*' bit value to the targets natural
+ word size. Sign extend the value if needed.
+
+ ALIGN_*(VALUE): Round the value upwards so that it is aligned to a
+ `_*' byte boundary.
- ALIGN_*(VALUE): Round upwards the value so that it is aligned.
+ FLOOR_*(VALUE): Truncate the value so that it is aligned to a `_*'
+ byte boundary.
- FLOOR_*(VALUE): Truncate the value so that it is aligned.
+ ROT*(VALUE, NR_BITS): Return the `*' bit VALUE rotated by NR_BITS
+ right (positive) or left (negative).
- ROTL*(VALUE, NR_BITS): Return the value rotated by NR_BITS left.
+ ROTL*(VALUE, NR_BITS): Return the `*' bit value rotated by NR_BITS
+ left. 0 <= NR_BITS <= `*'.
- ROTR*(VALUE, NR_BITS): Return the value rotated by NR_BITS right.
+ ROTR*(VALUE, NR_BITS): Return the `*' bit value rotated by NR_BITS
+ right. 0 <= NR_BITS <= N.
- SEXT*(VAL, SIGN_BIT): Treat SIGN_BIT as the sign, extend it.
+ SEXT*(VALUE, SIGN_BIT): Treat SIGN_BIT as VALUEs sign, extend it ti
+ `*' bits.
Note: Only the BIT* and MASK* macros return a constant that can be
used in variable declarations.
#endif
-/* Bit operations */
-
-#define _BITn(WIDTH, POS) ((natural##WIDTH)1 \
- << _LSB_SHIFT (WIDTH, POS))
+/* LS/MS Bit operations */
-#define BIT4(POS) (1 << _LSB_SHIFT (4, (POS)))
-#define BIT5(POS) (1 << _LSB_SHIFT (5, (POS)))
-#define BIT8(POS) (1 << _LSB_SHIFT (8, (POS)))
-#define BIT10(POS) (1 << _LSB_SHIFT (10, (POS)))
-#define BIT16(POS) _BITn (16, (POS))
-#define BIT32(POS) _BITn (32, (POS))
-#define BIT64(POS) _BITn (64, (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 BIT(POS) BIT64(POS)
-#endif
-#if (WITH_TARGET_WORD_BITSIZE == 32)
-#if (WITH_TARGET_WORD_MSB == 0)
-#define BIT(POS) ((POS) < 32 \
- ? 0 \
- : (1 << ((POS) < 32 ? 0 : _LSB_SHIFT(64, (POS)))))
+#define LSBIT(POS) LSBIT64 (POS)
#else
-#define BIT(POS) ((POS) >= 32 \
- ? 0 \
- : (1 << ((POS) >= 32 ? 0 : (POS))))
-#endif
-#endif
-#if !defined (BIT)
-#error "BIT never defined"
+#define LSBIT(POS) ((unsigned32)((POS) >= 32 \
+ ? 0 \
+ : (1 << ((POS) >= 32 ? 0 : (POS)))))
#endif
-/* LS/MS Bit operations */
-
-#define LSBIT8(POS) ((unsigned8)1 << (POS))
-#define LSBIT16(POS) ((unsigned16)1 << (POS))
-#define LSBIT32(POS) ((unsigned32)1 << (POS))
-#define LSBIT64(POS) ((unsigned64)1 << (POS))
-#define LSBIT(POS) ((unsigned_word)1 << (POS))
-
-#define MSBIT8(POS) ((unsigned8)1 << (8 - 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)))
-#define MSBIT(POS) ((unsigned_word)1 << (WITH_TARGET_WORD_BITSIZE - 1 - (POS)))
+
+#if (WITH_TARGET_WORD_BITSIZE == 64)
+#define MSBIT(POS) MSBIT64 (POS)
+#else
+#define MSBIT(POS) ((unsigned32)((POS) < 32 \
+ ? 0 \
+ : (1 << ((POS) < 32 ? 0 : (64 - 1) - (POS)))))
+#endif
+
+
+/* Bit operations */
+
+#define BIT4(POS) (1 << _LSB_SHIFT (4, (POS)))
+#define BIT5(POS) (1 << _LSB_SHIFT (5, (POS)))
+#define BIT10(POS) (1 << _LSB_SHIFT (10, (POS)))
+
+#if (WITH_TARGET_WORD_MSB == 0)
+#define BIT8 MSBIT8
+#define BIT16 MSBIT16
+#define BIT32 MSBIT32
+#define BIT64 MSBIT64
+#define BIT MSBIT
+#else
+#define BIT8 LSBIT8
+#define BIT16 LSBIT16
+#define BIT32 LSBIT32
+#define BIT64 LSBIT64
+#define BIT LSBIT
+#endif
+ _LSB_SHIFT (WIDTH, STOP))) \
<< _LSB_SHIFT (WIDTH, STOP))
-#define MASK16(START, STOP) _MASKn(16, (START), (STOP))
-#define MASK32(START, STOP) _MASKn(32, (START), (STOP))
-#define MASK64(START, STOP) _MASKn(64, (START), (STOP))
-
#if (WITH_TARGET_WORD_MSB == 0)
#define _POS_LE(START, STOP) (START <= STOP)
#else
#endif
-
/* Multi-bit mask on least significant bits */
-#if (WITH_TARGET_WORD_MSB == 0)
-#define _LSMASKn(WIDTH, NR_BITS) _MASKn(WIDTH, (WIDTH - NR_BITS), (WIDTH - 1))
-#else
-#define _LSMASKn(WIDTH, NR_BITS) _MASKn(WIDTH, (NR_BITS - 1), 0)
-#endif
+#define _LSMASKn(WIDTH, FIRST, LAST) _MASKn (WIDTH, \
+ _LSB_POS (WIDTH, FIRST), \
+ _LSB_POS (WIDTH, LAST))
-#define LSMASK16(NR_BITS) _LSMASKn (16, (NR_BITS))
-#define LSMASK32(NR_BITS) _LSMASKn (32, (NR_BITS))
-#define LSMASK64(NR_BITS) _LSMASKn (64, (NR_BITS))
+#define LSMASK8(FIRST, LAST) _LSMASKn ( 8, (FIRST), (LAST))
+#define LSMASK16(FIRST, LAST) _LSMASKn (16, (FIRST), (LAST))
+#define LSMASK32(FIRST, LAST) _LSMASKn (32, (FIRST), (LAST))
+#define LSMASK64(FIRST, LAST) _LSMASKn (64, (FIRST), (LAST))
-#if (WITH_TARGET_WORD_BITSIZE == 64)
-#define LSMASK(NR_BITS) ((NR_BITS) < 1 \
- ? 0 \
- : _MASKn (64, \
- _LSB_POS (64, \
- ((NR_BITS) < 1 ? 0 \
- : (NR_BITS) - 1)), \
- _LSB_POS (64, 0)))
-#endif
-#if (WITH_TARGET_WORD_BITSIZE == 32)
-#define LSMASK(NR_BITS) ((NR_BITS) < 1 \
- ? 0 \
- : _MASKn (32, \
- _LSB_POS (32, \
- ((NR_BITS) > 32 ? 31 \
- : (NR_BITS) < 1 ? 0 \
- : ((NR_BITS) - 1))), \
- _LSB_POS (32, 0)))
-#endif
-#if !defined (LSMASK)
-#error "LSMASK never defined"
-#endif
+#define LSMASK(FIRST, LAST) (MASK (_LSB_POS (64, FIRST), _LSB_POS (64, LAST)))
/* Multi-bit mask on most significant bits */
-#if (WITH_TARGET_WORD_MSB == 0)
-#define _MSMASKn(WIDTH, NR_BITS) _MASKn (WIDTH, 0, (NR_BITS - 1))
-#else
-#define _MSMASKn(WIDTH, NR_BITS) _MASKn (WIDTH, (WIDTH - 1), (WIDTH - NR_BITS))
-#endif
+#define _MSMASKn(WIDTH, FIRST, LAST) _MASKn (WIDTH, \
+ _MSB_POS (WIDTH, FIRST), \
+ _MSB_POS (WIDTH, LAST))
-#define MSMASK16(NR_BITS) _MSMASKn (16, (NR_BITS))
-#define MSMASK32(NR_BITS) _MSMASKn (32, (NR_BITS))
-#define MSMASK64(NR_BITS) _MSMASKn (64, (NR_BITS))
+#define MSMASK8(FIRST, LAST) _MSMASKn ( 8, (FIRST), (LAST))
+#define MSMASK16(FIRST, LAST) _MSMASKn (16, (FIRST), (LAST))
+#define MSMASK32(FIRST, LAST) _MSMASKn (32, (FIRST), (LAST))
+#define MSMASK64(FIRST, LAST) _MSMASKn (64, (FIRST), (LAST))
-#if (WITH_TARGET_WORD_BITSIZE == 64)
-#define MSMASK(NR_BITS) (NR_BITS < 1 \
- ? 0 \
- : _MASKn (64, \
- _MSB_POS (64, 0), \
- _MSB_POS (64, \
- ((NR_BITS) < 1 ? 0 \
- : (NR_BITS) - 1))))
-#endif
-#if (WITH_TARGET_WORD_BITSIZE == 32)
-#define MSMASK(NR_BITS) (NR_BITS <= 32 \
- ? 0 \
- : _MASKn (32, \
- _MSB_POS (32, 0), \
- _MSB_POS (32, \
- ((NR_BITS) <= 32 ? 0 \
- : (NR_BITS) - 33))))
-#endif
-#if !defined (MSMASK)
-#error "MSMASK never defined"
-#endif
+#define MSMASK(FIRST, LAST) (MASK (_MSB_POS (64, FIRST), _MSB_POS (64, LAST)))
-/* mask the required bits, leaving them in place */
-INLINE_SIM_BITS(unsigned16) MASKED16 (unsigned16 word, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned32) MASKED32 (unsigned32 word, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned64) MASKED64 (unsigned64 word, unsigned start, unsigned stop);
-
-INLINE_SIM_BITS(unsigned_word) MASKED (unsigned_word word, unsigned start, unsigned stop);
+#if (WITH_TARGET_WORD_MSB == 0)
+#define MASK8 MSMASK8
+#define MASK16 MSMASK16
+#define MASK32 MSMASK32
+#define MASK64 MSMASK64
+#else
+#define MASK8 LSMASK8
+#define MASK16 LSMASK16
+#define MASK32 LSMASK32
+#define MASK64 LSMASK64
+#endif
-/* Ditto but nr of ls-bits specified */
-INLINE_SIM_BITS(unsigned16) LSMASKED16 (unsigned16 word, unsigned nr_bits);
-INLINE_SIM_BITS(unsigned32) LSMASKED32 (unsigned32 word, unsigned nr_bits);
-INLINE_SIM_BITS(unsigned64) LSMASKED64 (unsigned64 word, unsigned nr_bits);
+/* mask the required bits, leaving them in place */
-INLINE_SIM_BITS(unsigned_word) LSMASKED (unsigned_word word, unsigned nr_bits);
+INLINE_SIM_BITS(unsigned8) LSMASKED8 (unsigned8 word, int first, int last);
+INLINE_SIM_BITS(unsigned16) LSMASKED16 (unsigned16 word, int first, int last);
+INLINE_SIM_BITS(unsigned32) LSMASKED32 (unsigned32 word, int first, int last);
+INLINE_SIM_BITS(unsigned64) LSMASKED64 (unsigned64 word, int first, int last);
+INLINE_SIM_BITS(unsigned_word) LSMASKED (unsigned_word word, int first, int last);
-/* Ditto but nr of ms-bits specified */
+INLINE_SIM_BITS(unsigned8) MSMASKED8 (unsigned8 word, int first, int last);
+INLINE_SIM_BITS(unsigned16) MSMASKED16 (unsigned16 word, int first, int last);
+INLINE_SIM_BITS(unsigned32) MSMASKED32 (unsigned32 word, int first, int last);
+INLINE_SIM_BITS(unsigned64) MSMASKED64 (unsigned64 word, int first, int last);
-INLINE_SIM_BITS(unsigned16) MSMASKED16 (unsigned16 word, unsigned nr_bits);
-INLINE_SIM_BITS(unsigned32) MSMASKED32 (unsigned32 word, unsigned nr_bits);
-INLINE_SIM_BITS(unsigned64) MSMASKED64 (unsigned64 word, unsigned nr_bits);
+INLINE_SIM_BITS(unsigned_word) MSMASKED (unsigned_word word, int first, int last);
-INLINE_SIM_BITS(unsigned_word) MSMASKED (unsigned_word word, unsigned nr_bits);
+#if (WITH_TARGET_WORD_MSB == 0)
+#define MASKED8 MSMASKED8
+#define MASKED16 MSMASKED16
+#define MASKED32 MSMASKED32
+#define MASKED64 MSMASKED64
+#define MASKED MSMASKED
+#else
+#define MASKED8 LSMASKED8
+#define MASKED16 LSMASKED16
+#define MASKED32 LSMASKED32
+#define MASKED64 LSMASKED64
+#define MASKED LSMASKED
+#endif
/* extract the required bits aligning them with the lsb */
-INLINE_SIM_BITS(unsigned16) LSEXTRACTED16 (unsigned16 val, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned32) LSEXTRACTED32 (unsigned32 val, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned64) LSEXTRACTED64 (unsigned64 val, unsigned start, unsigned stop);
+INLINE_SIM_BITS(unsigned8) LSEXTRACTED8 (unsigned8 val, int start, int stop);
+INLINE_SIM_BITS(unsigned16) LSEXTRACTED16 (unsigned16 val, int start, int stop);
+INLINE_SIM_BITS(unsigned32) LSEXTRACTED32 (unsigned32 val, int start, int stop);
+INLINE_SIM_BITS(unsigned64) LSEXTRACTED64 (unsigned64 val, int start, int stop);
+
+INLINE_SIM_BITS(unsigned_word) LSEXTRACTED (unsigned_word val, int start, int stop);
+
+INLINE_SIM_BITS(unsigned8) MSEXTRACTED8 (unsigned8 val, int start, int stop);
+INLINE_SIM_BITS(unsigned16) MSEXTRACTED16 (unsigned16 val, int start, int stop);
+INLINE_SIM_BITS(unsigned32) MSEXTRACTED32 (unsigned32 val, int start, int stop);
+INLINE_SIM_BITS(unsigned64) MSEXTRACTED64 (unsigned64 val, int start, int stop);
-INLINE_SIM_BITS(unsigned16) MSEXTRACTED16 (unsigned16 val, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned32) MSEXTRACTED32 (unsigned32 val, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned64) MSEXTRACTED64 (unsigned64 val, unsigned start, unsigned stop);
+INLINE_SIM_BITS(unsigned_word) MSEXTRACTED (unsigned_word val, int start, int stop);
#if (WITH_TARGET_WORD_MSB == 0)
-#define EXTRACTED16 MSEXTRACTED32
+#define EXTRACTED8 MSEXTRACTED8
+#define EXTRACTED16 MSEXTRACTED16
#define EXTRACTED32 MSEXTRACTED32
-#define EXTRACTED64 MSEXTRACTED32
+#define EXTRACTED64 MSEXTRACTED64
+#define EXTRACTED MSEXTRACTED
#else
-#define EXTRACTED16 LSEXTRACTED32
+#define EXTRACTED8 LSEXTRACTED8
+#define EXTRACTED16 LSEXTRACTED16
#define EXTRACTED32 LSEXTRACTED32
-#define EXTRACTED64 LSEXTRACTED32
+#define EXTRACTED64 LSEXTRACTED64
+#define EXTRACTED LSEXTRACTED
#endif
-
-INLINE_SIM_BITS(unsigned_word) EXTRACTED (unsigned_word val, unsigned start, unsigned stop);
-
-
-
/* move a single bit around */
/* NB: the wierdness (N>O?N-O:0) is to stop a warning from GCC */
#define _SHUFFLEDn(N, WORD, OLD, NEW) \
#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);
+INLINE_SIM_BITS(unsigned32) LSINSERTED32 (unsigned32 val, int start, int stop);
+INLINE_SIM_BITS(unsigned64) LSINSERTED64 (unsigned64 val, int start, int stop);
+INLINE_SIM_BITS(unsigned_word) LSINSERTED (unsigned_word val, int start, int stop);
-INLINE_SIM_BITS(unsigned16) INSERTED16 (unsigned16 val, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned32) INSERTED32 (unsigned32 val, unsigned start, unsigned stop);
-INLINE_SIM_BITS(unsigned64) INSERTED64 (unsigned64 val, unsigned start, unsigned stop);
+INLINE_SIM_BITS(unsigned8) MSINSERTED8 (unsigned8 val, int start, int stop);
+INLINE_SIM_BITS(unsigned16) MSINSERTED16 (unsigned16 val, int start, int stop);
+INLINE_SIM_BITS(unsigned32) MSINSERTED32 (unsigned32 val, int start, int stop);
+INLINE_SIM_BITS(unsigned64) MSINSERTED64 (unsigned64 val, int start, int stop);
+INLINE_SIM_BITS(unsigned_word) MSINSERTED (unsigned_word val, int start, int stop);
-INLINE_SIM_BITS(unsigned_word) INSERTED (unsigned_word val, unsigned start, unsigned stop);
+#if (WITH_TARGET_WORD_MSB == 0)
+#define INSERTED8 MSINSERTED8
+#define INSERTED16 MSINSERTED16
+#define INSERTED32 MSINSERTED32
+#define INSERTED64 MSINSERTED64
+#define INSERTED MSINSERTED
+#else
+#define INSERTED8 LSINSERTED8
+#define INSERTED16 LSINSERTED16
+#define INSERTED32 LSINSERTED32
+#define INSERTED64 LSINSERTED64
+#define INSERTED LSINSERTED
+#endif
+/* 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 EXTEND4(X) (LSSEXT ((X), 3))
+#define EXTEND5(X) (LSSEXT ((X), 4))
+#define EXTEND8(X) ((signed_word)(signed8)(X))
+#define EXTEND11(X) (LSSEXT ((X), 10))
+#define EXTEND15(X) (LSSEXT ((X), 14))
+#define EXTEND16(X) ((signed_word)(signed16)(X))
+#define EXTEND24(X) (LSSEXT ((X), 23))
+#define EXTEND32(X) ((signed_word)(signed32)(X))
+#define EXTEND64(X) ((signed_word)(signed64)(X))
+
/* depending on MODE return a 64bit or 32bit (sign extended) value */
#if (WITH_TARGET_WORD_BITSIZE == 64)
#define EXTENDED(X) ((signed64)(signed32)(X))
intentionally omited. */
+INLINE_SIM_BITS(unsigned8) ROT8 (unsigned8 val, int shift);
INLINE_SIM_BITS(unsigned16) ROT16 (unsigned16 val, int shift);
INLINE_SIM_BITS(unsigned32) ROT32 (unsigned32 val, int shift);
INLINE_SIM_BITS(unsigned64) ROT64 (unsigned64 val, int shift);
-INLINE_SIM_BITS(unsigned16) ROTL16 (unsigned16 val, unsigned shift);
-INLINE_SIM_BITS(unsigned32) ROTL32 (unsigned32 val, unsigned shift);
-INLINE_SIM_BITS(unsigned64) ROTL64 (unsigned64 val, unsigned shift);
+INLINE_SIM_BITS(unsigned8) ROTL8 (unsigned8 val, int shift);
+INLINE_SIM_BITS(unsigned16) ROTL16 (unsigned16 val, int shift);
+INLINE_SIM_BITS(unsigned32) ROTL32 (unsigned32 val, int shift);
+INLINE_SIM_BITS(unsigned64) ROTL64 (unsigned64 val, int shift);
-INLINE_SIM_BITS(unsigned16) ROTR16 (unsigned16 val, unsigned shift);
-INLINE_SIM_BITS(unsigned32) ROTR32 (unsigned32 val, unsigned shift);
-INLINE_SIM_BITS(unsigned64) ROTR64 (unsigned64 val, unsigned shift);
+INLINE_SIM_BITS(unsigned8) ROTR8 (unsigned8 val, int shift);
+INLINE_SIM_BITS(unsigned16) ROTR16 (unsigned16 val, int shift);
+INLINE_SIM_BITS(unsigned32) ROTR32 (unsigned32 val, int shift);
+INLINE_SIM_BITS(unsigned64) ROTR64 (unsigned64 val, int shift);
/* Sign extension operations */
-INLINE_SIM_BITS(unsigned16) SEXT16 (signed16 val, unsigned sign_bit);
-INLINE_SIM_BITS(unsigned32) SEXT32 (signed32 val, unsigned sign_bit);
-INLINE_SIM_BITS(unsigned64) SEXT64 (signed64 val, unsigned sign_bit);
+INLINE_SIM_BITS(unsigned8) LSSEXT8 (signed8 val, int sign_bit);
+INLINE_SIM_BITS(unsigned16) LSSEXT16 (signed16 val, int sign_bit);
+INLINE_SIM_BITS(unsigned32) LSSEXT32 (signed32 val, int sign_bit);
+INLINE_SIM_BITS(unsigned64) LSSEXT64 (signed64 val, int sign_bit);
+INLINE_SIM_BITS(unsigned_word) LSSEXT (signed_word val, int sign_bit);
+
+INLINE_SIM_BITS(unsigned8) MSSEXT8 (signed8 val, int sign_bit);
+INLINE_SIM_BITS(unsigned16) MSSEXT16 (signed16 val, int sign_bit);
+INLINE_SIM_BITS(unsigned32) MSSEXT32 (signed32 val, int sign_bit);
+INLINE_SIM_BITS(unsigned64) MSSEXT64 (signed64 val, int sign_bit);
+INLINE_SIM_BITS(unsigned_word) MSSEXT (signed_word val, int sign_bit);
-INLINE_SIM_BITS(unsigned_word) SEXT (signed_word val, unsigned sign_bit);
+#if (WITH_TARGET_WORD_MSB == 0)
+#define SEXT8 MSSEXT8
+#define SEXT16 MSSEXT16
+#define SEXT32 MSSEXT32
+#define SEXT64 MSSEXT64
+#define SEXT MSSEXT
+#else
+#define SEXT8 LSSEXT8
+#define SEXT16 LSSEXT16
+#define SEXT32 LSSEXT32
+#define SEXT64 LSSEXT64
+#define SEXT LSSEXT
+#endif
-#if ((SIM_BITS_INLINE & INCLUDE_MODULE) && (SIM_BITS_INLINE & INCLUDED_BY_MODULE))
+#if H_REVEALS_MODULE_P (SIM_BITS_INLINE)
#include "sim-bits.c"
#endif