replace BITSWAP8/16/24/32 macros with constexpr function that works for any number of bits

This commit is contained in:
Vas Crabb 2016-08-16 17:07:46 +10:00
parent af6b18bd68
commit 8aebdfc06d
6 changed files with 19 additions and 36 deletions

View File

@ -19,7 +19,6 @@
#define CLOCK_MULTIPLIER 1
#define BIT(x,n) (((x)>>(n))&1)
#define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1))
#define CLR_BITS(x,m,n) ((x) & ~((((UINT32)1 << ((m) - (n) + 1)) - 1) << n))

View File

@ -284,7 +284,6 @@ void s3c44b0_device::device_reset()
#define CLOCK_MULTIPLIER 1
#define BIT(x,n) (((x)>>(n))&1)
#define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1))
#define CLR_BITS(x,m,n) ((x) & ~((((UINT32)1 << ((m) - (n) + 1)) - 1) << n))

View File

@ -26,7 +26,6 @@ static inline void ATTR_PRINTF(3,4) verboselog( device_t &device, int n_level, c
}
}
#define BIT(x,n) (((x)>>(n))&1)
#define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1))
#define GF4500_FRAMEBUF_OFFSET 0x20000

View File

@ -7,10 +7,10 @@
General core utilities and macros used throughout the emulator.
***************************************************************************/
#pragma once
#ifndef MAME_EMU_EMUCORE_H
#define MAME_EMU_EMUCORE_H
#ifndef __EMUCORE_H__
#define __EMUCORE_H__
#pragma once
// standard C includes
#include <assert.h>
@ -240,36 +240,24 @@ inline TYPE operator--(TYPE &value, int) { TYPE const old(value); --value; retur
#define ENDIAN_VALUE_NE_NNE(endian,neval,nneval) (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval))
// useful macros to deal with bit shuffling encryptions
#define BIT(x,n) (((x)>>(n))&1)
// useful functions to deal with bit shuffling encryptions
#define BIT(x, n) (((x) >> (n)) & 1)
#define BITSWAP8(val,B7,B6,B5,B4,B3,B2,B1,B0) \
((BIT(val,B7) << 7) | (BIT(val,B6) << 6) | (BIT(val,B5) << 5) | (BIT(val,B4) << 4) | \
(BIT(val,B3) << 3) | (BIT(val,B2) << 2) | (BIT(val,B1) << 1) | (BIT(val,B0) << 0))
template <typename T, typename U> constexpr T bitswap(T val, U b)
{
return BIT(val, b) << 0U;
}
#define BITSWAP16(val,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \
((BIT(val,B15) << 15) | (BIT(val,B14) << 14) | (BIT(val,B13) << 13) | (BIT(val,B12) << 12) | \
(BIT(val,B11) << 11) | (BIT(val,B10) << 10) | (BIT(val, B9) << 9) | (BIT(val, B8) << 8) | \
(BIT(val, B7) << 7) | (BIT(val, B6) << 6) | (BIT(val, B5) << 5) | (BIT(val, B4) << 4) | \
(BIT(val, B3) << 3) | (BIT(val, B2) << 2) | (BIT(val, B1) << 1) | (BIT(val, B0) << 0))
template <typename T, typename U, typename... V> constexpr T bitswap(T val, U b, V... c)
{
return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...);
}
#define BITSWAP24(val,B23,B22,B21,B20,B19,B18,B17,B16,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \
((BIT(val,B23) << 23) | (BIT(val,B22) << 22) | (BIT(val,B21) << 21) | (BIT(val,B20) << 20) | \
(BIT(val,B19) << 19) | (BIT(val,B18) << 18) | (BIT(val,B17) << 17) | (BIT(val,B16) << 16) | \
(BIT(val,B15) << 15) | (BIT(val,B14) << 14) | (BIT(val,B13) << 13) | (BIT(val,B12) << 12) | \
(BIT(val,B11) << 11) | (BIT(val,B10) << 10) | (BIT(val, B9) << 9) | (BIT(val, B8) << 8) | \
(BIT(val, B7) << 7) | (BIT(val, B6) << 6) | (BIT(val, B5) << 5) | (BIT(val, B4) << 4) | \
(BIT(val, B3) << 3) | (BIT(val, B2) << 2) | (BIT(val, B1) << 1) | (BIT(val, B0) << 0))
#define BITSWAP32(val,B31,B30,B29,B28,B27,B26,B25,B24,B23,B22,B21,B20,B19,B18,B17,B16,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \
((BIT(val,B31) << 31) | (BIT(val,B30) << 30) | (BIT(val,B29) << 29) | (BIT(val,B28) << 28) | \
(BIT(val,B27) << 27) | (BIT(val,B26) << 26) | (BIT(val,B25) << 25) | (BIT(val,B24) << 24) | \
(BIT(val,B23) << 23) | (BIT(val,B22) << 22) | (BIT(val,B21) << 21) | (BIT(val,B20) << 20) | \
(BIT(val,B19) << 19) | (BIT(val,B18) << 18) | (BIT(val,B17) << 17) | (BIT(val,B16) << 16) | \
(BIT(val,B15) << 15) | (BIT(val,B14) << 14) | (BIT(val,B13) << 13) | (BIT(val,B12) << 12) | \
(BIT(val,B11) << 11) | (BIT(val,B10) << 10) | (BIT(val, B9) << 9) | (BIT(val, B8) << 8) | \
(BIT(val, B7) << 7) | (BIT(val, B6) << 6) | (BIT(val, B5) << 5) | (BIT(val, B4) << 4) | \
(BIT(val, B3) << 3) | (BIT(val, B2) << 2) | (BIT(val, B1) << 1) | (BIT(val, B0) << 0))
// legacy names for backwards compatibility
template <typename T, typename... U> constexpr T BITSWAP8(T val, U... b) { return bitswap(val, b...); }
template <typename T, typename... U> constexpr T BITSWAP16(T val, U... b) { return bitswap(val, b...); }
template <typename T, typename... U> constexpr T BITSWAP24(T val, U... b) { return bitswap(val, b...); }
template <typename T, typename... U> constexpr T BITSWAP32(T val, U... b) { return bitswap(val, b...); }
@ -426,4 +414,4 @@ inline UINT64 d2u(double d)
return u.vv;
}
#endif /* __EMUCORE_H__ */
#endif /* MAME_EMU_EMUCORE_H */

View File

@ -39,7 +39,6 @@ SYSINTR_GPS = INT_EINT3, INT_EINT8_23 (EINT18)
#define VERBOSE_LEVEL ( 0 )
#define BIT(x,n) (((x)>>(n))&1)
#define BITS(x,m,n) (((x)>>(n))&(((UINT32)1<<((m)-(n)+1))-1))
class gizmondo_state : public driver_device

View File

@ -43,7 +43,6 @@ static inline void ATTR_PRINTF(3,4) verboselog(device_t &device, int n_level, co
#define MPLLCON 1
#define UPLLCON 2
#define BIT(x,n) (((x)>>(n))&1)
#define BITS(x,m,n) (((x)>>(n))&((1<<((m)-(n)+1))-1))