#include "sim-xcat.h"
-#ifdef __STDC__
+#if defined(__STDC__) && defined(signed)
/* If signed were defined to be say __signed (ie, some versions of Linux),
then the signedN macro would not work correctly. If we have a standard
compiler, we have signed. */
/* NOTE: See end of file for #undef */
#define unsignedN XCONCAT2(unsigned,N)
#define signedN XCONCAT2(signed,N)
-#define MASKEDn XCONCAT2(MASKED,N)
#define MASKn XCONCAT2(MASK,N)
#define LSMASKEDn XCONCAT2(LSMASKED,N)
#define LSMASKn XCONCAT2(LSMASK,N)
#define MSMASKEDn XCONCAT2(MSMASKED,N)
#define MSMASKn XCONCAT2(MSMASK,N)
-#define EXTRACTEDn XCONCAT2(EXTRACTED,N)
+#define LSEXTRACTEDn XCONCAT2(LSEXTRACTED,N)
+#define MSEXTRACTEDn XCONCAT2(MSEXTRACTED,N)
#define INSERTEDn XCONCAT2(INSERTED,N)
#define ROTn XCONCAT2(ROT,N)
#define ROTLn XCONCAT2(ROTL,N)
#define ROTRn XCONCAT2(ROTR,N)
#define SEXTn XCONCAT2(SEXT,N)
+/* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
INLINE_SIM_BITS\
(unsignedN)
-MASKEDn (unsignedN word,
- unsigned start,
- unsigned stop)
+LSMASKEDn (unsignedN word,
+ int start,
+ int stop)
{
- return (word & MASKn (start, stop));
+ word &= LSMASKn (start, stop);
+ return word;
}
+/* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
INLINE_SIM_BITS\
(unsignedN)
-LSMASKEDn (unsignedN word,
- unsigned nr_bits)
+MSMASKEDn (unsignedN word,
+ int start,
+ int stop)
{
- return (word & LSMASKn (nr_bits));
+ word &= MSMASKn (start, stop);
+ return word;
}
+/* TAGS: LSEXTRACTED16 LSEXTRACTED32 LSEXTRACTED64 */
INLINE_SIM_BITS\
(unsignedN)
-MSMASKEDn (unsignedN word,
- unsigned nr_bits)
+LSEXTRACTEDn (unsignedN val,
+ int start,
+ int stop)
{
- return (word & MSMASKn (nr_bits));
+ val <<= (N - 1 - start); /* drop high bits */
+ val >>= (N - 1 - start) + (stop); /* drop low bits */
+ return val;
}
+/* TAGS: MSEXTRACTED16 MSEXTRACTED32 MSEXTRACTED64 */
INLINE_SIM_BITS\
(unsignedN)
-EXTRACTEDn (unsignedN val,
- unsigned start,
- unsigned stop)
+MSEXTRACTEDn (unsignedN val,
+ int start,
+ int stop)
{
- val <<= _MSB_SHIFT (N, start);
- val >>= (_MSB_SHIFT (N, start) + _LSB_SHIFT (N, stop));
+ val <<= (start); /* drop high bits */
+ val >>= (start) + (N - 1 - stop); /* drop low bits */
return val;
}
+/* TAGS: INSERTED16 INSERTED32 INSERTED64 */
INLINE_SIM_BITS\
(unsignedN)
INSERTEDn (unsignedN val,
- unsigned start,
- unsigned stop)
+ int start,
+ int stop)
{
- val &= LSMASKn (_MAKE_WIDTH (start, stop));
val <<= _LSB_SHIFT (N, stop);
+ val &= MASKn (start, stop);
return val;
}
+/* TAGS: ROT16 ROT32 ROT64 */
INLINE_SIM_BITS\
(unsignedN)
return val;
}
+/* TAGS: ROTL16 ROTL32 ROTL64 */
INLINE_SIM_BITS\
(unsignedN)
ROTLn (unsignedN val,
- unsigned shift)
+ int shift)
{
unsignedN result;
ASSERT (shift <= N);
return result;
}
+/* TAGS: ROTR16 ROTR32 ROTR64 */
INLINE_SIM_BITS\
(unsignedN)
ROTRn (unsignedN val,
- unsigned shift)
+ int shift)
{
unsignedN result;
ASSERT (shift <= N);
return result;
}
+/* TAGS: SEXT16 SEXT32 SEXT64 */
INLINE_SIM_BITS\
(unsignedN)
SEXTn (signedN val,
- unsigned sign_bit)
+ int sign_bit)
{
/* make the sign-bit most significant and then smear it back into
position */
#undef ROTRn
#undef ROTn
#undef INSERTEDn
-#undef EXTRACTEDn
+#undef LSEXTRACTEDn
+#undef MSEXTRACTEDn
#undef LSMASKEDn
#undef LSMASKn
#undef MSMASKEDn