#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*(FIRST, LAST): Like MASK - LS bit is zero.
IEA_MASKED(SHOULD_MASK, ADDR): Convert the address to the targets
natural size. If in 32bit mode, discard the high 32bits.
- EXTENDED*(VALUE): Convert the `*' bit value to the targets natural
- word size. Sign extned the value if needed.
+ 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.
#define _MSB_32(START, STOP) (START <= STOP \
? (START < 32 ? 0 : START - 32) \
: (STOP < 32 ? 0 : STOP - 32))
+#define _MSB_16(START, STOP) (START <= STOP \
+ ? (START < 48 ? 0 : START - 48) \
+ : (STOP < 48 ? 0 : STOP - 48))
#else
#define _MSB_32(START, STOP) (START >= STOP \
? (START >= 32 ? 31 : START) \
: (STOP >= 32 ? 31 : STOP))
+#define _MSB_16(START, STOP) (START >= STOP \
+ ? (START >= 16 ? 15 : START) \
+ : (STOP >= 16 ? 15 : STOP))
#endif
#if (WITH_TARGET_WORD_MSB == 0)
#define _LSB_32(START, STOP) (START <= STOP \
? (STOP < 32 ? 0 : STOP - 32) \
: (START < 32 ? 0 : START - 32))
+#define _LSB_16(START, STOP) (START <= STOP \
+ ? (STOP < 48 ? 0 : STOP - 48) \
+ : (START < 48 ? 0 : START - 48))
#else
#define _LSB_32(START, STOP) (START >= STOP \
? (STOP >= 32 ? 31 : STOP) \
: (START >= 32 ? 31 : START))
+#define _LSB_16(START, STOP) (START >= STOP \
+ ? (STOP >= 16 ? 15 : STOP) \
+ : (START >= 16 ? 15 : START))
#endif
#if (WITH_TARGET_WORD_MSB == 0)
#if (WITH_TARGET_WORD_BITSIZE == 64)
#define LSBIT(POS) LSBIT64 (POS)
-#else
+#endif
+#if (WITH_TARGET_WORD_BITSIZE == 32)
#define LSBIT(POS) ((unsigned32)((POS) >= 32 \
? 0 \
: (1 << ((POS) >= 32 ? 0 : (POS)))))
#endif
+#if (WITH_TARGET_WORD_BITSIZE == 16)
+#define LSBIT(POS) ((unsigned16)((POS) >= 16 \
+ ? 0 \
+ : (1 << ((POS) >= 16 ? 0 : (POS)))))
+#endif
#define MSBIT8(POS) ((unsigned8) 1 << ( 8 - 1 - (POS)))
#if (WITH_TARGET_WORD_BITSIZE == 64)
#define MSBIT(POS) MSBIT64 (POS)
-#else
+#endif
+#if (WITH_TARGET_WORD_BITSIZE == 32)
#define MSBIT(POS) ((unsigned32)((POS) < 32 \
? 0 \
: (1 << ((POS) < 32 ? 0 : (64 - 1) - (POS)))))
#endif
+#if (WITH_TARGET_WORD_BITSIZE == 16)
+#define MSBIT(POS) ((unsigned16)((POS) < 48 \
+ ? 0 \
+ : (1 << ((POS) < 48 ? 0 : (64 - 1) - (POS)))))
+#endif
/* Bit operations */
_MSB_POS (32, 0), \
_MSB_32 ((START), (STOP))))))
#endif
+#if (WITH_TARGET_WORD_BITSIZE == 16)
+#define MASK(START, STOP) \
+ (_POS_LE ((START), (STOP)) \
+ ? (_POS_LE ((STOP), _MSB_POS (64, 15)) \
+ ? 0 \
+ : _MASKn (16, \
+ _MSB_16 ((START), (STOP)), \
+ _LSB_16 ((START), (STOP)))) \
+ : (_MASKn (16, \
+ _LSB_16 ((START), (STOP)), \
+ _LSB_POS (16, 0)) \
+ | (_POS_LE ((STOP), _MSB_POS (64, 15)) \
+ ? 0 \
+ : _MASKn (16, \
+ _MSB_POS (16, 0), \
+ _MSB_16 ((START), (STOP))))))
+#endif
#if !defined (MASK)
#error "MASK never undefined"
#endif
/* 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))
#if (WITH_TARGET_WORD_BITSIZE == 32)
#define EXTENDED(X) (X)
#endif
+#if (WITH_TARGET_WORD_BITSIZE == 16)
+#define EXTENDED(X) (X)
+#endif
/* memory alignment macro's */
-#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